1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the humbug/php-scoper package. |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2017 Théo FIDRY <[email protected]>, |
9
|
|
|
* Pádraic Brady <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Humbug\PhpScoper; |
16
|
|
|
|
17
|
|
|
use Iterator; |
18
|
|
|
use PackageVersions\Versions; |
19
|
|
|
use function array_pop; |
20
|
|
|
use function count; |
21
|
|
|
use function Safe\substr; |
22
|
|
|
use function str_split; |
23
|
|
|
use function strrpos; |
24
|
|
|
|
25
|
|
|
function get_php_scoper_version(): string |
26
|
|
|
{ |
27
|
|
|
// Since PHP-Scoper relies on COMPOSER_ROOT_VERSION the version parsed by PackageVersions, we rely on Box |
28
|
|
|
// placeholders in order to get the right version for the PHAR. |
29
|
|
|
if (0 === strpos(__FILE__, 'phar:')) { |
30
|
|
|
return '@git_version_placeholder@'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$rawVersion = Versions::getVersion('humbug/php-scoper'); |
34
|
|
|
|
35
|
|
|
[$prettyVersion, $commitHash] = explode('@', $rawVersion); |
36
|
|
|
|
37
|
|
|
return $prettyVersion.'@'.substr($commitHash, 0, 7); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string[] $paths Absolute paths |
42
|
|
|
*/ |
43
|
|
|
function get_common_path(array $paths): string |
44
|
|
|
{ |
45
|
|
|
$nbPaths = count($paths); |
46
|
|
|
|
47
|
|
|
if (0 === $nbPaths) { |
48
|
|
|
return ''; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$pathRef = (string) array_pop($paths); |
52
|
|
|
|
53
|
|
|
if (1 === $nbPaths) { |
54
|
|
|
$commonPath = $pathRef; |
55
|
|
|
} else { |
56
|
|
|
$commonPath = ''; |
57
|
|
|
|
58
|
|
|
foreach (str_split($pathRef) as $pos => $char) { |
59
|
|
|
foreach ($paths as $path) { |
60
|
|
|
if (!isset($path[$pos]) || $path[$pos] !== $char) { |
61
|
|
|
break 2; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$commonPath .= $char; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
foreach (['/', '\\'] as $separator) { |
70
|
|
|
$lastSeparatorPos = strrpos($commonPath, $separator); |
71
|
|
|
|
72
|
|
|
if (false !== $lastSeparatorPos) { |
73
|
|
|
$commonPath = rtrim(substr($commonPath, 0, $lastSeparatorPos), $separator); |
|
|
|
|
74
|
|
|
|
75
|
|
|
break; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $commonPath; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function chain(iterable ...$iterables): Iterator |
83
|
|
|
{ |
84
|
|
|
foreach ($iterables as $iterable) { |
85
|
|
|
yield from $iterable; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.