1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\Behat3SymfonyExtension\Handler; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
5
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
6
|
|
|
use Yoanm\Behat3SymfonyExtension\Event\KernelEvent; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Handler to shutdown/boot sf kernel |
10
|
|
|
*/ |
11
|
|
|
class KernelHandler |
12
|
|
|
{ |
13
|
|
|
/** @var EventDispatcherInterface */ |
14
|
|
|
private $behatEventDispatcher; |
15
|
|
|
|
16
|
|
|
/** @var Kernel */ |
17
|
|
|
private $sfKernel; |
18
|
|
|
/** |
19
|
|
|
* @param EventDispatcherInterface $behatEventDispatcher |
20
|
|
|
* @param Kernel $sfKernel |
21
|
|
|
*/ |
22
|
4 |
|
public function __construct( |
23
|
|
|
EventDispatcherInterface $behatEventDispatcher, |
24
|
|
|
Kernel $sfKernel |
25
|
|
|
) { |
26
|
4 |
|
$this->behatEventDispatcher = $behatEventDispatcher; |
27
|
4 |
|
$this->sfKernel = $sfKernel; |
28
|
4 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return Kernel |
32
|
|
|
*/ |
33
|
1 |
|
public function getSfKernel() |
34
|
|
|
{ |
35
|
1 |
|
return $this->sfKernel; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Will reboot sf kernel |
40
|
|
|
*/ |
41
|
1 |
|
public function rebootSfKernel() |
42
|
|
|
{ |
43
|
1 |
|
$this->shutdownSfKernel(); |
44
|
1 |
|
$this->bootSfKernel(); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Will shutdown sf kernel |
49
|
|
|
*/ |
50
|
2 |
|
public function shutdownSfKernel() |
51
|
|
|
{ |
52
|
2 |
|
$event = new KernelEvent($this->sfKernel); |
53
|
2 |
|
$this->behatEventDispatcher->dispatch( |
54
|
2 |
|
KernelEvent::BEFORE_SHUTDOWN, |
55
|
|
|
$event |
56
|
2 |
|
); |
57
|
2 |
|
$this->sfKernel->shutdown(); |
58
|
2 |
|
$this->behatEventDispatcher->dispatch( |
59
|
2 |
|
KernelEvent::AFTER_SHUTDOWN, |
60
|
|
|
$event |
61
|
2 |
|
); |
62
|
2 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Will boot sf kernel |
66
|
|
|
*/ |
67
|
2 |
|
public function bootSfKernel() |
68
|
|
|
{ |
69
|
2 |
|
$event = new KernelEvent($this->sfKernel); |
70
|
2 |
|
$this->behatEventDispatcher->dispatch( |
71
|
2 |
|
KernelEvent::BEFORE_BOOT, |
72
|
|
|
$event |
73
|
2 |
|
); |
74
|
2 |
|
$this->sfKernel->boot(); |
75
|
2 |
|
$this->behatEventDispatcher->dispatch( |
76
|
2 |
|
KernelEvent::AFTER_BOOT, |
77
|
|
|
$event |
78
|
2 |
|
); |
79
|
2 |
|
} |
80
|
|
|
} |
81
|
|
|
|