|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
namespace Symfony\Component\HttpKernel\DependencyInjection; |
|
|
4 |
|
|
|
5 |
use Symfony\Component\Config\Definition\Processor; |
|
|
6 |
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
|
7 |
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; |
|
|
8 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
9 |
use Symfony\Component\DependencyInjection\Container; |
|
|
10 |
|
|
|
11 |
/* |
|
|
12 |
* This file is part of the Symfony framework. |
|
|
13 |
* |
|
|
14 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
15 |
* |
|
|
16 |
* This source file is subject to the MIT license that is bundled |
|
|
17 |
* with this source code in the file LICENSE. |
|
|
18 |
*/ |
|
|
19 |
|
|
|
20 |
/** |
|
|
21 |
* Provides useful features shared by many extensions. |
|
|
22 |
* |
|
|
23 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
24 |
*/ |
|
|
25 |
abstract class Extension implements ExtensionInterface |
|
|
26 |
{ |
|
|
27 |
private $classes = array(); |
|
|
28 |
|
|
|
29 |
/** |
|
|
30 |
* Gets the classes to cache. |
|
|
31 |
* |
|
|
32 |
* @return array An array of classes |
|
|
33 |
*/ |
|
|
34 |
public function getClassesToCompile() |
|
|
35 |
{ |
|
|
36 |
return $this->classes; |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
/** |
|
|
40 |
* Adds classes to the class cache. |
|
|
41 |
* |
|
|
42 |
* @param array $classes An array of classes |
|
|
43 |
*/ |
|
|
44 |
public function addClassesToCompile(array $classes) |
|
|
45 |
{ |
|
|
46 |
$this->classes = array_merge($this->classes, $classes); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
/** |
|
|
50 |
* Returns the base path for the XSD files. |
|
|
51 |
* |
|
|
52 |
* @return string The XSD base path |
|
|
53 |
*/ |
|
|
54 |
public function getXsdValidationBasePath() |
|
|
55 |
{ |
|
|
56 |
return false; |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
/** |
|
|
60 |
* Returns the namespace to be used for this extension (XML namespace). |
|
|
61 |
* |
|
|
62 |
* @return string The XML namespace |
|
|
63 |
*/ |
|
|
64 |
public function getNamespace() |
|
|
65 |
{ |
|
|
66 |
return 'http://example.org/schema/dic/'.$this->getAlias(); |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
/** |
|
|
70 |
* Returns the recommended alias to use in XML. |
|
|
71 |
* |
|
|
72 |
* This alias is also the mandatory prefix to use when using YAML. |
|
|
73 |
* |
|
|
74 |
* This convention is to remove the "Extension" postfix from the class |
|
|
75 |
* name and then lowercase and underscore the result. So: |
|
|
76 |
* |
|
|
77 |
* AcmeHelloExtension |
|
|
78 |
* |
|
|
79 |
* becomes |
|
|
80 |
* |
|
|
81 |
* acme_hello |
|
|
82 |
* |
|
|
83 |
* This can be overridden in a sub-class to specify the alias manually. |
|
|
84 |
* |
|
|
85 |
* @return string The alias |
|
|
86 |
*/ |
|
|
87 |
public function getAlias() |
|
|
88 |
{ |
|
|
89 |
$className = get_class($this); |
|
|
90 |
if (substr($className, -9) != 'Extension') { |
|
|
91 |
throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.'); |
|
|
92 |
} |
|
|
93 |
$classBaseName = substr(strrchr($className, '\\'), 1, -9); |
|
|
94 |
|
|
|
95 |
return Container::underscore($classBaseName); |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
protected final function processConfiguration(ConfigurationInterface $configuration, array $configs) |
|
|
99 |
{ |
|
|
100 |
$processor = new Processor(); |
|
|
101 |
|
|
|
102 |
return $processor->processConfiguration($configuration, $configs); |
|
|
103 |
} |
|
|
104 |
} |