承接 vmporcayom/laravel-xml 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

vmporcayom/laravel-xml

Composer 安装命令:

composer require vmporcayom/laravel-xml

包简介

Laravel XML Support with Tramite label

README 文档

README

Code Quality Code Style Total Downloads Latest Stable Version License Documentation

This package comes with the much desired xml support for you Laravel project including middleware to accept only xml requests, http response in xml, and more utilities for xml conversions as well as validation.

Supports: Laravel versions v5.3 and above

Installation

$ composer require bmatovu/laravel-xml

Requests

Get the request content (body).

$request->xml();

* Returns Bmatovu\LaravelXml\Support\XMLElement object.

Determine if the request content type is XML.

$request->isXml();

Determine if the current request is accepting XML.

$request->wantsXml();

Validate XML content

Xml::is_valid($request->xml());

Validation - Against XML Schema Definition

$errors = Xml::validate($request->xml(), 'path_to/sample.xsd');

if ($errors) {
    return response()->xml(['error' => $errors], 422);
}

Responses

Expects an array, convent you're objects to arrays prior...

Route::get('/users', function () {
    $users = App\User::all();
    return response()->xml(['users' => $users->toArray()]);
});

Sample response from above snippet

<?xml version="1.0" encoding="UTF-8"?>
<document>
    <users>
        <id>1</id>
        <name>John Doe</name>
        <email>jdoe@example.com</email>
        <created_at>2018-07-12 17:06:13</created_at>
        <updated_at>2018-07-12 18:00:05</updated_at>
    </users>
    <users>
        <id>2</id>
        <name>Gary Plant</name>
        <email>gplant@example.com</email>
        <created_at>2018-07-12 18:02:26</created_at>
        <updated_at>2018-07-13 11:22:44</updated_at>
    </users>
</document>

And will automatically set the content type to xml

Content-Type → text/xml; charset=UTF-8

Middleware

First register the middleware in app\Http\Kernel.php

protected $routeMiddleware = [
    // ...
    'xml' => \Bmatovu\LaravelXml\Http\Middleware\RequireXml::class,
];

Then use the middleware on your routes, or in the controllers.

Route::post('/user/store', function (Request, $request) {
    // do something...
})->middleware('xml');

In case of the request content-type is not xml, the response will be;

[415 - Unsupported Media Type]

<?xml version="1.0" encoding="UTF-8"?>
<document>
    <error>Only accepting xml content</error>
</document>

Utilities

Encode: Array to Xml

Xml::encode(['key' => 'value']);

Or

xml_encode(['key' => 'value']);

Decode: Xml to Array

Xml::decode('<?xml version="1.0" encoding="UTF-8"?><document><key>value</key></document>');

Or

xml_decode('<?xml version="1.0" encoding="UTF-8"?><document><key>value</key></document>');

Credits

Under the hood, I'm using;

Spatie's array to XML convernsion

Hakre's XML to JSON conversion

Akande's XML validation

Reporting bugs

If you've stumbled across a bug, please help us by leaving as much information about the bug as possible, e.g.

  • Steps to reproduce
  • Expected result
  • Actual result

This will help us to fix the bug as quickly as possible, and if you do wish to fix it yourself; feel free to fork the package on GitHub and submit a pull request!

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-11-30