Passed
Push — master ( 18d828...33264b )
by Enrico
04:07 queued 13s
created

RelayServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 16
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 2
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