hamzaouaghad/multilayering

一个用于加速多层级约定工作流程的Laravel小包

0.1.1 2015-08-12 14:32 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:05:20 UTC


README

Software License

这个包是一个小巧的Laravel包,可以生成 artisan 命令,以更快的速度生成多层级约定,并加快工作流程。

如果你不知道什么是多层级,可以快速阅读一下coderwall

安装

通过Composer

$ composer require hamzaouaghad/multilayering

用法

确保你在 Config\app.php 中添加以下行

 'providers' => [

 Hamzaouaghad\Multilayering\MultilayerGeneratorServiceProvider::class,
 Hamzaouaghad\Multilayering\RegisterCommandsServiceProvider::class,

 ],

保存并运行

 $ composer dumpautoload -o
 $ php artisan vendor:publish

现在前往你的 'app/providers/' 目录,你会看到一个新添加的提供者

MultilayerGeneratorServiceProvider

如果你是第一次,并且还需要生成新的文件夹结构,请运行

php artisan make:multilayer

然后,再次,将以下内容添加到你的提供者中

App\Providers\MultilayerGeneratorServiceProvider`.

再次,

$ composer dumpautoload -o
$ php artisan vendor:publish

我可以很容易地自动化添加所有这些服务提供者并为你调用它们的过程,然而,这永远不是最好的方法,如果不是一种坏习惯,因为手动添加它们——与自动注册不同——实际上会跟踪你使用的所有服务提供者,在你的提供者数组中。

所以,忍受一下保持工作有序的痛苦,这是值得的。

如果你想快速复制并粘贴所有内容,可以使用以下命令

php artisan bake:all ClassName

这个命令将生成一个 eloquent 类,为其生成接口和一个使用该接口的存储库。同时,在 http 层,为它生成一个注入该存储库的引擎。

如果你想使用特定选项生成所有内容,可以使用以下选项

--interface : The name of the interface to be created for our calss
--motor : the name of the motor to be created for our class
--trait : the name of the trait that your motor maye use
--repository : the name of the repository that this class would be covered under.

在生成每个文件之后,你需要运行

$ php artisan vendor:publish

就像它每次都会提到的那样,所以我想你不会忘记。

##示例

php artisan bake:all User --repository=Accounts --interface=Security --motor=STAFF --trait=Authentication

这将创建

class User extends Eloquent

interface SecurityInterface

class AccountsRepository implements SecurityInterface

class STAFFmotor extends Motor
{
 public function __construct(AccountsRepository $repo)
 {
    $this->repository = $repo;
 }

 use /Authentication;
}

在此之后,Providers\MultilayerGeneratorServiceProvider 将更新如下

class MultilayerGeneratorServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->booting(function(){
            $loader = \Illuminate\Foundation\AliasLoader::getInstance();
        /*
         |
         | Repositories Classes
         |
         */

             $loader->alias('AccountsRepository', 'App\DataLayer\Repositories\AccountsRepository');
             $loader->alias('AccountsRepoInterface', 'AccountsRepository');
            
        /*
         |
         | Object Classes
         |
         */
         
             $loader->alias('User', 'App\DataLayer\Objects\User');

        /*
         |
         | Traits 
         |  
         */
            $loader->alias('CRUDtrait', 'App\Http\Traits\CRUDtrait');//don't modify this.
            $loader->alias('AuthenticationTrait', 'App\Http\Traits\AuthenticationTrait');

        /*
         |
         | Motors
         |  
         */

            $loader->alias('Motor', 'App\Http\Motors\Motor');
            $loader->alias('STAFFmotor', 'App\Http\Controllers\Motors\STAFFmotor');
        });
    }
}

可用命令

 bake
  bake:all                   Creates an eloquent class, an interface and a repository for it, also a motor, and a trait if specified.
  bake:datalayer             Bake the data layer for the given class
 make
  make:controller            Create a new resource controller class
  make:datalayer             Creates the datalayer directory structure
  make:datalayer:class       Creates an eloquent class, its interface and its repository.
  make:datalayer:interface   Creates an interface.
  make:datalayer:repository  Creates a repository
  make:httplayer             Creates the httplayer directory structure
  make:httplayer:basemotor   Creates an abstract motor class for inheritence.
  make:httplayer:motor       Creates a motor, with the injected specified repository, and the trait to be used.
  make:httplayer:trait
  make:multilayer            This command generates the directory structure for the multilayering conventions.
  

如果你希望走自己的路,不进行批量烘焙,可以使用以下命令

php artisan make:datalayer:class <name>

php artisan make:datalayer:interface <name>

php artisan make:datalayer:repository <name> (with options: --interface= the one you wish your repo to implement, --class=The class whose repo is this

php artisan make:httplayer:motor <name>  --trait= : The trait that is desired to be used --repository= : A specific repository to be implemented

php artisan make:httplayer:trait <name>

贡献

请参阅CONTRIBUTING 获取详细信息。

安全性

如果你发现任何与安全性相关的问题,请通过电子邮件ouaghad.hamza@gmail.com 而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。