1 | <?php |
||
29 | class FluentHandler extends AbstractProcessingHandler |
||
30 | { |
||
31 | /** @var LoggerInterface */ |
||
32 | protected $logger; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $tagFormat = '{{channel}}.{{level_name}}'; |
||
36 | |||
37 | /** |
||
38 | * FluentHandler constructor. |
||
39 | * |
||
40 | * @param LoggerInterface $logger |
||
41 | * @param null|string $tagFormat |
||
42 | * @param int $level |
||
43 | * @param bool $bubble |
||
44 | */ |
||
45 | public function __construct( |
||
57 | |||
58 | /** |
||
59 | * @param array $record |
||
60 | */ |
||
61 | protected function write(array $record) |
||
73 | |||
74 | /** |
||
75 | * @param array $record |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | protected function populateTag(array $record): string |
||
83 | |||
84 | /** |
||
85 | * @param array $record |
||
86 | * @param string $tag |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | protected function processFormat(array $record, string $tag): string |
||
103 | |||
104 | /** |
||
105 | * returns the context |
||
106 | * @return array | string |
||
107 | */ |
||
108 | protected function getContext($context) |
||
115 | |||
116 | /** |
||
117 | * Identifies the content type of the given $context |
||
118 | * @param mixed $context |
||
119 | * @return bool |
||
120 | */ |
||
121 | protected function contextHasException($context): bool |
||
129 | |||
130 | /** |
||
131 | * Returns the entire exception trace as a string |
||
132 | * @param array $context |
||
133 | * @return string |
||
134 | */ |
||
135 | protected function getContextExceptionTrace(array $context): string |
||
139 | |||
140 | /** |
||
141 | * @return LoggerInterface |
||
142 | */ |
||
143 | public function getLogger(): LoggerInterface |
||
147 | } |
||
148 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.