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

StratigilityServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 28 2
1
<?php
2
namespace EXAMPLE;
3
use Pimple\ServiceProviderInterface;
4
use Pimple\Container;
5
6
use Zend\Diactoros\Response;
7
use Zend\Stratigility\Middleware\NotFoundHandler;
8
use function Zend\Stratigility\middleware;
9
use function Zend\Stratigility\path;
10
11
/**
12
 * this configuration reuse middleware and other
13
 * components available from Zend Stratigility  component
14
 */
15
class StratigilityServiceProvider implements ServiceProviderInterface
16
{
17
18
    public function register(Container $app)
19
    {
20
        // using middleware function
21
        $app['home_page'] = function($app) {
22
            return middleware(function($req, $handler) use ($app) {
23
                if (!in_array($req->getUri()->getPath(), [$app['basepath'].'/', $app['basepath']], true)) {
24
                    return $handler->handle($req);
25
                }
26
                
27
                $response = new Response();
28
                $response->getBody()->write("This is the home. Try '/hi' or  anithing else");
29
                
30
                return $response;
31
            });
32
        };
33
        
34
        // using path function
35
        $app['hello_page'] = function($app) {
36
            return path($app['basepath'].'/hi', middleware(function($req, $handler) {
37
                $response = new Response();
38
                $response->getBody()->write("Hi. Try anything but/hi");
39
                
40
                return $response;
41
            }));
42
        };
43
        
44
        // using standard middleware as defaultt page
45
        $app['default_page'] = function($app) { return new MyMiddleware($app);};
46
47
    }
48
}
49