diff --git a/composer.json b/composer.json index a052002..acb481d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ballen/clip", - "version": "2.0.0", + "version": "2.1.0", "description": "A package for speeding up development of PHP console (CLI) applications.", "type": "library", "keywords": ["cli", "commands", "command", "console"], diff --git a/examples/Commands/FlagsHandler.php b/examples/Commands/FlagsHandler.php index 5248823..74fe350 100644 --- a/examples/Commands/FlagsHandler.php +++ b/examples/Commands/FlagsHandler.php @@ -5,7 +5,6 @@ use Ballen\Clip\ConsoleApplication; use Ballen\Clip\Traits\RecievesArgumentsTrait; use Ballen\Clip\Interfaces\CommandInterface; -use Ballen\Clip\Utilities\ArgumentsParser; /** * Clip diff --git a/src/ConsoleApplication.php b/src/ConsoleApplication.php index 02310ea..bb712bb 100644 --- a/src/ConsoleApplication.php +++ b/src/ConsoleApplication.php @@ -34,12 +34,12 @@ class ConsoleApplication /** * Console Application Constructor - * @param array $argv The PHP $argv array (Pass $argv global if you wish to access the CLI arguments) + * @param ArgumentsParser $argv The PHP $argv array (Pass $argv global if you wish to access the CLI arguments) * @return void */ - public function __construct($argv = []) + public function __construct(ArgumentsParser $argv) { - $this->arguments = new ArgumentsParser($argv); + $this->arguments = $argv; $this->router = new CommandRouter(); } diff --git a/src/Interfaces/CommandInterface.php b/src/Interfaces/CommandInterface.php index f65a04b..45f92ba 100644 --- a/src/Interfaces/CommandInterface.php +++ b/src/Interfaces/CommandInterface.php @@ -2,6 +2,8 @@ namespace Ballen\Clip\Interfaces; +use Ballen\Clip\Utilities\ArgumentsParser; + /** * Clip * @@ -16,5 +18,5 @@ interface CommandInterface { - function __construct($argv); + function __construct(ArgumentsParser $argv); } diff --git a/src/Traits/RecievesArgumentsTrait.php b/src/Traits/RecievesArgumentsTrait.php index f825cc0..2394d23 100644 --- a/src/Traits/RecievesArgumentsTrait.php +++ b/src/Traits/RecievesArgumentsTrait.php @@ -2,6 +2,8 @@ namespace Ballen\Clip\Traits; +use Ballen\Clip\Utilities\ArgumentsParser; + /** * Clip * @@ -19,7 +21,7 @@ trait RecievesArgumentsTrait /** * Injects the parent consructor with the CLI arguments. */ - public function __construct($argv) + public function __construct(ArgumentsParser $argv) { parent::__construct($argv); } diff --git a/src/Utilities/ClassMethodHandler.php b/src/Utilities/ClassMethodHandler.php index 185bb2a..deba11a 100644 --- a/src/Utilities/ClassMethodHandler.php +++ b/src/Utilities/ClassMethodHandler.php @@ -53,7 +53,7 @@ class ClassMethodHandler */ public function __construct($handler, $constructor_arguments = []) { - $this->constructor_arguments = func_get_args($constructor_arguments); + $this->constructor_arguments = $constructor_arguments; $this->extract($handler); $this->validate(); } diff --git a/src/Utilities/CommandRouter.php b/src/Utilities/CommandRouter.php index a083169..3bfbbfc 100644 --- a/src/Utilities/CommandRouter.php +++ b/src/Utilities/CommandRouter.php @@ -24,6 +24,11 @@ class CommandRouter * @var Collection */ private $routes; + + /** + * CLI arguments + * @var type + */ private $arguments; public function __construct($arguments = []) @@ -55,7 +60,7 @@ public function dispatch($call = false) $command = $this->routes->get($call, false); } if ($command) { - $handler = new ClassMethodHandler($command); + $handler = new ClassMethodHandler($command, $this->arguments); return $handler->call($this->arguments); } throw new CommandNotFoundException(sprintf('Command %s is not registered.', $call));