zendframework / zend-expressive-zendrouter

zend-mvc Router integration for Expressive
BSD 3-Clause "New" or "Revised" License
10 stars 8 forks source link

Regex in zend-expressive-zendrouter #22

Open mano87 opened 7 years ago

mano87 commented 7 years ago

Hello, we will migrate our ZF2 MVC Application to ZF3 Expressive. For some functions we use Regex to build the routes. When can I use Regex in zend-expressive-zendrouter?

For example:

'vcalendar' => [
  'type' => 'regex',
  'options' => [
    'regex' => '/vcalendar/(?<room>[0-9]+)(\.(?<format>(html|ics)))?',
    'defaults' => [
      'action' => 'vcalendar',
      'format' => 'ics'
    ],
    'spec' => '/vcalendar/%room%.%format%',
  ],
],
weierophinney commented 7 years ago

You can't, at least not using the Expressive API for attaching routes to middleware, due to a need to keep the API compatible between all routing implementations. In particular, we found that HTTP method negotiation, while supported directly in other routing implementations, was something we had to "hack" around to make work with zend-router; we ended up injecting a method route as a child route on the primary route to make it happen.

We could potentially support this by allowing you to provide the route type via route options (which would be handled in the ZendRouter::injectRoute() method); if anybody would like to try their hand at this, I'd welcome a pull request.

weierophinney commented 4 years ago

This repository has been closed and moved to mezzio/mezzio-laminasrouter; a new issue has been opened at https://github.com/mezzio/mezzio-laminasrouter/issues/1.