|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mpclarkson\ResqueBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
8
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* This is the class that loads and manages your bundle configuration |
|
12
|
|
|
* |
|
13
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
|
14
|
|
|
*/ |
|
15
|
|
|
class ResqueExtension extends Extension |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritDoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
21
|
|
|
{ |
|
22
|
|
|
$configuration = new Configuration(); |
|
23
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
24
|
|
|
|
|
25
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
26
|
|
|
$loader->load('services.xml'); |
|
27
|
|
|
|
|
28
|
|
|
$container->setParameter('resque.vendor_dir', $config['vendor_dir']); |
|
29
|
|
|
$container->setParameter('resque.app_include', $config['app_include']); |
|
30
|
|
|
$container->setParameter('resque.class', $config['class']); |
|
31
|
|
|
$container->setParameter('resque.redis.host', $config['redis']['host']); |
|
32
|
|
|
$container->setParameter('resque.redis.port', $config['redis']['port']); |
|
33
|
|
|
$container->setParameter('resque.redis.database', $config['redis']['database']); |
|
34
|
|
|
|
|
35
|
|
|
if (!empty($config['prefix'])) { |
|
36
|
|
|
$container->setParameter('resque.prefix', $config['prefix']); |
|
37
|
|
|
$container->getDefinition('resque')->addMethodCall('setPrefix', [$config['prefix']]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if (!empty($config['worker']['root_dir'])) { |
|
41
|
|
|
$container->setParameter('resque.worker.root_dir', $config['worker']['root_dir']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (!empty($config['auto_retry'])) { |
|
45
|
|
|
if (isset($config['auto_retry'][0])) { |
|
46
|
|
|
$container->getDefinition('resque')->addMethodCall('setGlobalRetryStrategy', [$config['auto_retry'][0]]); |
|
47
|
|
|
} else { |
|
48
|
|
|
if (isset($config['auto_retry']['default'])) { |
|
49
|
|
|
$container->getDefinition('resque')->addMethodCall('setGlobalRetryStrategy', [$config['auto_retry']['default']]); |
|
50
|
|
|
unset($config['auto_retry']['default']); |
|
51
|
|
|
} |
|
52
|
|
|
$container->getDefinition('resque')->addMethodCall('setJobRetryStrategy', [$config['auto_retry']]); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|