|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Webfactory\ShortcodeBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Loads the bundle configuration. |
|
13
|
|
|
*/ |
|
14
|
|
|
final class WebfactoryShortcodeExtension extends Extension |
|
15
|
|
|
{ |
|
16
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
17
|
|
|
{ |
|
18
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
19
|
|
|
$loader->load('shortcodes.xml'); |
|
20
|
|
|
$loader->load('guide.xml'); |
|
21
|
|
|
|
|
22
|
|
|
$configuration = new Configuration(); |
|
23
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
24
|
|
|
|
|
25
|
|
|
$container->setAlias('webfactory_shortcode.parser', 'webfactory_shortcode.'.$config['parser'].'_parser'); |
|
26
|
|
|
|
|
27
|
|
|
$container->setParameter('webfactory_shortcode.recursion_depth', $config['recursion_depth']); |
|
28
|
|
|
$container->setParameter('webfactory_shortcode.max_iterations', $config['max_iterations']); |
|
29
|
|
|
|
|
30
|
|
|
foreach ($config['shortcodes'] as $shortcodeName => $shortcodeDefinition) { |
|
31
|
|
|
$definition = new ChildDefinition('Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.'.$shortcodeDefinition['method']); |
|
32
|
|
|
$definition->replaceArgument(1, $shortcodeDefinition['controller']); |
|
33
|
|
|
$definition->addTag('webfactory.shortcode', ['shortcode' => $shortcodeName, 'description' => $shortcodeDefinition['description'], 'example' => $shortcodeDefinition['example']]); |
|
34
|
|
|
$container->setDefinition('webfactory_shortcode.handler.'.$shortcodeName, $definition); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|