Completed
Pull Request — master (#34)
by Wachter
23:54
created

TaskExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 38
ccs 16
cts 18
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 17 2
A loadDoctrineAdapter() 0 8 2
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\Definition;
17
use Symfony\Component\DependencyInjection\Loader;
18
use Symfony\Component\DependencyInjection\Reference;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
use Task\Event\Events;
21
use Task\TaskBundle\EventListener\TaskExecutionListener;
22
23
/**
24
 * Container extension for php-task library.
25
 */
26
class TaskExtension extends Extension
27
{
28 15
    /**
29
     * {@inheritdoc}
30 15
     */
31 15
    public function load(array $configs, ContainerBuilder $container)
32
    {
33 15
        $configuration = new Configuration();
34 15
        $config = $this->processConfiguration($configuration, $configs);
35 15
36 15
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
37 15
        $loader->load(sprintf('storage/%s.xml', $config['storage']));
38
        $loader->load('task_event_listener.xml');
39 15
        $loader->load('scheduler.xml');
40
        $loader->load('command.xml');
41
42
        if ($config['run']['mode'] === 'listener') {
43 15
            $loader->load('listener.xml');
44
        }
45 15
46 15
        $this->loadDoctrineAdapter($config['adapters']['config'], $container);
47 15
    }
48 15
49 15
    /**
50 15
     * Load doctrine adapter.
51
     *
52
     * @param array $config
53
     * @param ContainerBuilder $container
54
     */
55
    private function loadDoctrineAdapter(array $config, ContainerBuilder $container)
56
    {
57
        if ($config['clear']) {
58
            $definition = new Definition(TaskExecutionListener::class, [new Reference('doctrine.orm.entity_manager')]);
59
            $definition->addTag(Events::TASK_AFTER, ['method' => 'clearEntityManagerAfterTask']);
60
            $container->setDefinition('task.adapter.doctrine.execution_listener', $definition);
61
        }
62
    }
63
}
64