geggleto / setter-strategy
slim 3的替代分发策略
0.0.3
2016-03-08 14:28 UTC
Requires
- slim/slim: ^3.0
Requires (Dev)
- phpunit/phpunit: 5.2.10
This package is auto-updated.
Last update: 2024-08-29 04:31:03 UTC
README
setter-injection-strategy
此包旨在替换Slim中的默认调用处理程序。此策略强制控制器实现SetterInjectionReceiver
,告诉Slim设置响应、请求和参数,而不是通过方法签名传递。这可以在您的控制器中的所有操作方法上节省空间。
简而言之,它会将这个。
class abcController { //... public function myAction (Request $request, Response $response, $args = []) { //.. } //... }
变成这个。
class abcController implements SetterInjectionReceiver { //.. Implement and store the Objects somewhere up here. //... public function myAction () { //.. This is now much more Slim 2 style } //... }
或者如果你有参数的话,会是这样。
class abcController implements SetterInjectionReceiver { //.. Implement and store the Objects somewhere up here. //... public function myAction ($arg1, $arg2, $arg3) { //.. This is now much more Slim 2 style } //... }
安装
此包可通过Composer获取。运行composer install geggleto/setter-strategy
用法
您需要在您的Slim应用程序中做一些配置更改。如果您只想在部分可调用对象上使用SetterInjection,如果您的控制器没有实现Receiver接口,则默认回退到使用RequestResponseArgs样式
// Setup the Strategy in the container by adding a factory method like below. $container['foundHandler'] = function ($c) { return new SetterInjectionStrategy(); };