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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Codeception\Lib\Connector;
class Symfony extends \Symfony\Component\HttpKernel\Client
{
/**
* @var boolean
*/
private $rebootable = true;
/**
* @var boolean
*/
private $hasPerformedRequest = false;
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
private $container = null;
/**
* @var array
*/
public $persistentServices = [];
/**
* Constructor.
*
* @param \Symfony\Component\HttpKernel\Kernel $kernel A booted HttpKernel instance
* @param array $services An injected services
* @param boolean $rebootable
*/
public function __construct(\Symfony\Component\HttpKernel\Kernel $kernel, array $services = [], $rebootable = true)
{
parent::__construct($kernel);
$this->followRedirects(true);
$this->rebootable = (boolean)$rebootable;
$this->persistentServices = $services;
$this->rebootKernel();
}
/**
* @param \Symfony\Component\HttpFoundation\Request $request
*/
protected function doRequest($request)
{
if ($this->rebootable) {
if ($this->hasPerformedRequest) {
$this->rebootKernel();
} else {
$this->hasPerformedRequest = true;
}
}
return parent::doRequest($request);
}
/**
* Reboot kernel
*
* Services from the list of persistent services
* are updated from service container before kernel shutdown
* and injected into newly initialized container after kernel boot.
*/
public function rebootKernel()
{
if ($this->container) {
foreach ($this->persistentServices as $serviceName => $service) {
if ($this->container->has($serviceName)) {
$this->persistentServices[$serviceName] = $this->container->get($serviceName);
}
}
}
$this->kernel->shutdown();
$this->kernel->boot();
$this->container = $this->kernel->getContainer();
if ($this->container->has('profiler')) {
$this->container->get('profiler')->enable();
}
foreach ($this->persistentServices as $serviceName => $service) {
$this->container->set($serviceName, $service);
}
}
}