1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the uSilex framework. |
5
|
|
|
* |
6
|
|
|
* (c) Enrico Fagnoni <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This service provider uses http://relayphp.com/2.x to define |
14
|
|
|
* uSilex.httpHandler service. |
15
|
|
|
* |
16
|
|
|
* Add this dependency to your project: |
17
|
|
|
* |
18
|
|
|
* composer require "relay/relay" "2.x@dev" |
19
|
|
|
* |
20
|
|
|
* USAGE: |
21
|
|
|
* you need do define the service handler.queue that contains the list |
22
|
|
|
* of middleware to execute. You can use the id of a service that realize a middleware, |
23
|
|
|
* a concrete middleware instance or a callable with the signatur recognized by relay |
24
|
|
|
* |
25
|
|
|
* $app->register( new RelayServiceProvider() ); |
26
|
|
|
* $app['handler.queue'] = [ |
27
|
|
|
* 'a_middleware_service_id', // should be defined $app['a_middleware_service_id'] |
28
|
|
|
* new MyMiddleware(), // a class that implements PSR-15 Middleware interface |
29
|
|
|
* function( $request, $next ){} // a closure |
30
|
|
|
* ]; |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
namespace uSilex\Provider\Psr15; |
34
|
|
|
|
35
|
|
|
use Pimple\Container; |
36
|
|
|
use Pimple\ServiceProviderInterface; |
37
|
|
|
use Relay\Relay; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class RelayServiceProvider implements ServiceProviderInterface |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
1 |
|
public function register(Container $app) |
46
|
|
|
{ |
47
|
1 |
|
$app['handler.queue'] = []; |
48
|
|
|
|
49
|
|
|
$app['uSilex.httpHandler'] = function($app) { |
50
|
|
|
|
51
|
|
|
$resolver = function($entry) use($app){ |
52
|
|
|
return is_string($entry) ? $app[$entry] : $entry; |
53
|
1 |
|
}; |
54
|
|
|
|
55
|
1 |
|
return new Relay($app['handler.queue'], $resolver); |
56
|
|
|
}; |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|