Passed
Push — master ( eb3d65...8de60e )
by Andreas
18:09
created

midcom   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 76
ccs 4
cts 18
cp 0.2222
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register_service_class() 0 3 1
A init() 0 12 2
A get() 0 11 3
A get_registered_service_classes() 0 3 1
1
<?php
2
/**
3
 * @package midcom
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * @package midcom
11
 */
12
class midcom
13
{
14
    /**
15
     * MidCOM version
16
     *
17
     * @var string
18
     */
19
    const VERSION = '9.8.0+git';
20
21
    /**
22
     * Main application singleton
23
     *
24
     * @var midcom_application
25
     */
26
    private static $_application;
27
28
    /**
29
     * Mapping of service names to classes implementing the service
30
     */
31
    private static $_service_classes = [];
32
33
    /**
34
     * @throws midcom_error
35
     */
36
    public static function init(string $environment = 'prod', bool $debug = false) : midcom_application
37
    {
38
        // Instantiate the MidCOM main class
39
        self::$_application = new midcom_application($environment, $debug);
40
41
        // Define default constants
42
        if (!defined('MIDCOM_STATIC_URL')) {
43
            define('MIDCOM_STATIC_URL', '/midcom-static');
44
        }
45
        define('MIDCOM_STATIC_ROOT', self::$_application->getProjectDir() . '/web' . MIDCOM_STATIC_URL);
46
        define('OPENPSA2_THEME_ROOT', self::$_application->getProjectDir() . '/var/themes/');
47
        return self::$_application;
48
    }
49
50
    /**
51
     * Get midcom_application instance
52
     *
53
     * Services can also be loaded this way by passing their name as an argument,
54
     * but this feature will likely be removed at some point
55
     *
56
     * @param string $name The service name as listed in the _service_classes array or null to get midcom_application
57
     * @return midcom_application The midcom application instance
58
     */
59 712
    public static function get(string $name = null)
60
    {
61 712
        if (!self::$_application) {
62
            self::init();
63
        }
64
65 712
        if (null === $name) {
66 712
            return self::$_application;
67
        }
68
69
        return self::$_application->getContainer()->get($name);
70
    }
71
72
    /**
73
     * Register a service class
74
     *
75
     * (Experimental, use with caution)
76
     */
77
    public static function register_service_class(string $name, string $class)
78
    {
79
        self::$_service_classes[$name] = $class;
80
    }
81
82
    /**
83
     * @internal
84
     */
85
    public static function get_registered_service_classes() : array
86
    {
87
        return self::$_service_classes;
88
    }
89
}
90