{"id":22917425,"url":"https://github.com/mtownsend5512/request-xml","last_synced_at":"2025-04-04T13:10:53.728Z","repository":{"id":33159743,"uuid":"153556762","full_name":"mtownsend5512/request-xml","owner":"mtownsend5512","description":"The missing XML support for Laravel's Request class.","archived":false,"fork":false,"pushed_at":"2025-02-21T15:04:08.000Z","size":30,"stargazers_count":42,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T12:07:45.460Z","etag":null,"topics":["isxml","laravel","laravel-package","middleware","request","validation","wantsxml","xml"],"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/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-10-18T03:14:09.000Z","updated_at":"2025-02-21T15:03:46.000Z","dependencies_parsed_at":"2024-06-18T22:43:19.784Z","dependency_job_id":"c231c0e7-9ccb-4006-b7a5-dd388b1a7be4","html_url":"https://github.com/mtownsend5512/request-xml","commit_stats":{"total_commits":31,"total_committers":7,"mean_commits":4.428571428571429,"dds":"0.29032258064516125","last_synced_commit":"1387d353a5769ca99edc4991edcaf8dba5f7d060"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Frequest-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Frequest-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Frequest-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Frequest-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/request-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182365,"owners_count":20897380,"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":["isxml","laravel","laravel-package","middleware","request","validation","wantsxml","xml"],"created_at":"2024-12-14T06:17:54.746Z","updated_at":"2025-04-04T13:10:53.711Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"The missing XML support for Laravel's Request class.\n\nThis package is designed to work with the [Laravel](https://laravel.com) framework.\n\n## Installation\n\nInstall via composer:\n\n```\ncomposer require mtownsend/request-xml\n```\n\n### Registering the service provider\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\RequestXml\\Providers\\RequestXmlServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\RequestXml\\Providers\\RequestXmlServiceProvider::class);\n```\n\n### Middleware\n\nIt's important to register the middleware so your application can convert an XML request and merge it into the Request object. You will then be able to run XML through Laravel's powerful validation system.\n\n**Please note:**\n\nOnce you register the middleware, you do not need to do anything special to access your request xml. It will be available in the Request object like it would if it was a json or form request.\n\nTo setup the middleware, open up your ``app/Http/Kernel.php`` file.\n\nTo add the middleware globally:\n\n```php\nprotected $middleware = [\n    \\Mtownsend\\RequestXml\\Middleware\\XmlRequest::class,\n];\n```\n\nTo add the middleware to web routes only:\n\n```php\nprotected $middlewareGroups = [\n    'web' =\u003e [\n        \\Mtownsend\\RequestXml\\Middleware\\XmlRequest::class,\n    ],\n];\n```\n\nTo add the middleware to api routes only:\n\n```php\nprotected $middlewareGroups = [\n    'api' =\u003e [\n        \\Mtownsend\\RequestXml\\Middleware\\XmlRequest::class,\n    ],\n];\n```\n\nOr, if you want named middleware for specific routes:\n\n```php\nprotected $routeMiddleware = [\n    'xml' =\u003e \\Mtownsend\\RequestXml\\Middleware\\XmlRequest::class,\n];\n```\n\n## Quick start\n\n### Determine if the request wants an xml response\n\n```php\nif (request()-\u003ewantsXml()) {\n    // send xml response\n}\n```\n\n### Determine if the request contains xml\n\n```php\nif (request()-\u003eisXml()) {\n    // do something\n}\n```\n\n### Get the converted xml as an array\n\n```php\n$data = request()-\u003exml();\n```\n\n## Methods\n\n**Request method**\n\n``-\u003ewantsXml()``\n\nWorks very similar to Laravel's ``-\u003ewantsJson()`` method by returning a boolean. It will tell you if the incoming request would like to receive an XML response back.\n\n**Request method**\n\n``-\u003eisXml()``\n\nReturns a boolean. This will tell you if the incoming request is XML.\n\n**Request method**\n\n``-\u003exml()``\n\nReturns an array. This converts the XML request into a PHP array. You are free to cast it to an object:\n\n```php\n$xml = (object) request()-\u003exml();\n```\n\nOr wrap it in a collection:\n\n```php\n$xml = collect(request()-\u003exml());\n```\n\n## Exceptions\n\nIn the event invalid XML is received in a request, the application will throw an Exception containing the raw, invalid XML. If you would like to handle this exception whenever it occurs in your application, you can easily catch it and supply your own code in your applications ``app/Exceptions/Handler.php`` like so:\n\n```php\nif ($exception instanceof \\Mtownsend\\RequestXml\\Exceptions\\CouldNotParseXml) {\n    // do something\n}\n```\n\n## Purpose\n\nHave you ever wondered why Laravel offered useful methods for transforming data into JSON but completely forgot about XML? This package aims to add the missing XML functionality to Laravel's Request class. Your Laravel application may now detect and auto-merge incoming XML requests into the Request object. You can run an XML request through Laravel's built in validation system - it just works! XML's days of being a second class citizen in your Laravel app have come to an end.\n\n## Other packages you may be interested in\n\n- [mtownsend/collection-xml](https://github.com/mtownsend5512/collection-xml)\n- [mtownsend/response-xml](https://github.com/mtownsend5512/response-xml)\n- [mtownsend/xml-to-array](https://github.com/mtownsend5512/xml-to-array)\n\n## Credits\n\n- Mark Townsend\n- [All Contributors](../../contributors)\n\n## Testing\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Frequest-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Frequest-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Frequest-xml/lists"}