|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Go! AOP framework |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Go\Symfony\GoAopBundle\DependencyInjection; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
18
|
|
|
|
|
19
|
|
|
class GoAopExtension extends Extension |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getNamespace() |
|
25
|
|
|
{ |
|
26
|
|
|
return 'http://go.aopphp.com/xsd-schema/go-aop-bundle'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getXsdValidationBasePath() |
|
33
|
|
|
{ |
|
34
|
|
|
return __DIR__ . '/../Resources/config/schema'; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Loads a specific configuration. |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $config An array of configuration values |
|
41
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
|
42
|
|
|
* |
|
43
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
|
44
|
|
|
* |
|
45
|
|
|
* @api |
|
46
|
|
|
*/ |
|
47
|
|
|
public function load(array $config, ContainerBuilder $container) |
|
48
|
|
|
{ |
|
49
|
|
|
$configurator = new Configuration(); |
|
50
|
|
|
$config = $this->processConfiguration($configurator, $config); |
|
51
|
|
|
|
|
52
|
|
|
$normalizedOptions = array(); |
|
53
|
|
|
foreach ($config['options'] as $optionKey => $value) { |
|
54
|
|
|
// this will convert 'under_scores' into 'underScores' |
|
55
|
|
|
$optionKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $optionKey)))); |
|
56
|
|
|
$normalizedOptions[$optionKey] = $value; |
|
57
|
|
|
} |
|
58
|
|
|
$container->setParameter('goaop.options', $normalizedOptions); |
|
59
|
|
|
|
|
60
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
61
|
|
|
$loader->load('services.xml'); |
|
62
|
|
|
$loader->load('commands.xml'); |
|
63
|
|
|
|
|
64
|
|
|
if ($config['cache_warmer']) { |
|
65
|
|
|
$definition = $container->getDefinition('goaop.cache.warmer'); |
|
66
|
|
|
$definition->addTag('kernel.cache_warmer'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($config['doctrine_support']) { |
|
70
|
|
|
$container |
|
71
|
|
|
->getDefinition('goaop.bridge.doctrine.metadata_load_interceptor') |
|
72
|
|
|
->addTag('doctrine.event_subscriber'); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
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.