-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWebfactoryShortcodeExtension.php
More file actions
37 lines (30 loc) · 1.73 KB
/
WebfactoryShortcodeExtension.php
File metadata and controls
37 lines (30 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Webfactory\ShortcodeBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
/**
* Loads the bundle configuration.
*/
final class WebfactoryShortcodeExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('shortcodes.php');
$loader->load('guide.php');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setAlias('webfactory_shortcode.parser', 'webfactory_shortcode.'.$config['parser'].'_parser');
$container->setParameter('webfactory_shortcode.recursion_depth', $config['recursion_depth']);
$container->setParameter('webfactory_shortcode.max_iterations', $config['max_iterations']);
foreach ($config['shortcodes'] as $shortcodeName => $shortcodeDefinition) {
$definition = new ChildDefinition('Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.'.$shortcodeDefinition['method']);
$definition->replaceArgument(1, $shortcodeDefinition['controller']);
$definition->addTag('webfactory.shortcode', ['shortcode' => $shortcodeName, 'description' => $shortcodeDefinition['description'], 'example' => $shortcodeDefinition['example']]);
$container->setDefinition('webfactory_shortcode.handler.'.$shortcodeName, $definition);
}
}
}