Completed
Push — 5.0 ( d49403...9430f0 )
by Marc André
03:11 queued 01:48
created

Core::init()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 13
nc 4
nop 0
1
<?php
2
3
4
/**
5
 *
6
 * Copyright (c) 2010-2018 Nevraxe inc. & Marc André Audet <[email protected]>. All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without modification, are
9
 * permitted provided that the following conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above copyright notice, this list of
12
 *       conditions and the following disclaimer.
13
 *
14
 *   2. Redistributions in binary form must reproduce the above copyright notice, this list
15
 *       of conditions and the following disclaimer in the documentation and/or other materials
16
 *       provided with the distribution.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL NEVRAXE INC. & MARC ANDRÉ AUDET BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 */
30
31
32
namespace Cervo;
33
34
35
use Cervo\Config\BaseConfig;
36
37
38
/**
39
 * Core class for Cervo.
40
 *
41
 * @author Marc André Audet <[email protected]>
42
 */
43
final class Core
44
{
45
    private $context = null;
46
47
    public function __construct(?BaseConfig $config = null) {
48
        $this->context = new Context($config);
49
    }
50
51
    public function init()
52
    {
53
        /** @var Events $events */
54
        $events = $this->context->getSingletons()->get(Events::class);
55
56
        /** @var Router $router */
57
        $router = $this->context->getSingletons()->get(Router::class);
58
59
        foreach ($this->context->getModulesManager()->getAllModules() as [$vendor_name, $module_name, $path]) {
60
            $events->loadPath($path);
0 ignored issues
show
Bug introduced by
The variable $path does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
61
            $router->loadPath($path);
62
        }
63
64
        $events->fire('Cervo/System/Before');
65
66
        $route = $router->dispatch();
67
68
        if ($route instanceof Route) {
69
            $events->fire('Cervo/Route/Before');
70
            (new ControllerReflection($this->context, $route))();
71
            $events->fire('Cervo/Route/After');
72
        }
73
74
        $events->fire('Cervo/System/After');
75
76
        // TODO: Implement Routing and Controllers logic
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
77
    }
78
79
    public function getContext()
80
    {
81
        return $this->context;
82
    }
83
}
84