|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Goetas\TwitalBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Goetas\TwitalBundle\Assetic\DirectoryResourceDefinition; |
|
|
|
|
|
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
* @author Asmir Mustafic <[email protected]> |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
class GoetasTwitalExtension extends Extension |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritDoc} |
|
21
|
|
|
*/ |
|
22
|
7 |
|
public function load(array $configs, ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
7 |
|
$configuration = new Configuration(); |
|
25
|
7 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
26
|
|
|
|
|
27
|
7 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
28
|
7 |
|
$loader->load('twital.xml'); |
|
29
|
|
|
|
|
30
|
|
|
$regex = array(); |
|
31
|
7 |
|
$loaderDefinition = $container->getDefinition("twital.loader"); |
|
32
|
7 |
|
foreach ($config["source_adapters"] as $id => $regs) { |
|
33
|
7 |
|
foreach ($regs["pattern"] as $reg) { |
|
34
|
7 |
|
$regex[] = $reg; |
|
35
|
|
|
$loaderDefinition->addMethodCall('addSourceAdapter', array($reg, new Reference($id))); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
7 |
|
$container->setParameter("twital.loader_regexs", array_unique($regex)); |
|
39
|
7 |
|
|
|
40
|
1 |
|
$bundles = $container->getParameter("kernel.bundles"); |
|
41
|
|
|
if (isset($bundles["AsseticBundle"])) { |
|
42
|
|
|
$loader->load('assetic.xml'); |
|
43
|
7 |
|
} |
|
44
|
1 |
|
|
|
45
|
1 |
|
if (!empty($config["full_twig_compatibility"])) { |
|
46
|
|
|
$twitalDefinitioin = $container->getDefinition("twital"); |
|
47
|
|
|
$twitalDefinitioin->addMethodCall('addExtension', array(new Reference('twital.extension.full_twig_compatibility'))); |
|
48
|
7 |
|
} |
|
49
|
7 |
|
|
|
50
|
|
|
if (!class_exists('Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface')) { |
|
51
|
|
|
$container->removeDefinition('twital.cache_warmer'); |
|
52
|
7 |
|
} |
|
53
|
7 |
|
|
|
54
|
|
|
if (!interface_exists('Symfony\Component\Templating\EngineInterface') |
|
55
|
|
|
|| !class_exists('Symfony\Bundle\TwigBundle\TwigEngine')) { |
|
56
|
7 |
|
$container->removeDefinition('templating.engine.twital'); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: