From a9bee379b5034d60f0895adeae301f72ceba7ef9 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Wed, 8 May 2013 19:48:13 +0200 Subject: [PATCH 01/29] refactored unit tests --- test/CommandlineMatcherTest.php | 990 ++++++++++++++++++++++++++++++++ 1 file changed, 990 insertions(+) create mode 100644 test/CommandlineMatcherTest.php diff --git a/test/CommandlineMatcherTest.php b/test/CommandlineMatcherTest.php new file mode 100644 index 0000000..1dfa08b --- /dev/null +++ b/test/CommandlineMatcherTest.php @@ -0,0 +1,990 @@ + array( + '--foo --bar', + array('a','b','--baz'), + null + ), + 'mandatory-long-flag-no-partial-match' => array( + '--foo --bar', + array('--foo','--baz'), + null + ), + 'mandatory-long-flag-match' => array( + '--foo --bar', + array('--foo','--bar'), + array('foo' => true, 'bar' => true) + ), + 'mandatory-long-flag-match-with-zero-value' => array( + '--foo=', + array('--foo=0'), + array('foo' => 0) + ), + 'mandatory-long-flag-mixed-order-match' => array( + '--foo --bar', + array('--bar','--foo'), + array('foo' => true, 'bar' => true) + ), + 'mandatory-long-flag-whitespace-in-definition' => array( + ' --foo --bar ', + array('--bar','--foo'), + array( + 'foo' => true, + 'bar' => true, + 'baz' => null, + ) + ), + 'mandatory-long-flag-alternative1' => array( + ' ( --foo | --bar )', + array('--foo'), + array( + 'foo' => true, + 'bar' => false, + 'baz' => null, + ) + ), + 'mandatory-long-flag-alternative2' => array( + ' ( --foo | --bar )', + array('--bar'), + array( + 'foo' => false, + 'bar' => true, + 'baz' => null, + ) + ), + 'mandatory-long-flag-alternative3' => array( + ' ( --foo | --bar )', + array('--baz'), + null + ), + + // -- mandatory short flags + 'mandatory-short-flag-no-match' => array( + '-f -b', + array('a','b','-f'), + null + ), + 'mandatory-short-flag-no-partial-match' => array( + '-f -b', + array('-f','-z'), + null + ), + 'mandatory-short-flag-match' => array( + '-f -b', + array('-f','-b'), + array('f' => true, 'b' => true) + ), + 'mandatory-short-flag-mixed-order-match' => array( + '-f -b', + array('-b','-f'), + array('f' => true, 'b' => true) + ), + 'mandatory-short-flag-whitespace-in-definition' => array( + ' -f -b ', + array('-b','-f'), + array( + 'f' => true, + 'b' => true, + 'baz' => null, + ) + ), + 'mandatory-short-flag-alternative1' => array( + ' ( -f | -b )', + array('-f'), + array( + 'f' => true, + 'b' => false, + 'baz' => null, + ) + ), + 'mandatory-short-flag-alternative2' => array( + ' ( -f | -b )', + array('-b'), + array( + 'f' => false, + 'b' => true, + 'baz' => null, + ) + ), + 'mandatory-short-flag-alternative3' => array( + ' ( -f | -b )', + array('--baz'), + null + ), + + // -- optional long flags + 'optional-long-flag-non-existent' => array( + '--foo [--bar]', + array('--foo'), + array( + 'foo' => true, + 'bar' => null, + 'baz' => null, + ) + ), + 'literal-optional-long-flag' => array( + 'foo [--bar]', + array('foo', '--bar'), + array( + 'foo' => null, + 'bar' => true, + ) + ), + 'optional-long-flag-partial-mismatch' => array( + '--foo [--bar]', + array('--foo', '--baz'), + null + ), + 'optional-long-flag-match' => array( + '--foo [--bar]', + array('--foo','--bar'), + array( + 'foo' => true, + 'bar' => true + ) + ), + 'optional-long-value-flag-non-existent' => array( + '--foo [--bar=]', + array('--foo'), + array( + 'foo' => true, + 'bar' => false + ) + ), + 'optional-long-flag-match-with-zero-value' => array( + '[--foo=]', + array('--foo=0'), + array('foo' => 0) + ), + 'optional-long-value-flag' => array( + '--foo [--bar=]', + array('--foo', '--bar=4'), + array( + 'foo' => true, + 'bar' => 4 + ) + ), + 'optional-long-value-flag-non-existent-mixed-case' => array( + '--foo [--barBaz=]', + array('--foo', '--barBaz=4'), + array( + 'foo' => true, + 'barBaz' => 4 + ) + ), + 'value-optional-long-value-flag' => array( + ' [--bar=]', + array('value', '--bar=4'), + array( + 'foo' => 'value', + 'bar' => 4 + ) + ), + 'literal-optional-long-value-flag' => array( + 'foo [--bar=]', + array('foo', '--bar=4'), + array( + 'foo' => null, + 'bar' => 4, + ) + ), + 'optional-long-flag-mixed-order-match' => array( + '--foo --bar', + array('--bar','--foo'), + array('foo' => true, 'bar' => true) + ), + 'optional-long-flag-whitespace-in-definition' => array( + ' --foo [--bar] ', + array('--bar','--foo'), + array( + 'foo' => true, + 'bar' => true, + 'baz' => null, + ) + ), + 'optional-long-flag-whitespace-in-definition2' => array( + ' --foo [--bar ] ', + array('--bar','--foo'), + array( + 'foo' => true, + 'bar' => true, + 'baz' => null, + ) + ), + 'optional-long-flag-whitespace-in-definition3' => array( + ' --foo [ --bar ] ', + array('--bar','--foo'), + array( + 'foo' => true, + 'bar' => true, + 'baz' => null, + ) + ), + + + // -- value flags + 'mandatory-value-flag-syntax-1' => array( + '--foo=s', + array('--foo','bar'), + array( + 'foo' => 'bar', + 'bar' => null + ) + ), + 'mandatory-value-flag-syntax-2' => array( + '--foo=', + array('--foo','bar'), + array( + 'foo' => 'bar', + 'bar' => null + ) + ), + 'mandatory-value-flag-syntax-3' => array( + '--foo=anystring', + array('--foo','bar'), + array( + 'foo' => 'bar', + 'bar' => null + ) + ), + + // -- edge cases for value flags values + 'mandatory-value-flag-equals-complex-1' => array( + '--foo=', + array('--foo=SomeComplexValue=='), + array('foo' => 'SomeComplexValue==') + ), + 'mandatory-value-flag-equals-complex-2' => array( + '--foo=', + array('--foo=..., '..., array( + '--foo=', + array('--foo====--'), + array('foo' => '===--') + ), + 'mandatory-value-flag-space-complex-1' => array( + '--foo=', + array('--foo','SomeComplexValue=='), + array('foo' => 'SomeComplexValue==') + ), + 'mandatory-value-flag-space-complex-2' => array( + '--foo=', + array('--foo','..., '..., array( + '--foo=', + array('--foo','===--'), + array('foo' => '===--') + ), + + // -- required literal params + 'mandatory-literal-match-1' => array( + 'foo', + array('foo'), + array('foo' => null) + ), + 'mandatory-literal-match-2' => array( + 'foo bar baz', + array('foo','bar','baz'), + array('foo' => null, 'bar' => null, 'baz' => null, 'bazinga' => null) + ), + 'mandatory-literal-mismatch' => array( + 'foo', + array('fooo'), + null + ), + 'mandatory-literal-order' => array( + 'foo bar', + array('bar','foo'), + null + ), + 'mandatory-literal-partial-mismatch' => array( + 'foo bar baz', + array('foo','bar'), + null + ), + 'mandatory-literal-alternative-match-1' => array( + 'foo ( bar | baz )', + array('foo','bar'), + array('foo' => null, 'bar' => true, 'baz' => false) + ), + 'mandatory-literal-alternative-match-2' => array( + 'foo (bar|baz)', + array('foo','bar'), + array('foo' => null, 'bar' => true, 'baz' => false) + ), + 'mandatory-literal-alternative-match-3' => array( + 'foo ( bar | baz )', + array('foo','baz'), + array('foo' => null, 'bar' => false, 'baz' => true) + ), + 'mandatory-literal-alternative-mismatch' => array( + 'foo ( bar | baz )', + array('foo','bazinga'), + null + ), + 'mandatory-literal-namedAlternative-match-1' => array( + 'foo ( bar | baz ):altGroup', + array('foo','bar'), + array('foo' => null, 'altGroup'=>'bar', 'bar' => true, 'baz' => false) + ), + 'mandatory-literal-namedAlternative-match-2' => array( + 'foo ( bar | baz ):altGroup9', + array('foo','baz'), + array('foo' => null, 'altGroup9'=>'baz', 'bar' => false, 'baz' => true) + ), + 'mandatory-literal-namedAlternative-mismatch' => array( + 'foo ( bar | baz ):altGroup9', + array('foo','bazinga'), + null + ), + + // -- optional literal params + 'optional-literal-match' => array( + 'foo [bar] [baz]', + array('foo','bar'), + array('foo' => null, 'bar' => true, 'baz' => null) + ), + 'optional-literal-mismatch' => array( + 'foo [bar] [baz]', + array('baz','bar'), + null + ), + 'optional-literal-shuffled-mismatch' => array( + 'foo [bar] [baz]', + array('foo','baz','bar'), + null + ), + 'optional-literal-alternative-match' => array( + 'foo [bar | baz]', + array('foo','baz'), + array('foo' => null, 'baz' => true, 'bar' => false) + ), + 'optional-literal-alternative-mismatch' => array( + 'foo [bar | baz]', + array('foo'), + array('foo' => null, 'baz' => false, 'bar' => false) + ), + 'optional-literal-namedAlternative-match-1' => array( + 'foo [bar | baz]:altGroup1', + array('foo','baz'), + array('foo' => null, 'altGroup1' => 'baz', 'baz' => true, 'bar' => false) + ), + 'optional-literal-namedAlternative-match-2' => array( + 'foo [bar | baz | bazinga]:altGroup100', + array('foo','bazinga'), + array('foo' => null, 'altGroup100' => 'bazinga', 'bazinga' => true, 'baz' => false, 'bar' => false) + ), + 'optional-literal-namedAlternative-match-3' => array( + 'foo [ bar ]:altGroup100', + array('foo','bar'), + array('foo' => null, 'altGroup100' => 'bar', 'bar' => true, 'baz' => null) + ), + 'optional-literal-namedAlternative-mismatch' => array( + 'foo [ bar | baz ]:altGroup9', + array('foo'), + array('foo' => null, 'altGroup9'=> null, 'bar' => false, 'baz' => false) + ), + + // -- value params + 'mandatory-value-param-syntax-1' => array( + 'FOO', + array('bar'), + array( + 'foo' => 'bar', + 'bar' => null + ) + ), + 'mandatory-value-param-syntax-2' => array( + '', + array('bar'), + array( + 'foo' => 'bar', + 'bar' => null + ) + ), + 'mandatory-value-param-mixed-with-literal' => array( + 'a b c', + array('a','b','bar','c'), + array( + 'a' => null, + 'b' => null, + 'foo' => 'bar', + 'bar' => null, + 'c' => null, + ), + ), + 'optional-value-param-1' => array( + 'a b []', + array('a','b','bar'), + array( + 'a' => null, + 'b' => null, + 'c' => 'bar', + 'bar' => null, + ), + ), + 'optional-value-param-2' => array( + 'a b []', + array('a','b'), + array( + 'a' => null, + 'b' => null, + 'c' => null, + 'bar' => null, + ), + ), + 'optional-value-param-3' => array( + 'a b []', + array('a','b','--c'), + null + ), + + // -- combinations + 'mandatory-long-short-alternative-1' => array( + ' ( --foo | -f )', + array('--foo'), + array( + 'foo' => true, + 'f' => false, + 'baz' => null, + ) + ), + 'mandatory-long-short-alternative-2' => array( + ' ( --foo | -f )', + array('-f'), + array( + 'foo' => false, + 'f' => true, + 'baz' => null, + ) + ), + 'optional-long-short-alternative-1' => array( + 'a [ --foo | -f ]', + array('a','bar'), + array( + 'a' => null, + 'b' => 'bar', + 'foo' => false, + 'f' => false, + 'baz' => null, + ) + ), + 'optional-long-short-alternative-2' => array( + 'a [ --foo | -f ]', + array('a','bar', '-f'), + array( + 'a' => null, + 'b' => 'bar', + 'foo' => false, + 'f' => true, + 'baz' => null, + ) + ), + 'optional-long-short-alternative-3' => array( + 'a [ --foo | -f ]', + array('a','--foo', 'bar'), + array( + 'a' => null, + 'b' => 'bar', + 'foo' => true, + 'f' => false, + 'baz' => null, + ) + ), + + + 'mandatory-and-optional-value-params-with-flags-1' => array( + 'a b [] [--eee|-e] [--fff|-f]', + array('a','b','foo','bar'), + array( + 'a' => null, + 'b' => null, + 'c' => 'foo', + 'd' => 'bar', + 'e' => false, + 'eee' => false, + 'fff' => false, + 'f' => false, + ), + ), + 'mandatory-and-optional-value-params-with-flags-2' => array( + 'a b [] [--eee|-e] [--fff|-f]', + array('a','b','--eee', 'foo','bar'), + array( + 'a' => null, + 'b' => null, + 'c' => 'foo', + 'd' => 'bar', + 'e' => false, + 'eee' => true, + 'fff' => false, + 'f' => false, + ), + ), + + + // -- overflows + 'too-many-arguments1' => array( + 'foo bar', + array('foo','bar','baz'), + null + ), + 'too-many-arguments2' => array( + 'foo bar [baz]', + array('foo','bar','baz','woo'), + null, + ), + 'too-many-arguments3' => array( + 'foo bar [--baz]', + array('foo','bar','--baz','woo'), + null, + ), + 'too-many-arguments4' => array( + 'foo bar [--baz] woo', + array('foo','bar','woo'), + array( + 'foo' => null, + 'bar' => null, + 'baz' => false, + 'woo' => null + ) + ), + 'too-many-arguments5' => array( + '--foo --bar [--baz] woo', + array('--bar','--foo','woo'), + array( + 'foo' => true, + 'bar' => true, + 'baz' => false, + 'woo' => null + ) + ), + 'too-many-arguments6' => array( + '--foo --bar [--baz]', + array('--bar','--foo','woo'), + null + ), + + // other (combination) + 'combined-1' => array( + 'literal [--foo=] --baz', + array('literal', 'oneBar', '--foo=4', '--baz'), + array( + 'literal' => null, + 'bar' => 'oneBar', + 'foo' => 4, + 'baz' => true + ) + ), + // group with group name diferent than options (short) + 'group-1' => array( + 'group [-t|--test]:testgroup', + array('group', '-t'), + array( + 'group' => null, + 'testgroup' => true, + ) + ), + // group with group name diferent than options (long) + 'group-2' => array( + 'group [-t|--test]:testgroup', + array('group', '--test'), + array( + 'group' => null, + 'testgroup' => true, + ) + ), + // group with same name as option (short) + 'group-3' => array( + 'group [-t|--test]:test', + array('group', '-t'), + array( + 'group' => null, + 'test' => true, + ) + ), + // group with same name as option (long) + 'group-4' => array( + 'group [-t|--test]:test', + array('group', '--test'), + array( + 'group' => null, + 'test' => true, + ) + ), + 'group-5' => array( + 'group (-t | --test ):test', + array('group', '--test'), + array( + 'group' => null, + 'test' => true, + ), + ), + 'group-6' => array( + 'group (-t | --test ):test', + array('group', '-t'), + array( + 'group' => null, + 'test' => true, + ), + ), + 'group-7' => array( + 'group [-x|-y|-z]:test', + array('group', '-y'), + array( + 'group' => null, + 'test' => true, + ), + ), + 'group-8' => array( + 'group [--foo|--bar|--baz]:test', + array('group', '--foo'), + array( + 'group' => null, + 'test' => true, + ), + ), + 'group-9' => array( + 'group (--foo|--bar|--baz):test', + array('group', '--foo'), + array( + 'group' => null, + 'test' => true, + ), + ), + + /** + * @bug ZF2-4315 + * @link https://github.com/zendframework/zf2/issues/4315 + */ + 'literal-with-dashes' => array( + 'foo-bar-baz [--bar=]', + array('foo-bar-baz',), + array( + 'foo-bar-baz' => null, + 'foo' => null, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + + 'literal-optional-with-dashes' => array( + '[foo-bar-baz] [--bar=]', + array('foo-bar-baz'), + array( + 'foo-bar-baz' => true, + 'foo' => null, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-with-dashes2' => array( + 'foo [foo-bar-baz] [--bar=]', + array('foo'), + array( + 'foo-bar-baz' => false, + 'foo' => null, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-alternative-with-dashes' => array( + '(foo-bar|foo-baz) [--bar=]', + array('foo-bar',), + array( + 'foo-bar' => true, + 'foo-baz' => false, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-alternative-with-dashes' => array( + '[foo-bar|foo-baz] [--bar=]', + array('foo-baz',), + array( + 'foo-bar' => false, + 'foo-baz' => true, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-alternative-with-dashes2' => array( + 'foo [foo-bar|foo-baz] [--bar=]', + array('foo',), + array( + 'foo' => null, + 'foo-bar' => false, + 'foo-baz' => false, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-flag-with-dashes' => array( + 'foo --bar-baz', + array('foo','--bar-baz'), + array( + 'foo' => null, + 'bar-baz' => true, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-flag-with-dashes' => array( + 'foo [--bar-baz]', + array('foo','--bar-baz'), + array( + 'foo' => null, + 'bar-baz' => true, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-flag-with-dashes2' => array( + 'foo [--bar-baz]', + array('foo'), + array( + 'foo' => null, + 'bar-baz' => false, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-flag-alternative-with-dashes' => array( + 'foo [--foo-bar|--foo-baz]', + array('foo','--foo-baz'), + array( + 'foo' => null, + 'foo-bar' => false, + 'foo-baz' => true, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'literal-optional-flag-alternative-with-dashes2' => array( + 'foo [--foo-bar|--foo-baz]', + array('foo'), + array( + 'foo' => null, + 'foo-bar' => false, + 'foo-baz' => false, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'value-with-dashes' => array( + ' [--bar=]', + array('abc',), + array( + 'foo-bar-baz' => 'abc', + 'foo' => null, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + + 'value-optional-with-dashes' => array( + '[] [--bar=]', + array('abc'), + array( + 'foo-bar-baz' => 'abc', + 'foo' => null, + 'bar' => null, + 'baz' => null, + 'something' => null, + ) + ), + 'value-optional-with-dashes2' => array( + '[] [--bar=]', + array('--bar','abc'), + array( + 'foo-bar-baz' => null, + 'foo' => null, + 'bar' => 'abc', + 'baz' => null, + 'something' => null, + ) + ), + + + ); + } + + /** + * @dataProvider routeProvider + * @param string $routeDefinition + * @param array $arguments + * @param array|null $params + */ + public function testMatching($routeDefinition, array $arguments = array(), array $params = null) + { + $route = new CommandlineMatcher($routeDefinition); + $match = $route->match($arguments); + + + if ($params === null) { + $this->assertNull($match, "The route must not match"); + } else { + $this->assertInternalType('array', $match); + + foreach ($params as $key => $value) { + $this->assertEquals( + $value, + isset($match[$key])?$match[$key]:null, + $value === null ? "Param $key is not present" : "Param $key is present and is equal to $value" + ); + } + } + } + + public function testCannotMatchWithEmptyMandatoryParam() + { + $arguments = array('--foo='); + $route = new CommandlineMatcher('--foo='); + $match = $route->match($arguments); + $this->assertEquals(null, $match); + } + + public static function routeDefaultsProvider() + { + return array( + 'required-literals-no-defaults' => array( + 'create controller', + array(), + array('create', 'controller'), + array('create' => null, 'controller' => null), + ), + 'required-literals-defaults' => array( + 'create controller', + array('controller' => 'value'), + array('create', 'controller'), + array('create' => null, 'controller' => 'value'), + ), + 'value-param-no-defaults' => array( + 'create controller ', + array(), + array('create', 'controller', 'foo'), + array('create' => null, 'controller' => 'foo'), + ), + 'value-param-defaults-overridden' => array( + 'create controller ', + array('controller' => 'defaultValue'), + array('create', 'controller', 'foo'), + array('create' => null, 'controller' => 'foo'), + ), + 'optional-value-param-defaults' => array( + 'create controller []', + array('controller' => 'defaultValue'), + array('create', 'controller'), + array('create' => null, 'controller' => 'defaultValue'), + ), + 'alternative-literal-non-present' => array( + '(foo | bar)', + array('bar' => 'something'), + array('foo'), + array('foo' => true, 'bar' => false), + ), + 'alternative-literal-present' => array( + '(foo | bar)', + array('bar' => 'something'), + array('bar'), + array('foo' => false, 'bar' => 'something'), + ), + 'alternative-flag-non-present' => array( + '(--foo | --bar)', + array('bar' => 'something'), + array('--foo'), + array('foo' => true, 'bar' => false), + ), + 'alternative-flag-present' => array( + '(--foo | --bar)', + array('bar' => 'something'), + array('--bar'), + array('foo' => false, 'bar' => 'something'), + ), + 'optional-literal-non-present' => array( + 'foo [bar]', + array('bar' => 'something'), + array('foo'), + array('foo' => null, 'bar' => false), + ), + 'optional-literal-present' => array( + 'foo [bar]', + array('bar' => 'something'), + array('foo', 'bar'), + array('foo' => null, 'bar' => 'something'), + ), + ); + } + + /** + * @dataProvider routeDefaultsProvider + * @param string $routeDefinition + * @param array $defaults + * @param array $arguments + * @param array|null $params + */ + public function testMatchingWithDefaults( + $routeDefinition, + array $defaults = array(), + array $arguments = array(), + array $params = null + ) { + $route = new CommandlineMatcher($routeDefinition, array(), $defaults); + $match = $route->match($arguments); + + if ($params === null) { + $this->assertNull($match, "The route must not match"); + } else { + $this->assertInternalType('array', $match); + + foreach ($params as $key => $value) { + $this->assertSame( + $value, + isset($match[$key])?$match[$key]:null, + $value === null ? "Param $key is not present" : "Param $key is present and is equal to '$value'" + ); + } + } + } +} From 3a10bffb150072e40a1398a8e0297e2d8cedbc18 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Wed, 8 May 2013 21:22:59 +0200 Subject: [PATCH 02/29] Renamed to "ConsoleRouteMatcher" --- ...{CommandlineMatcher.php => ConsoleRouteMatcher.php} | 4 ++-- ...lineMatcherTest.php => ConsoleRouteMatcherTest.php} | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) rename src/{CommandlineMatcher.php => ConsoleRouteMatcher.php} (99%) rename test/{CommandlineMatcherTest.php => ConsoleRouteMatcherTest.php} (99%) diff --git a/src/CommandlineMatcher.php b/src/ConsoleRouteMatcher.php similarity index 99% rename from src/CommandlineMatcher.php rename to src/ConsoleRouteMatcher.php index 4dc3535..c758165 100644 --- a/src/CommandlineMatcher.php +++ b/src/ConsoleRouteMatcher.php @@ -9,7 +9,7 @@ namespace Zend\Console; -class CommandlineMatcher +class ConsoleRouteMatcher { /** * Parts of the route. @@ -39,7 +39,7 @@ class CommandlineMatcher * @param array $constraints * @param array $defaults * @param array $aliases - * @return \Zend\Console\CommandlineMatcher + * @return \Zend\Console\ConsoleRouteMatcher */ public function __construct( $route, diff --git a/test/CommandlineMatcherTest.php b/test/ConsoleRouteMatcherTest.php similarity index 99% rename from test/CommandlineMatcherTest.php rename to test/ConsoleRouteMatcherTest.php index 1dfa08b..e36babb 100644 --- a/test/CommandlineMatcherTest.php +++ b/test/ConsoleRouteMatcherTest.php @@ -10,7 +10,7 @@ namespace ZendTest\Console; -use Zend\Console\CommandlineMatcher; +use Zend\Console\ConsoleRouteMatcher; /** * @category Zend @@ -18,7 +18,7 @@ * @subpackage UnitTests * @group Zend_Console */ -class CommandlineMatcherTest extends \PHPUnit_Framework_TestCase +class ConsoleRouteMatcherTest extends \PHPUnit_Framework_TestCase { public static function routeProvider() @@ -858,7 +858,7 @@ public static function routeProvider() */ public function testMatching($routeDefinition, array $arguments = array(), array $params = null) { - $route = new CommandlineMatcher($routeDefinition); + $route = new ConsoleRouteMatcher($routeDefinition); $match = $route->match($arguments); @@ -880,7 +880,7 @@ public function testMatching($routeDefinition, array $arguments = array(), array public function testCannotMatchWithEmptyMandatoryParam() { $arguments = array('--foo='); - $route = new CommandlineMatcher('--foo='); + $route = new ConsoleRouteMatcher('--foo='); $match = $route->match($arguments); $this->assertEquals(null, $match); } @@ -970,7 +970,7 @@ public function testMatchingWithDefaults( array $arguments = array(), array $params = null ) { - $route = new CommandlineMatcher($routeDefinition, array(), $defaults); + $route = new ConsoleRouteMatcher($routeDefinition, array(), $defaults); $match = $route->match($arguments); if ($params === null) { From e16796c05ac7f0bdfc9a7180529270f2481c63a6 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Wed, 8 May 2013 22:02:17 +0200 Subject: [PATCH 03/29] CS --- src/ConsoleRouteMatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConsoleRouteMatcher.php b/src/ConsoleRouteMatcher.php index c758165..9e5aea7 100644 --- a/src/ConsoleRouteMatcher.php +++ b/src/ConsoleRouteMatcher.php @@ -677,4 +677,4 @@ public function match($params) return array_replace($this->defaults, $matches); } -} \ No newline at end of file +} From 2d581fbbabb036bea3c2c58d5c52c3f104d5f52a Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Wed, 8 May 2013 22:35:16 +0200 Subject: [PATCH 04/29] updated docblocks and comments --- src/ConsoleRouteMatcher.php | 84 ++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/src/ConsoleRouteMatcher.php b/src/ConsoleRouteMatcher.php index 9e5aea7..d13fc56 100644 --- a/src/ConsoleRouteMatcher.php +++ b/src/ConsoleRouteMatcher.php @@ -39,7 +39,7 @@ class ConsoleRouteMatcher * @param array $constraints * @param array $defaults * @param array $aliases - * @return \Zend\Console\ConsoleRouteMatcher + * @return self */ public function __construct( $route, @@ -53,8 +53,8 @@ public function __construct( $this->parts = $this->parseDefinition($route); } - - /** Parse a route definition. + /** + * Parse a route definition. * * @param string $def * @return array @@ -69,7 +69,7 @@ protected function parseDefinition($def) $unnamedGroupCounter = 1; while ($pos < $length) { - /** + /* * Mandatory long param * --param= * --param=whatever @@ -84,7 +84,7 @@ protected function parseDefinition($def) 'hasValue' => !empty($m['hasValue']), ); } - /** + /* * Optional long flag * [--param] */ @@ -100,7 +100,7 @@ protected function parseDefinition($def) 'hasValue' => false, ); } - /** + /* * Optional long param * [--param=] * [--param=whatever] @@ -117,7 +117,7 @@ protected function parseDefinition($def) 'hasValue' => !empty($m['hasValue']), ); } - /** + /* * Mandatory short param * -a * -a=i @@ -134,7 +134,7 @@ protected function parseDefinition($def) 'hasValue' => !empty($m['type']) ? $m['type'] : null, ); } - /** + /* * Optional short param * [-a] * [-a=n] @@ -150,7 +150,7 @@ protected function parseDefinition($def) 'hasValue' => !empty($m['type']) ? $m['type'] : null, ); } - /** + /* * Optional literal param alternative * [ something | somethingElse | anotherOne ] * [ something | somethingElse | anotherOne ]:namedGroup @@ -190,7 +190,7 @@ protected function parseDefinition($def) ); } - /** + /* * Required literal param alternative * ( something | somethingElse | anotherOne ) * ( something | somethingElse | anotherOne ):namedGroup @@ -228,7 +228,7 @@ protected function parseDefinition($def) 'hasValue' => false, ); } - /** + /* * Required long/short flag alternative * ( --something | --somethingElse | --anotherOne | -s | -a ) * ( --something | --somethingElse | --anotherOne | -s | -a ):namedGroup @@ -271,7 +271,7 @@ protected function parseDefinition($def) 'hasValue' => false, ); } - /** + /* * Optional flag alternative * [ --something | --somethingElse | --anotherOne | -s | -a ] * [ --something | --somethingElse | --anotherOne | -s | -a ]:namedGroup @@ -314,7 +314,7 @@ protected function parseDefinition($def) 'hasValue' => false, ); } - /** + /* * Optional literal param, i.e. * [something] */ @@ -327,7 +327,7 @@ protected function parseDefinition($def) 'hasValue' => false, ); } - /** + /* * Optional value param, i.e. * [SOMETHING] */ @@ -340,7 +340,7 @@ protected function parseDefinition($def) 'hasValue' => true, ); } - /** + /* * Optional value param, syntax 2, i.e. * [] */ @@ -353,7 +353,7 @@ protected function parseDefinition($def) 'hasValue' => true, ); } - /** + /* * Mandatory value param, i.e. * */ @@ -366,7 +366,7 @@ protected function parseDefinition($def) 'hasValue' => true, ); } - /** + /* * Mandatory value param, i.e. * SOMETHING */ @@ -379,7 +379,7 @@ protected function parseDefinition($def) 'hasValue' => true, ); } - /** + /* * Mandatory literal param, i.e. * something */ @@ -404,11 +404,17 @@ protected function parseDefinition($def) return $parts; } + /** + * Match parameters against route passed to constructor + * + * @param $params + * @return array|null + */ public function match($params) { $matches = array(); - /** + /* * Extract positional and named parts */ $positional = $named = array(); @@ -420,11 +426,11 @@ public function match($params) } } - /** + /* * Scan for named parts inside Console params */ foreach ($named as &$part) { - /** + /* * Prepare match regex */ if (isset($part['alternatives'])) { @@ -456,7 +462,7 @@ public function match($params) } } - /** + /* * Look for param */ $value = $param = null; @@ -482,14 +488,14 @@ public function match($params) if (!$param) { - /** + /* * Drop out if that was a mandatory param */ if ($part['required']) { return null; } - /** + /* * Continue to next positional param */ else { @@ -498,14 +504,14 @@ public function match($params) } - /** + /* * Value for flags is always boolean */ if ($param && !$part['hasValue']) { $value = true; } - /** + /* * Try to retrieve value if it is expected */ if ((null === $value || "" === $value) && $part['hasValue']) { @@ -521,7 +527,7 @@ public function match($params) } } - /** + /* * Validate the value against constraints */ if ($part['hasValue'] && isset($this->constraints[$part['name']])) { @@ -533,7 +539,7 @@ public function match($params) } } - /** + /* * Store the value */ if ($part['hasValue']) { @@ -542,7 +548,7 @@ public function match($params) $matches[$part['name']] = true; } - /** + /* * If there are alternatives, fill them */ if (isset($part['alternatives'])) { @@ -566,7 +572,7 @@ public function match($params) } } - /** + /* * Scan for left-out flags that should result in a mismatch */ foreach ($params as $param) { @@ -575,12 +581,12 @@ public function match($params) } } - /** + /* * Go through all positional params */ $argPos = 0; foreach ($positional as &$part) { - /** + /* * Check if param exists */ if (!isset($params[$argPos])) { @@ -595,7 +601,7 @@ public function match($params) $value = $params[$argPos]; - /** + /* * Check if literal param matches */ if ($part['literal']) { @@ -607,7 +613,7 @@ public function match($params) } } - /** + /* * Validate the value against constraints */ if ($part['hasValue'] && isset($this->constraints[$part['name']])) { @@ -619,13 +625,13 @@ public function match($params) } } - /** + /* * Store the value */ if ($part['hasValue']) { $matches[$part['name']] = $value; } elseif (isset($part['alternatives'])) { - // from all alternativesm set matching parameter to TRUE and the rest to FALSE + // from all alternatives set matching parameter to TRUE and the rest to FALSE foreach ($part['alternatives'] as $alt) { if ($alt == $value) { $matches[$alt] = isset($this->defaults[$alt])? $this->defaults[$alt] : true; @@ -642,21 +648,21 @@ public function match($params) $matches[$name] = isset($this->defaults[$name])? $this->defaults[$name] : true; } - /** + /* * Advance to next argument */ $argPos++; } - /** + /* * Check if we have consumed all positional parameters */ if ($argPos < count($params)) { return null; // there are extraneous params that were not consumed } - /** + /* * Any optional flags that were not entered have value false */ foreach ($this->parts as &$part) { From 6944da9edfe9e639756e48b60fdfcbd4027e79e6 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Fri, 17 May 2013 19:43:58 +0200 Subject: [PATCH 05/29] RouteMatcherInterface --- .../DefaultRouteMatcher.php} | 8 ++++--- src/RouteMatcher/RouteMatcherInterface.php | 23 +++++++++++++++++++ .../DefaultRouteMatcherTest.php} | 12 +++++----- 3 files changed, 34 insertions(+), 9 deletions(-) rename src/{ConsoleRouteMatcher.php => RouteMatcher/DefaultRouteMatcher.php} (99%) create mode 100644 src/RouteMatcher/RouteMatcherInterface.php rename test/{ConsoleRouteMatcherTest.php => RouteMatcher/DefaultRouteMatcherTest.php} (99%) diff --git a/src/ConsoleRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php similarity index 99% rename from src/ConsoleRouteMatcher.php rename to src/RouteMatcher/DefaultRouteMatcher.php index d13fc56..e49b337 100644 --- a/src/ConsoleRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -7,9 +7,11 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace Zend\Console; +namespace Zend\Console\RouteMatcher; -class ConsoleRouteMatcher +use Zend\Console\Exception; + +class DefaultRouteMatcher implements RouteMatcherInterface { /** * Parts of the route. @@ -407,7 +409,7 @@ protected function parseDefinition($def) /** * Match parameters against route passed to constructor * - * @param $params + * @param array $params * @return array|null */ public function match($params) diff --git a/src/RouteMatcher/RouteMatcherInterface.php b/src/RouteMatcher/RouteMatcherInterface.php new file mode 100644 index 0000000..e165676 --- /dev/null +++ b/src/RouteMatcher/RouteMatcherInterface.php @@ -0,0 +1,23 @@ +match($arguments); @@ -880,7 +880,7 @@ public function testMatching($routeDefinition, array $arguments = array(), array public function testCannotMatchWithEmptyMandatoryParam() { $arguments = array('--foo='); - $route = new ConsoleRouteMatcher('--foo='); + $route = new DefaultRouteMatcher('--foo='); $match = $route->match($arguments); $this->assertEquals(null, $match); } @@ -970,7 +970,7 @@ public function testMatchingWithDefaults( array $arguments = array(), array $params = null ) { - $route = new ConsoleRouteMatcher($routeDefinition, array(), $defaults); + $route = new DefaultRouteMatcher($routeDefinition, array(), $defaults); $match = $route->match($arguments); if ($params === null) { From fe9efbd311930b82f7f12a07eb200f8390d6f66a Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Fri, 17 May 2013 19:52:36 +0200 Subject: [PATCH 06/29] allow injecting custom route matcher to route object --- src/RouteMatcher/DefaultRouteMatcher.php | 46 +++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index e49b337..95b1bc9 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -34,6 +34,16 @@ class DefaultRouteMatcher implements RouteMatcherInterface */ protected $aliases; + /** + * @var \Zend\Validator\ValidatorChain + */ + protected $validators; + + /** + * @var \Zend\Filter\FilterChain + */ + protected $filters; + /** * Class constructor * @@ -41,18 +51,52 @@ class DefaultRouteMatcher implements RouteMatcherInterface * @param array $constraints * @param array $defaults * @param array $aliases + * @param null $filters + * @param null $validators + * @throws InvalidArgumentException * @return self */ public function __construct( $route, array $constraints = array(), array $defaults = array(), - array $aliases = array() + array $aliases = array(), + $filters = null, + $validators = null ) { $this->defaults = $defaults; $this->constraints = $constraints; $this->aliases = $aliases; $this->parts = $this->parseDefinition($route); + + if ($filters !== null) { + if ($filters instanceof FilterChain) { + $this->filters = $filters; + } elseif ($filters instanceof Traversable) { + $this->filters = new FilterChain(array( + 'filters' => ArrayUtils::iteratorToArray($filters, false) + )); + } elseif (is_array($filters)) { + $this->filters = new FilterChain(array( + 'filters' => $filters + )); + } else { + throw new InvalidArgumentException('Cannot use ' . gettype($filters) . ' as filters for ' . __CLASS__); + } + } + + if ($validators !== null) { + if ($validators instanceof ValidatorChain) { + $this->validators = $validators; + } elseif ($validators instanceof Traversable || is_array($validators)) { + $this->validators = new ValidatorChain(); + foreach ($validators as $v) { + $this->validators->attach($v); + } + } else { + throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validators for ' . __CLASS__); + } + } } /** From 93a16c990f97e5595bfa67bc4c336390cc9235bf Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Sat, 18 May 2013 11:49:39 +0200 Subject: [PATCH 07/29] test constraints --- test/RouteMatcher/DefaultRouteMatcherTest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index 629a626..666b5fe 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -987,4 +987,95 @@ public function testMatchingWithDefaults( } } } + + public static function routeConstraintsProvider() + { + return array( + 'simple-constraints' => array( + ' ', + array( + 'numeric' => '/^[0-9]+$/', + 'alpha' => '/^[a-zA-Z]+$/', + ), + array('1234', 'test'), + true + ), + 'constraints-on-optional-param' => array( + ' []', + array( + 'numeric' => '/^[0-9]+$/', + 'alpha' => '/^[a-zA-Z]+$/', + ), + array('test', '1234'), + true + ), + 'optional-empty-param' => array( + ' []', + array( + 'numeric' => '/^[0-9]+$/', + 'alpha' => '/^[a-zA-Z]+$/', + ), + array('test'), + true + ), + 'named-param' => array( + '--foo=', + array( + 'foo' => '/^bar$/' + ), + array('--foo=bar'), + true, + ), + 'failing-param' => array( + ' ', + array( + 'good1' => '/^[a-zA-Z]+$/', + 'good2' => '/^[a-zA-Z]+$/', + 'bad' => '/^[a-zA-Z]+$/', + ), + array('foo', 'bar', 'foo123bar'), + false + ), + 'failing-optional-param' => array( + ' []', + array( + 'good2' => '/^(foo|bar)$/', + 'bad' => '/^(foo|bar)$/', + ), + array('foo', 'baz'), + false + ), + 'failing-named-param' => array( + '--foo=', + array( + 'foo' => '/^bar$/' + ), + array('--foo=baz'), + false, + ), + ); + } + + /** + * @dataProvider routeConstraintsProvider + * @param string $routeDefinition + * @param array $constraints + * @param array $arguments + * @param bool $shouldMatch + */ + public function testMatchingWithConstraints( + $routeDefinition, + array $constraints = array(), + array $arguments = array(), + $shouldMatch = true + ) { + $route = new DefaultRouteMatcher($routeDefinition, $constraints); + $match = $route->match($arguments); + + if ($shouldMatch === false) { + $this->assertNull($match, "The route must not match"); + } else { + $this->assertInternalType('array', $match); + } + } } From a18ff008eadc2c43aa486d990c69e52bf21fd5e5 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Sat, 18 May 2013 12:06:53 +0200 Subject: [PATCH 08/29] param aliases --- src/RouteMatcher/DefaultRouteMatcher.php | 51 +++++++++-- test/RouteMatcher/DefaultRouteMatcherTest.php | 90 +++++++++++++++++++ 2 files changed, 135 insertions(+), 6 deletions(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index 95b1bc9..4974a4f 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -450,6 +450,37 @@ protected function parseDefinition($def) return $parts; } + /** + * Returns list of names representing single parameter + * + * @param string $name + * @return string + */ + private function getAliases($name) + { + $namesToMatch = array($name); + foreach ($this->aliases as $alias => $canonical) { + if ($name == $canonical) { + $namesToMatch[] = $alias; + } + } + return $namesToMatch; + } + + /** + * Returns canonical name of a parameter + * + * @param string $name + * @return string + */ + private function getCanonicalName($name) + { + if (isset($this->aliases[$name])) { + return $this->aliases[$name]; + } + return $name; + } + /** * Match parameters against route passed to constructor * @@ -482,7 +513,13 @@ public function match($params) if (isset($part['alternatives'])) { // an alternative of flags $regex = '/^\-+(?P'; - $regex .= join('|', $part['alternatives']); + + $alternativeAliases = array(); + foreach ($part['alternatives'] as $alternative) { + $alternativeAliases[] = '(?:' . implode('|', $this->getAliases($alternative)) . ')'; + } + + $regex .= join('|', $alternativeAliases); if ($part['hasValue']) { $regex .= ')(?:\=(?P.*?)$)?$/'; @@ -491,19 +528,21 @@ public function match($params) } } else { // a single named flag + $name = '(?:' . implode('|', $this->getAliases($part['name'])) . ')'; + if ($part['short'] === true) { // short variant if ($part['hasValue']) { - $regex = '/^\-' . $part['name'] . '(?:\=(?P.*?)$)?$/i'; + $regex = '/^\-' . $name . '(?:\=(?P.*?)$)?$/i'; } else { - $regex = '/^\-' . $part['name'] . '$/i'; + $regex = '/^\-' . $name . '$/i'; } } elseif ($part['short'] === false) { // long variant if ($part['hasValue']) { - $regex = '/^\-{2,}' . $part['name'] . '(?:\=(?P.*?)$)?$/i'; + $regex = '/^\-{2,}' . $name . '(?:\=(?P.*?)$)?$/i'; } else { - $regex = '/^\-{2,}' . $part['name'] . '$/i'; + $regex = '/^\-{2,}' . $name . '$/i'; } } } @@ -525,7 +564,7 @@ public function match($params) } if (isset($m['name'])) { - $matchedName = $m['name']; + $matchedName = $this->getCanonicalName($m['name']); } break; diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index 666b5fe..a4885d7 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -1078,4 +1078,94 @@ public function testMatchingWithConstraints( $this->assertInternalType('array', $match); } } + + public static function routeAliasesProvider() + { + return array( + 'simple-alias' => array( + '--user=', + array( + 'username' => 'user' + ), + array('--username=JohnDoe'), + array( + 'user' => 'JohnDoe' + ) + ), + 'multiple-aliases' => array( + '--name= --email=', + array( + 'username' => 'name', + 'useremail' => 'email' + ), + array('--username=JohnDoe', '--useremail=johndoe@domain.com'), + array( + 'name' => 'JohnDoe', + 'email' => 'johndoe@domain.com', + ) + ), + 'flags' => array( + 'foo --bar', + array( + 'baz' => 'bar' + ), + array('foo', '--baz'), + array( + 'bar' => true + ) + ), + 'with-alternatives' => array( + 'do-something (--remove|--update)', + array( + 'delete' => 'remove' + ), + array('do-something', '--delete'), + array( + 'remove' => true, + ) + ), + 'with-alternatives-2' => array( + 'do-something (--update|--remove)', + array( + 'delete' => 'remove' + ), + array('do-something', '--delete'), + array( + 'remove' => true, + ) + ) + ); + } + + /** + * @dataProvider routeAliasesProvider + * @param string $routeDefinition + * @param array $aliases + * @param array $arguments + * @param array|null $params + */ + public function testMatchingWithAliases( + $routeDefinition, + array $aliases = array(), + array $arguments = array(), + array $params = null + ) + { + $route = new DefaultRouteMatcher($routeDefinition, array(), array(), $aliases); + $match = $route->match($arguments); + + if ($params === null) { + $this->assertNull($match, "The route must not match"); + } else { + $this->assertInternalType('array', $match); + + foreach ($params as $key => $value) { + $this->assertEquals( + $value, + isset($match[$key])?$match[$key]:null, + $value === null ? "Param $key is not present" : "Param $key is present and is equal to $value" + ); + } + } + } } From 40a19f2f719b0f0c33470d8208d34deccd58afc4 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Mon, 20 May 2013 23:39:50 +0200 Subject: [PATCH 09/29] param validators --- src/RouteMatcher/DefaultRouteMatcher.php | 40 +++++++++------ test/RouteMatcher/DefaultRouteMatcherTest.php | 51 +++++++++++++++++++ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index 4974a4f..2bb2774 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -10,6 +10,7 @@ namespace Zend\Console\RouteMatcher; use Zend\Console\Exception; +use Zend\Validator\ValidatorInterface; class DefaultRouteMatcher implements RouteMatcherInterface { @@ -35,9 +36,9 @@ class DefaultRouteMatcher implements RouteMatcherInterface protected $aliases; /** - * @var \Zend\Validator\ValidatorChain + * @var ValidatorInterface[] */ - protected $validators; + protected $validators = array(); /** * @var \Zend\Filter\FilterChain @@ -51,8 +52,8 @@ class DefaultRouteMatcher implements RouteMatcherInterface * @param array $constraints * @param array $defaults * @param array $aliases - * @param null $filters - * @param null $validators + * @param array $filters + * @param ValidatorInterface[] $validators * @throws InvalidArgumentException * @return self */ @@ -61,13 +62,12 @@ public function __construct( array $constraints = array(), array $defaults = array(), array $aliases = array(), - $filters = null, - $validators = null + array $filters = null, + array $validators = null ) { $this->defaults = $defaults; $this->constraints = $constraints; $this->aliases = $aliases; - $this->parts = $this->parseDefinition($route); if ($filters !== null) { if ($filters instanceof FilterChain) { @@ -86,17 +86,15 @@ public function __construct( } if ($validators !== null) { - if ($validators instanceof ValidatorChain) { - $this->validators = $validators; - } elseif ($validators instanceof Traversable || is_array($validators)) { - $this->validators = new ValidatorChain(); - foreach ($validators as $v) { - $this->validators->attach($v); + foreach ($validators as $name => $validator) { + if (!$validator instanceof ValidatorInterface) { + throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validator for ' . __CLASS__); } - } else { - throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validators for ' . __CLASS__); + $this->validators[$name] = $validator; } } + + $this->parts = $this->parseDefinition($route); } /** @@ -766,6 +764,18 @@ public function match($params) } } + // run validators + $valid = true; + foreach ($matches as $name => $value) { + if (isset($this->validators[$name])) { + $valid &= $this->validators[$name]->isValid($value); + } + } + + if (!$valid) { + return null; + } + return array_replace($this->defaults, $matches); } } diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index a4885d7..45d50e3 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -1168,4 +1168,55 @@ public function testMatchingWithAliases( } } } + + public static function routeValidatorsProvider() + { + return array( + 'validators-valid' => array( + ' ', + array( + 'string' => new \Zend\Validator\StringLength(array('min' => 5, 'max' => 12)), + 'number' => new \Zend\Validator\Digits() + ), + array('foobar', '12345'), + true + ), + 'validators-invalid' => array( + ' ', + array( + 'string' => new \Zend\Validator\StringLength(array('min' => 5, 'max' => 12)), + 'number' => new \Zend\Validator\Digits() + ), + array('foo', '12345'), + false + ), + 'validators-invalid2' => array( + ' ', + array( + 'string' => new \Zend\Validator\StringLength(array('min' => 5, 'max' => 12)), + 'number' => new \Zend\Validator\Digits() + ), + array('foozbar', 'not_digits'), + false + ), + ); + } + + /** + * @dataProvider routeValidatorsProvider + * @param string $routeDefinition + * @param array $validators + * @param array $arguments + * @param bool $shouldMatch + */ + public function testParamsCanBeValidated($routeDefinition, $validators, $arguments, $shouldMatch) + { + $matcher = new DefaultRouteMatcher($routeDefinition, array(), array(), array(), null, $validators); + $match = $matcher->match($arguments); + if ($shouldMatch === false) { + $this->assertNull($match, "The route must not match"); + } else { + $this->assertInternalType('array', $match); + } + } } From e5fa44c5ccba024e8f7397e8a9351ca4655dbaba Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Tue, 21 May 2013 00:13:21 +0200 Subject: [PATCH 10/29] param filters --- src/RouteMatcher/DefaultRouteMatcher.php | 31 ++++---- test/RouteMatcher/DefaultRouteMatcherTest.php | 72 ++++++++++++++++++- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index 2bb2774..94a9b91 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -11,6 +11,7 @@ use Zend\Console\Exception; use Zend\Validator\ValidatorInterface; +use Zend\Filter\FilterInterface; class DefaultRouteMatcher implements RouteMatcherInterface { @@ -41,9 +42,9 @@ class DefaultRouteMatcher implements RouteMatcherInterface protected $validators = array(); /** - * @var \Zend\Filter\FilterChain + * @var FilterInterface[] */ - protected $filters; + protected $filters = array(); /** * Class constructor @@ -70,25 +71,18 @@ public function __construct( $this->aliases = $aliases; if ($filters !== null) { - if ($filters instanceof FilterChain) { - $this->filters = $filters; - } elseif ($filters instanceof Traversable) { - $this->filters = new FilterChain(array( - 'filters' => ArrayUtils::iteratorToArray($filters, false) - )); - } elseif (is_array($filters)) { - $this->filters = new FilterChain(array( - 'filters' => $filters - )); - } else { - throw new InvalidArgumentException('Cannot use ' . gettype($filters) . ' as filters for ' . __CLASS__); + foreach ($filters as $name => $filter) { + if (!$filter instanceof FilterInterface) { + throw new Exception\InvalidArgumentException('Cannot use ' . gettype($filters) . ' as filter for ' . __CLASS__); + } + $this->filters[$name] = $filter; } } if ($validators !== null) { foreach ($validators as $name => $validator) { if (!$validator instanceof ValidatorInterface) { - throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validator for ' . __CLASS__); + throw new Exception\InvalidArgumentException('Cannot use ' . gettype($validator) . ' as validator for ' . __CLASS__); } $this->validators[$name] = $validator; } @@ -764,6 +758,13 @@ public function match($params) } } + // run filters + foreach ($matches as $name => $value) { + if (isset($this->filters[$name])) { + $matches[$name] = $this->filters[$name]->filter($value); + } + } + // run validators $valid = true; foreach ($matches as $name => $value) { diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index 45d50e3..ba06a95 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -1169,7 +1169,7 @@ public function testMatchingWithAliases( } } - public static function routeValidatorsProvider() + public function routeValidatorsProvider() { return array( 'validators-valid' => array( @@ -1199,6 +1199,7 @@ public static function routeValidatorsProvider() array('foozbar', 'not_digits'), false ), + ); } @@ -1219,4 +1220,73 @@ public function testParamsCanBeValidated($routeDefinition, $validators, $argumen $this->assertInternalType('array', $match); } } + + public function routeFiltersProvider() + { + $genericFilter = $this->getMock('Zend\Filter\FilterInterface', array('filter')); + $genericFilter->expects($this->once())->method('filter') + ->with('foobar')->will($this->returnValue('foobaz')); + + return array( + 'filters-generic' => array( + '', + array( + 'param' => $genericFilter + ), + array('foobar'), + array( + 'param' => 'foobaz' + ) + ), + 'filters-single' => array( + '', + array( + 'number' => new \Zend\Filter\Int() + ), + array('123four'), + array( + 'number' => 123 + ) + ), + 'filters-multiple' => array( + ' ', + array( + 'number' => new \Zend\Filter\Int(), + 'strtolower' => new \Zend\Filter\StringToLower(), + ), + array('nan', 'FOOBAR'), + array( + 'number' => 0, + 'strtolower' => 'foobar' + ) + ), + ); + } + + /** + * @dataProvider routeFiltersProvider + * @param string $routeDefinition + * @param array $filters + * @param array $arguments + * @param array $params + */ + public function testParamsCanBeFiltered($routeDefinition, $filters, $arguments, $params) + { + $matcher = new DefaultRouteMatcher($routeDefinition, array(), array(), array(), $filters); + $match = $matcher->match($arguments); + + if (null === $match) { + $this->fail("Route '$routeDefinition' must match.'"); + } + + $this->assertInternalType('array', $match); + + foreach ($params as $key => $value) { + $this->assertEquals( + $value, + isset($match[$key])?$match[$key]:null, + $value === null ? "Param $key is not present" : "Param $key is present and is equal to $value" + ); + } + } } From d7afa70736acbcac5e6282af582c4787e2d6e7e9 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Tue, 21 May 2013 00:16:49 +0200 Subject: [PATCH 11/29] two more tests --- test/RouteMatcher/DefaultRouteMatcherTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index ba06a95..2fde5dd 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -1289,4 +1289,20 @@ public function testParamsCanBeFiltered($routeDefinition, $filters, $arguments, ); } } + + public function testConstructorDoesNotAcceptInvalidFilters() + { + $this->setExpectedException('Zend\Console\Exception\InvalidArgumentException'); + new DefaultRouteMatcher('', array(), array(), array(), array( + new \stdClass() + )); + } + + public function testConstructorDoesNotAcceptInvalidValidators() + { + $this->setExpectedException('Zend\Console\Exception\InvalidArgumentException'); + new DefaultRouteMatcher('', array(), array(), array(), array(), array( + new \stdClass() + )); + } } From 91f70dc2d57375a0ae6378c948809690b90bfcb3 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 22 May 2013 10:54:35 -0500 Subject: [PATCH 12/29] [zendframework/zf2#4449] docblock fixes - Ensured docblock references were correct --- src/RouteMatcher/DefaultRouteMatcher.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index 94a9b91..e897234 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -55,8 +55,7 @@ class DefaultRouteMatcher implements RouteMatcherInterface * @param array $aliases * @param array $filters * @param ValidatorInterface[] $validators - * @throws InvalidArgumentException - * @return self + * @throws Exception\InvalidArgumentException */ public function __construct( $route, From 788c28074e9e12c86fb967c891efa4c496a61ef1 Mon Sep 17 00:00:00 2001 From: neilime Date: Thu, 13 Jun 2013 18:20:33 +0200 Subject: [PATCH 13/29] Fix cs issues, improve encodeText method / call --- src/Adapter/AbstractAdapter.php | 30 +++++++++++++--------------- src/Adapter/AdapterInterface.php | 8 -------- test/Adapter/AbstractAdapterTest.php | 4 ++-- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 951f303..a5bb9db 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -505,25 +505,23 @@ public function readChar($mask = null) /** * Encode a text to match console encoding * - * @param string $text + * @param string $text * @return string the encoding text */ public function encodeText($text) { - $textIsUtf8 = StringUtils::isValidUtf8($text); - - if($this->isUtf8()){ - if($textIsUtf8){ - return $text; - } - else{ - return utf8_encode($text); - } - } - else if($textIsUtf8){ - return utf8_decode($text); - } - - return $text; + if ($this->isUtf8()) { + if (StringUtils::isValidUtf8($text)) { + return $text; + } + + return utf8_encode($text); + } + + if (StringUtils::isValidUtf8($text)) { + return utf8_decode($text); + } + + return $text; } } diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 62c8f56..eb3f8d3 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -246,12 +246,4 @@ public function readLine($maxLength = 2048); * @return string */ public function readChar($mask = null); - - /** - * Encode a text to match console encoding - * - * @param string $text - * @return string the encoding text - */ - public function encodeText($text); } diff --git a/test/Adapter/AbstractAdapterTest.php b/test/Adapter/AbstractAdapterTest.php index 01ee96b..c863ce6 100644 --- a/test/Adapter/AbstractAdapterTest.php +++ b/test/Adapter/AbstractAdapterTest.php @@ -121,8 +121,8 @@ public function testReadCharWithMaskInsensitiveCase() $this->assertEquals($char, 'r'); } - public function testEncodeText(){ - + public function testEncodeText() + { //Utf8 string $text = '\u00E9\u00E9\u00E9'; From bcb455277b488c6444cab8635d649556c916495b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 28 Jun 2013 09:17:44 -0500 Subject: [PATCH 14/29] [zendframework/zf2#4606] CS and logic flow fixes - `s/\t/ /g` - Reflow logic in Console\DefaultRenderingStrategy to make it easier to read, and to re-use common values --- src/Adapter/AbstractAdapter.php | 7 +++-- test/Adapter/AbstractAdapterTest.php | 40 ++++++++++++++-------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index a5bb9db..2cbfd81 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -53,11 +53,10 @@ abstract class AbstractAdapter implements AdapterInterface */ public function write($text, $color = null, $bgColor = null) { + //Encode text to match console encoding + $text = $this->encodeText($text); - //Encode text to match console encoding - $text = $this->encodeText($text); - - if ($color !== null || $bgColor !== null) { + if ($color !== null || $bgColor !== null) { echo $this->colorize($text, $color, $bgColor); } else { echo $text; diff --git a/test/Adapter/AbstractAdapterTest.php b/test/Adapter/AbstractAdapterTest.php index c863ce6..4a12888 100644 --- a/test/Adapter/AbstractAdapterTest.php +++ b/test/Adapter/AbstractAdapterTest.php @@ -123,25 +123,25 @@ public function testReadCharWithMaskInsensitiveCase() public function testEncodeText() { - //Utf8 string - $text = '\u00E9\u00E9\u00E9'; - - //Console UTF8 - Text utf8 - $this->adapter->setTestUtf8(true); - $encodedText = $this->adapter->encodeText($text); - $this->assertEquals($text,$encodedText); - - //Console UTF8 - Text not utf8 - $encodedText = $this->adapter->encodeText(utf8_decode($text)); - $this->assertEquals($text,$encodedText); - - //Console not UTF8 - Text utf8 - $this->adapter->setTestUtf8(false); - $encodedText = $this->adapter->encodeText($text); - $this->assertEquals(utf8_decode($text),$encodedText); - - //Console not UTF8 - Text not utf8 - $encodedText = $this->adapter->encodeText(utf8_decode($text)); - $this->assertEquals(utf8_decode($text),$encodedText); + //Utf8 string + $text = '\u00E9\u00E9\u00E9'; + + //Console UTF8 - Text utf8 + $this->adapter->setTestUtf8(true); + $encodedText = $this->adapter->encodeText($text); + $this->assertEquals($text,$encodedText); + + //Console UTF8 - Text not utf8 + $encodedText = $this->adapter->encodeText(utf8_decode($text)); + $this->assertEquals($text,$encodedText); + + //Console not UTF8 - Text utf8 + $this->adapter->setTestUtf8(false); + $encodedText = $this->adapter->encodeText($text); + $this->assertEquals(utf8_decode($text),$encodedText); + + //Console not UTF8 - Text not utf8 + $encodedText = $this->adapter->encodeText(utf8_decode($text)); + $this->assertEquals(utf8_decode($text),$encodedText); } } From fab0f2cef9a45a7e352e9c150fdddf7de3978241 Mon Sep 17 00:00:00 2001 From: Kathryn Reeve Date: Tue, 31 Dec 2013 16:11:41 +0000 Subject: [PATCH 15/29] copyright update for 2014 - Zend Library --- src/Adapter/AbstractAdapter.php | 2 +- src/Adapter/AdapterInterface.php | 2 +- src/Adapter/Posix.php | 2 +- src/Adapter/Virtual.php | 2 +- src/Adapter/Windows.php | 2 +- src/Adapter/WindowsAnsicon.php | 2 +- src/Charset/Ascii.php | 2 +- src/Charset/AsciiExtended.php | 2 +- src/Charset/CharsetInterface.php | 2 +- src/Charset/DECSG.php | 2 +- src/Charset/Utf8.php | 2 +- src/Charset/Utf8Heavy.php | 2 +- src/Color/Xterm256.php | 2 +- src/ColorInterface.php | 2 +- src/Console.php | 2 +- src/Exception/BadMethodCallException.php | 2 +- src/Exception/ExceptionInterface.php | 2 +- src/Exception/InvalidArgumentException.php | 2 +- src/Exception/RuntimeException.php | 2 +- src/Getopt.php | 2 +- src/Prompt/AbstractPrompt.php | 2 +- src/Prompt/Char.php | 2 +- src/Prompt/Confirm.php | 2 +- src/Prompt/Line.php | 2 +- src/Prompt/Number.php | 2 +- src/Prompt/PromptInterface.php | 2 +- src/Prompt/Select.php | 2 +- src/Request.php | 2 +- src/Response.php | 2 +- src/RouteMatcher/DefaultRouteMatcher.php | 2 +- src/RouteMatcher/RouteMatcherInterface.php | 2 +- 31 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 2cbfd81..80df193 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index eb3f8d3..2fa1eb8 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 7e5c505..5f07863 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index bd983cb..f1b1eb9 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 9ba1b9c..22ef674 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 850c8f1..591b3fd 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/Ascii.php b/src/Charset/Ascii.php index 4bda285..072c2d6 100644 --- a/src/Charset/Ascii.php +++ b/src/Charset/Ascii.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/AsciiExtended.php b/src/Charset/AsciiExtended.php index 8561d71..e8e071f 100644 --- a/src/Charset/AsciiExtended.php +++ b/src/Charset/AsciiExtended.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/CharsetInterface.php b/src/Charset/CharsetInterface.php index 138f642..c64656c 100644 --- a/src/Charset/CharsetInterface.php +++ b/src/Charset/CharsetInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/DECSG.php b/src/Charset/DECSG.php index 038809a..3bb3d60 100644 --- a/src/Charset/DECSG.php +++ b/src/Charset/DECSG.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/Utf8.php b/src/Charset/Utf8.php index 634e7b4..f882793 100644 --- a/src/Charset/Utf8.php +++ b/src/Charset/Utf8.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Charset/Utf8Heavy.php b/src/Charset/Utf8Heavy.php index cad5ac7..ca51452 100644 --- a/src/Charset/Utf8Heavy.php +++ b/src/Charset/Utf8Heavy.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Color/Xterm256.php b/src/Color/Xterm256.php index b3d3ba4..1728014 100644 --- a/src/Color/Xterm256.php +++ b/src/Color/Xterm256.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/ColorInterface.php b/src/ColorInterface.php index fa5d321..b2cc770 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Console.php b/src/Console.php index 3db0206..6e96542 100644 --- a/src/Console.php +++ b/src/Console.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index f95109c..ac0d6fb 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index b0893dd..70d8baf 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 3380d5c..ad3b4e9 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 21e2771..6551912 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Getopt.php b/src/Getopt.php index 7352e27..b986a00 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index 7ccb28c..cd717cf 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 648ff2c..7a7dde1 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 93399e3..77db665 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 45a885a..4abcd5e 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index 7bb299b..8ce5330 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/PromptInterface.php b/src/Prompt/PromptInterface.php index 4f1ece4..a4f1376 100644 --- a/src/Prompt/PromptInterface.php +++ b/src/Prompt/PromptInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 6eb5e42..896a8c1 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Request.php b/src/Request.php index 16d6bf0..57b48bb 100644 --- a/src/Request.php +++ b/src/Request.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Response.php b/src/Response.php index df580c9..9ed1362 100644 --- a/src/Response.php +++ b/src/Response.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index e897234..67bf354 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/RouteMatcher/RouteMatcherInterface.php b/src/RouteMatcher/RouteMatcherInterface.php index e165676..66e5a41 100644 --- a/src/RouteMatcher/RouteMatcherInterface.php +++ b/src/RouteMatcher/RouteMatcherInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ From 2303ab729e4f13e3133e68717fce1b979787ee93 Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Sun, 12 Jan 2014 12:56:00 -0500 Subject: [PATCH 16/29] CS fix, fixed @param doc --- src/Adapter/Posix.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 5f07863..1128892 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -225,9 +225,9 @@ public function setPos($x, $y) /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param int $color - * @param null|int $bgColor + * @param string $string + * @param int $color + * @param null|int $bgColor * @throws Exception\BadMethodCallException * @return string */ @@ -235,6 +235,7 @@ public function colorize($string, $color = null, $bgColor = null) { $color = $this->getColorCode($color, 'fg'); $bgColor = $this->getColorCode($bgColor, 'bg'); + return ($color !== null ? "\x1b[" . $color . 'm' : '') . ($bgColor !== null ? "\x1b[" . $bgColor . 'm' : '') . $string @@ -244,7 +245,7 @@ public function colorize($string, $color = null, $bgColor = null) /** * Change current drawing color. * - * @param int $color + * @param int $color * @throws Exception\BadMethodCallException */ public function setColor($color) @@ -256,7 +257,7 @@ public function setColor($color) /** * Change current drawing background color * - * @param int $bgColor + * @param int $bgColor * @throws Exception\BadMethodCallException */ public function setBgColor($bgColor) @@ -308,13 +309,14 @@ public function getDefaultCharset() if ($this->isUtf8()) { return new Charset\Utf8; } + return new Charset\DECSG(); } /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars + * @param string|null $mask A list of allowed chars * @return string */ public function readChar($mask = null) @@ -328,6 +330,7 @@ public function readChar($mask = null) fclose($stream); $this->restoreTTYMode(); + return $char; } @@ -372,7 +375,8 @@ protected function setTTYMode($mode) /** * Get the final color code and throw exception on error * - * @param null|int|Xterm256 $color + * @param null|int|Xterm256 $color + * @param string $type (optional) Foreground 'fg' or background 'bg'. * @throws Exception\BadMethodCallException * @return string */ @@ -386,6 +390,7 @@ protected function getColorCode($color, $type = 'fg') } else { $code = sprintf($code, $color::BACKGROUND); } + return $code; } From a9df9727c463ec51233fa69b31803a510bcaeca8 Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Sun, 12 Jan 2014 14:39:12 -0500 Subject: [PATCH 17/29] Params sanity checks --- src/Adapter/AbstractAdapter.php | 27 ++++++++++++++++++++------- test/Adapter/AbstractAdapterTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 6767ed6..c61afec 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -280,13 +280,14 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * @param string $text Text to write - * @param int $width Maximum block width. Negative value means distance from right edge. - * @param int|null $height Maximum block height. Negative value means distance from bottom edge. - * @param int $x Block X coordinate (column) - * @param int $y Block Y coordinate (row) - * @param null|int $color (optional) Text color - * @param null|int $bgColor (optional) Text background color + * @param string $text Text to write + * @param int $width Maximum block width. Negative value means distance from right edge. + * @param int|null $height Maximum block height. Negative value means distance from bottom edge. + * @param int $x Block X coordinate (column) + * @param int $y Block Y coordinate (row) + * @param null|int $color (optional) Text color + * @param null|int $bgColor (optional) Text background color + * @throws Exception\InvalidArgumentException */ public function writeTextBlock( $text, @@ -297,6 +298,18 @@ public function writeTextBlock( $color = null, $bgColor = null ) { + if ($x < 0 || $y < 0) { + throw new Exception\InvalidArgumentException('Supplied X,Y coordinates are invalid.'); + } + + if ($width < 1) { + throw new Exception\InvalidArgumentException('Invalid width supplied.'); + } + + if (null !== $height && $height < 1) { + throw new Exception\InvalidArgumentException('Invalid height supplied.'); + } + //ensure the text is not wider than the width if (strlen($text) > $width) { $text = wordwrap($text, $width, PHP_EOL, true); diff --git a/test/Adapter/AbstractAdapterTest.php b/test/Adapter/AbstractAdapterTest.php index e21eed5..d6046f3 100644 --- a/test/Adapter/AbstractAdapterTest.php +++ b/test/Adapter/AbstractAdapterTest.php @@ -185,4 +185,31 @@ public function testTextBlockLongerThanHeight() //just get rid of the data in ob ob_get_clean(); } + + /** + * @expectedException \Zend\Console\Exception\InvalidArgumentException + * @expectedExceptionMessage Supplied X,Y coordinates are invalid. + */ + public function testInvalidCoords() + { + $this->adapter->writeTextBlock('', 1, 1, -1, -9); + } + + /** + * @expectedException \Zend\Console\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid width supplied. + */ + public function testInvalidWidth() + { + $this->adapter->writeTextBlock('', 0); + } + + /** + * @expectedException \Zend\Console\Exception\InvalidArgumentException + * @expectedExceptionMessage Invalid height supplied. + */ + public function testInvalidHeight() + { + $this->adapter->writeTextBlock('', 80, 0, 2, 2); + } } From fa2a4ad6e7cebf5157ccf17a845fc992d290c14c Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Fri, 28 Feb 2014 17:25:53 -0500 Subject: [PATCH 18/29] Removed style changes --- src/Adapter/AbstractAdapter.php | 38 ++++++++++++++++----------------- src/Adapter/Posix.php | 16 +++++++------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index c61afec..d9fd1a2 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -108,16 +108,16 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null) * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge * of the console (respectively). * - * @param int $x1 Top-left corner X coordinate (column) - * @param int $y1 Top-left corner Y coordinate (row) - * @param int $x2 Bottom-right corner X coordinate (column) - * @param int $y2 Bottom-right corner Y coordinate (row) - * @param int $lineStyle (optional) Box border style. - * @param int $fillStyle (optional) Box fill style or a single character to fill it with. - * @param int $color (optional) Foreground color - * @param int $bgColor (optional) Background color - * @param null|int $fillColor (optional) Foreground color of box fill - * @param null|int $fillBgColor (optional) Background color of box fill + * @param int $x1 Top-left corner X coordinate (column) + * @param int $y1 Top-left corner Y coordinate (row) + * @param int $x2 Bottom-right corner X coordinate (column) + * @param int $y2 Bottom-right corner Y coordinate (row) + * @param int $lineStyle (optional) Box border style. + * @param int $fillStyle (optional) Box fill style or a single character to fill it with. + * @param int $color (optional) Foreground color + * @param int $bgColor (optional) Background color + * @param null|int $fillColor (optional) Foreground color of box fill + * @param null|int $fillBgColor (optional) Background color of box fill * @throws Exception\BadMethodCallException if coordinates are invalid */ public function writeBox( @@ -280,13 +280,13 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * @param string $text Text to write - * @param int $width Maximum block width. Negative value means distance from right edge. - * @param int|null $height Maximum block height. Negative value means distance from bottom edge. - * @param int $x Block X coordinate (column) - * @param int $y Block Y coordinate (row) - * @param null|int $color (optional) Text color - * @param null|int $bgColor (optional) Text background color + * @param string $text Text to write + * @param int $width Maximum block width. Negative value means distance from right edge. + * @param int|null $height Maximum block height. Negative value means distance from bottom edge. + * @param int $x Block X coordinate (column) + * @param int $y Block Y coordinate (row) + * @param null|int $color (optional) Text color + * @param null|int $bgColor (optional) Text background color * @throws Exception\InvalidArgumentException */ public function writeTextBlock( @@ -512,7 +512,7 @@ public function clearScreen() /** * Read a single line from the console input * - * @param int $maxLength Maximum response length + * @param int $maxLength Maximum response length * @return string */ public function readLine($maxLength = 2048) @@ -527,7 +527,7 @@ public function readLine($maxLength = 2048) /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars + * @param string|null $mask A list of allowed chars * @return string */ public function readChar($mask = null) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 1128892..1010fcd 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -225,9 +225,9 @@ public function setPos($x, $y) /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param int $color - * @param null|int $bgColor + * @param string $string + * @param int $color + * @param null|int $bgColor * @throws Exception\BadMethodCallException * @return string */ @@ -245,7 +245,7 @@ public function colorize($string, $color = null, $bgColor = null) /** * Change current drawing color. * - * @param int $color + * @param int $color * @throws Exception\BadMethodCallException */ public function setColor($color) @@ -257,7 +257,7 @@ public function setColor($color) /** * Change current drawing background color * - * @param int $bgColor + * @param int $bgColor * @throws Exception\BadMethodCallException */ public function setBgColor($bgColor) @@ -316,7 +316,7 @@ public function getDefaultCharset() /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars + * @param string|null $mask A list of allowed chars * @return string */ public function readChar($mask = null) @@ -375,8 +375,8 @@ protected function setTTYMode($mode) /** * Get the final color code and throw exception on error * - * @param null|int|Xterm256 $color - * @param string $type (optional) Foreground 'fg' or background 'bg'. + * @param null|int|Xterm256 $color + * @param string $type (optional) Foreground 'fg' or background 'bg'. * @throws Exception\BadMethodCallException * @return string */ From 23f82c6dd561cccdefb3abab0173c43a1c98ee88 Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Fri, 28 Feb 2014 17:28:45 -0500 Subject: [PATCH 19/29] Removed more stylistic changes --- src/Adapter/AbstractAdapter.php | 3 +-- src/Adapter/Posix.php | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index d9fd1a2..b75d53c 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -244,6 +244,7 @@ public function writeBox( } } + // Draw corners if ($lineStyle !== static::LINE_NONE) { if ($color !== null) { @@ -520,7 +521,6 @@ public function readLine($maxLength = 2048) $f = fopen('php://stdin','r'); $line = stream_get_line($f, $maxLength, PHP_EOL); fclose($f); - return rtrim($line,"\n\r"); } @@ -537,7 +537,6 @@ public function readChar($mask = null) $char = fread($f,1); } while ("" === $char || ($mask !== null && false === strstr($mask, $char))); fclose($f); - return $char; } diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 1010fcd..5ad9cff 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -235,7 +235,6 @@ public function colorize($string, $color = null, $bgColor = null) { $color = $this->getColorCode($color, 'fg'); $bgColor = $this->getColorCode($bgColor, 'bg'); - return ($color !== null ? "\x1b[" . $color . 'm' : '') . ($bgColor !== null ? "\x1b[" . $bgColor . 'm' : '') . $string @@ -309,7 +308,6 @@ public function getDefaultCharset() if ($this->isUtf8()) { return new Charset\Utf8; } - return new Charset\DECSG(); } @@ -330,7 +328,6 @@ public function readChar($mask = null) fclose($stream); $this->restoreTTYMode(); - return $char; } @@ -404,7 +401,6 @@ protected function getColorCode($color, $type = 'fg') return static::$ansiColorMap[$type][$color]; } - return null; } } From fb17277b1ab0a4fb68f8d1e781a31fe205fe6dcd Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Fri, 28 Feb 2014 17:30:28 -0500 Subject: [PATCH 20/29] Yet another stylistic change reverted --- src/Adapter/Posix.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 5ad9cff..0beb935 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -387,7 +387,6 @@ protected function getColorCode($color, $type = 'fg') } else { $code = sprintf($code, $color::BACKGROUND); } - return $code; } @@ -401,6 +400,7 @@ protected function getColorCode($color, $type = 'fg') return static::$ansiColorMap[$type][$color]; } + return null; } } From e64b77838719b539bd8400fe8377f95c4c0a11b5 Mon Sep 17 00:00:00 2001 From: Nick Ilyin Date: Fri, 28 Feb 2014 17:40:44 -0500 Subject: [PATCH 21/29] Removed stylistic changes --- src/Getopt.php | 75 +++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index b629353..653acc7 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -199,9 +199,9 @@ class Getopt * The third parameter is an array of configuration parameters * to control the behavior of this instance of Getopt; it is optional. * - * @param array $rules - * @param array $argv - * @param array $getoptConfig + * @param array $rules + * @param array $argv + * @param array $getoptConfig * @throws Exception\InvalidArgumentException */ public function __construct($rules, $argv = null, $getoptConfig = array()) @@ -252,10 +252,8 @@ public function __isset($key) $this->parse(); if (isset($this->ruleMap[$key])) { $key = $this->ruleMap[$key]; - return isset($this->options[$key]); } - return false; } @@ -304,9 +302,9 @@ public function __unset($key) * Define additional command-line arguments. * These are appended to those defined when the constructor was called. * - * @param array $argv + * @param array $argv * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter - * @return \Zend\Console\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function addArguments($argv) { @@ -315,7 +313,6 @@ public function addArguments($argv) } $this->argv = array_merge($this->argv, $argv); $this->parsed = false; - return $this; } @@ -323,9 +320,9 @@ public function addArguments($argv) * Define full set of command-line arguments. * These replace any currently defined. * - * @param array $argv + * @param array $argv * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter - * @return \Zend\Console\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setArguments($argv) { @@ -334,7 +331,6 @@ public function setArguments($argv) } $this->argv = $argv; $this->parsed = false; - return $this; } @@ -343,7 +339,7 @@ public function setArguments($argv) * These are not program options, but properties to configure * the behavior of Zend\Console\Getopt. * - * @param array $getoptConfig + * @param array $getoptConfig * @return \Zend\Console\Getopt Provides a fluent interface */ public function setOptions($getoptConfig) @@ -353,7 +349,6 @@ public function setOptions($getoptConfig) $this->setOption($key, $value); } } - return $this; } @@ -362,8 +357,8 @@ public function setOptions($getoptConfig) * These are not program options, but properties to configure * the behavior of Zend\Console\Getopt. * - * @param string $configKey - * @param string $configValue + * @param string $configKey + * @param string $configValue * @return \Zend\Console\Getopt Provides a fluent interface */ public function setOption($configKey, $configValue) @@ -371,7 +366,6 @@ public function setOption($configKey, $configValue) if ($configKey !== null) { $this->getoptConfig[$configKey] = $configValue; } - return $this; } @@ -379,7 +373,7 @@ public function setOption($configKey, $configValue) * Define additional option rules. * These are appended to the rules defined when the constructor was called. * - * @param array $rules + * @param array $rules * @return \Zend\Console\Getopt Provides a fluent interface */ public function addRules($rules) @@ -391,7 +385,7 @@ public function addRules($rules) $this->_addRulesModeZend($rules); break; } - // intentional fallthrough + // intentional fallthrough case self::MODE_GNU: $this->_addRulesModeGnu($rules); break; @@ -405,7 +399,6 @@ public function addRules($rules) $this->$method($rules); } $this->parsed = false; - return $this; } @@ -421,7 +414,6 @@ public function toString() foreach ($this->options as $flag => $value) { $s[] = $flag . '=' . ($value === true ? 'true' : $value); } - return implode(' ', $s); } @@ -444,7 +436,6 @@ public function toArray() $s[] = $value; } } - return $s; } @@ -467,7 +458,6 @@ public function toJson() } $json = \Zend\Json\Json::encode($j); - return $json; } @@ -491,7 +481,6 @@ public function toXml() $optionsNode->appendChild($optionNode); } $xml = $doc->saveXML(); - return $xml; } @@ -503,7 +492,6 @@ public function toXml() public function getOptions() { $this->parse(); - return array_keys($this->options); } @@ -529,7 +517,6 @@ public function getOption($flag) return $this->options[$flag]; } } - return null; } @@ -541,7 +528,6 @@ public function getOption($flag) public function getRemainingArgs() { $this->parse(); - return $this->remainingArgs; } @@ -551,7 +537,6 @@ public function getArguments() foreach ($this->getOptions() as $option) { $result[$option] = $this->getOption($option); } - return $result; } @@ -602,10 +587,9 @@ public function getUsageMessage() } foreach ($lines as $linepart) { $usage .= sprintf("%s %s\n", - str_pad($linepart['name'], $maxLen), - $linepart['help']); + str_pad($linepart['name'], $maxLen), + $linepart['help']); } - return $usage; } @@ -615,9 +599,9 @@ public function getUsageMessage() * The parameter $aliasMap is an associative array * mapping option name (short or long) to an alias. * - * @param array $aliasMap + * @param array $aliasMap * @throws \Zend\Console\Exception\ExceptionInterface - * @return \Zend\Console\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setAliases($aliasMap) { @@ -637,7 +621,6 @@ public function setAliases($aliasMap) $this->rules[$flag]['alias'][] = $alias; $this->ruleMap[$alias] = $flag; } - return $this; } @@ -647,7 +630,7 @@ public function setAliases($aliasMap) * The parameter $helpMap is an associative array * mapping option name (short or long) to the help string. * - * @param array $helpMap + * @param array $helpMap * @return \Zend\Console\Getopt Provides a fluent interface */ public function setHelp($helpMap) @@ -659,7 +642,6 @@ public function setHelp($helpMap) $flag = $this->ruleMap[$flag]; $this->rules[$flag]['help'] = $help; } - return $this; } @@ -789,8 +771,8 @@ protected function _parseShortOptionCluster(&$argv) /** * Parse command-line arguments for a single option. * - * @param string $flag - * @param mixed $argv + * @param string $flag + * @param mixed $argv * @throws \Zend\Console\Exception\ExceptionInterface * @return void */ @@ -811,7 +793,7 @@ protected function _parseSingleOption($flag, &$argv) throw new Exception\RuntimeException( "Option \"$flag\" is not recognized.", $this->getUsageMessage() - ); + ); } // Magic methods in future will use this mark as real flag value @@ -834,7 +816,7 @@ protected function _parseSingleOption($flag, &$argv) throw new Exception\RuntimeException( "Option \"$flag\" requires a parameter.", $this->getUsageMessage() - ); + ); } break; case 'optional': @@ -859,7 +841,7 @@ protected function _parseSingleOption($flag, &$argv) * Throw runtime exception if this action is deny by configuration * or no one numeric option handlers is defined * - * @param int $value + * @param int $value * @throws Exception\RuntimeException * @return void */ @@ -921,8 +903,8 @@ protected function _setSingleOptionValue($flag, $value) protected function _setBooleanFlagValue($flag) { $this->options[$flag] = array_key_exists($flag, $this->options) - ? (int) $this->options[$flag] + 1 - : true; + ? (int) $this->options[$flag] + 1 + : true; } /** @@ -930,8 +912,8 @@ protected function _setBooleanFlagValue($flag) * the option $flag. * Throw an exception in most other cases. * - * @param string $flag - * @param string $param + * @param string $flag + * @param string $param * @throws \Zend\Console\Exception\ExceptionInterface * @return bool */ @@ -960,7 +942,6 @@ protected function _checkParameterType($flag, $param) default: break; } - return true; } @@ -1001,7 +982,7 @@ protected function _addRulesModeGnu($rules) /** * Define legal options using the Zend-style format. * - * @param array $rules + * @param array $rules * @throws \Zend\Console\Exception\ExceptionInterface * @return void */ @@ -1076,4 +1057,4 @@ protected function _addRulesModeZend($rules) $this->rules[$mainFlag] = $rule; } } -} +} \ No newline at end of file From 4c5928199c6afc0f7f38644a58d3592b6829fdd7 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 4 Mar 2014 15:20:04 -0600 Subject: [PATCH 22/29] [zendframework/zf2#5711] CS fixes - space after opening comment - removed a conditional by rephrasing and returning in the conditional body --- src/Adapter/AbstractAdapter.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index b75d53c..b7c039d 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -311,26 +311,25 @@ public function writeTextBlock( throw new Exception\InvalidArgumentException('Invalid height supplied.'); } - //ensure the text is not wider than the width - if (strlen($text) > $width) { - $text = wordwrap($text, $width, PHP_EOL, true); - } else { - //just write the line at the spec'd position + // ensure the text is not wider than the width + if (strlen($text) <= $width) { + // just write the line at the spec'd position $this->setPos($x, $y); $this->write($text, $color, $bgColor); - return; } - //convert to array of lines + $text = wordwrap($text, $width, PHP_EOL, true); + + // convert to array of lines $lines = explode(PHP_EOL, $text); - //truncate if height was specified + // truncate if height was specified if (null !== $height && count($lines) > $height) { $lines = array_slice($lines, 0, $height); } - //write each line + // write each line $curY = $y; foreach ($lines as $line) { $this->setPos($x, $curY); From a7fe006b781547a9565b73dd9baf5622c7e3491a Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 4 Mar 2014 15:26:30 -0600 Subject: [PATCH 23/29] [zendframework/zf2#5713] CS fixes - One argument per line on multi-line function calls - @return self (instead of \Zend\Console\Getopt); performed throughout class for consistency - Removed all @return void and @return null annotations - Relative namespace qualification for all @throws annotations --- src/Getopt.php | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 653acc7..a16d232 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -262,7 +262,6 @@ public function __isset($key) * * @param string $key * @param string $value - * @return void */ public function __set($key, $value) { @@ -287,7 +286,6 @@ public function __toString() * Unset an option. * * @param string $key - * @return void */ public function __unset($key) { @@ -303,8 +301,8 @@ public function __unset($key) * These are appended to those defined when the constructor was called. * * @param array $argv - * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter - * @return \Zend\Console\Getopt Provides a fluent interface + * @throws Exception\InvalidArgumentException When not given an array as parameter + * @return self */ public function addArguments($argv) { @@ -321,8 +319,8 @@ public function addArguments($argv) * These replace any currently defined. * * @param array $argv - * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter - * @return \Zend\Console\Getopt Provides a fluent interface + * @throws Exception\InvalidArgumentException When not given an array as parameter + * @return self */ public function setArguments($argv) { @@ -340,7 +338,7 @@ public function setArguments($argv) * the behavior of Zend\Console\Getopt. * * @param array $getoptConfig - * @return \Zend\Console\Getopt Provides a fluent interface + * @return self */ public function setOptions($getoptConfig) { @@ -359,7 +357,7 @@ public function setOptions($getoptConfig) * * @param string $configKey * @param string $configValue - * @return \Zend\Console\Getopt Provides a fluent interface + * @return self */ public function setOption($configKey, $configValue) { @@ -374,7 +372,7 @@ public function setOption($configKey, $configValue) * These are appended to the rules defined when the constructor was called. * * @param array $rules - * @return \Zend\Console\Getopt Provides a fluent interface + * @return self */ public function addRules($rules) { @@ -586,9 +584,11 @@ public function getUsageMessage() $lines[] = $linepart; } foreach ($lines as $linepart) { - $usage .= sprintf("%s %s\n", + $usage .= sprintf( + "%s %s\n", str_pad($linepart['name'], $maxLen), - $linepart['help']); + $linepart['help'] + ); } return $usage; } @@ -600,8 +600,8 @@ public function getUsageMessage() * mapping option name (short or long) to an alias. * * @param array $aliasMap - * @throws \Zend\Console\Exception\ExceptionInterface - * @return \Zend\Console\Getopt Provides a fluent interface + * @throws Exception\ExceptionInterface + * @return self */ public function setAliases($aliasMap) { @@ -631,7 +631,7 @@ public function setAliases($aliasMap) * mapping option name (short or long) to the help string. * * @param array $helpMap - * @return \Zend\Console\Getopt Provides a fluent interface + * @return self */ public function setHelp($helpMap) { @@ -652,13 +652,14 @@ public function setHelp($helpMap) * Also find option parameters, and remaining arguments after * all options have been parsed. * - * @return \Zend\Console\Getopt|null Provides a fluent interface + * @return self */ public function parse() { if ($this->parsed === true) { - return; + return $this; } + $argv = $this->argv; $this->options = array(); $this->remainingArgs = array(); @@ -702,7 +703,7 @@ public function parse() * false then an Exception\RuntimeException will be thrown indicating that * there is a parse issue with this option. * - * @return \Zend\Console\Getopt Fluent interface. + * @return self */ public function setOptionCallback($option, \Closure $callback) { @@ -738,7 +739,6 @@ protected function triggerCallbacks() * Long options may not be clustered. * * @param mixed &$argv - * @return void */ protected function _parseLongOption(&$argv) { @@ -758,7 +758,6 @@ protected function _parseLongOption(&$argv) * Short options may be clustered. * * @param mixed &$argv - * @return void */ protected function _parseShortOptionCluster(&$argv) { @@ -773,8 +772,7 @@ protected function _parseShortOptionCluster(&$argv) * * @param string $flag * @param mixed $argv - * @throws \Zend\Console\Exception\ExceptionInterface - * @return void + * @throws Exception\ExceptionInterface */ protected function _parseSingleOption($flag, &$argv) { @@ -867,7 +865,6 @@ protected function _setNumericOptionValue($value) * * @param string $flag * @param string $value - * @return null */ protected function _setSingleOptionValue($flag, $value) { @@ -898,7 +895,6 @@ protected function _setSingleOptionValue($flag, $value) * In other case increase value to show count of flags' usage * * @param string $flag - * @return null */ protected function _setBooleanFlagValue($flag) { @@ -914,7 +910,7 @@ protected function _setBooleanFlagValue($flag) * * @param string $flag * @param string $param - * @throws \Zend\Console\Exception\ExceptionInterface + * @throws Exception\ExceptionInterface * @return bool */ protected function _checkParameterType($flag, $param) @@ -949,7 +945,6 @@ protected function _checkParameterType($flag, $param) * Define legal options using the gnu-style format. * * @param string $rules - * @return void */ protected function _addRulesModeGnu($rules) { @@ -983,8 +978,7 @@ protected function _addRulesModeGnu($rules) * Define legal options using the Zend-style format. * * @param array $rules - * @throws \Zend\Console\Exception\ExceptionInterface - * @return void + * @throws Exception\ExceptionInterface */ protected function _addRulesModeZend($rules) { @@ -1057,4 +1051,4 @@ protected function _addRulesModeZend($rules) $this->rules[$mainFlag] = $rule; } } -} \ No newline at end of file +} From f67dde7ef7fea04f0d7569b600f6b6c6340b73e3 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Tue, 11 Mar 2014 20:52:22 +0100 Subject: [PATCH 24/29] Fix console route matcher was lowercasing optional value params' names. --- test/RouteMatcher/DefaultRouteMatcherTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index afb171d..3e3e95d 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -845,6 +845,28 @@ public static function routeProvider() 'something' => null, ) ), + 'value-optional-with-mixed-case' => array( + '[] [--bar=]', + array('aBc', '--bar','abc'), + array( + 'mixedCaseParam' => 'aBc', + 'foo' => null, + 'bar' => 'abc', + 'baz' => null, + 'something' => null, + ) + ), + 'value-optional-with-upper-case' => array( + '[] [--bar=]', + array('aBc', '--bar', 'abc'), + array( + 'UPPERCASEPARAM' => 'aBc', + 'foo' => null, + 'bar' => 'abc', + 'baz' => null, + 'something' => null, + ) + ), /** * @bug ZF2-5671 * @link https://github.com/zendframework/zf2/issues/5671 From 0e602dece6677bf18638e27fc90e3b294b35c51b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 13 Mar 2014 12:51:17 +0100 Subject: [PATCH 25/29] Upgrading branch aliases for components: 2.2-dev -> 2.3-dev, 2.3-dev -> 2.4-dev --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a49f132..9aefbc9 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" } }, "autoload-dev": { From 54cd9ec18c227c7687e36148f866b050fe39ec5e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 25 Feb 2014 02:28:37 +0700 Subject: [PATCH 26/29] patch zendframework/zf2#5860 : on Console component --- src/Adapter/AbstractAdapter.php | 2 +- src/Adapter/AdapterInterface.php | 93 +++++++++++++++++++------------- src/Adapter/Posix.php | 2 +- src/Adapter/Windows.php | 2 +- src/Color/Xterm256.php | 2 +- src/Prompt/Line.php | 2 +- src/Prompt/PromptInterface.php | 1 + 7 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index b7c039d..a0cf8b7 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -361,7 +361,7 @@ public function getHeight() /** * Determine and return current console width and height. * - * @return array array($width, $height) + * @return int[] array($width, $height) */ public function getSize() { diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 2fa1eb8..50ddd1b 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -26,18 +26,20 @@ interface AdapterInterface /** * Write a chunk of text to console. * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor + * @return void */ public function write($text, $color = null, $bgColor = null); /** * Alias for write() * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor + * @return void */ public function writeText($text, $color = null, $bgColor = null); @@ -45,20 +47,22 @@ public function writeText($text, $color = null, $bgColor = null); * Write a single line of text to console and advance cursor to the next line. * If the text is longer than console width it will be truncated. * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor + * @return void */ public function writeLine($text = "", $color = null, $bgColor = null); /** * Write a piece of text at the coordinates of $x and $y * - * @param string $text Text to write - * @param int $x Console X coordinate (column) - * @param int $y Console Y coordinate (row) - * @param null|int $color - * @param null|int $bgColor + * @param string $text Text to write + * @param int $x Console X coordinate (column) + * @param int $y Console Y coordinate (row) + * @param null|int $color + * @param null|int $bgColor + * @return void */ public function writeAt($text, $x, $y, $color = null, $bgColor = null); @@ -67,16 +71,17 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null); * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge * of the console (respectively). * - * @param int $x1 Top-left corner X coordinate (column) - * @param int $y1 Top-left corner Y coordinate (row) - * @param int $x2 Bottom-right corner X coordinate (column) - * @param int $y2 Bottom-right corner Y coordinate (row) - * @param int $lineStyle (optional) Box border style. - * @param int $fillStyle (optional) Box fill style or a single character to fill it with. - * @param int $color (optional) Foreground color - * @param int $bgColor (optional) Background color - * @param null|int $fillColor (optional) Foreground color of box fill - * @param null|int $fillBgColor (optional) Background color of box fill + * @param int $x1 Top-left corner X coordinate (column) + * @param int $y1 Top-left corner Y coordinate (row) + * @param int $x2 Bottom-right corner X coordinate (column) + * @param int $y2 Bottom-right corner Y coordinate (row) + * @param int $lineStyle (optional) Box border style. + * @param int $fillStyle (optional) Box fill style or a single character to fill it with. + * @param int $color (optional) Foreground color + * @param int $bgColor (optional) Background color + * @param null|int $fillColor (optional) Foreground color of box fill + * @param null|int $fillBgColor (optional) Background color of box fill + * @return void */ public function writeBox( $x1, @@ -96,13 +101,14 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * @param string $text Text to write - * @param int $width Maximum block width. Negative value means distance from right edge. - * @param int|null $height Maximum block height. Negative value means distance from bottom edge. - * @param int $x Block X coordinate (column) - * @param int $y Block Y coordinate (row) - * @param null|int $color (optional) Text color - * @param null|int $bgColor (optional) Text background color + * @param string $text Text to write + * @param int $width Maximum block width. Negative value means distance from right edge. + * @param int|null $height Maximum block height. Negative value means distance from bottom edge. + * @param int $x Block X coordinate (column) + * @param int $y Block Y coordinate (row) + * @param null|int $color (optional) Text color + * @param null|int $bgColor (optional) Text background color + * @return void */ public function writeTextBlock( $text, @@ -146,18 +152,21 @@ public function isUtf8(); /** * Set cursor position * - * @param int $x - * @param int $y + * @param int $x + * @param int $y + * @return void */ public function setPos($x, $y); /** * Hide console cursor + * @return void */ public function hideCursor(); /** * Show console cursor + * @return void */ public function showCursor(); @@ -171,28 +180,32 @@ public function getTitle(); /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param null|int $color Foreground color - * @param null|int $bgColor Background color + * @param string $string + * @param null|int $color Foreground color + * @param null|int $bgColor Background color + * @return string */ public function colorize($string, $color = null, $bgColor = null); /** * Change current drawing color. * - * @param int $color + * @param int $color + * @return void */ public function setColor($color); /** * Change current drawing background color * - * @param int $color + * @param int $color + * @return void */ public function setBgColor($color); /** * Reset color to console default. + * @return void */ public function resetColor(); @@ -201,6 +214,7 @@ public function resetColor(); * Set Console charset to use. * * @param CharsetInterface $charset + * @return void */ public function setCharset(CharsetInterface $charset); @@ -218,16 +232,19 @@ public function getDefaultCharset(); /** * Clear console screen + * @return void */ public function clear(); /** * Clear line at cursor position + * @return void */ public function clearLine(); /** * Clear console screen + * @return void */ public function clearScreen(); diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 0beb935..9304dee 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -358,7 +358,7 @@ protected function restoreTTYMode() * Change TTY (Console) mode * * @link http://en.wikipedia.org/wiki/Stty - * @param $mode + * @param string $mode */ protected function setTTYMode($mode) { diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 22ef674..8d6090c 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -64,7 +64,7 @@ public function getWidth() /** * Determine and return current console height. * - * @return false|int + * @return int */ public function getHeight() { diff --git a/src/Color/Xterm256.php b/src/Color/Xterm256.php index 1728014..8b36778 100644 --- a/src/Color/Xterm256.php +++ b/src/Color/Xterm256.php @@ -40,7 +40,7 @@ protected function __construct($color = null) * Calcluate the X11 color value of a hexadecimal color * * @param string $hexColor - * @return string + * @return self */ public static function calculate($hexColor) { diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 4abcd5e..7a7427d 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -51,7 +51,7 @@ public function __construct($promptText = 'Please enter value: ', $allowEmpty = /** * Show the prompt to user and return the answer. * - * @return mixed + * @return string */ public function show() { diff --git a/src/Prompt/PromptInterface.php b/src/Prompt/PromptInterface.php index a4f1376..da1b621 100644 --- a/src/Prompt/PromptInterface.php +++ b/src/Prompt/PromptInterface.php @@ -38,6 +38,7 @@ public function getConsole(); * Set console adapter to use when showing prompt. * * @param ConsoleAdapter $adapter + * @return void */ public function setConsole(ConsoleAdapter $adapter); } From ba76fe7f0e8ea962f47201ea1a299ef5aaac0ccc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 25 Feb 2014 04:29:58 +0700 Subject: [PATCH 27/29] feedback on Console : avoid cosmetic changes --- src/Adapter/AdapterInterface.php | 76 ++++++++++++++++---------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 50ddd1b..f218baf 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -26,9 +26,9 @@ interface AdapterInterface /** * Write a chunk of text to console. * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor * @return void */ public function write($text, $color = null, $bgColor = null); @@ -36,9 +36,9 @@ public function write($text, $color = null, $bgColor = null); /** * Alias for write() * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor * @return void */ public function writeText($text, $color = null, $bgColor = null); @@ -47,9 +47,9 @@ public function writeText($text, $color = null, $bgColor = null); * Write a single line of text to console and advance cursor to the next line. * If the text is longer than console width it will be truncated. * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor * @return void */ public function writeLine($text = "", $color = null, $bgColor = null); @@ -57,11 +57,11 @@ public function writeLine($text = "", $color = null, $bgColor = null); /** * Write a piece of text at the coordinates of $x and $y * - * @param string $text Text to write - * @param int $x Console X coordinate (column) - * @param int $y Console Y coordinate (row) - * @param null|int $color - * @param null|int $bgColor + * @param string $text Text to write + * @param int $x Console X coordinate (column) + * @param int $y Console Y coordinate (row) + * @param null|int $color + * @param null|int $bgColor * @return void */ public function writeAt($text, $x, $y, $color = null, $bgColor = null); @@ -71,16 +71,16 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null); * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge * of the console (respectively). * - * @param int $x1 Top-left corner X coordinate (column) - * @param int $y1 Top-left corner Y coordinate (row) - * @param int $x2 Bottom-right corner X coordinate (column) - * @param int $y2 Bottom-right corner Y coordinate (row) - * @param int $lineStyle (optional) Box border style. - * @param int $fillStyle (optional) Box fill style or a single character to fill it with. - * @param int $color (optional) Foreground color - * @param int $bgColor (optional) Background color - * @param null|int $fillColor (optional) Foreground color of box fill - * @param null|int $fillBgColor (optional) Background color of box fill + * @param int $x1 Top-left corner X coordinate (column) + * @param int $y1 Top-left corner Y coordinate (row) + * @param int $x2 Bottom-right corner X coordinate (column) + * @param int $y2 Bottom-right corner Y coordinate (row) + * @param int $lineStyle (optional) Box border style. + * @param int $fillStyle (optional) Box fill style or a single character to fill it with. + * @param int $color (optional) Foreground color + * @param int $bgColor (optional) Background color + * @param null|int $fillColor (optional) Foreground color of box fill + * @param null|int $fillBgColor (optional) Background color of box fill * @return void */ public function writeBox( @@ -101,13 +101,13 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * @param string $text Text to write - * @param int $width Maximum block width. Negative value means distance from right edge. - * @param int|null $height Maximum block height. Negative value means distance from bottom edge. - * @param int $x Block X coordinate (column) - * @param int $y Block Y coordinate (row) - * @param null|int $color (optional) Text color - * @param null|int $bgColor (optional) Text background color + * @param string $text Text to write + * @param int $width Maximum block width. Negative value means distance from right edge. + * @param int|null $height Maximum block height. Negative value means distance from bottom edge. + * @param int $x Block X coordinate (column) + * @param int $y Block Y coordinate (row) + * @param null|int $color (optional) Text color + * @param null|int $bgColor (optional) Text background color * @return void */ public function writeTextBlock( @@ -152,8 +152,8 @@ public function isUtf8(); /** * Set cursor position * - * @param int $x - * @param int $y + * @param int $x + * @param int $y * @return void */ public function setPos($x, $y); @@ -180,9 +180,9 @@ public function getTitle(); /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param null|int $color Foreground color - * @param null|int $bgColor Background color + * @param string $string + * @param null|int $color Foreground color + * @param null|int $bgColor Background color * @return string */ public function colorize($string, $color = null, $bgColor = null); @@ -190,7 +190,7 @@ public function colorize($string, $color = null, $bgColor = null); /** * Change current drawing color. * - * @param int $color + * @param int $color * @return void */ public function setColor($color); @@ -198,7 +198,7 @@ public function setColor($color); /** * Change current drawing background color * - * @param int $color + * @param int $color * @return void */ public function setBgColor($color); From 626c1e19f7244b1ba6179c40552ad7584eed7110 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 19 Mar 2014 17:46:05 +0100 Subject: [PATCH 28/29] typo on comment fixed --- src/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console.php b/src/Console.php index 6e96542..a3c7013 100644 --- a/src/Console.php +++ b/src/Console.php @@ -30,7 +30,7 @@ abstract class Console /** * Create and return Adapter\AdapterInterface instance. * - * @param null|string $forceAdapter Optional adapter class name. Ccan be absolute namespace or class name + * @param null|string $forceAdapter Optional adapter class name. Can be absolute namespace or class name * relative to Zend\Console\Adapter\. If not provided, a best matching * adapter will be automatically selected. * @param null|string $forceCharset optional charset name can be absolute namespace or class name relative to From 1a0af39edc814618625211474afcdcf30218504b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 6 Aug 2014 22:03:07 +0200 Subject: [PATCH 29/29] zendframework/zf2#6532 - removing redundant indentation on sprintf+exception throw --- src/Adapter/Posix.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 51ff14b..184e6ad 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -392,12 +392,11 @@ protected function getColorCode($color, $type = 'fg') if ($color !== null) { if (!isset(static::$ansiColorMap[$type][$color])) { - throw new Exception\BadMethodCallException( - sprintf( - 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants or use Zend\Console\Color\Xterm256::calculate', - $color - ) - ); + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants ' + . 'or use Zend\Console\Color\Xterm256::calculate', + $color + )); } return static::$ansiColorMap[$type][$color];