Completed
Push — 2.0 ( ad4dbf...722633 )
by Vitaly
14:10 queued 04:13
created

Core::start()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 41
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 41
rs 8.5806
cc 4
eloc 14
nc 8
nop 1
1
<?php
2
namespace samsonphp\core;
3
4
use samsonframework\core\SystemInterface;
5
use samsonphp\config\Scheme;
6
use samsonphp\event\Event;
7
8
/**
9
 * Core
10
 *
11
 * @package samsonphp/core
12
 * @author Vitaly Iegorov <[email protected]>
13
 */
14
class Core implements CoreInterface
15
{
16
    /** @var string Current system environment */
17
    protected $environment;
18
19
    /** @var Module[] Loaded modules collection */
20
    protected $modules;
21
22
    /**
23
     * Core constructor
24
     */
25
    public function __construct()
26
    {
27
        // Fire core creation event
28
        Event::fire(self::E_CREATED, [&$this]);
29
    }
30
31
    /**
32
     * Change current system working environment.
33
     *
34
     * @param string $environment Environment identifier
35
     *
36
     * @return $this Chaining
37
     */
38
    public function environment($environment = Scheme::BASE)
39
    {
40
        $this->environment = $environment;
41
42
        // Fire core environment change
43
        Event::fire(self::E_ENVIRONMENT, [&$this, $environment]);
44
45
        return $this;
46
    }
47
48
    /**
49
     * Load module.
50
     *
51
     * @param ModuleInterface $instance Module ancestor for loading
52
     *
53
     * @return $this Chaining
54
     */
55
    public function load($instance, $alias = null)
56
    {
57
        // Fire core before module loading
58
        Event::fire(self::E_BEFORE_LOADED, [&$this, &$instance, $alias]);
59
60
        // Store module instance by alias or class name
61
        $this->modules[$alias ?: get_class($instance)] = $instance;
62
63
        // Fire core before module loading
64
        Event::fire(self::E_AFTER_LOADED, [&$this, &$instance, $alias]);
65
66
        return $this;
67
    }
68
}
69