mevada-kalpesh / repo-structure
您可以使用单个命令创建您的仓库结构,包括所有必需的文件。
dev-main
2024-06-01 03:14 UTC
Requires
- php: ^8.0
This package is auto-updated.
Last update: 2024-09-10 18:02:08 UTC
README
Repo Structure 是一个 Laravel 扩展包,允许您通过单个命令创建仓库结构,包括类、接口、Provider 以及绑定代码。
安装
您可以通过 composer 安装此包,如果命令出错,请将 :dev-main
作为版本添加到末尾
composer require mevada-kalpesh/repo-structure
安装包后,在 config/app.php
中的 Providers
下添加此 Provider
App\Providers\RepositoryProvider::class
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Kalpesh\RepoStructure\RepoStructureProvider"
这是已发布配置文件的内容
// config/repo-sturcture.php <?php return [ /** * Prefix of Class File Example PostRepositoryClass */ "class_file_prefix" => 'RepositoryClass', /** * Prefix of Interface File Example PostRepositoryInterface */ "interface_file_prefix" => 'RepositoryInterface', /** * File Directory for create files * app_path is require */ "file_dir" => app_path('Repository'), /** * Interface Folder Name */ "interface_folder" => "Interfaces", /** * Class Folder Name */ "class_folder" => "Classes", ];
使用方法
只需运行以下命令即可构建完整的仓库结构,包括接口、类、Provider 以及 Provider 中的绑定代码。您可以从控制器开始使用 repo。
php artisan make:repo Post
运行此命令后,将创建如下文件结构
-- app -- Repository -- Classes -- PostRepositoryClass.php -- Interfces -- PostRepositoryInterface.php
您的仓库类 PostRepositoryClass.php
看起来像这样
<?php namespace App\Repository\Classes; use App\Repository\Interfaces\PostRepositoryInterface; class PostRepositoryClass implements PostRepositoryInterface { //here is your method }
您的仓库接口 PostRepositoryInterface.php
看起来像这样。
<?php namespace App\Repository\Interfaces; interface PostRepositoryInterface { // here is your method }
您的仓库 Provider RepositoryProvider.php
看起来像这样。
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use App\Repository\Classes\PostRepositoryClass; use App\Repository\Interfaces\PostRepositoryInterface; class RepositoryProvider extends ServiceProvider { /** * Register services. */ public function register(): void { $this->app->bind(PostRepositoryInterface::class, function () { return new PostRepositoryClass(); }); } /** * Bootstrap services. */ public function boot(): void { // } }
请确保正确添加命名空间,如上所示。
测试
composer test
更新日志
有关最近更改的更多信息,请参阅更新日志。
贡献
有关详细信息,请参阅贡献指南。
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。