P
P
phpus2015-04-03 00:29:50
PHP
phpus, 2015-04-03 00:29:50

How to write a good router or where to get ready?

Help to write a normal router + url.
This is how he looks like now

class Route {
  //тут был код)
  }
  
}

Written a long time ago, I know it's not great.
Here Url
И тут тоже
This is just a part of the code (as an example)
What do you advise?
How to write this whole thing?
Or does this router have a chance at life?
If you look towards ready-made solutions, what is the most optimal?
Option 1
Second
Third

Links run through rg. vyp.
It turns out :
In the usual form, something like this: domen.ru/class.php?option=1&id=17#page=3
In the processed: domen.ru/class/option1/17#page3
And CNC: domen.ru/classname /opionname/name/page1 Of
course, the load changes, I want everything to be correct and that the links would at least look normal, you can also use partial NC.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-04-03
@phpus

Or does this router have a chance at life?

There is, of course, but it will die quickly. Well, either the user of your router (or the one who gets it for support) will long for his death.
No statics (static factory methods do not count), dependency inversion, and most importantly, take PhpSpec and try to design through specs. This will greatly limit your desire to write some kind of filth, because then it will not be convenient to write tests right away.
https://packagist.org/search/?q=router and in particular https://github.com/nikic/FastRoute
and reading for the night: nikic.github.io/2014/02/18/Fast-request- routing-us...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question