-
Notifications
You must be signed in to change notification settings - Fork 5
/
scoper.inc.php
80 lines (72 loc) · 2.71 KB
/
scoper.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* PHP-Scoper configuration
*
* @package skautis-integration
*/
use Isolated\Symfony\Component\Finder\Finder;
/**
* Safely replaces pattern with replacement in string.
*
* @param string $pattern The pattern to be replaced.
* @param string $replacement The replacement.
* @param string $value The string to replace in.
*
* @return string The string with replacement, if it can be replaced.
*/
function safe_replace( $pattern, $replacement, $value ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
$replacement = mb_ereg_replace( $pattern, $replacement, $value );
if ( false === $replacement || null === $replacement ) {
return $value;
}
return $replacement;
}
/**
* Constructs a finder for composer dependencies.
*
* @return Finder The initialized Finder.
*/
function dependency_finder() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec
exec( 'composer show --no-dev --name-only', $dependencies );
$finder = Finder::create()->files()->name( array( '*.php', '/LICENSE(.txt)?/' ) )->in( 'vendor' );
foreach ( $dependencies as $dependency ) {
$finder->path( '#^' . $dependency . '/#' );
}
return $finder;
}
return array(
'prefix' => 'Skautis_Integration\\Vendor',
'output-dir' => 'dist/vendor',
'tag-declarations-as-internal' => false,
'expose-global-constants' => true,
'expose-global-classes' => false,
'expose-global-functions' => false,
'finders' => array(
dependency_finder(),
Finder::create()->files()
->name( array( '*.php', '/LICENSE(.txt)?/' ) )
->depth( 0 )
->in( 'vendor/composer' ),
Finder::create()->files()
->name( 'autoload.php' )
->depth( 0 )
->in( 'vendor' ),
),
'patchers' => array(
static function ( $file_path, $prefix, $contents ) {
$replace_prefix = mb_ereg_replace( '\\\\', '\\\\', $prefix );
$underscore_prefix = mb_ereg_replace( '\\\\', '_', $prefix );
if ( __DIR__ . '/vendor/composer/autoload_real.php' === $file_path ) {
$contents = safe_replace( "if \\('Composer\\\\\\\\Autoload\\\\\\\\ClassLoader' === \\\$class\\)", "if ('{$replace_prefix}\\\\Composer\\\\Autoload\\\\ClassLoader' === \$class)", $contents );
$contents = safe_replace( "\\\\spl_autoload_unregister\\(array\\('ComposerAutoloaderInit", "\\spl_autoload_unregister(array('{$replace_prefix}\\\\ComposerAutoloaderInit", $contents );
$contents = safe_replace(
"\\\$GLOBALS\['__composer_autoload_files'\]",
"\$GLOBALS['__composer_autoload_files_{$underscore_prefix}']",
$contents
);
}
return $contents;
},
),
);