PHP Classes

A few bugs/issues found

Recommend this page to a friend!

      PHP URL Router Class  >  All threads  >  A few bugs/issues found  >  (Un) Subscribe thread alerts  
Subject:A few bugs/issues found
Summary:A few bugs/issues found
Messages:1
Author:Michal Kozusznik
Date:2014-06-11 22:47:30
 

  1. A few bugs/issues found   Reply   Report abuse  
Picture of Michal Kozusznik Michal Kozusznik - 2014-06-11 22:47:30
Hello.
I tried your class but found a few bugs/issues. In case you have plans to to improve the class I'm writing this post

ISSUE 1

There is no possibility to generate URL with prefixed values.
For example pattern for URL:
some_name,id123.html
will be like this
/(^title)(,id#id)
which is properly parsed in match method but reverse generating url doesn't work because there are strict delimiters defined.

I played a bit with regex and here is update which works for me. but I didn't tested it intensively. Probably doesn't satisfy all test cases.

$pattern = '/(?:[\(\/](?<delims>.*?))(?:\()?[$|:|#|*|~|^](?<placeholders>[a-z]+)/';


ISSUE 2

In match() method you have used:
$matches = array_filter($matches);

To be honest cannot see a reason (of course there were some). However array_filter by default removes all values which can be cast to false. Unfortunately 0 (zero) is one of such values. For example such url part

some_name,a10,0.html
/($title)(,a#id)(,$:ix).html
will result no ix index which is bad thing imo.


ISSUE 3

Method url() doesn't respect default values defined in a route.
Here is draft fix for 'full' method:

case 'full':
$data = array_merge($data, $url['defaults'], $params);


ISSUE 4
Probably a feature rather than bug, but looks like your router works only with defined placeholders. But what about url like this:
some_name,id1.html
Why I have to define html as placeholder and then set default value for it? It's plain text, no need to convert it to regex. Note to work with default values, ISSUE 3 must be solved

ISSUE 5
no support for hostnames

ISSUE 6
Using arrays instead of specialized class objects. I suggest to make use of objects to conform OOP. Additionally the code will be not sensitive on missing/wrongly passed data. More control over data could be done in constructors etc (notices free code)


with regards