hyder/facade-pattern
Composer 安装命令:
composer require hyder/facade-pattern
包简介
In this pattern, you would create Facade classes that provide a simplified, static interface to the underlying service implementations. The service classes would perform the actual business logic and communicate with the database or other external systems.
README 文档
README
This package provides scaffolding for the Facade Pattern in Laravel. The Facade Pattern is a design pattern that helps to separate the business logic from the controller or other client code, making it easier to maintain and test.
Why Facade Pattern instead of Repository Pattern?
In the Repository Pattern, the implementation of the data access layer is abstracted behind an interface. This interface defines the methods that the repository must implement, but it doesn't provide any way to access the underlying implementation details.
This lack of flexibility can be problematic in cases where you need to access the implementation details of the repository from other parts of the code. For example, if you need to access the repository from within a queued job or another simple class, you can't simply create a new instance of the repository because it's abstracted behind an interface.
One workaround for this issue is to pass the repository instance to the queued job or simple class as a parameter, but this can lead to tight coupling and make the code harder to maintain.
Another workaround is to use a dependency injection container to provide an instance of the repository to the queued job or simple class. However, this can add additional complexity and require additional configuration.
Overall, the lack of flexibility in the Repository Pattern can be a disadvantage in certain situations, especially when you need to access the implementation details of the repository from other parts of the code.
Here comes the solution with Facade Pattern. You can easily access the Facade from within a queued job or another simple class.
Installation
You can install the package via composer:
composer require hyder/facade-pattern --dev
Publish Provider
After installation, you need to run the vendor:publish command to publishing provider file. You can do this by running the following command:
php artisan vendor:publish --provider=Hyder\FacadePattern\FacadePatternServiceProvider --tag=provider
This will publish the package's FacadeServiceProvider to the app/Providers directory, which you can then modify as needed.
The FacadeServiceProvider class is responsible for registering the service classes for Facade with the Laravel container. This allows you to easily swap out the implementation of the service classes if needed.
Configuration
You have to manually add the service provider in your config/app.php file:
'providers' => [ // ... App\Providers\FacadeServiceProvider::class, ];
Create Scaffolding
Now you can run the facade-pattern:scaffold command to generate the necessary scafolding files. You can do this by running the following command:
php artisan facade-pattern:scaffold Example
This will create the following files in your app directory:
app/
└── Patterns/
├── Facades/
│ ├── <name>Facade.php
│ └── ... other facades
├── Interfaces/
│ ├── <name>Interface.php
│ └── ... other interfaces
└── Services/
├── <name>FacadeService.php
└── ... other services
-
The
Patterns/Facadesdirectory contains the Facade classes, which provide a simple, consistent interface to the underlying service classes. You can create additional Facade classes as needed. -
The
Patterns/Interfacesdirectory contains the repository interfaces, which define the methods that the service classes must implement. You can create additional interface files as needed. -
The
Patterns/Servicesdirectory contains the service classes, which perform the actual business logic and communicate with the database or other external systems. You can create additional service classes as needed.
Create Facade, Interface and Service
By running the facade-pattern:facade, facade-pattern:interface, and facade-pattern:service command you can generate the necessary file. You can do this by running the following command:
Facade
php artisan facade-pattern:facade ExampleFacade
Interface
php artisan facade-pattern:interface ExampleInterface
Service
php artisan facade-pattern:service ExampleFacadeService
Don't forget to register your facade service class in FacadeServiceProvider provider's register() method.
That's it! You can now start using the Facade Pattern in your Laravel application.
Contributing
If you would like to contribute to this package, please create a pull request or open an issue.
License
This package is open-source software released under the MIT license. Feel free to modify and use the package in your own projects.
hyder/facade-pattern 适用场景与选型建议
hyder/facade-pattern 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pattern」 「laravel」 「facade-pattern」 「hyder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hyder/facade-pattern 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hyder/facade-pattern 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hyder/facade-pattern 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for the Repository Design Pattern.
Inbox pattern process implementation for your Laravel Applications
A library for simple pattern matching.
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
A PHP library to implement the observer pattern
Alfabank REST API integration
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-20