Skip to content

Commit

Permalink
Fix #7 potential never-ending loop looking for autoload file.
Browse files Browse the repository at this point in the history
See: #7
  • Loading branch information
john-arcus committed Oct 14, 2018
1 parent 96dfc01 commit a1b2ac7
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions bin/capture-lookups
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
#!/usr/bin/env php
<?php

set_time_limit(0);

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = dirname($vendor);
//START - Autoloader inclusion

//Determine if autoloader can be found.
$possibleAutoloaderPaths = array(
__DIR__.'/../../../../vendor/autoload.php', //for when package bin is in vendor directory
__DIR__.'/../vendor/autoload.php', //for when standalone bin is in root
);

$autoloaderFound = FALSE;
foreach ($possibleAutoloaderPaths as $autoloaderFile) {
if (file_exists($autoloaderFile)) {
$autoloaderFound = TRUE;
break;
}
}

//Either require autoloader.php or gracefully report error.
if ($autoloaderFound){
require_once $autoloaderFile;
} else {
//Tell the user in a friendly way:

//Compose the messages.
$feedbackLines = array(
'The autoload.php was not found.',
'The script searched for it at:',
);

foreach ($possibleAutoloaderPaths as $autoloaderFile) {
$feedbackLines[] = '[' . $autoloaderFile . ']';
}

//Extra spaces to highlight the suggestion.
$feedbackLines[] =
PHP_EOL
. 'Maybe you forgot to run \'composer install\'?'
. PHP_EOL;

//Write them out.
foreach($feedbackLines as $line){
fwrite(STDERR, $line . PHP_EOL);
}


//Exit with non-zero (i.e error) code.
exit(1);
}
require $vendor.'/vendor/autoload.php';
//END - Autoloader inclusion


$command = new \XmlSquad\CaptureLookups\Command\CaptureLookupsCommand();
$application = new \Symfony\Component\Console\Application();
Expand Down

0 comments on commit a1b2ac7

Please sign in to comment.