Hi. I’m a little curious about CUrlRule’s constructor, specifically at line 648. CUrlRule has quite a few useful / interesting public properties but not all of them are exposed when setting rules in the UrlManager. The way in which the properties are set do not throw any noticeable error if a user attempts to set an ‘illegal’ property.
In my case, I had hoped to create the following rule:
...
'<module>/<controller>/<action:index>' => array('<module>/<controller>/<action>', 'template' => '<module>/<controller>'),
...
As described in the CUrlRule documentation, template is used to construct a URL. In my case, this would allow me to create urls so that:
Yii::app()->createUrl('cms/user/index');
would produce
/cms/user
All, in all it should be a pretty simple operation and not something that should require a custom class especially with the ‘template’ property already defined. What I found (that’s not exactly buggy but buggy-ish), was the following snippet (CurlManager.php@L646).
if(is_array($route))
{
foreach(array('urlSuffix', 'caseSensitive', 'defaultParams', 'matchValue', 'verb', 'parsingOnly') as $name)
{
if(isset($route[$name]))
$this->$name=$route[$name];
}
if(isset($route['pattern']))
$pattern=$route['pattern'];
$route=$route[0];
}
By using the array to limit parameters passed into route not only is it pretty obfuscated but it doesn’t throw a meaningful error if an illegal value is passed. The way it is now, my route would successfully parse even if it looked like:
...
'<module>/<controller>/<action:index>' => array('<module>/<controller>/<action>', 'siracha' => 'Rooster Sauce!'),
...
The wiki only documents the ‘approved’ list of parameters and is in-keeping with the function itself. Personally, I’d like to see the remaining properties opened up for value assignment with something like:
@L646
if(is_array($route))
{
$r=array_shift($route);
if(isset($route['pattern']))
{
$pattern=$route['pattern'];
unset($route['pattern'];
}
foreach($route as $name=>$value)
{
$this->$name=$value // 'illegal' properties would naturally throw here
}
$route=$r;
}
Some of the other code in the constructor would need to be checked for isset() and some of the properties might want to have their visibility revisited in case they need to be auto-generated, but generally this would be relatively minor surgery and would help improve the transparency and functionality of CUrlRule.
As I said before, this isn’t exactly a bug, but silently dropping those parameters is bug-like since it’s easy assume that all the public properties of CUrlRule are exposed to the user (when it’s really only a subset). What do you think? Is it worth it for me to spin up a small patch to expose those other features?