{"id":20310152,"url":"https://github.com/phpro/api-problem-bundle","last_synced_at":"2025-10-24T04:43:48.549Z","repository":{"id":32933262,"uuid":"139486819","full_name":"phpro/api-problem-bundle","owner":"phpro","description":"RFC7807 Problem details integration for Symfony","archived":false,"fork":false,"pushed_at":"2025-01-30T08:10:46.000Z","size":76,"stargazers_count":24,"open_issues_count":2,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-11T01:35:06.628Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-02T19:44:52.000Z","updated_at":"2025-01-30T08:10:22.000Z","dependencies_parsed_at":"2024-11-07T11:31:26.345Z","dependency_job_id":"a172b3ad-46ee-4c87-b7a2-6a7e7fb64633","html_url":"https://github.com/phpro/api-problem-bundle","commit_stats":{"total_commits":34,"total_committers":7,"mean_commits":4.857142857142857,"dds":0.5,"last_synced_commit":"466aabf8bdf182eedd86a40ae3293248dcf797e2"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fapi-problem-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fapi-problem-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fapi-problem-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fapi-problem-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpro","download_url":"https://codeload.github.com/phpro/api-problem-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353746,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T17:30:15.524Z","updated_at":"2025-10-24T04:43:48.489Z","avatar_url":"https://github.com/phpro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Installs](https://img.shields.io/packagist/dt/phpro/api-problem-bundle.svg)](https://packagist.org/packages/phpro/api-problem-bundle/stats)\n[![Packagist](https://img.shields.io/packagist/v/phpro/api-problem-bundle.svg)](https://packagist.org/packages/phpro/api-problem-bundle)\n\n\n# Api Problem Bundle\n\nThis package provides a [RFC7807](https://tools.ietf.org/html/rfc7807) Problem details exception listener for Symfony.\nInternal, this package uses the models provided by [`phpro/api-problem`](https://www.github.com/phpro/api-problem).\nWhen an `ApiProblemException` is triggered, this bundle will return the correct response.\n\n\n## Installation\n\n```sh\ncomposer require phpro/api-problem-bundle\n```\n\nIf you are not using `symfony/flex`, you'll have to manually add the bundle to your bundles file:\n\n```php\n// config/bundles.php\n\nreturn [\n    // ...\n    Phpro\\ApiProblemBundle\\ApiProblemBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Supported response formats\n\n- application/problem+json\n\n\n## How it works\n\n```php\nuse Phpro\\ApiProblem\\Exception\\ApiProblemException;\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;\n\nclass SomeController\n{\n    /**\n     * @Route('/some-route', defaults={\"_format\" = \"json\"})\n     */\n    public function someAction() {\n        throw new ApiProblemException(\n            new HttpApiProblem('400', 'It aint all bad ...')\n        );\n    }\n}\n```\n\nWhen the controller is marked as a \"json\" format, the request `Content-Type` is `*/json` or the request `Accept` header first value contains json (i.e. `application/json, text/html`), this bundle kicks in.\nIt will transform the exception to following response:\n\nHeaders:\n```\nContent-Type: application/problem+json\n```\n\nBody:\n```json\n{\n    \"status\": 400,\n    \"type\": \"http:\\/\\/www.w3.org\\/Protocols\\/rfc2616\\/rfc2616-sec10.html\",\n    \"title\": \"Bad Request\",\n    \"detail\": \"It ain't all bad ...\"\n}\n```\n\nAs an alternative, use ```ApiProblemHttpException``` instead of ```ApiProblemException```, to make it possible to\n[exclude the specific status code from the log](https://symfony.com/doc/current/logging/monolog_exclude_http_codes.html)\n\n## Adding custom exception transformations\n\nCurrently, we automatically transform exceptions from following packages to an ApiProblem instance:\n\n- phpro/api-problem\n- symfony/http-kernel\n- symfony/security\n\nBesides that, all other errors are transformed to a basic `ExceptionApiProblem` instance.\n\nIf you want to add custom transformations, you can implement the `ExceptionTransformerInterface`\n and register it in the symfony container with the `phpro.api_problem.exception_transformer` tag.\n \n```php\nuse Phpro\\ApiProblemBundle\\Transformer\\ExceptionTransformerInterface;\n\nclass MyTransformer implements ExceptionTransformerInterface\n{\n    public function transform(\\Throwable $exception): ApiProblemInterface\n    {\n        return new MyApiProblem($exception);\n    }\n\n    public function accepts(\\Throwable $exception): bool\n    {\n        return $exception instanceof MyException;\n    }\n}\n```\n\n## About\n\n### Submitting bugs and feature requests\n\nBugs and feature request are tracked on [GitHub](https://github.com/phpro/api-problem-bundle/issues).\nPlease take a look at our rules before [contributing your code](CONTRIBUTING).\n\n### License\n\napi-problem-bundle is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fapi-problem-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpro%2Fapi-problem-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fapi-problem-bundle/lists"}