RelayServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
eloc 8
c 2
b 1
f 0
dl 0
loc 19
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 14 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
class RelayServiceProvider implements ServiceProviderInterface
40
{
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function register(Container $app)
45
    {
46 1
        $app['handler.queue'] = [];
47
        
48
        $app['relay.pimpleResolver'] = $app->protect(function ($entry) use ($app) {
49
            return is_string($entry) ? $app[$entry] : $entry;
50 1
        });
51
        
52
        $app['relay.factory'] = $app->protect(function ($queue) use ($app) {
53 1
            return new Relay($queue, $app['relay.pimpleResolver']);
54 1
        });
55
        
56
        $app['uSilex.httpHandler'] = function ($app) {
57 1
            return $app['relay.factory']($app['handler.queue']);
58
        };
59 1
    }
60
}
61