globalxtreme/parser
最新稳定版本:2.0.0
Composer 安装命令:
composer require globalxtreme/parser
包简介
GlobalXtreme Parser Pattern
README 文档
README
Install with composer
To install with Composer, simply require the latest version of this package.
composer require globalxtreme/parser
You can install parser class with command.
php artisan make:gx-parser {{ class }}
Using
- Install parser class.
php artisan make:gx-parser Custom\CustomParser - You can add custom function in your parser
use GlobalXtreme\Parser\BaseParser; class CustomParser extends BaseParser { use HasParser; public function tests($collections) { if (!$collections || count($collections) == 0) { return null; } $data = []; foreach ($collections as $collection) { $data[] = $collection->toArray(); } return $data; } }
- Register your parser to model.
use App\Packages\Parser\Custom\CustomParser; use GlobalXtreme\Parser\Trait\HasParser; class Custom extends Model { use HasParser; public $parserClass = CustomParser::class; }
- Using parser with controller.
use App\Http\Controllers\Controller; use App\Models\Custom; use App\Packages\Parser\Custom\CustomParser; use GlobalXtreme\Parser\Parser; class CustomController extends Controller { public function testing() { // Get more than one data $customs = Custom::get(); // Display data using CustomParser and your custom function $results = CustomParser::get($customs); $results = CustomParser::tests($customs); // Display data using parser class from package // with default function or custom function from CustomParser $results = Parser::get($customs); $results = Parser::tests($customs); // Get one data $custom = Custom::first(); // Display data using custom parser $result = CustomParser::first($custom); // Display data using parser class from package $result = Parser::first($custom); } }
统计信息
- 总下载量: 195
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-22