I’m building a web app using MVC architecture in PHP, and one of the first components I am building is the router. Currently, it works like this:
// Cleans the URI
SimpleRouter::init();
// Adds a new URI matching rule
SimpleRouter::add_route( '\/app\-admin\/products\/edit\/([0-9]+)\/', 'MyFunc' );
I want my code to look like this though, to make it a bit more readable/easier to remember
// Adds a new URI matching rule
SimpleRouter::add_route( '/app-admin/products/edit/([0-9]+)/', 'MyFunc' );
Any ideas how I might implement this?
You don’t need to escape the dash.
As for the slash, if you start and end your regex with something else (any character, such as #, or |) you don’t need to escape the slash either.
P.S.: Don’t use static access.. otherwise what’s the point of making it OOP? How do I subclass it, etc..