sruupl / batflat

Lightweight, fast and easy CMS for free. Bootstrap ready. https://batflat.org
MIT License
134 stars 54 forks source link

Potential Router problems #52

Closed Every0ne closed 4 years ago

Every0ne commented 5 years ago

Right now the way the Router works will produce conflicts when two (or more) modules have overlapping route rules. Let's consider an alternative Pages plugin, PagesEx for example, with route pattern (?:([a-z]{2})/)?([-\w/]+).

  1. Pages module has a page with slug starting-page
  2. PagesEx module has a page with slug extended-page and a subpage of extended-page with url i-has-bucket, its full url being extended-page/i-has-bucket.

The problem is that 2. will never work, because the Pages module "steals" its route with rule (:str)/(:str), not finding the page and serving 404 instead.

Current workarounds are:

To fix this issue changes in core and modules are required to make it work as follows:

  1. Router searches for matching pattern.
  2. Pattern match is found, execution is turned over to the owning module while waiting for response.
  3. Module tries to get data and either A - succedes or B - fails 4A. Module found data and reported success to the Router, which stops further search and returns. 4B. Module reports failure to the Router, which continues search for further matches. 5B. Router either finds another match or no other matches are found and router.notfound event is called.