|
1 | 1 | #!/usr/bin/env php
|
2 | 2 | <?php
|
| 3 | + |
3 | 4 | set_time_limit(0);
|
4 | 5 |
|
5 |
| -$vendor = __DIR__; |
6 |
| -while (!file_exists($vendor.'/vendor')) { |
7 |
| - $vendor = dirname($vendor); |
| 6 | +//START - Autoloader inclusion |
| 7 | + |
| 8 | +//Determine if autoloader can be found. |
| 9 | +$possibleAutoloaderPaths = array( |
| 10 | + __DIR__.'/../../../../vendor/autoload.php', //for when package bin is in vendor directory |
| 11 | + __DIR__.'/../vendor/autoload.php', //for when standalone bin is in root |
| 12 | +); |
| 13 | + |
| 14 | +$autoloaderFound = FALSE; |
| 15 | +foreach ($possibleAutoloaderPaths as $autoloaderFile) { |
| 16 | + if (file_exists($autoloaderFile)) { |
| 17 | + $autoloaderFound = TRUE; |
| 18 | + break; |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +//Either require autoloader.php or gracefully report error. |
| 23 | +if ($autoloaderFound){ |
| 24 | + require_once $autoloaderFile; |
| 25 | +} else { |
| 26 | + //Tell the user in a friendly way: |
| 27 | + |
| 28 | + //Compose the messages. |
| 29 | + $feedbackLines = array( |
| 30 | + 'The autoload.php was not found.', |
| 31 | + 'The script searched for it at:', |
| 32 | + ); |
| 33 | + |
| 34 | + foreach ($possibleAutoloaderPaths as $autoloaderFile) { |
| 35 | + $feedbackLines[] = '[' . $autoloaderFile . ']'; |
| 36 | + } |
| 37 | + |
| 38 | + //Extra spaces to highlight the suggestion. |
| 39 | + $feedbackLines[] = |
| 40 | + PHP_EOL |
| 41 | + . 'Maybe you forgot to run \'composer install\'?' |
| 42 | + . PHP_EOL; |
| 43 | + |
| 44 | + //Write them out. |
| 45 | + foreach($feedbackLines as $line){ |
| 46 | + fwrite(STDERR, $line . PHP_EOL); |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + //Exit with non-zero (i.e error) code. |
| 51 | + exit(1); |
8 | 52 | }
|
9 |
| -require $vendor.'/vendor/autoload.php'; |
| 53 | +//END - Autoloader inclusion |
| 54 | + |
10 | 55 |
|
11 | 56 | $command = new \XmlSquad\CaptureLookups\Command\CaptureLookupsCommand();
|
12 | 57 | $application = new \Symfony\Component\Console\Application();
|
|
0 commit comments