diff --git a/composer/bin/phpab b/composer/bin/phpab index df320bd..3813456 100755 --- a/composer/bin/phpab +++ b/composer/bin/phpab @@ -1,7 +1,7 @@ #!/usr/bin/env php + * Copyright (c) 2009-2023 Arne Blankerts * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -59,5 +59,5 @@ foreach ($files as $file) { require __DIR__ . '/../../src/autoload.php'; $factory = new \TheSeer\Autoload\Factory(); -$rc = $factory->getCLI()->run($_SERVER); +$rc = $factory->getCLI()->run(); exit($rc); diff --git a/phpab.php b/phpab.php index 9b6042c..77dad37 100755 --- a/phpab.php +++ b/phpab.php @@ -51,5 +51,5 @@ require __DIR__ . '/src/autoload.php'; $factory = new \TheSeer\Autoload\Factory(); -$rc = $factory->getCLI()->run($_SERVER); +$rc = $factory->getCLI()->run(); exit($rc); diff --git a/src/CLI.php b/src/CLI.php index bf4988d..564d1f1 100644 --- a/src/CLI.php +++ b/src/CLI.php @@ -71,16 +71,25 @@ public function __construct(Factory $factory) { /** * Main executor method * + * @param array|null $options Command line arguments. Will be forwarded as process arguments. + * @param array|null $env Environment variables used to configure the homeDirectory. + * * @return int exit code */ - public function run(array $env) { + public function run( array $options = null, array $env = null) { try { $this->preBootstrap(); + + if (isset($options)) { + // add $args[0] + array_unshift($options, __FILE__); + } + $input = $this->setupInput(); - $input->process(); + $input->process($options); if ($input->getOption('help')->value === TRUE) { $this->showVersion(); @@ -93,7 +102,7 @@ public function run(array $env) { return CLI::RC_OK; } - $config = $this->configure($env, $input); + $config = $this->configure($input, $env); $this->factory->setConfig($config); if (!$config->isQuietMode()) { $this->showVersion(); @@ -140,7 +149,7 @@ public function run(array $env) { * * @return \TheSeer\Autoload\Config */ - private function configure(array $env, \ezcConsoleInput $input) { + private function configure(\ezcConsoleInput $input, array $env = null) { $config = new Config($input->getArguments()); if ($input->getOption('quiet')->value) { $config->setQuietMode(TRUE); @@ -253,7 +262,7 @@ private function configure(array $env, \ezcConsoleInput $input) { if (strpos($var, '=')===FALSE) { throw new \RuntimeException("Variable defintion '$var' is invalid and cannot be processed."); } - list($name, $value) = explode('=', $var, 2); + [$name, $value] = explode('=', $var, 2); $config->setVariable($name, $value); } } @@ -262,6 +271,10 @@ private function configure(array $env, \ezcConsoleInput $input) { $config->setTrusting(FALSE); } + if ($env === null) { + $env = $_SERVER; + } + if (isset($env['HOME'])) { $config->setHomeDirectory($env['HOME']); } elseif (isset($env['HOMEDRIVE']) && isset($env['HOMEPATH'])) {