Skip to content

Commit

Permalink
feat: make php-scoper more configurable and predefine symfony-polyfil…
Browse files Browse the repository at this point in the history
…l whitelist
  • Loading branch information
matzeeable committed May 14, 2020
1 parent f9898d4 commit 2cc63ae
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions common/php-scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
use Isolated\Symfony\Component\Finder\Finder;
//use Symfony\Component\Finder\Finder;

////////////////////
// Configuration
////////////////////

$apiFolder = getcwd() . '/inc/api/';
$whitelistFolders = ['vendor/symfony/polyfill*'];
$whiteListNamespaces = [
// Do not scope polyfills
'Symfony\\Polyfill\\*'
];

////////////////////

// Obtain original namespace (must be the first entry in autoload.psr-4)
$composerJson = json_decode(file_get_contents('composer.json'), true);
$psr4 = array_keys($composerJson['autoload']['psr-4'])[0];
Expand All @@ -18,7 +31,28 @@
$whiteListPlugins[$key] = array_keys($composerJson['autoload']['psr-4'])[0] . '*';
}

$apiFolder = getcwd() . '/inc/api/';
// Expand all files from folders to absolute file pathes
$whitelistFoldersFiles = [];
foreach ($whitelistFolders as $whitelistFolder) {
try {
$whitelistFoldersFiles = array_merge(
$whitelistFoldersFiles,
array_map(
'realpath',
array_keys(
iterator_to_array(
Finder::create()
->files()
->ignoreUnreadableDirs()
->in($whitelistFolder)
)
)
)
);
} catch (Exception $e) {
// Silence is golden.
}
}

return [
'prefix' => $psr4 . 'Vendor',
Expand Down Expand Up @@ -69,8 +103,9 @@ function ($filePath, $prefix, $content) use ($stubsJson) {
return $content;
}
],
'whitelist' => $whiteListPlugins,
'whitelist' => array_merge($whiteListPlugins, $whiteListNamespaces),
'files-whitelist' => array_merge(
$whitelistFoldersFiles,
array_map(
'realpath',
array_keys(
Expand Down

0 comments on commit 2cc63ae

Please sign in to comment.