Skip to content

Commit

Permalink
Better handling of phar archives
Browse files Browse the repository at this point in the history
This fixes a bug that prevented compressed archives & archives whose file
extension had been modified from running.
  • Loading branch information
fpoirotte committed May 12, 2018
1 parent 282de33 commit 4c5ef93
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions bin/xrl
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,25 @@ foreach ($extensions as $ext) {
DIRECTORY_SEPARATOR . 'autoload.php'
);

if (!strncasecmp(substr(__FILE__, -5), '.phar', 5)) {
try {
Phar::mapPhar();
} catch (Exception $e) {
echo "Cannot process XRL phar:" . PHP_EOL;
echo $e->getMessage() . PHP_EOL;
exit -1;
}
$error = new \RuntimeException();
try {
Phar::mapPhar();
$base = 'phar://' . __FILE__;
} else {
} catch (\Exception $error) {
$base = dirname(__DIR__);
}

$autoload = $base .
DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Autoload.php';
if (!class_exists('\\fpoirotte\\XRL\\Autoload')) {
require_once(
$base .
DIRECTORY_SEPARATOR . 'src' .
DIRECTORY_SEPARATOR . 'Autoload.php'
);
\fpoirotte\XRL\Autoload::register();
if (file_exists($autoload)) {
require_once($autoload);
\fpoirotte\XRL\Autoload::register();
} else {
echo "Cannot process the archive: " . $error->getMessage() . PHP_EOL;
exit -1;
}
}

$cli = new \fpoirotte\XRL\CLI();
Expand Down

0 comments on commit 4c5ef93

Please sign in to comment.