承接 zain/laravel-doctrine-jetpack 相关项目开发

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

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

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.

Build Status Latest Stable Version License Total Downloads

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 return your model from a controller, or inspect it in tinker. (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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-27