Skip to content

Commit

Permalink
Prefix all code bundled in PHAR distribution with random/unique names…
Browse files Browse the repository at this point in the history
…pace
  • Loading branch information
kambo-1st committed Apr 8, 2018
1 parent 8dd2e69 commit b0ffc97
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
17 changes: 16 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@
<arg value="${type}"/>
</exec>

<exec executable="${basedir}/build/tools/php-scoper.phar" taskname="php-scoper">
<arg value="add-prefix" />
<arg value="--no-ansi" />
<arg value="--config" />
<arg path="${basedir}/build/scoper.inc.php" />
<arg value="--no-interaction" />
<arg value="--stop-on-failure" />
<arg value="--output-dir" />
<arg path="${basedir}/build/phar-prefixed" />
<arg value="--prefix" />
<arg value="PHPUnit" />
<arg path="${basedir}/build/phar" />
</exec>

<exec executable="${basedir}/build/tools/phpab" taskname="phpab">
<arg value="--all" />
<arg value="--static" />
Expand Down Expand Up @@ -364,12 +378,13 @@
<arg path="${basedir}/build/phpunit-${_version}.phar" />
<arg value="--template" />
<arg path="${basedir}/build/binary-phar-autoload.php" />
<arg path="${basedir}/build/phar" />
<arg path="${basedir}/build/phar-prefixed" />
</exec>

<chmod file="${basedir}/build/phpunit-${_version}.phar" perm="ugo+rx"/>

<delete dir="${basedir}/build/phar"/>
<delete dir="${basedir}/build/phar-prefixed"/>
<delete file="${basedir}/build/binary-phar-autoload.php"/>
</target>

Expand Down
37 changes: 37 additions & 0 deletions build/scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

function getWhiteListedClasses(array $classMap, array $folders) : array {
$whitelistedClasses = [];
foreach ($classMap as $className => $classPath) {
if (isWhitelisted($classPath, $folders)) {
$whitelistedClasses[] = $className;
}
}

return $whitelistedClasses;
}

function isWhitelisted(string $classPath, array $folders) : bool {
foreach ($folders as $folderPath) {
if(strpos($classPath, $folderPath) !== false) {
return true;
}
}

return false;
}

$classMap = include(realpath(dirname(__FILE__)).'/../vendor/composer/autoload_classmap.php');

$whitelistFolderClasses = [
'src/Framework',
'phpunit/phpunit-mock-objects',
'phpunit/php-code-coverage',
'phpunit/php-token-stream', // This must be also whitelisted, because of the dynamic object instantiation in Stream.php
];

return [
'whitelist' => getWhiteListedClasses($classMap, $whitelistFolderClasses),
];
Binary file added build/tools/php-scoper.phar
Binary file not shown.
14 changes: 14 additions & 0 deletions build/tools/php-scoper.phar.pubkey
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAxKi/ABhiCMn7hqH9/W0x
v2WKZDtUTDoSFRMl3WMBRL0wEmwvEajOJkzgAZLLomg6DCGrH7dSgZXBaxWyq1yY
efw1qj9HcFlRs82Y8OfzdDRGDbRobERXH+sulukN0Su7jADOJHyILlQgc64Zql2J
+BXQbBXJGIeoVk3I1hKg6GALpoA5kfFMw3l8FztKiRFcBMSRdeFQJlcsB/FCXnfN
LJMnaB2LJnnV6eTj4xD3dXrKky8KxBKMxrryxNFcXqMMfL5gBdaU6CH4VUn5yPDs
R/1KBsCgTmnFY6QmRlp+kI1ogmS5Eqk66xs5WBmuCHeB+phP7CFwvfF4kFGIGITl
5nKMJ7GJWG9CFEbPlZAcfgK3e12NyHuX+XUoc94IxbfzvcWxC/ZiuFSOAbTG95ut
Ue51KkeIxq0GmW8djFySSJM4PZbPHtr7b2LhkJzjQ66dXWyTJjqxZRskmKQota6o
qe8YWALClKLaG+LYM7ZFC4Q6fb4gs1x05feucbmuiWboeJyfL/CmoafnB6MqYXxX
DXXJhMWYbrTZuawNXUe/WhEQIdiGJsoI61y7DgvKw6ExdnelIakAO9EOfkffY5wE
KVZf+2kuEqm5UPvKmwozp/g/WmMAEEn6OJbHxeqKX7Ds/eLFiE2WlZm1YO3/JNbF
HshwDz0FnMzwQom3CiykuOsCAwEAAQ==
-----END PUBLIC KEY-----

0 comments on commit b0ffc97

Please sign in to comment.