Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey179 committed Aug 15, 2014
1 parent 3804bda commit a187eac
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 379 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* change of annotation value names in request broker for user input classes: `name` must now be `paramName`, group must now be `paramGroup`
* changed all thrown stubbles/core exceptions to those recommended with stubbles/core 5.0.0
* removed `stubbles\console\Executor::getOutputStream()`, use `stubbles\console\Executor::out()` instead, was deprecated since 3.0.0
* deprecated `stubbles\console\ConsoleApp::createArgumentsBindingModule()`, use `stubbles\console\ConsoleApp::bindArguments()` instead, will be removed with 5.0.0
* deprecated `stubbles\console\ConsoleApp::createConsoleBindingModule()`, console binding module will be added by default, will be removed with 5.0.0


Expand Down
18 changes: 15 additions & 3 deletions src/main/php/ConsoleApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @package stubbles\console
*/
namespace stubbles\console;
use stubbles\console\ioc\ArgumentsBindingModule;
use stubbles\console\ioc\Arguments;
use stubbles\console\ioc\ConsoleBindingModule;
use stubbles\ioc\App;
use stubbles\streams\OutputStream;
Expand Down Expand Up @@ -135,11 +135,23 @@ protected static function getBindingsForApp($className, $projectPath)
* creates argument binding module
*
* @api
* @return \stubbles\console\ioc\ArgumentsBindingModule
* @return \stubbles\console\ioc\Arguments
*/
protected static function bindArguments()
{
return new Arguments(self::$stubcli);
}

/**
* creates argument binding module
*
* @api
* @return \stubbles\console\ioc\Arguments
* @deprecated since 4.0.0, use bindArguments() instead, will be removed with 5.0.0
*/
protected static function createArgumentsBindingModule()
{
return new ArgumentsBindingModule(self::$stubcli);
return self::bindArguments();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/
namespace stubbles\console\ioc;
use stubbles\input\broker\RequestBroker;
use stubbles\input\console\BaseConsoleRequest;
use stubbles\ioc\Binder;
use stubbles\ioc\module\BindingModule;
use stubbles\lang\exception\ConfigurationException;
/**
* Binding module to configure the binder with arguments.
*/
class ArgumentsBindingModule implements BindingModule
class Arguments implements BindingModule
{
/**
* switch whether stubcli was used to run the command
Expand Down Expand Up @@ -57,15 +57,15 @@ public function __construct($stubcliUsed = false)
*
* @api
* @param string $options
* @return \stubbles\console\ioc\ArgumentsBindingModule
* @return \stubbles\console\ioc\Arguments
*/
public function withOptions($options)
{
$this->options = $options;
if ($this->stubcliUsed && !strstr($options, 'c')) {
$options .= 'c:';
$this->options .= 'c:';
}

$this->options = $options;
return $this;
}

Expand All @@ -74,7 +74,7 @@ public function withOptions($options)
*
* @api
* @param string[] $options
* @return \stubbles\console\ioc\ArgumentsBindingModule
* @return \stubbles\console\ioc\Arguments
*/
public function withLongOptions(array $options)
{
Expand All @@ -90,7 +90,7 @@ public function withLongOptions(array $options)
* sets class to store user input into
*
* @param string $className
* @return \stubbles\console\ioc\ArgumentsBindingModule
* @return \stubbles\console\ioc\Arguments
*/
public function withUserInput($className)
{
Expand All @@ -117,7 +117,7 @@ public function configure(Binder $binder)
->to($value);
}

$request = new \stubbles\input\console\BaseConsoleRequest($args, $_SERVER);
$request = new BaseConsoleRequest($args, $_SERVER);
$binder->bind('stubbles\input\Request')
->toInstance($request);
$binder->bind('stubbles\input\console\ConsoleRequest')
Expand All @@ -138,7 +138,7 @@ public function configure(Binder $binder)
* returns parsed arguments
*
* @return array
* @throws \stubbles\lang\exception\ConfigurationException
* @throws \RuntimeException
*/
private function parseArgs()
{
Expand All @@ -149,7 +149,7 @@ private function parseArgs()
$this->parseOptions();
$parsedVars = $this->getopt($this->options, $this->longopts);
if (false === $parsedVars) {
throw new ConfigurationException('Error parsing "' . join(' ', $_SERVER['argv']) . '" with ' . $this->options . ' and ' . join(' ', $this->longopts));
throw new \RuntimeException('Error parsing "' . join(' ', $_SERVER['argv']) . '" with ' . $this->options . ' and ' . join(' ', $this->longopts));
}

return $this->fixArgs($_SERVER['argv'], $parsedVars);
Expand Down
11 changes: 11 additions & 0 deletions src/test/helper/ConsoleAppUsingBindingModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
*/
class ConsoleAppUsingBindingModule extends ConsoleApp
{
/**
* creates mode binding module
*
* @return ArgumentsBindingModule
*/
public static function returnBindArguments()
{
return self::bindArguments();
}

/**
* creates mode binding module
*
* @return ArgumentsBindingModule
* @deprecated since 4.0.0
*/
public static function getArgumentsBindingModule()
{
Expand All @@ -31,6 +41,7 @@ public static function getArgumentsBindingModule()
* creates properties binding module
*
* @return ConsoleBindingModule
* @deprecated since 4.0.0
*/
public static function getConsoleBindingModule()
{
Expand Down
16 changes: 15 additions & 1 deletion src/test/php/ConsoleAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,35 @@ public function commandReturnCodeIsReturned()
);
}

/**
* @since 4.0.0
* @test
*/
public function canCreateArguments()
{
$this->assertInstanceOf(
'stubbles\console\ioc\Arguments',
ConsoleAppUsingBindingModule::returnBindArguments()
);
}

/**
* @since 2.0.0
* @test
* @deprecated since 4.0.0
*/
public function canCreateArgumentsBindingModule()
{
$this->assertInstanceOf(
'stubbles\console\ioc\ArgumentsBindingModule',
'stubbles\console\ioc\Arguments',
ConsoleAppUsingBindingModule::getArgumentsBindingModule()
);
}

/**
* @since 2.0.0
* @test
* @deprecated since 4.0.0
*/
public function canCreateConsoleBindingModule()
{
Expand Down
Loading

0 comments on commit a187eac

Please sign in to comment.