clean-code-studio / laravel-make-facades
Laravel Artisan 命令用于生成 Facades (php artisan make generator 现在执行时排除 Facadename Facade)
1.0.6
2019-10-26 05:15 UTC
Requires
- php: ^7.1.3
This package is auto-updated.
Last update: 2024-09-06 07:34:39 UTC
README
Laravel Make Facades (简化包教程)
安装
Comoser 安装
composer require clean-code-studio/laravel-make-facades --dev
通过 Artisan 发布包
发布配置文件
php artisan vendor:publish
- 选择
CleanCodeStudio\MakeFacades\ServiceProvider
配置包设置
定义配置设置
- 打开
config/make-facades.php
- 注意:
config/make-facades.php
在通过 artisan 发布此包时创建
- 注意:
- 配置
config/make-facades.php
设置- 路径: Facades 文件夹路径(使用此包创建的新 Facades 将存储在此处)
- 命名空间: 使用此包创建的每个 Facade 的命名空间
- 提供者路径: 更新以支持 Laravel 8 版本(见 @see zhorton34#4)
- 自动别名 Facades: 是否希望自动将给定文件夹内的所有服务绑定到其自己的 Facade。
Laravel Make Facades - 配置设置
- 文件路径:
config/make-facade.php 示例
return [ // Directory path save your facades 'path' => 'app/facades', // Namespace Of Your Facades 'namespace' => 'App\\Facades', // Providers path (@see https://github.com/zhorton34/laravel-make-facades/issues/4) 'providers_path' => 'app/Providers', // This will find all of the aliases and services defined in your path settings and // 1. Bind the service classes for each facade to the service container automatically // 2. Register aliases for each facade base on the Class Name the Facade Reference to the service container automatically 'auto_alias_facades' => true, ];
使用 Make Facades 服务
- 运行:
php artisan make:facade MyCoolService
- 为
MyCoolService
类创建支架 - 为
MyCoolServiceFacade
类创建支架 - 注意
- 如果
config/make-facade.php
中的'auto_alias_facades' => true
,则服务将自动绑定到您的服务容器 - 如果
config/make-facade.php
中的'auto_alias_facades' => false
,则您需要在任何服务提供者中绑定您生成的服务类到服务容器,以便 Facade 能够正常工作。
- 为
MyCoolService 类
- 默认创建为
App\Facades\MyCoolService\MyCoolService.php
<?php namespace App\Facades\MyCoolService; class MyCoolService { // create MyCoolService class }
MyCoolServiceFacade 类
- 默认创建为
App\Facades\MyCoolService\MyCoolServiceFacade.php
<?php namespace App\Facades\MyCoolService; use Illuminate\Support\Facades\Facade; class MyCoolServiceFacade extends Facade { protected static function getFacadeAccessor() { return 'MyCoolService'; } }
注意:配置中的 auto_alias_facades
- 如果
config/make-facade.php
中的'auto_alias_facades' => true
,则服务将自动绑定到您的服务容器 - 如果
config/make-facade.php
中的'auto_alias_facades' => false
,则您需要在任何服务提供者中绑定您生成的服务类到服务容器,以便 Facade 能够正常工作。
Laravel Make Facades YouTube 教程
Laravel Make Facades (简化包教程)
- 屏幕录像
- Laravel Facades 教程
- 此包的安装和使用
总结
-
A. 记住您可以通过在
config/make-facades.php
文件中将auto_alias_facades
设置为 TRUE 来自动绑定服务和自动别名您的服务 Facades!简单、快捷、方便。 -
B. 如果您更改了配置中的命名空间或文件路径,旧命名空间和旧文件路径中的 Facades 和 Facade 服务将不会自动注册到容器中。
-
C. 如果您不想自动注册或自动添加生成的 Facades 的别名,只需在您的
config/make-facades.php
文件中将auto_alias_facades
设置为 false 即可。
整洁代码工作室 ~ 整洁代码,整洁生活 ~ 简化!