lhsazevedo/restatic
Composer 安装命令:
composer require lhsazevedo/restatic
包简介
Laravel like facades por PSR11 containers
README 文档
README
Laravel like Facades (static proxies) for PSR11 containers.
class HomeController { public function __invoke() { // It just works! return View::render('home.index', [ 'articles' => DB::query('SELECT * FROM articles') ]); } }
Requirements
PHP 7.2+ or 8+
Usage
Setup Container
$container = new \DI\Container(); $container->set('db', function () { return new PDO('mysql:dbname=testdb;host=127.0.0.1', 'dbuser', 'dbpass'); });
Create Static Proxies
// app/Facades/DB.php class DB extends StaticProxy { public static function getInstanceIdentifier() { return 'db'; } }
Setup Facades
$proxyManager = new ProxyManager($container); $proxyManager->addProxy('DB', DB::class); $proxyManager->addProxy('View', View::class); $proxyManager->enable(ProxyManager::ROOT_NAMESPACE_ANY);
Concepts
- Static Proxy – Static class that proxies static method calls to instance methods on its Proxy Subject.
- Proxy Subject (Instance) – An object instance, stored in a Container, that is linked to a Static Proxy.
- Proxy Manager – Mediating object used to associate Static Proxies to an Alias Loader and Container.
- Alias – A memorable class name used as an alias to a fully-qualified class name of a Static Proxy class.
- Alias Loader – Maintainer of the associations between Aliases and Static Proxies. It is injected into the autoloader stack to handle Aliases as they are referenced.
- Container – A IoC container (e.g., a Service Locator or DIC) that provides the Proxy Subject instances. It must
implement the PSR-11 stardard's
ContainerInterface. - Instance Identifier – An identifier used to fetch a Proxy Subject from a Container. Each Static Proxy must specify the Instance Identifier needed to get its Proxy Subject.
- Root Namespace – The namespace that an Alias can be referenced in. This can be configured as the global namespace (default), a specific namespace, or any namespace (i.e., the Alias works from any namespace).
More
Inspiration
ReStatic is based on the awesome package XStatic created by Jeremy Lindblom.
Disclaimer
I would not consider myself to be for or against the use of static proxy interfaces (or Laravel's "Facades"), but I do think it is a fascinating and unique idea, and that it is very cool that you can write code this way and still have it work and be testable. I am curious to see if developers, especially library and framework developers, find ways to use, but not require, these static proxy interfaces in order to make their projects appeal to a wider range of PHP developers.
— Jeremy Lindblom
lhsazevedo/restatic 适用场景与选型建议
lhsazevedo/restatic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 365 次下载、GitHub Stars 达 7, 最近一次更新时间为 2019 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「container」 「static」 「proxy」 「interface」 「facade」 「service locator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lhsazevedo/restatic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lhsazevedo/restatic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lhsazevedo/restatic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
TwigStan is a static analyzer for Twig templates powered by PHPStan
A fast and intuitive dependency injection container.
Arc5 provides a set of static classes for the Mvc5 Framework
Dependency injection container for the Monolith framework.
统计信息
- 总下载量: 365
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 27
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-30