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; |
12
|
|
|
|
13
|
|
|
use Closure; |
14
|
|
|
use Riimu\Kit\PHPEncoder\PHPEncoder; |
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 exportDefines(array $defines): string |
63
|
|
|
{ |
64
|
|
|
$res = ''; |
65
|
|
|
foreach ($defines as $key => $value) { |
66
|
|
|
$var = static::exportVar($value); |
67
|
|
|
$res .= "defined('$key') or define('$key', $var);\n"; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $res; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns PHP-executable string representation of given value. |
75
|
|
|
* Uses Riimu/Kit-PHPEncoder based `var_export` alternative. |
76
|
|
|
* And Opis/Closure to dump closures as PHP code. |
77
|
|
|
* @param mixed $value |
78
|
|
|
* @return string |
79
|
|
|
* @throws \ReflectionException |
80
|
|
|
*/ |
81
|
|
|
public static function exportVar($value): string |
82
|
|
|
{ |
83
|
|
|
return static::getEncoder()->encode($value); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private static $encoder; |
87
|
|
|
|
88
|
|
|
private static function getEncoder() |
89
|
|
|
{ |
90
|
|
|
if (static::$encoder === null) { |
|
|
|
|
91
|
|
|
static::$encoder = static::createEncoder(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return static::$encoder; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
private static function createEncoder() |
98
|
|
|
{ |
99
|
|
|
$encoder = new PHPEncoder([ |
100
|
|
|
'object.format' => 'serialize', |
101
|
|
|
]); |
102
|
|
|
$encoder->addEncoder(new ClosureEncoder(), true); |
103
|
|
|
|
104
|
|
|
return $encoder; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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