Skip to content

Instantly share code, notes, and snippets.

@AydinHassan
Last active August 29, 2015 14:01
Show Gist options
  • Save AydinHassan/33b62ec0feba2f80b590 to your computer and use it in GitHub Desktop.
Save AydinHassan/33b62ec0feba2f80b590 to your computer and use it in GitHub Desktop.
ZF2 console route with minus number as parameter
Not sure if this is an issue or expected:
I have the following console route:
return [
'console' => [
'router' => [
'routes' => [
'set-user-starting-balance' => [
'options' => [
'route' => 'set user init-balance <userEmail> <balance>',
'defaults' => [
'controller' => 'JhFlexiTime\Controller\RunningBalanceCli',
'action' => 'set-user-starting-balance'
],
'constraints' => array(
//regex to match decimal and floats
'balance' => '/^-?\d{1,4}(.\d{1,2})?$/'
),
],
],
]
]
]
];
This route matches fine for the following commands:
php public/index.php set user init-balance aydin@hotmail.co.uk 2.25
php public/index.php set user init-balance aydin@hotmail.co.uk 1
php public/index.php set user init-balance aydin@hotmail.co.uk 0.25
The following doesn't work:
//note the dash, "-2", minus 2
php public/index.php set user init-balance aydin@hotmail.co.uk -2
And you can see the Regular Expression works here: http://regexr.com/38spt
When I say it doesn't work, the following error is returned:
"Reason for failure: Invalid arguments or no arguments provided"
I'm assuming this maybe has something do with: https://github.com/zendframework/zf2/blob/master/library/Zend/Console/RouteMatcher/DefaultRouteMatcher.php
matching that parameter as an option or something?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment