定制 metawesome/laravel-request-xml 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

metawesome/laravel-request-xml

Composer 安装命令:

composer require metawesome/laravel-request-xml

包简介

The missing XML support for Laravel's Request class.

README 文档

README

The missing XML support for Laravel's Request class.

This package is designed to work with the Laravel framework.

Installation

Install via composer:

composer require Meta/request-xml

Registering the service provider

For Laravel 5.4 and lower, add the following line to your config/app.php:

/*
 * Package Service Providers...
 */
Meta\RequestXml\Providers\RequestXmlServiceProvider::class,

For Laravel 5.5 and greater, the package will auto register the provider for you.

Using Lumen

To register the service provider, add the following line to app/bootstrap/app.php:

$app->register(Meta\RequestXml\Providers\RequestXmlServiceProvider::class);

Middleware

It'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.

Please note:

Once 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.

To setup the middleware, open up your app/Http/Kernel.php file.

To add the middleware globally:

protected $middleware = [
    \Meta\RequestXml\Middleware\XmlRequest::class,
];

To add the middleware to web routes only:

protected $middlewareGroups = [
    'web' => [
        \Meta\RequestXml\Middleware\XmlRequest::class,
    ],
];

To add the middleware to api routes only:

protected $middlewareGroups = [
    'api' => [
        \Meta\RequestXml\Middleware\XmlRequest::class,
    ],
];

Or, if you want named middleware for specific routes:

protected $routeMiddleware = [
    'xml' => \Meta\RequestXml\Middleware\XmlRequest::class,
];

Quick start

Determine if the request wants an xml response

if (request()->wantsXml()) {
    // send xml response
}

Determine if the request contains xml

if (request()->isXml()) {
    // do something
}

Get the converted xml as an array

$data = request()->xml();

Methods

Request method

->wantsXml()

Works very similar to Laravel's ->wantsJson() method by returning a boolean. It will tell you if the incoming request would like to receive an XML response back.

Request method

->isXml()

Returns a boolean. This will tell you if the incoming request is XML.

Request method

->xml()

Returns an array. This converts the XML request into a PHP array. You are free to cast it to an object:

$xml = (object) request()->xml();

Or wrap it in a collection:

$xml = collect(request()->xml());

Exceptions

In 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:

if ($exception instanceof \Meta\RequestXml\Exceptions\CouldNotParseXml) {
    // do something
}

Testing

You can run the tests with:

./vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

metawesome/laravel-request-xml 适用场景与选型建议

metawesome/laravel-request-xml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「xml」 「api」 「request」 「laravel」 「isXml」 「wantsXml」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 metawesome/laravel-request-xml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 metawesome/laravel-request-xml 我们能提供哪些服务?
定制开发 / 二次开发

基于 metawesome/laravel-request-xml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 52
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-09