This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoper.inc.php
62 lines (54 loc) · 2.32 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
<?php
/**
* PHP-Scoper configuration
*
* @package skaut-fio-bank-transactions
*/
use Isolated\Symfony\Component\Finder\Finder;
/**
* Constructs a finder for composer dependencies.
*
* @return Finder The initialized Finder.
*/
function dependency_finder() {
// 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' => 'FioTransactions\\Vendor',
'output-dir' => 'dist/vendor',
'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 ) {
$regex_prefix = mb_ereg_replace( '\\\\', '\\\\\\\\', $prefix );
$replace_prefix = mb_ereg_replace( '\\\\', '\\\\', $prefix );
if ( __DIR__ . '/vendor/composer/autoload_real.php' === $file_path ) {
$contents = mb_ereg_replace( "if \\('Composer\\\\\\\\Autoload\\\\\\\\ClassLoader' === \\\$class\\)", "if ('{$replace_prefix}\\\\Composer\\\\Autoload\\\\ClassLoader' === \$class)", $contents );
$contents = mb_ereg_replace( "\\\\spl_autoload_unregister\\(array\\('ComposerAutoloaderInit", "\\spl_autoload_unregister(array('{$replace_prefix}\\\\ComposerAutoloaderInit", $contents );
}
// PSR-0 support
if ( __DIR__ . '/vendor/composer/ClassLoader.php' === $file_path ) {
$contents = mb_ereg_replace( "// PSR-0 lookup\n", "// PSR-0 lookup\n \$scoperPrefix = '{$replace_prefix}\\\\';\n if (substr(\$class, 0, strlen(\$scoperPrefix)) == \$scoperPrefix) {\n \$class = substr(\$class, strlen(\$scoperPrefix));\n \$first = \$class[0];\n \$logicalPathPsr4 = substr(\$logicalPathPsr4, strlen(\$scoperPrefix));\n }\n", $contents );
}
return $contents;
},
),
);