|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\RedirectBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
|
6
|
|
|
use Symfony\Component\Config\FileLocator; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
9
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Kevin Bond <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class ZenstruckRedirectExtension extends ConfigurableExtension |
|
15
|
|
|
{ |
|
16
|
7 |
|
protected function loadInternal(array $mergedConfig, ContainerBuilder $container) |
|
17
|
|
|
{ |
|
18
|
7 |
|
if (null === $mergedConfig['redirect_class'] && null === $mergedConfig['not_found_class']) { |
|
19
|
1 |
|
throw new InvalidConfigurationException('A "redirect_class" or "not_found_class" must be set for "zenstruck_redirect".'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
6 |
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
23
|
6 |
|
$modelManagerName = $mergedConfig['model_manager_name'] ?: 'default'; |
|
24
|
|
|
|
|
25
|
6 |
|
$container->setAlias('zenstruck_redirect.entity_manager', \sprintf('doctrine.orm.%s_entity_manager', $modelManagerName)); |
|
26
|
|
|
|
|
27
|
6 |
|
if (null !== $mergedConfig['redirect_class']) { |
|
28
|
5 |
|
$container->setParameter('zenstruck_redirect.redirect_class', $mergedConfig['redirect_class']); |
|
29
|
|
|
|
|
30
|
5 |
|
$loader->load('redirect.xml'); |
|
31
|
5 |
|
$loader->load('form.xml'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
6 |
|
if (null !== $mergedConfig['not_found_class']) { |
|
35
|
4 |
|
$container->setParameter('zenstruck_redirect.not_found_class', $mergedConfig['not_found_class']); |
|
36
|
|
|
|
|
37
|
4 |
|
$loader->load('not_found.xml'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
6 |
|
if ($mergedConfig['remove_not_founds'] && null !== $mergedConfig['not_found_class'] && null !== $mergedConfig['redirect_class']) { |
|
41
|
2 |
|
$loader->load('remove_not_found_subscriber.xml'); |
|
42
|
|
|
} |
|
43
|
6 |
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|