|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MesHighlightBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Mes\Misc\HighlightBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
17
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class MesHighlightExtension. |
|
21
|
|
|
*/ |
|
22
|
|
|
class MesHighlightExtension extends ConfigurableExtension |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param array $config |
|
26
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Mes\Misc\HighlightBundle\DependencyInjection\Configuration |
|
29
|
|
|
*/ |
|
30
|
4 |
|
public function getConfiguration(array $config, ContainerBuilder $container) |
|
31
|
|
|
{ |
|
32
|
4 |
|
return new Configuration($container->getParameter('kernel.root_dir').'/Resources/'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @codeCoverageIgnore |
|
37
|
|
|
* |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getNamespace() |
|
41
|
|
|
{ |
|
42
|
|
|
return 'http://multimediaexperiencestudio.it/schema/dic/highlight'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @codeCoverageIgnore |
|
47
|
|
|
* |
|
48
|
|
|
* @return string|bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getXsdValidationBasePath() |
|
51
|
|
|
{ |
|
52
|
|
|
return __DIR__.'/../Resources/config/schema'; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Configures the passed container according to the merged configuration. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array $mergedConfig |
|
59
|
|
|
* @param ContainerBuilder $container |
|
60
|
|
|
*/ |
|
61
|
3 |
|
protected function loadInternal(array $mergedConfig, ContainerBuilder $container) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$loader = new XMLFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config')); |
|
64
|
3 |
|
$loader->load('highlighter.xml'); |
|
65
|
|
|
|
|
66
|
3 |
|
$container->setParameter('mes_highlight.supported_languages', $mergedConfig['supported_languages']); |
|
67
|
3 |
|
$container->setParameter('mes_highlight.root_path', $mergedConfig['root_path']); |
|
68
|
3 |
|
$container->setParameter('mes_highlight.left_code_delimiter', $mergedConfig['left_delimiter']); |
|
69
|
3 |
|
$container->setParameter('mes_highlight.right_code_delimiter', $mergedConfig['right_delimiter']); |
|
70
|
3 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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.