1 | <?php |
||
22 | class ArrayConfiguration implements ConfigurationInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | const PERSISTENCE = 'persistence'; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | const PERSISTENCE_ARGS = 'persistenceArgs'; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | const VARIABLE_RESOLVER = 'variableResolver'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | const WORKFLOW_FACTORY = 'factory'; |
||
43 | |||
44 | /** |
||
45 | * Флаг определяющий было ли иницилизированно workflow |
||
46 | * |
||
47 | * @var bool |
||
48 | */ |
||
49 | protected $initialized = true; |
||
50 | |||
51 | /** |
||
52 | * Фабрика для создания workflow |
||
53 | * |
||
54 | * @var WorkflowFactoryInterface |
||
55 | */ |
||
56 | protected $factory; |
||
57 | |||
58 | /** |
||
59 | * Хранилище состояния workflow |
||
60 | * |
||
61 | * @var WorkflowStoreInterface |
||
62 | */ |
||
63 | protected $workflowStore; |
||
64 | |||
65 | /** |
||
66 | * Имя класса хранилища состяония workflow |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $persistence; |
||
71 | |||
72 | /** |
||
73 | * Опции для настройки хранилища стостояния workflow |
||
74 | * |
||
75 | * @var array |
||
76 | */ |
||
77 | protected $persistenceArgs = []; |
||
78 | |||
79 | /** |
||
80 | * @var VariableResolverInterface |
||
81 | */ |
||
82 | protected $variableResolver; |
||
83 | |||
84 | /** |
||
85 | * @param $options |
||
86 | * |
||
87 | * @throws \OldTown\Workflow\Exception\FactoryException |
||
88 | * @throws \OldTown\Workflow\Config\Exception\InvalidVariableResolverException |
||
89 | * @throws \OldTown\Workflow\Config\Exception\InvalidWorkflowFactoryException |
||
90 | */ |
||
91 | 19 | public function __construct(array $options = []) |
|
95 | |||
96 | /** |
||
97 | * @param array $options |
||
98 | * |
||
99 | * @throws \OldTown\Workflow\Exception\FactoryException |
||
100 | * @throws \OldTown\Workflow\Config\Exception\InvalidVariableResolverException |
||
101 | * @throws \OldTown\Workflow\Config\Exception\InvalidWorkflowFactoryException |
||
102 | */ |
||
103 | 19 | protected function init(array $options = []) |
|
141 | |||
142 | /** |
||
143 | * @return WorkflowFactoryInterface |
||
144 | */ |
||
145 | public function getFactory() |
||
149 | |||
150 | /** |
||
151 | * Определяет была ли иницилазированна дананя конфигурация |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | 19 | public function isInitialized() |
|
159 | |||
160 | /** |
||
161 | * Определяет есть ли возможность модифицировать workflow с з |
||
162 | * |
||
163 | * @param string $name |
||
164 | * |
||
165 | * @return bool |
||
166 | */ |
||
167 | public function isModifiable($name) |
||
171 | |||
172 | /** |
||
173 | * Возвращает имя класса хранилища состяония workflow |
||
174 | * |
||
175 | * @return string |
||
176 | */ |
||
177 | 19 | public function getPersistence() |
|
181 | |||
182 | /** |
||
183 | * Возвращает опции для настройки хранилища стостояния workflow |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | 19 | public function getPersistenceArgs() |
|
191 | |||
192 | /** |
||
193 | * |
||
194 | * @return VariableResolverInterface |
||
195 | */ |
||
196 | 19 | public function getVariableResolver() |
|
200 | |||
201 | /** |
||
202 | * @param string $name |
||
203 | * |
||
204 | * @return WorkflowDescriptor |
||
205 | * |
||
206 | * @throws Exception\InvalidWorkflowDescriptorException |
||
207 | */ |
||
208 | 19 | public function getWorkflow($name) |
|
219 | |||
220 | /** |
||
221 | * @return \String[] |
||
222 | */ |
||
223 | public function getWorkflowNames() |
||
227 | |||
228 | /** |
||
229 | * @return WorkflowStoreInterface |
||
230 | * @throws Exception\StoreException |
||
231 | */ |
||
232 | 19 | public function getWorkflowStore() |
|
254 | |||
255 | /** |
||
256 | * @param UriInterface|null $url |
||
257 | * |
||
258 | * @throws Exception\MethodNotSupportedException |
||
259 | */ |
||
260 | public function load(UriInterface $url = null) |
||
265 | |||
266 | /** |
||
267 | * @param string $workflow |
||
268 | * |
||
269 | * @return bool|void |
||
270 | */ |
||
271 | public function removeWorkflow($workflow) |
||
275 | |||
276 | /** |
||
277 | * @param string $name |
||
278 | * @param WorkflowDescriptor $descriptor |
||
279 | * @param bool|false $replace |
||
280 | * |
||
281 | * @return bool|void |
||
282 | */ |
||
283 | public function saveWorkflow($name, WorkflowDescriptor $descriptor, $replace = false) |
||
287 | } |
||
288 |
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.