Skip to content

Commit 9e6fd09

Browse files
committed
updated to PSR11 container
updated controller middleware to PSR15 updated url helper plugin to use leverage additional parameters from expressive helpers > 3.0
1 parent 8de640e commit 9e6fd09

8 files changed

Lines changed: 78 additions & 61 deletions

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
## 0.2.0 - 2017-03-15
2+
3+
### Changed
4+
* Updated factories to use PSR11 container
5+
* Updated base controller classes to use PSR15 middleware
6+
* Updated `UrlHelperPlugin` to use new version of expressive helpers
7+
8+
### Added
9+
* `UrlHelperPlugin` now supports the additional `UrlHelper` generate parameters
10+
* Abstract controller added property `DelegateInterface` $delegate, replacing the $next
11+
12+
### Deprecated
13+
* Nothing
14+
15+
### Removed
16+
* $next property from AbstractController(use $delegate instead)
17+
* $response property from AbstractController
18+
19+
### Fixed
20+
* Nothing
21+
22+
123
## 0.1.1 - 2017-03-11
224

325
### Added

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
"require": {
1313
"php": "^7.1",
1414
"psr/http-message": "^1.0",
15-
"container-interop/container-interop": "^1.1",
16-
"zendframework/zend-servicemanager": "^3.0",
15+
"http-interop/http-middleware": "^0.4.1",
16+
"zendframework/zend-servicemanager": "^3.3.0",
1717

18-
"dotkernel/dot-event": "^0.1"
18+
"dotkernel/dot-event": "^0.2"
1919
},
2020
"require-dev": {
2121
"zendframework/zend-expressive-template": "^1.0",
22-
"zendframework/zend-expressive-helpers": "^2.0",
22+
"zendframework/zend-expressive-helpers": "^3.0",
2323

2424
"phpunit/phpunit": "^4.8",
2525
"squizlabs/php_codesniffer": "^2.3"
@@ -36,7 +36,8 @@
3636
},
3737
"extra": {
3838
"branch-alias": {
39-
"dev-master": "0.2-dev"
39+
"dev-master": "0.2-dev",
40+
"dev-develop": "0.3-dev"
4041
}
4142
}
4243
}

src/AbstractActionController.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ abstract class AbstractActionController extends AbstractController
2323
*/
2424
public function dispatch(): ResponseInterface
2525
{
26-
$request = $this->request;
27-
28-
$action = strtolower(trim($request->getAttribute('action', 'index')));
26+
$action = strtolower(trim($this->request->getAttribute('action', 'index')));
2927
if (empty($action)) {
3028
$action = 'index';
3129
}
@@ -34,19 +32,20 @@ public function dispatch(): ResponseInterface
3432

3533
if (method_exists($this, $action)) {
3634
$r = $this->dispatchEvent(ControllerEvent::EVENT_CONTROLLER_DISPATCH, [
37-
'request' => $request,
38-
'next' => $this->getNext(),
35+
'request' => $this->request,
36+
'delegate' => $this->getDelegate(),
3937
'method' => $action
4038
]);
4139
if ($r instanceof ResponseInterface) {
4240
return $r;
4341
}
4442

43+
$this->request = $r->getParam('request');
4544
return $this->$action();
4645
}
4746

4847
//just go the the next middleware, it will eventually hit a 404 if no one handles the request
49-
$next = $this->getNext();
50-
return $next($this->getRequest(), $this->getResponse());
48+
$delegate = $this->getDelegate();
49+
return $delegate->process($this->request);
5150
}
5251
}

src/AbstractController.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Dot\Controller\Plugin\PluginInterface;
1414
use Dot\Controller\Plugin\PluginManager;
1515
use Dot\Controller\Plugin\PluginManagerAwareInterface;
16+
use Interop\Http\ServerMiddleware\DelegateInterface;
17+
use Interop\Http\ServerMiddleware\MiddlewareInterface;
1618
use Psr\Http\Message\ResponseInterface;
1719
use Psr\Http\Message\ServerRequestInterface;
1820
use Zend\EventManager\EventManagerAwareInterface;
@@ -22,6 +24,7 @@
2224
* @package Dot\Controller
2325
*/
2426
abstract class AbstractController implements
27+
MiddlewareInterface,
2528
PluginManagerAwareInterface,
2629
EventManagerAwareInterface
2730
{
@@ -33,11 +36,8 @@ abstract class AbstractController implements
3336
/** @var ServerRequestInterface */
3437
protected $request;
3538

36-
/** @var ResponseInterface */
37-
protected $response;
38-
39-
/** @var callable */
40-
protected $next;
39+
/** @var DelegateInterface */
40+
protected $delegate;
4141

4242
/** @var bool */
4343
protected $debug = false;
@@ -58,20 +58,10 @@ public static function getMethodFromAction(string $action): string
5858
return $method;
5959
}
6060

61-
/**
62-
* @param ServerRequestInterface $request
63-
* @param ResponseInterface $response
64-
* @param callable|null $next
65-
* @return ResponseInterface
66-
*/
67-
public function __invoke(
68-
ServerRequestInterface $request,
69-
ResponseInterface $response,
70-
callable $next = null
71-
): ResponseInterface {
61+
public function process(ServerRequestInterface $request, DelegateInterface $delegate): ResponseInterface
62+
{
7263
$this->request = $request;
73-
$this->response = $response;
74-
$this->next = $next;
64+
$this->delegate = $delegate;
7565

7666
return $this->dispatch();
7767
}
@@ -87,19 +77,11 @@ public function getRequest(): ServerRequestInterface
8777
}
8878

8979
/**
90-
* @return ResponseInterface
91-
*/
92-
public function getResponse(): ResponseInterface
93-
{
94-
return $this->response;
95-
}
96-
97-
/**
98-
* @return callable
80+
* @return DelegateInterface
9981
*/
100-
public function getNext(): callable
82+
public function getDelegate(): DelegateInterface
10183
{
102-
return $this->next;
84+
return $this->delegate;
10385
}
10486

10587
/**

src/Factory/ControllerEventListenersInitializer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
use Dot\Controller\AbstractController;
1313
use Dot\Controller\Event\ControllerEventListenerInterface;
1414
use Dot\Controller\Exception\RuntimeException;
15-
use Interop\Container\ContainerInterface;
16-
use Zend\ServiceManager\Initializer\InitializerInterface;
15+
use Psr\Container\ContainerInterface;
1716

1817
/**
1918
* Class ControllerEventListenersInitializer
2019
* @package Dot\Controller\Factory
2120
*/
22-
class ControllerEventListenersInitializer implements InitializerInterface
21+
class ControllerEventListenersInitializer
2322
{
2423
/**
2524
* @param ContainerInterface $container
26-
* @param object $instance
25+
* @param $instance
2726
*/
2827
public function __invoke(ContainerInterface $container, $instance)
2928
{
@@ -32,6 +31,10 @@ public function __invoke(ContainerInterface $container, $instance)
3231
}
3332
}
3433

34+
/**
35+
* @param ContainerInterface $container
36+
* @param AbstractController $controller
37+
*/
3538
public function attachControllerListeners(ContainerInterface $container, AbstractController $controller)
3639
{
3740
$config = $container->get('config')['dot_controller'];

src/Factory/PluginManagerAwareInitializer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
use Dot\Controller\AbstractController;
1313
use Dot\Controller\Plugin\PluginManager;
1414
use Dot\Controller\Plugin\PluginManagerAwareInterface;
15-
use Interop\Container\ContainerInterface;
16-
use Zend\ServiceManager\Initializer\InitializerInterface;
15+
use Psr\Container\ContainerInterface;
1716

1817
/**
1918
* Class PluginManagerAwareInitializer
2019
* @package Dot\Controller\Factory
2120
*/
22-
class PluginManagerAwareInitializer implements InitializerInterface
21+
class PluginManagerAwareInitializer
2322
{
2423
/**
2524
* @param ContainerInterface $container

src/Factory/PluginManagerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Dot\Controller\Plugin\PluginManager;
1313
use Dot\Controller\Plugin\TemplatePlugin;
1414
use Dot\Controller\Plugin\UrlHelperPlugin;
15-
use Interop\Container\ContainerInterface;
15+
use Psr\Container\ContainerInterface;
1616
use Zend\Expressive\Helper\UrlHelper;
1717
use Zend\Expressive\Template\TemplateRendererInterface;
1818

src/Plugin/UrlHelperPlugin.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,42 @@ public function __construct(UrlHelper $helper)
3131

3232
/**
3333
* @param string|null $routeName
34-
* @param array|null $routeParams
35-
* @return mixed
34+
* @param array $routeParams
35+
* @param array $queryParams
36+
* @param null $fragmentIdentifier
37+
* @param array $options
38+
* @return UrlHelperPlugin|string
3639
*/
37-
public function __invoke(string $routeName = null, array $routeParams = [])
38-
{
40+
public function __invoke(
41+
string $routeName = null,
42+
array $routeParams = [],
43+
$queryParams = [],
44+
$fragmentIdentifier = null,
45+
array $options = []
46+
) {
3947
$args = func_get_args();
4048
if (empty($args)) {
4149
return $this;
4250
}
4351

44-
return $this->generate($routeName, $routeParams);
52+
return $this->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options);
4553
}
4654

4755
/**
48-
* @param string $routeName
56+
* @param string|null $routeName
4957
* @param array $routeParams
58+
* @param array $queryParams
59+
* @param null $fragmentIdentifier
60+
* @param array $options
5061
* @return string
5162
*/
5263
public function generate(
53-
string $routeName,
54-
array $routeParams = []
64+
string $routeName = null,
65+
array $routeParams = [],
66+
$queryParams = [],
67+
$fragmentIdentifier = null,
68+
array $options = []
5569
): string {
56-
return $this->urlHelper->generate(
57-
$routeName,
58-
$routeParams
59-
);
70+
return $this->urlHelper->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options);
6071
}
6172
}

0 commit comments

Comments
 (0)