Completed
Push — master ( e2c326...ee1def )
by Wachter
06:24
created

TaskExtension::load()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3.0123

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 16
cts 18
cp 0.8889
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 2
crap 3.0123
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader;
17
use Symfony\Component\DependencyInjection\Reference;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
/**
21
 * Container extension for php-task library.
22
 */
23
class TaskExtension extends Extension
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 15
    public function load(array $configs, ContainerBuilder $container)
29
    {
30 15
        $configuration = new Configuration();
31 15
        $config = $this->processConfiguration($configuration, $configs);
32
33 15
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
34 15
        $loader->load(sprintf('storage/%s.xml', $config['storage']));
35 15
        $loader->load('task_event_listener.xml');
36 15
        $loader->load('scheduler.xml');
37 15
        $loader->load('command.xml');
38
39 15
        if ($config['run']['mode'] === 'listener') {
40
            $loader->load('listener.xml');
41
        }
42
43 15
        if ('doctrine' === $config['storage']) {
44
            // FIXME move to compiler pass
45 15
            $container->getDefinition('task.command.schedule_task')
46 15
                ->addArgument(new Reference('doctrine.orm.entity_manager'));
47 15
            $container->getDefinition('task.command.run')
48 15
                ->addArgument(new Reference('doctrine.orm.entity_manager'));
49 15
        }
50 15
    }
51
}
52