lagdo/facades
Composer 安装命令:
composer require lagdo/facades
包简介
Base classes to implement service facades.
关键字:
README 文档
README
Base classes for service facades
This package provides base classes for service facades implementations.
The goal of the separation between this package and the framework related ones is to make the facades portable across different frameworks.
A service facade can be use without any change with various frameworks, provided that a package for this framework is available, or a PSR-11 container can be provided.
The following packages are currently available:
- Symfony: https://github.com/lagdo/symfony-facades
- Laravel: https://github.com/lagdo/laravel-facades
- CakePHP: https://github.com/lagdo/cake-facades
- Yii: https://github.com/lagdo/yii-facades
Facades definition
The Lagdo\Facades\AbstractFacade abstract class is the base class for user defined service facades.
namespace App\Facades; use App\Services\MyService; use Lagdo\Facades\AbstractFacade; /** * @extends AbstractFacade<MyService> */ class MyFacade extends AbstractFacade { /** * @inheritDoc */ protected static function getServiceIdentifier(): string { return MyService::class; } }
If a given service doesn't need to be fetched from the container at each call, it can be saved in its facade class by using the Lagdo\Facades\ServiceInstance trait.
namespace App\Facades; use App\Services\MyService; use Lagdo\Facades\AbstractFacade; use Lagdo\Facades\ServiceInstance; /** * @extends AbstractFacade<MyService> */ class MyFacade extends AbstractFacade { use ServiceInstance; /** * @inheritDoc */ protected static function getServiceIdentifier(): string { return MyService::class; } }
Important
The Lagdo\Facades\ServiceInstance trait must be used in each service facade class, and not in a parent class. The same instance will be shared by all the classes inheriting the same base class using the trait, and the service facades will ot work as expected.
The service container will be called only once in the above example.
MyFacade::myMethod1(); // Calls the service container MyFacade::myMethod2(); // Doesn't call the service container MyFacade::myMethod1(); // Doesn't call the service container
Container setup
The Lagdo\Facades\ContainerWrapper class gives access to the underlying container.
It needs to be provided with a PSR-11 container, which will be done by the framework specific packages, but can also be done by the developer in case a package is not available.
use Lagdo\Facades\ContainerWrapper; ContainerWrapper::setContainer($container); $container = ContainerWrapper::getContainer();
Provided facade and service
A default facade and a default service are provided for logging.
If the provided PSR-11 container already has a PSR-3 logger registered, then the Lagdo\Facades\Logger facade can be used.
use Lagdo\Facades\Logger; Logger::info('This is an information');
A simple PSR-3 logger implementation is also provided.
It will return the local services, and revert to the already defined container for the other services.
use Lagdo\Facades\ContainerWrapper; use Lagdo\Facades\Logger; ContainerWrapper::registerLocalServices([ 'filename' => '/path/to/logs/dir/app', 'extension' => '.log', ]); // Log a message in the '/path/to/logs/dir/app.log' file. Logger::info('This is an information');
Contribute
- Issue Tracker: github.com/lagdo/facades/issues
- Source Code: github.com/lagdo/facades
License
The package is licensed under the 3-Clause BSD license.
lagdo/facades 适用场景与选型建议
lagdo/facades 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.72k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「Service Facades」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lagdo/facades 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lagdo/facades 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lagdo/facades 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A fast and intuitive dependency injection container.
Laravel Artisan Command To Generate Facades (php artisan make generator now execpts facade Facadename)
Registry service.
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Service auto install for Nette Framework
JMS format service provider and facade for laravel 5.x framework
统计信息
- 总下载量: 35.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-03-30