1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Composer plugin for config assembling |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/composer-config-plugin |
6
|
|
|
* @package composer-config-plugin |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\composer\config\utils; |
12
|
|
|
|
13
|
|
|
use Riimu\Kit\PHPEncoder\PHPEncoder; |
14
|
|
|
use hiqdev\composer\config\utils\RemoveArrayKeys; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Helper class. |
18
|
|
|
* |
19
|
|
|
* @author Andrii Vasyliev <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Helper |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Merges two or more arrays into one recursively. |
25
|
|
|
* Based on Yii2 yii\helpers\BaseArrayHelper::merge. |
26
|
|
|
* @return array the merged array |
27
|
|
|
*/ |
28
|
|
|
public static function mergeConfig(): array |
29
|
|
|
{ |
30
|
|
|
$args = \func_get_args(); |
31
|
|
|
$res = array_shift($args) ?: []; |
32
|
|
|
foreach ($args as $items) { |
33
|
|
|
if (!\is_array($items)) { |
34
|
|
|
continue; |
35
|
|
|
} |
36
|
|
|
foreach ($items as $k => $v) { |
37
|
|
|
if ($v instanceof \yii\helpers\UnsetArrayValue || $v instanceof \Yiisoft\Arrays\UnsetArrayValue) { |
|
|
|
|
38
|
|
|
unset($res[$k]); |
39
|
|
|
} elseif ($v instanceof \yii\helpers\ReplaceArrayValue || $v instanceof \Yiisoft\Arrays\ReplaceArrayValue) { |
|
|
|
|
40
|
|
|
$res[$k] = $v->value; |
41
|
|
|
} elseif (\is_int($k)) { |
42
|
|
|
/// XXX skip repeated values |
43
|
|
|
if (\in_array($v, $res, true)) { |
44
|
|
|
continue; |
45
|
|
|
} |
46
|
|
|
if (isset($res[$k])) { |
47
|
|
|
$res[] = $v; |
48
|
|
|
} else { |
49
|
|
|
$res[$k] = $v; |
50
|
|
|
} |
51
|
|
|
} elseif (\is_array($v) && isset($res[$k]) && \is_array($res[$k])) { |
52
|
|
|
$res[$k] = self::mergeConfig($res[$k], $v); |
53
|
|
|
} else { |
54
|
|
|
$res[$k] = $v; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $res; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public static function fixConfig(array $config): array |
63
|
|
|
{ |
64
|
|
|
$remove = false; |
65
|
|
|
foreach ($config as $key => &$value) { |
66
|
|
|
if (is_array($value)) { |
67
|
|
|
$value = static::fixConfig($value); |
68
|
|
|
} elseif ($value instanceof RemoveArrayKeys) { |
69
|
|
|
$remove = true; |
70
|
|
|
unset($config[$key]); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
if ($remove) { |
74
|
|
|
return array_values($config); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $config; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public static function exportDefines(array $defines): string |
81
|
|
|
{ |
82
|
|
|
$res = ''; |
83
|
|
|
foreach ($defines as $key => $value) { |
84
|
|
|
$var = static::exportVar($value); |
85
|
|
|
$res .= "defined('$key') or define('$key', $var);\n"; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $res; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns PHP-executable string representation of given value. |
93
|
|
|
* Uses Riimu/Kit-PHPEncoder based `var_export` alternative. |
94
|
|
|
* And Opis/Closure to dump closures as PHP code. |
95
|
|
|
* @param mixed $value |
96
|
|
|
* @return string |
97
|
|
|
* @throws \ReflectionException |
98
|
|
|
*/ |
99
|
|
|
public static function exportVar($value): string |
100
|
|
|
{ |
101
|
|
|
return static::getEncoder()->encode($value); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
private static $encoder; |
105
|
|
|
|
106
|
|
|
private static function getEncoder() |
107
|
|
|
{ |
108
|
|
|
if (static::$encoder === null) { |
|
|
|
|
109
|
|
|
static::$encoder = static::createEncoder(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return static::$encoder; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
private static function createEncoder() |
116
|
|
|
{ |
117
|
|
|
$encoder = new PHPEncoder([ |
118
|
|
|
'object.format' => 'serialize', |
119
|
|
|
]); |
120
|
|
|
$encoder->addEncoder(new ClosureEncoder(), true); |
121
|
|
|
|
122
|
|
|
return $encoder; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths