mezzio / mezzio-router

Router subcomponent for Mezzio
https://docs.mezzio.dev/mezzio/features/router/intro/
BSD 3-Clause "New" or "Revised" License
24 stars 13 forks source link

Remove "MUST raise Exception" from docblock of RouterInterface->match() #2

Closed weierophinney closed 4 years ago

weierophinney commented 4 years ago

The docblock annotation of RouterInterface states that implementations MUST throw an exception if addRoute is called after calling match() or generateUri().

Currently no implementation does this:

I've opened an issue in the FastRoute wrapper repo and @froschdesign and @xtreamwayz seem to indicate that they want to change the "MUST" to a "CAN".

Whats your opinion?


Originally posted by @MatthiasKuehneEllerhold at https://github.com/zendframework/zend-expressive-router/pull/77

weierophinney commented 4 years ago

The original reason was to ensure that once match() or generateUri() were called, we wanted to ensure that subsequent calls with the same values would have the same results.

However, in practice, we discovered that adding routes one at a time was problematic: we generally couldn't determine what HTTP methods were allowed for a given route match string until all routes were present. As such, we introduced code to delay route injection into the underlying router until the first time match() or generateUri() is called. This of course means that none of the implementations will throw from addRoute().

As such, I'm fine with us just removing those paragraphs from the interface definition entirely. If we do not indicate that an exception can be thrown, but simultaneously do not indicate they cannot be thrown, implementations can choose how to behave.


Originally posted by @weierophinney at https://github.com/zendframework/zend-expressive-router/pull/77#issuecomment-427844516