forked from resquebundle/resque
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContainerAwareJob.php
69 lines (59 loc) · 1.55 KB
/
ContainerAwareJob.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace ResqueBundle\Resque;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Class ContainerAwareJob
* @package ResqueBundle\Resque
*/
abstract class ContainerAwareJob extends Job
{
/**
* @var KernelInterface
*/
private $kernel = NULL;
/**
* @param array $kernelOptions
*/
public function setKernelOptions(array $kernelOptions)
{
$this->args = \array_merge($this->args, $kernelOptions);
}
/**
*
*/
public function tearDown()
{
if ($this->kernel) {
$this->kernel->shutdown();
}
}
/**
* @return ContainerInterface
*/
protected function getContainer()
{
if ($this->kernel === NULL) {
$this->kernel = $this->createKernel();
$this->kernel->boot();
}
return $this->kernel->getContainer();
}
/**
* @return KernelInterface
*/
protected function createKernel()
{
$finder = new Finder();
$finder->name('*Kernel.php')->depth(0)->in($this->args['kernel.root_dir']);
$results = iterator_to_array($finder);
$file = current($results);
$class = $file->getBasename('.php');
require_once $file;
return new $class(
isset($this->args['kernel.environment']) ? $this->args['kernel.environment'] : 'dev',
isset($this->args['kernel.debug']) ? $this->args['kernel.debug'] : TRUE
);
}
}