1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Incenteev\TranslationCheckerBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
6
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
|
10
|
|
|
class IncenteevTranslationCheckerExtension extends ConfigurableExtension |
11
|
|
|
{ |
12
|
4 |
|
public function loadInternal(array $config, ContainerBuilder $container) |
13
|
|
|
{ |
14
|
4 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
15
|
4 |
|
$loader->load('services.xml'); |
16
|
|
|
|
17
|
|
|
// supports autoconfiguration of extractors in Symfony 3.3+ |
18
|
4 |
|
if (method_exists($container, 'registerForAutoconfiguration')) { |
19
|
4 |
|
$container->registerForAutoconfiguration('Incenteev\TranslationCheckerBundle\Translator\Extractor\ExtractorInterface') |
20
|
4 |
|
->addTag('incenteev_translation_checker.extractor'); |
21
|
|
|
} |
22
|
|
|
|
23
|
4 |
|
$dirs = array(); |
24
|
4 |
|
$overridePath = '%%kernel.root_dir%%/Resources/%s/views'; |
25
|
4 |
|
$registeredBundles = $container->getParameter('kernel.bundles'); |
26
|
|
|
|
27
|
4 |
|
foreach ($config['extraction']['bundles'] as $bundle) { |
28
|
2 |
|
if (!isset($registeredBundles[$bundle])) { |
29
|
1 |
|
throw new \InvalidArgumentException(sprintf('The bundle %s is not registered in the kernel.', $bundle)); |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
$reflection = new \ReflectionClass($registeredBundles[$bundle]); |
33
|
1 |
|
$dirs[] = dirname($reflection->getFilename()).'/Resources/views'; |
34
|
1 |
|
$dirs[] = sprintf($overridePath, $bundle); |
35
|
|
|
} |
36
|
3 |
|
$dirs[] = '%kernel.root_dir%/Resources/views'; |
37
|
|
|
|
38
|
3 |
|
$container->setParameter('incenteev_translation_checker.extractor.symfony.paths', $dirs); |
39
|
3 |
|
} |
40
|
|
|
} |
41
|
|
|
|