1 | <?php |
||
11 | class Level |
||
12 | { |
||
13 | const DEFAULT_VALUE = self::DEBUG; |
||
14 | |||
15 | const DEBUG = 100; |
||
16 | const INFO = 200; |
||
17 | const NOTICE = 300; |
||
18 | const WARNING = 400; |
||
19 | const ERROR = 500; |
||
20 | const CRITICAL = 600; |
||
21 | const ALERT = 700; |
||
22 | const EMERGENCY = 800; |
||
23 | |||
24 | /** @var array */ |
||
25 | public static $names = [ |
||
26 | self::DEBUG => LogLevel::DEBUG, |
||
27 | self::INFO => LogLevel::INFO, |
||
28 | self::NOTICE => LogLevel::NOTICE, |
||
29 | self::WARNING => LogLevel::WARNING, |
||
30 | self::ERROR => LogLevel::ERROR, |
||
31 | self::CRITICAL => LogLevel::CRITICAL, |
||
32 | self::ALERT => LogLevel::ALERT, |
||
33 | self::EMERGENCY => LogLevel::EMERGENCY, |
||
34 | ]; |
||
35 | |||
36 | /** @var int */ |
||
37 | protected $level; |
||
38 | |||
39 | /** @var string */ |
||
40 | protected $name; |
||
41 | |||
42 | /** |
||
43 | * @param mixed $value |
||
44 | */ |
||
45 | 32 | public function __construct($value = self::DEFAULT_VALUE) |
|
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | 1 | public function __toString() |
|
57 | |||
58 | /** |
||
59 | * @param string $name |
||
60 | * |
||
61 | * @return Level |
||
62 | * @throws InvalidArgumentException |
||
63 | */ |
||
64 | 13 | public static function createFromName($name) |
|
78 | |||
79 | /** |
||
80 | * @return int |
||
81 | */ |
||
82 | 30 | public function getValue() |
|
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | 29 | public function getName() |
|
98 | |||
99 | /** |
||
100 | * @param mixed $value |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | 32 | protected function hasValue($value) |
|
110 | } |
||
111 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: