Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 81 additions & 81 deletions library/Zend/Mvc/Router/Console/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,90 @@ protected function parseRouteDefinition($def)
$unnamedGroupCounter = 1;

while ($pos < $length) {
/**
* Optional value param, i.e.
* [SOMETHING]
*/
if (preg_match('/\G\[(?P<name>[A-Z][A-Z0-9\_\-]*?)\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => false,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory value param, i.e.
* SOMETHING
*/
elseif (preg_match('/\G(?P<name>[A-Z][A-Z0-9\_\-]*?)(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => true,
'positional' => true,
'hasValue' => true,
);
}
/**
* Optional literal param, i.e.
* [something]
*/
elseif (preg_match('/\G\[ *?(?P<name>[a-zA-Z][a-zA-Z0-9\_\-]*?) *?\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => true,
'required' => false,
'positional' => true,
'hasValue' => false,
);
}
/**
* Optional value param, syntax 2, i.e.
* [<something>]
*/
elseif (preg_match('/\G\[ *\<(?P<name>[a-zA-Z][a-zA-Z0-9\_\-]*?)\> *\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => false,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory value param, i.e.
* <something>
*/
elseif (preg_match('/\G\< *(?P<name>[a-zA-Z][a-zA-Z0-9\_\-]*?) *\>(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => false,
'required' => true,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory literal param, i.e.
* something
*/
elseif (preg_match('/\G(?P<name>[a-zA-Z][a-zA-Z0-9\_\-]*?)(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => true,
'required' => true,
'positional' => true,
'hasValue' => false,
);
}
/**
* Mandatory long param
* --param=
* --param=whatever
*/
if (preg_match('/\G--(?P<name>[a-zA-Z0-9][a-zA-Z0-9\_\-]+)(?P<hasValue>=\S*?)?(?: +|$)/s', $def, $m, 0, $pos)) {
elseif (preg_match('/\G--(?P<name>[a-zA-Z0-9][a-zA-Z0-9\_\-]+)(?P<hasValue>=\S*?)?(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'short' => false,
Expand Down Expand Up @@ -281,7 +359,7 @@ protected function parseRouteDefinition($def)
(?P<options>
(?:
\ *?
(?P<name>[a-z0-9][a-zA-Z0-9_\-]*?)
(?P<name>[a-zA-Z][a-zA-Z0-9_\-]*?)
\ *?
(?:\||(?=\]))
\ *?
Expand Down Expand Up @@ -321,7 +399,7 @@ protected function parseRouteDefinition($def)
(?P<options>
(?:
\ *?
(?P<name>[a-z0-9][a-zA-Z0-9_\-]+)
(?P<name>[a-zA-Z][a-zA-Z0-9_\-]+)
\ *?
(?:\||(?=\)))
\ *?
Expand Down Expand Up @@ -433,84 +511,6 @@ protected function parseRouteDefinition($def)
'alternatives' => $options,
'hasValue' => false,
);
}
/**
* Optional literal param, i.e.
* [something]
*/
elseif (preg_match('/\G\[ *?(?P<name>[a-z0-9][a-zA-Z0-9\_\-]*?) *?\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => true,
'required' => false,
'positional' => true,
'hasValue' => false,
);
}
/**
* Optional value param, i.e.
* [SOMETHING]
*/
elseif (preg_match('/\G\[(?P<name>[a-z0-9][a-zA-Z0-9\_\-]*?)\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => false,
'positional' => true,
'hasValue' => true,
);
}
/**
* Optional value param, syntax 2, i.e.
* [<SOMETHING>]
*/
elseif (preg_match('/\G\[ *\<(?P<name>[a-z0-9][a-zA-Z0-9\_\-]*?)\> *\](?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => false,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory value param, i.e.
* <something>
*/
elseif (preg_match('/\G\< *(?P<name>[a-z0-9][a-zA-Z0-9\_\-]*?) *\>(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => false,
'required' => true,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory value param, i.e.
* SOMETHING
*/
elseif (preg_match('/\G(?P<name>[A-Z][a-zA-Z0-9\_\-]*?)(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => strtolower($m['name']),
'literal' => false,
'required' => true,
'positional' => true,
'hasValue' => true,
);
}
/**
* Mandatory literal param, i.e.
* something
*/
elseif (preg_match('/\G(?P<name>[a-z0-9][a-zA-Z0-9\_\-]*?)(?: +|$)/s', $def, $m, 0, $pos)) {
$item = array(
'name' => $m['name'],
'literal' => true,
'required' => true,
'positional' => true,
'hasValue' => false,
);
} else {
throw new Exception\InvalidArgumentException(
'Cannot understand Console route at "' . substr($def, $pos) . '"'
Expand Down
39 changes: 39 additions & 0 deletions tests/ZendTest/Mvc/Router/Console/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,45 @@ public static function routeProvider()
)
),

/**
* @bug ZF2-5671
* @link https://github.com/zendframework/zf2/issues/5671
*/
'mandatory-literal-camel-case' => array(
'FooBar',
array('FooBar'),
array(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this test case.

Why is the expected result an empty array() ? If you're defining a mandatory literal parameter, then the result must be array('FooBar' => null) - see previous test cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

),
'mandatory-literal-camel-case-no-match' => array(
'FooBar',
array('foobar'),
null,
),
'optional-literal-camel-case' => array(
'[FooBar]',
array('FooBar'),
array(),
),
'optional-literal-camel-case-no-match' => array(
'[FooBar]',
array('foobar'),
null,
),
'optional-literal-alternative-camel-case' => array(
'[ FooBar | FoozBar ]',
array('FooBar'),
array(),
),
'required-literal-alternative-camel-case' => array(
'( FooBar | FoozBar )',
array('FooBar'),
array(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem in all of the above cases... this smells like regression.

),
'required-literal-alternative-camel-case-no-match' => array(
'( FooBar | FoozBar )',
array('baz'),
null,
),

);
}
Expand Down