Skip to content

Commit

Permalink
Fixes bug where the constructor was not recieving the arguments in th…
Browse files Browse the repository at this point in the history
…e latest release.
  • Loading branch information
allebb committed Jan 20, 2016
1 parent 18f5e36 commit 9e81582
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
1 change: 0 additions & 1 deletion examples/Commands/FlagsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Ballen\Clip\ConsoleApplication;
use Ballen\Clip\Traits\RecievesArgumentsTrait;
use Ballen\Clip\Interfaces\CommandInterface;
use Ballen\Clip\Utilities\ArgumentsParser;

/**
* Clip
Expand Down
6 changes: 3 additions & 3 deletions src/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Interfaces/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ballen\Clip\Interfaces;

use Ballen\Clip\Utilities\ArgumentsParser;

/**
* Clip
*
Expand All @@ -16,5 +18,5 @@
interface CommandInterface
{

function __construct($argv);
function __construct(ArgumentsParser $argv);
}
4 changes: 3 additions & 1 deletion src/Traits/RecievesArgumentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ballen\Clip\Traits;

use Ballen\Clip\Utilities\ArgumentsParser;

/**
* Clip
*
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ClassMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
7 changes: 6 additions & 1 deletion src/Utilities/CommandRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class CommandRouter
* @var Collection
*/
private $routes;

/**
* CLI arguments
* @var type
*/
private $arguments;

public function __construct($arguments = [])
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9e81582

Please sign in to comment.