Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geggleto/setter-injection-strategy
https://github.com/geggleto/setter-injection-strategy
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/geggleto/setter-injection-strategy
- Owner: geggleto
- License: mit
- Created: 2016-03-04T15:38:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-03-08T14:35:05.000Z (over 8 years ago)
- Last Synced: 2024-04-17T10:38:56.342Z (7 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/geggleto/setter-injection-strategy.svg?branch=master)](https://travis-ci.org/geggleto/setter-injection-strategy)
# setter-injection-strategy
This package is intended to replace the default Invocation handler in Slim.
This strategy forces controllers to implement `SetterInjectionReceiver` which tells Slim to set the Response, Request, and Arg instead of
passing it through the method signature. This saves space on all of your action methods in your controller.In short it will turn this.
```php
class abcController {
//...
public function myAction (Request $request, Response $response, $args = []) {
//..
}
//...
}
```Into This.
```php
class abcController implements SetterInjectionReceiver {
//.. Implement and store the Objects somewhere up here.
//...
public function myAction () {
//.. This is now much more Slim 2 style
}
//...
}
```Or this if you have arguments
```php
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
}
//...
}
```## Install
This package is available via Composer. `composer install geggleto/setter-strategy`## Usage
There are some configuration changes you will need to make in your Slim application.
**If you only wish to use SetterInjection on some of your callables, It will default back to using the RequestResponseArgs style if your controller does not implement the Receiver Interface**```php
// Setup the Strategy in the container by adding a factory method like below.
$container['foundHandler'] = function ($c) {
return new SetterInjectionStrategy();
};
```