| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of PHPUnit.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace PHPUnit\TextUI\XmlConfiguration;
|
|
|
11 |
|
|
|
12 |
use const PATH_SEPARATOR;
|
|
|
13 |
use function constant;
|
|
|
14 |
use function define;
|
|
|
15 |
use function defined;
|
|
|
16 |
use function getenv;
|
|
|
17 |
use function implode;
|
|
|
18 |
use function ini_get;
|
|
|
19 |
use function ini_set;
|
|
|
20 |
use function putenv;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @internal This class is not covered by the backward compatibility promise for PHPUnit
|
|
|
24 |
*/
|
|
|
25 |
final class PhpHandler
|
|
|
26 |
{
|
|
|
27 |
public function handle(Php $configuration): void
|
|
|
28 |
{
|
|
|
29 |
$this->handleIncludePaths($configuration->includePaths());
|
|
|
30 |
$this->handleIniSettings($configuration->iniSettings());
|
|
|
31 |
$this->handleConstants($configuration->constants());
|
|
|
32 |
$this->handleGlobalVariables($configuration->globalVariables());
|
|
|
33 |
$this->handleServerVariables($configuration->serverVariables());
|
|
|
34 |
$this->handleEnvVariables($configuration->envVariables());
|
|
|
35 |
$this->handleVariables('_POST', $configuration->postVariables());
|
|
|
36 |
$this->handleVariables('_GET', $configuration->getVariables());
|
|
|
37 |
$this->handleVariables('_COOKIE', $configuration->cookieVariables());
|
|
|
38 |
$this->handleVariables('_FILES', $configuration->filesVariables());
|
|
|
39 |
$this->handleVariables('_REQUEST', $configuration->requestVariables());
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
private function handleIncludePaths(DirectoryCollection $includePaths): void
|
|
|
43 |
{
|
|
|
44 |
if (!$includePaths->isEmpty()) {
|
|
|
45 |
$includePathsAsStrings = [];
|
|
|
46 |
|
|
|
47 |
foreach ($includePaths as $includePath) {
|
|
|
48 |
$includePathsAsStrings[] = $includePath->path();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
ini_set(
|
|
|
52 |
'include_path',
|
|
|
53 |
implode(PATH_SEPARATOR, $includePathsAsStrings) .
|
|
|
54 |
PATH_SEPARATOR .
|
|
|
55 |
ini_get('include_path')
|
|
|
56 |
);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private function handleIniSettings(IniSettingCollection $iniSettings): void
|
|
|
61 |
{
|
|
|
62 |
foreach ($iniSettings as $iniSetting) {
|
|
|
63 |
$value = $iniSetting->value();
|
|
|
64 |
|
|
|
65 |
if (defined($value)) {
|
|
|
66 |
$value = (string) constant($value);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
ini_set($iniSetting->name(), $value);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
private function handleConstants(ConstantCollection $constants): void
|
|
|
74 |
{
|
|
|
75 |
foreach ($constants as $constant) {
|
|
|
76 |
if (!defined($constant->name())) {
|
|
|
77 |
define($constant->name(), $constant->value());
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private function handleGlobalVariables(VariableCollection $variables): void
|
|
|
83 |
{
|
|
|
84 |
foreach ($variables as $variable) {
|
|
|
85 |
$GLOBALS[$variable->name()] = $variable->value();
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
private function handleServerVariables(VariableCollection $variables): void
|
|
|
90 |
{
|
|
|
91 |
foreach ($variables as $variable) {
|
|
|
92 |
$_SERVER[$variable->name()] = $variable->value();
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function handleVariables(string $target, VariableCollection $variables): void
|
|
|
97 |
{
|
|
|
98 |
foreach ($variables as $variable) {
|
|
|
99 |
$GLOBALS[$target][$variable->name()] = $variable->value();
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
private function handleEnvVariables(VariableCollection $variables): void
|
|
|
104 |
{
|
|
|
105 |
foreach ($variables as $variable) {
|
|
|
106 |
$name = $variable->name();
|
|
|
107 |
$value = $variable->value();
|
|
|
108 |
$force = $variable->force();
|
|
|
109 |
|
|
|
110 |
if ($force || getenv($name) === false) {
|
|
|
111 |
putenv("{$name}={$value}");
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
$value = getenv($name);
|
|
|
115 |
|
|
|
116 |
if ($force || !isset($_ENV[$name])) {
|
|
|
117 |
$_ENV[$name] = $value;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|