Commit cf4843c6 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge pull request #369 from basdenooijer/Hywan-phar

Fix and improve PHAR generator
parents 83249bb5 afe290b1
build /build
phpunit.xml /phpunit.xml
composer.phar /composer.phar
composer.lock /composer.lock
vendor /vendor
/phar/solarium.phar
...@@ -49,27 +49,36 @@ $strip = (isset($options['s']) && $options['s'] == '1'); ...@@ -49,27 +49,36 @@ $strip = (isset($options['s']) && $options['s'] == '1');
$start = microtime(true); $start = microtime(true);
// Create a new Solarium phar file // Create a new Solarium PHAR file.
@unlink('solarium.phar'); @unlink('solarium.phar');
$phar = new Phar('solarium.phar', 0, 'solarium.phar'); $phar = new Phar('solarium.phar', 0, 'solarium.phar');
$phar->setStub(file_get_contents("stub.php")); $phar->setStub(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stub.php'));
$phar->setSignatureAlgorithm(Phar::SHA1); $phar->setSignatureAlgorithm(Phar::SHA1);
// Add files to the phar // Add files to the PHAR.
$basePath = realpath(__DIR__."/../library/Solarium"); $basePath = dirname(__DIR__);
if ($strip) { $directoryIterator = new AppendIterator();
$directoryIterator = new RecursiveIteratorIterator( $directoryIterator->append(
new RecursiveDirectoryIterator($basePath), new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($basePath . DIRECTORY_SEPARATOR . 'library'),
RecursiveIteratorIterator::SELF_FIRST
)
);
$directoryIterator->append(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($basePath . DIRECTORY_SEPARATOR . 'vendor'),
RecursiveIteratorIterator::SELF_FIRST RecursiveIteratorIterator::SELF_FIRST
); )
);
if ($strip) {
foreach ($directoryIterator as $file) { foreach ($directoryIterator as $file) {
if (preg_match('/\\.php$/i', $file)) { if (0 !== preg_match('/\\.php$/i', $file)) {
$phar->addFromString(substr($file, strlen($basePath) + 1), php_strip_whitespace($file)); $phar->addFromString(substr($file, strlen($basePath) + 1), php_strip_whitespace($file));
} }
} }
} else { } else {
$phar->buildFromDirectory($basePath, '/\.php$/'); $phar->buildFromIterator($directoryIterator, $basePath);
} }
// Create compressed versions // Create compressed versions
...@@ -79,4 +88,4 @@ if ($compress) { ...@@ -79,4 +88,4 @@ if ($compress) {
} }
$time = round(microtime(true)-$start, 5); $time = round(microtime(true)-$start, 5);
echo "\nDONE ($time seconds)\n\n"; echo "\nDONE ($time seconds)\nsolarium.phar has been created.\n\n";
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
*/ */
Phar::mapPhar("solarium.phar"); Phar::mapPhar("solarium.phar");
require_once 'phar://solarium.phar/Autoloader.php'; require_once 'phar://solarium.phar/vendor/autoload.php';
\Solarium\Autoloader::register(); \Solarium\Autoloader::register();
if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'][0]) && isset($_SERVER['argv'][1])) { if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'][0]) && isset($_SERVER['argv'][1])) {
...@@ -46,9 +46,8 @@ if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv' ...@@ -46,9 +46,8 @@ if ('cli' === php_sapi_name() && basename(__FILE__) === basename($_SERVER['argv'
break; break;
default: default:
echo "Unknown command '" . $_SERVER['argv'][1] . "' (Supported commands: version)\n"; echo 'Unknown command \'' . $_SERVER['argv'][1] . '\' (Supported commands: version)' . "\n";
} }
} }
__HALT_COMPILER(); __HALT_COMPILER();
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment