|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Bldr.io |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Aaron Scherer <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bldr\Block\Core; |
|
13
|
|
|
|
|
14
|
|
|
use Bldr\DependencyInjection\AbstractBlock; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @author Aaron Scherer <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class BldrBlock extends AbstractBlock |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritDoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function assemble(array $config, SymfonyContainerBuilder $container) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->addTaskOptions($config, $this->originalConfiguration); |
|
28
|
|
|
|
|
29
|
|
|
$this->setParameter('name', $config['name']); |
|
30
|
|
|
$this->setParameter('description', $config['description']); |
|
31
|
|
|
$this->setParameter('profiles', $config['profiles']); |
|
32
|
|
|
$this->setParameter('jobs', $config['jobs']); |
|
33
|
|
|
|
|
34
|
|
|
$this->addService('bldr.dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher'); |
|
35
|
|
|
$this->addService('bldr.registry.job', 'Bldr\Registry\JobRegistry'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritDoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getCompilerPasses() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
new CompilerPass\CoreCompilerPass() |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritDoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function getConfigurationClass() |
|
52
|
|
|
{ |
|
53
|
|
|
return 'Bldr\Block\Core\Configuration'; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param array $configuration |
|
58
|
|
|
* @param array $configs |
|
59
|
|
|
*/ |
|
60
|
|
|
private function addTaskOptions(array &$configuration, array $configs) |
|
61
|
|
|
{ |
|
62
|
|
|
foreach ($configs as $config) { |
|
63
|
|
|
foreach ($configuration['jobs'] as $name => $job) { |
|
64
|
|
|
if (!isset($config['jobs'])) { |
|
65
|
|
|
continue; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
foreach ($job['tasks'] as $index => $task) { |
|
69
|
|
|
if (isset($config['jobs'][$name], $config['jobs'][$name]['tasks'][$index])) { |
|
70
|
|
|
$options = $config['jobs'][$name]['tasks'][$index]; |
|
71
|
|
|
$configuration['jobs'][$name]['tasks'][$index] = array_merge($task, $options); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
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_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.