Author: ts
Date: Mon Jan 7 17:11:06 2008
New Revision: 7091
Log:
- Fixed issue #11435: ConsoleInput does not reset $option->value;. The newly
added reset() method can in addtion be used to manually reset all option and
argument values.
Modified:
trunk/ConsoleTools/ChangeLog
trunk/ConsoleTools/src/input.php
trunk/ConsoleTools/tests/input_test.php
Modified: trunk/ConsoleTools/ChangeLog
==============================================================================
--- trunk/ConsoleTools/ChangeLog [iso-8859-1] (original)
+++ trunk/ConsoleTools/ChangeLog [iso-8859-1] Mon Jan 7 17:11:06 2008
@@ -6,6 +6,13 @@
(ezcConsoleQuestionMappingValidator) was introduced for this, which extends
ezcConsoleQuestionCollectionValidator and is now used for the
yes-no-question.
+
+1.3.2 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed issue #11435: ConsoleInput does not reset $option->value;. The newly
+ added reset() method can in addtion be used to manually reset all option and
+ argument values.
1.3.1 - Wednesday 28 November 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Modified: trunk/ConsoleTools/src/input.php
==============================================================================
--- trunk/ConsoleTools/src/input.php [iso-8859-1] (original)
+++ trunk/ConsoleTools/src/input.php [iso-8859-1] Mon Jan 7 17:11:06 2008
@@ -165,6 +165,12 @@
*/
private $arguments = array();
+ /**
+ * Wether the process() method has already been called.
+ *
+ * @var bool
+ */
+ private $processed = false;
/**
* Indicates if an option was submitted, that has the isHelpOption flag
set.
@@ -476,6 +482,12 @@
*/
public function process( array $args = null )
{
+ if ( $this->processed )
+ {
+ $this->reset();
+ }
+ $this->processed = true;
+
if ( !isset( $args ) )
{
$args = isset( $argv ) ? $argv : isset( $_SERVER['argv'] ) ?
$_SERVER['argv'] : array();
@@ -514,6 +526,30 @@
}
$this->processArguments( $args, $i );
$this->checkRules();
+ }
+
+ /**
+ * Resets all option and argument values.
+ *
+ * This method is called automatically by [EMAIL PROTECTED] process()}, if
this method
+ * is called twice or more, and may also be used to manually reset the
+ * values of all registered [EMAIL PROTECTED] and [EMAIL PROTECTED]
+ * ezcConsoleArgument} objects.
+ */
+ public function reset()
+ {
+ foreach ( $this->options as $option )
+ {
+ $option->value = false;
+ }
+ if ( $this->argumentDefinition !== null )
+ {
+ foreach ( $this->argumentDefinition as $argument )
+ {
+ $argument->value = null;
+ }
+ }
+ $this->arguments = array();
}
/**
Modified: trunk/ConsoleTools/tests/input_test.php
==============================================================================
--- trunk/ConsoleTools/tests/input_test.php [iso-8859-1] (original)
+++ trunk/ConsoleTools/tests/input_test.php [iso-8859-1] Mon Jan 7 17:11:06
2008
@@ -1468,6 +1468,78 @@
$this->commonProcessTestFailure( $args,
"ezcConsoleOptionArgumentsViolationException" );
}
+ public function testReset()
+ {
+ $this->input->argumentDefinition = new ezcConsoleArguments();
+ $this->input->argumentDefinition[0] = new ezcConsoleArgument( "number"
);
+ $this->input->argumentDefinition[0]->type = ezcConsoleInput::TYPE_INT;
+ $this->input->argumentDefinition[1] = new ezcConsoleArgument( "string"
);
+ $this->input->argumentDefinition[2] = new ezcConsoleArgument( "array"
);
+ $this->input->argumentDefinition[2]->multiple = true;
+
+ $args = array( "foo.php", "-o", "'test file'", "-b", "23", "42",
"'test string'", "val1", "val2" );
+
+ $res = array(
+ 'o' => "test file",
+ 'b' => 23,
+ );
+ $this->commonProcessTestSuccess( $args, $res );
+
+ $this->assertEquals( 42,
$this->input->argumentDefinition["number"]->value );
+ $this->assertEquals( "test string",
$this->input->argumentDefinition["string"]->value );
+ $this->assertEquals( array( "val1", "val2" ),
$this->input->argumentDefinition["array"]->value );
+
+ // Old handling
+ $this->assertEquals( array( 42, "test string", "val1", "val2"),
$this->input->getArguments() );
+
+ $this->input->reset();
+
+ $this->assertEquals( array(), $this->input->getOptionValues() );
+ foreach ( $this->input->argumentDefinition as $argument )
+ {
+ $this->assertNull( $argument->value );
+ }
+ $this->assertEquals( array(), $this->input->getArguments() );
+ }
+
+ public function testProcessTwice()
+ {
+ $this->input->argumentDefinition = new ezcConsoleArguments();
+ $this->input->argumentDefinition[0] = new ezcConsoleArgument( "number"
);
+ $this->input->argumentDefinition[0]->type = ezcConsoleInput::TYPE_INT;
+ $this->input->argumentDefinition[1] = new ezcConsoleArgument( "string"
);
+ $this->input->argumentDefinition[1]->mandatory = false;
+
+ $args = array( "foo.php", "-o", "'test file'", "-b", "23", "42",
"'test string'" );
+
+ $res = array(
+ 'o' => "test file",
+ 'b' => 23,
+ );
+ $this->commonProcessTestSuccess( $args, $res );
+
+ $this->assertEquals( 42,
$this->input->argumentDefinition["number"]->value );
+ $this->assertEquals( "test string",
$this->input->argumentDefinition["string"]->value );
+
+ // Old handling
+ $this->assertEquals( array( 42, "test string" ),
$this->input->getArguments() );
+
+ // Second run
+
+ $args = array( "foo.php", "-t", '23' );
+
+ $res = array(
+ 't' => true
+ );
+ $this->commonProcessTestSuccess( $args, $res );
+
+ $this->assertEquals( 23,
$this->input->argumentDefinition["number"]->value );
+ $this->assertEquals( null,
$this->input->argumentDefinition["string"]->value );
+
+ // Old handling
+ $this->assertEquals( array( '23' ), $this->input->getArguments() );
+ }
+
public function testProcessFailureNewArgumentsComplexType()
{
$this->input->argumentDefinition = new ezcConsoleArguments();
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components