find autoload.php from multiple locations, support --help flag

This commit is contained in:
Pekka Laiho 2020-12-20 08:56:32 +07:00
parent c53eba8d23
commit cd8e4c1005

View File

@ -1,11 +1,20 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
if (php_sapi_name() != 'cli') { $autoload = null;
exit('Currently only cli usage is supported.'); foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
if (file_exists($file)) {
$autoload = $file;
break;
}
} }
require(__DIR__ . '/../vendor/autoload.php'); if ($autoload) {
require($autoload);
} else {
print('Unable to find Composer autoloader.' . PHP_EOL);
exit(1);
}
function ml_help() function ml_help()
{ {
@ -86,7 +95,7 @@ for ($i = 1; $i < $argc; $i++) {
$debugMode = true; $debugMode = true;
} elseif ($a == '-e') { } elseif ($a == '-e') {
} elseif ($a == '-h') { } elseif ($a == '-h' || $a == '--help') {
ml_help(); // exit ml_help(); // exit
} elseif ($a == '-q') { } elseif ($a == '-q') {
$loadInit = false; $loadInit = false;