This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
forked from michelsalib/BCCResqueBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContainerAwareJob.php
72 lines (58 loc) · 1.66 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
70
71
72
<?php
namespace BCC\ResqueBundle;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraints\DateTime;
abstract class ContainerAwareJob extends Job
{
/**
* @var KernelInterface
*/
private $kernel = null;
/**
* @return ContainerInterface
*/
protected function getContainer()
{
if ($this->kernel === null) {
$this->kernel = $this->createKernel();
$this->kernel->boot();
}
return $this->kernel->getContainer();
}
public function setKernelOptions(array $kernelOptions)
{
$this->args = \array_merge($this->args, $kernelOptions);
}
public function setBCCJobId($bccJobId)
{
$this->args['bcc_resque.job_id'] = $bccJobId;
}
public function getBCCJobId()
{
return $this->args['bcc_resque.job_id'];
}
/**
* @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
);
}
public function tearDown()
{
if ($this->kernel) {
$this->kernel->shutdown();
}
}
}