1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; |
4
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
7
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
8
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
9
|
|
|
use Task\TaskBundle\TaskBundle; |
10
|
|
|
|
11
|
|
|
class TestKernel extends Kernel |
12
|
|
|
{ |
13
|
|
|
const STORAGE_VAR_NAME = 'STORAGE'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $storage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public function registerBundles() |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
new FrameworkBundle(), |
27
|
|
|
new DoctrineBundle(), |
28
|
|
|
new TaskBundle(), |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
36
|
|
|
{ |
37
|
|
|
$this->storage = getenv(self::STORAGE_VAR_NAME); |
38
|
|
|
if ($this->storage === false) { |
39
|
|
|
$this->storage = 'array'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$loader->load(sprintf('%s/config/config.yml', __DIR__)); |
43
|
|
|
$loader->load(sprintf('%s/config/config.%s.yml', __DIR__, $this->storage)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
protected function buildContainer() |
50
|
|
|
{ |
51
|
|
|
$container = parent::buildContainer(); |
52
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config')); |
53
|
|
|
$loader->load('services.xml'); |
54
|
|
|
|
55
|
|
|
$container->setParameter('kernel.storage', $this->storage); |
56
|
|
|
|
57
|
|
|
return $container; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
protected function initializeContainer() |
64
|
|
|
{ |
65
|
|
|
$fresh = false; |
66
|
|
|
|
67
|
|
|
$container = $this->buildContainer(); |
68
|
|
|
$container->compile(); |
69
|
|
|
|
70
|
|
|
$this->container = $container; |
71
|
|
|
$this->container->set('kernel', $this); |
72
|
|
|
|
73
|
|
|
if (!$fresh && $this->container->has('cache_warmer')) { |
74
|
|
|
$this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
class TestHandler implements \Task\Handler\HandlerInterface |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function handle($workload) |
85
|
|
|
{ |
86
|
|
|
return strrev($workload); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.