zain/laravel-doctrine-jetpack
Composer 安装命令:
composer require zain/laravel-doctrine-jetpack
包简介
Helpful generators for Doctrine in Laravel
README 文档
README
A set of productivity boosting helpers to make life with Laravel Doctrine simpler and faster.
Installation
This package strictly requires php >= 7.4.
Require the package using Composer.
composer require szainmehdi/laravel-doctrine-jetpack
Laravel automatically discovers the package. No additional steps are necessary.
Usage
Generators
This package includes a few generators that allow you to speed up your workflow when it comes to writing entities and mapping classes using Laravel Doctrine.
Entity Generator
Generate a new Doctrine entity using the included stub by running the following artisan command:
php artisan make:entity MyEntity
By default, this will create a new file in app/Entities called MyEntity.php, like so:
<?php declare(strict_types=1); namespace App\Entities; use Illuminate\Contracts\Support\{Arrayable, Jsonable}; use JsonSerializable; use Ramsey\Uuid\{Uuid, UuidInterface}; use Zain\LaravelDoctrine\Jetpack\Serializer\SerializesAttributes; class MyEntity implements Arrayable, Jsonable, JsonSerializable { use SerializesAttributes; protected UuidInterface $id; public function __construct() { $this->id = Uuid::uuid1(); } public function getId(): string { return $this->id->toString(); } }
Fluent Mapping Generator
This package comes with a generator for Laravel Doctrine's Fluent mapping driver, a very Laravel-like way of writing your Doctrine mappings.
The included command takes a target entity as an argument and generates a mapping file.
php artisan make:mapping MyEntity
By default, this will create a new file in app/Database/Doctrine/Mappings/ called MyEntityMapping.php, like so:
<?php declare(strict_types=1); namespace App\Database\Doctrine\Mappings; use App\Entities\MyEntity; use LaravelDoctrine\Fluent\EntityMapping; use LaravelDoctrine\Fluent\Fluent; class MyEntityMapping extends EntityMapping { public function mapFor() { return MyEntity::class; } public function map(Fluent $map) { $map->uuidPrimaryKey(); // ... $map->timestamps(); } }
Generate a Fluent Mapping class for a Value Object (Embeddable).
php artisan make:mapping MyValue --value
By default, this will create a new file in app/Database/Doctrine/Mappings/Values/ called MyValueMapping.php.
FlushEntityManager Middleware
Simplify the process of actually persisting your entities to the database using the included middleware.
Add the middleware to your app/Http/Kernel.php file like so:
class Kernel extends HttpKernel { // ... protected $middleware = [ // ... \Zain\LaravelDoctrine\Jetpack\Middleware\FlushEntityManager::class, ]; }
Helpers
Entity Serialization
This package also includes a helper trait that allows you to make your entities (and potentially any other class) serializable to JSON or an array with just a single line.
use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Jsonable; use JsonSerializable; use Zain\LaravelDoctrine\Jetpack\Serializer\SerializesAttributes; class MyEntity implements Arrayable, Jsonable, JsonSerializable { // Add this trait to your entities use SerializesAttributes; }
Note: for the best experience with Laravel, I recommend having your Entity classes implement the three standard interfaces in the example above. This is not necessary but it will allow you to simply
returnyour model from a controller, or inspect it intinker. (I am not recommending doing the former, but it is definitely useful for debugging in a pinch.)
Customization & Configuration
This package allows you to easily customize almost every aspect of the generators. Get started by publishing the config file.
php artisan vendor:publish --tag jetpack-config
This will create a file in your config directory called jetpack.php. Edit this file to change the default
namespace for your Entities, Value Objects, and Mapping classes.
For advanced customization, this package allow you to customize the built-in stub files to your own needs.
First, ensure you've already published the config file in the step above. Next, publish the stubs using the following command.
php artisan vendor:publish --tag jetpack-stubs
This will write the stub files to resources/jetpack/stubs. Feel free to edit the files as you please, but keep the
placeholder names intact.
Finally, update config/jetpack.php:
return [ 'generators' => [ 'stubs_directory' => resource_path('jetpack/stubs/'), // ... ], // ... ];
Development
All contributions are welcome. Found a bug? Open an issue in Github, or even better, submit a Pull Request.
Running Tests
Check out the project locally, and run:
composer install composer test # or, using docker docker-compose run --rm php composer test
zain/laravel-doctrine-jetpack 适用场景与选型建议
zain/laravel-doctrine-jetpack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.25k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「fluent」 「doctrine」 「mapping」 「laravel」 「entity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zain/laravel-doctrine-jetpack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zain/laravel-doctrine-jetpack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zain/laravel-doctrine-jetpack 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Presentation and Formatting helper with nice fluent interface.
Traits gathering fluent syntax common methods
A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.
A fluent PHP CURL wrapper
Make pimcore migration simple
统计信息
- 总下载量: 2.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-27