Kernel::critical()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * apparat-kernel
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Kernel
8
 * @subpackage  Apparat\Kernel\Ports
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Kernel\Ports;
38
39
use Apparat\Kernel\Domain\Contract\ModuleInterface;
40
use Apparat\Kernel\Infrastructure\DiceAdapter;
41
use Apparat\Kernel\Infrastructure\Logger;
42
use Psr\Log\LogLevel;
43
44
/**
45
 * Kernel facade
46
 *
47
 * @package Apparat\Kernel
48
 * @subpackage Apparat\Kernel\Ports
49
 */
50
class Kernel
51
{
52
    /**
53
     * Kernel instance
54
     *
55
     * @var \Apparat\Kernel\Domain\Model\Kernel
56
     */
57
    protected static $kernel = null;
58
59
    /**
60
     * Register an apparat module
61
     *
62
     * @param ModuleInterface $module Apparat module
63
     */
64 2
    public static function register(ModuleInterface $module)
65
    {
66 2
        self::getKernel()->register($module);
67 2
    }
68
69
    /**
70
     * Create an object instance
71
     *
72
     * @param string $name Object class name
73
     * @param array $args Object constructor arguments
74
     * @return object Object instance
75
     */
76 1
    public static function create($name, array $args = [])
77
    {
78 1
        return self::getKernel()->create($name, $args);
79
    }
80
81
    /**
82
     * System is unusable
83
     *
84
     * @param string $message
85
     * @param array $context
86
     * @return null
87
     */
88 1
    public static function emergency($message, array $context = array())
89
    {
90 1
        self::getKernel()->log(LogLevel::EMERGENCY, $message, $context);
91 1
    }
92
93
    /**
94
     * Action must be taken immediately
95
     *
96
     * Example: Entire website down, database unavailable, etc. This should
97
     * trigger the SMS alerts and wake you up.
98
     *
99
     * @param string $message
100
     * @param array $context
101
     * @return null
102
     */
103 1
    public static function alert($message, array $context = array())
104
    {
105 1
        self::getKernel()->log(LogLevel::ALERT, $message, $context);
106 1
    }
107
108
    /**
109
     * Critical conditions
110
     *
111
     * Example: Application component unavailable, unexpected exception.
112
     *
113
     * @param string $message
114
     * @param array $context
115
     * @return null
116
     */
117 1
    public static function critical($message, array $context = array())
118
    {
119 1
        self::getKernel()->log(LogLevel::CRITICAL, $message, $context);
120 1
    }
121
122
    /**
123
     * Runtime errors that do not require immediate action but should typically
124
     * be logged and monitored
125
     *
126
     * @param string $message
127
     * @param array $context
128
     * @return null
129
     */
130 1
    public static function error($message, array $context = array())
131
    {
132 1
        self::getKernel()->log(LogLevel::ERROR, $message, $context);
133 1
    }
134
135
    /**
136
     * Exceptional occurrences that are not errors
137
     *
138
     * Example: Use of deprecated APIs, poor use of an API, undesirable things
139
     * that are not necessarily wrong.
140
     *
141
     * @param string $message
142
     * @param array $context
143
     * @return null
144
     */
145 1
    public static function warning($message, array $context = array())
146
    {
147 1
        self::getKernel()->log(LogLevel::WARNING, $message, $context);
148 1
    }
149
150
    /**
151
     * Normal but significant events
152
     *
153
     * @param string $message
154
     * @param array $context
155
     * @return null
156
     */
157 1
    public static function notice($message, array $context = array())
158
    {
159 1
        self::getKernel()->log(LogLevel::NOTICE, $message, $context);
160 1
    }
161
162
    /**
163
     * Interesting events
164
     *
165
     * Example: User logs in, SQL logs.
166
     *
167
     * @param string $message
168
     * @param array $context
169
     * @return null
170
     */
171 1
    public static function info($message, array $context = array())
172
    {
173 1
        self::getKernel()->log(LogLevel::INFO, $message, $context);
174 1
    }
175
176
    /**
177
     * Detailed debug information
178
     *
179
     * @param string $message
180
     * @param array $context
181
     * @return null
182
     */
183 1
    public static function debug($message, array $context = array())
184
    {
185 1
        self::getKernel()->log(LogLevel::DEBUG, $message, $context);
186 1
    }
187
188
    /**
189
     * Logs with an arbitrary level
190
     *
191
     * @param mixed $level
192
     * @param string $message
193
     * @param array $context
194
     * @return null
195
     */
196 1
    public static function log($level, $message, array $context = array())
197
    {
198 1
        self::getKernel()->log($level, $message, $context);
199 1
    }
200
201
    /**
202
     * Create and return the kernel instance
203
     *
204
     * @return \Apparat\Kernel\Domain\Model\Kernel Kernel instance
205
     */
206 2
    protected static function getKernel()
207
    {
208 2
        if (self::$kernel === null) {
209 1
            self::$kernel = new \Apparat\Kernel\Domain\Model\Kernel(new DiceAdapter(), new Logger());
210 1
        }
211
212 2
        return self::$kernel;
213
    }
214
}
215