$defaultStub = $phar->createDefaultStub('run.php');
// Add the rest of the apps files
+ $escapedDir = preg_quote(__DIR__, '/');
$phar->addFile(__DIR__ . '/run.php', 'run.php');
- $phar->buildFromDirectory(__DIR__, '/src(.*)/');
- $phar->buildFromDirectory(__DIR__, '/vendor(.*)\.php$/');
+ $phar->buildFromDirectory(__DIR__, "/{$escapedDir}\\/src(.*)\.php$/");
+ $phar->buildFromDirectory(__DIR__, "/{$escapedDir}\\/vendor(.*)\.php$/");
// Customize the stub to add the shebang
$stub = "#!/usr/bin/env php \n" . $defaultStub;
# Make the file executable
chmod(__DIR__ . "/{$pharFile}", 0775);
+ if (filesize(__DIR__ . "/{$pharFile}") > 500000) {
+ throw new Exception("Phar size unusually large. Check extra files are not included by mistake.");
+ }
echo "$pharFile successfully created" . PHP_EOL;
} catch (Exception $e) {