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
|
|
|
|