1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the ekino Drupal Debug project. |
7
|
|
|
* |
8
|
|
|
* (c) ekino |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\Drupal\Debug\Configuration\Model; |
15
|
|
|
|
16
|
|
|
use Composer\Autoload\ClassLoader; |
17
|
|
|
use Ekino\Drupal\Debug\Configuration\ConfigurationManager; |
18
|
|
|
|
19
|
|
|
class SubstituteOriginalDrupalKernelConfiguration extends AbstractConfiguration |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ClassLoader|null |
23
|
|
|
*/ |
24
|
|
|
private $classLoader; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param array $processedConfiguration |
28
|
|
|
*/ |
29
|
2 |
|
public function __construct(array $processedConfiguration) |
30
|
|
|
{ |
31
|
2 |
|
parent::__construct($processedConfiguration); |
32
|
|
|
|
33
|
2 |
|
$this->classLoader = null; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function isEnabled(): bool |
40
|
|
|
{ |
41
|
|
|
return $this->processedConfiguration['enabled']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return ClassLoader |
46
|
|
|
*/ |
47
|
|
|
public function getClassLoader(): ClassLoader |
48
|
|
|
{ |
49
|
|
|
if (!$this->classLoader instanceof ClassLoader) { |
50
|
|
|
if (!$this->isEnabled()) { |
51
|
|
|
throw new \LogicException('The class loader getter should not be called if the original DrupalKernel substitution is disabled.'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$classLoader = require $this->processedConfiguration['composer_autoload_file_path']; |
55
|
|
|
if (!$classLoader instanceof ClassLoader) { |
56
|
|
|
throw new \RuntimeException(\sprintf('The composer autoload.php file did not return a "%s" instance.', ClassLoader::class)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->classLoader = $classLoader; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->classLoader; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getCacheDirectory(): string |
69
|
|
|
{ |
70
|
|
|
if (!$this->isEnabled()) { |
71
|
|
|
throw new \LogicException('The cache directory getter should not be called if the original DrupalKernel substitution is disabled.'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!isset($this->processedConfiguration['cache_directory'])) { |
75
|
|
|
return ConfigurationManager::getDefaultsConfiguration()->getCacheDirectory(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->processedConfiguration['cache_directory']; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
2 |
|
public function serialize(): ?string |
85
|
|
|
{ |
86
|
2 |
|
return \serialize(array( |
87
|
2 |
|
$this->processedConfiguration, |
88
|
|
|
null, |
89
|
|
|
)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public function unserialize($serialized): void |
96
|
|
|
{ |
97
|
|
|
list($this->processedConfiguration, $this->classLoader) = \unserialize($serialized); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|