Commit 0ea2603f authored by Ivan Enderlin's avatar Ivan Enderlin

Include vendors inside the PHAR.

Since Solarium has dependencies, this is more interesting to include
vendors (aka dependencies) inside the PHAR file.

Thus we include the `library/` directory with the `vendor/` directory.
parent 976c5b19
...@@ -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.php 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/library/Solarium/Autoloader.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])) {
......
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