Skip to content

Commit

Permalink
Return exit code from CLI::run(), rather than exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-rueegg authored and theseer committed Sep 18, 2023
1 parent 177e95d commit 2684aea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions composer/bin/phpab
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ foreach ($files as $file) {
require __DIR__ . '/../../src/autoload.php';

$factory = new \TheSeer\Autoload\Factory();
$factory->getCLI()->run($_SERVER);
exit(0);
$rc = $factory->getCLI()->run($_SERVER);
exit($rc);
4 changes: 2 additions & 2 deletions phpab.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
require __DIR__ . '/src/autoload.php';

$factory = new \TheSeer\Autoload\Factory();
$factory->getCLI()->run($_SERVER);
exit(0);
$rc = $factory->getCLI()->run($_SERVER);
exit($rc);
12 changes: 6 additions & 6 deletions src/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(Factory $factory) {
/**
* Main executor method
*
* @return void
* @return int exit code
*/
public function run(array $env) {

Expand Down Expand Up @@ -99,19 +99,19 @@ public function run(array $env) {
$this->showVersion();
}
$rc = $this->factory->getApplication()->run();
exit($rc);
return $rc;

} catch (CLIEnvironmentException $e) {
$this->showVersion();
fwrite(STDERR, 'Sorry, but your PHP environment is currently not able to run phpab due to');
fwrite(STDERR, "\nthe following issue(s):\n\n" . $e->getMessage() . "\n\n");
fwrite(STDERR, "Please adjust your PHP configuration and try again.\n\n");
exit(CLI::RC_EXEC_ERROR);
return CLI::RC_EXEC_ERROR;
} catch (\ezcConsoleException $e) {
$this->showVersion();
echo $e->getMessage() . "\n\n";
$this->showUsage();
exit(CLI::RC_PARAM_ERROR);
return CLI::RC_PARAM_ERROR;
} catch (CollectorException $e) {
switch($e->getCode()) {
case CollectorException::InFileRedeclarationFound:
Expand All @@ -126,11 +126,11 @@ public function run(array $env) {
}
$this->showVersion();
fwrite(STDERR, $message . "\n\n");
exit(CLI::RC_EXEC_ERROR);
return CLI::RC_EXEC_ERROR;
} catch (\Exception $e) {
$this->showVersion();
fwrite(STDERR, "\nError while processing request:\n - " . $e->getMessage()."\n");
exit(CLI::RC_EXEC_ERROR);
return CLI::RC_EXEC_ERROR;
}

}
Expand Down

0 comments on commit 2684aea

Please sign in to comment.