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

Commit

Permalink
Merge branch 'feature/5720' into develop
Browse files Browse the repository at this point in the history
Close #5720
Fixes #5671
  • Loading branch information
weierophinney committed Mar 4, 2014
2 parents d9e3a2b + 4f9bfe1 commit b717a85
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 96 deletions.
188 changes: 94 additions & 94 deletions library/Zend/Console/RouteMatcher/DefaultRouteMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,90 @@ protected function parseDefinition($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 All @@ -121,7 +199,7 @@ protected function parseDefinition($def)
'hasValue' => !empty($m['hasValue']),
);
}
/*
/**
* Optional long flag
* [--param]
*/
Expand All @@ -137,7 +215,7 @@ protected function parseDefinition($def)
'hasValue' => false,
);
}
/*
/**
* Optional long param
* [--param=]
* [--param=whatever]
Expand All @@ -154,7 +232,7 @@ protected function parseDefinition($def)
'hasValue' => !empty($m['hasValue']),
);
}
/*
/**
* Mandatory short param
* -a
* -a=i
Expand All @@ -171,7 +249,7 @@ protected function parseDefinition($def)
'hasValue' => !empty($m['type']) ? $m['type'] : null,
);
}
/*
/**
* Optional short param
* [-a]
* [-a=n]
Expand All @@ -187,7 +265,7 @@ protected function parseDefinition($def)
'hasValue' => !empty($m['type']) ? $m['type'] : null,
);
}
/*
/**
* Optional literal param alternative
* [ something | somethingElse | anotherOne ]
* [ something | somethingElse | anotherOne ]:namedGroup
Expand All @@ -198,7 +276,7 @@ protected function parseDefinition($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 @@ -227,7 +305,7 @@ protected function parseDefinition($def)
);
}

/*
/**
* Required literal param alternative
* ( something | somethingElse | anotherOne )
* ( something | somethingElse | anotherOne ):namedGroup
Expand All @@ -238,7 +316,7 @@ protected function parseDefinition($def)
(?P<options>
(?:
\ *?
(?P<name>[a-z0-9][a-zA-Z0-9_\-]+)
(?P<name>[a-zA-Z][a-zA-Z0-9_\-]+)
\ *?
(?:\||(?=\)))
\ *?
Expand All @@ -265,7 +343,7 @@ protected function parseDefinition($def)
'hasValue' => false,
);
}
/*
/**
* Required long/short flag alternative
* ( --something | --somethingElse | --anotherOne | -s | -a )
* ( --something | --somethingElse | --anotherOne | -s | -a ):namedGroup
Expand Down Expand Up @@ -295,8 +373,8 @@ protected function parseDefinition($def)

// remove prefix
array_walk($options, function (&$val, $key) {
$val = ltrim($val, '-');
});
$val = ltrim($val, '-');
});

// prepare item
$item = array(
Expand All @@ -308,7 +386,7 @@ protected function parseDefinition($def)
'hasValue' => false,
);
}
/*
/**
* Optional flag alternative
* [ --something | --somethingElse | --anotherOne | -s | -a ]
* [ --something | --somethingElse | --anotherOne | -s | -a ]:namedGroup
Expand Down Expand Up @@ -338,8 +416,8 @@ protected function parseDefinition($def)

// remove prefix
array_walk($options, function (&$val, $key) {
$val = ltrim($val, '-');
});
$val = ltrim($val, '-');
});

// prepare item
$item = array(
Expand All @@ -350,84 +428,6 @@ protected function parseDefinition($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
41 changes: 39 additions & 2 deletions tests/ZendTest/Console/RouteMatcher/DefaultRouteMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,45 @@ public static function routeProvider()
'something' => null,
)
),


/**
* @bug ZF2-5671
* @link https://github.com/zendframework/zf2/issues/5671
*/
'mandatory-literal-camel-case' => array(
'FooBar',
array('FooBar'),
array(),
),
'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(),
),
'required-literal-alternative-camel-case-no-match' => array(
'( FooBar | FoozBar )',
array('baz'),
null,
),
);
}

Expand Down

0 comments on commit b717a85

Please sign in to comment.