Completed
Push — dev-master ( 2e700a...a98bb1 )
by Derek Stephen
12s
created

Application::getContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Bone\Mvc;
4
5
use Bone\Server\Environment;
6
use Pimple\Container;
7
use Zend\Diactoros\ServerRequestFactory;
8
use Zend\Diactoros\Response;
9
10
class Application
11
{
12
    /** @var Registry $registry */
13
    private $registry;
14
15
    /** @var Container $registry */
16
    private $treasureChest;
17
18
    /**
19
     *  There be nay feckin wi' constructors on board this ship
20
     *  There be nay copyin' o' th'ship either
21
     *  This ship is a singleton!
22
     */
23
    public function __construct(){}
24
    public function __clone(){}
25
26
27
    /**
28
     *  Ahoy! There nay be boardin without yer configuration
29
     *
30
     * @param array $config
31
     * @return Application
32
     */
33 2
    public static function ahoy(array $config = [])
34 2
    {
35 2
        static $inst = null;
36 2
        if ($inst === null)
37
        {
38 1
            $inst = new Application();
39 1
            $inst->registry = Registry::ahoy();
40 1
            $inst->treasureChest = new Container();
41 1
            foreach($config as $key => $value)
42
            {
43 1
                $inst->registry->set($key,$value);
44 1
                $inst->treasureChest[$key] = $value;
45
            }
46
        }
47 2
        return $inst;
48
    }
49
50
    /**
51
     *  T' the high seas! Garrr!
52
     *
53
     * @throws \Exception
54
     */
55 1
    public function setSail()
56 1
    {
57 1
        $request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
58 1
        $response = new Response();
59 1
        $env = new Environment($_SERVER);
60 1
        $dispatcher = new Dispatcher($request, $response, $env);
61 1
        $dispatcher->fireCannons();
62 1
    }
63
64
    /**
65
     * @return Container
66
     */
67
    public function getContainer()
68
    {
69
        return $this->treasureChest;
70
    }
71
}