Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zend Framework Blog:
Using Configuration-Driven Routes in Expressive
Apr 05, 2017 @ 17:21:26

The Zend Framework blog continues their series of posts looking at the Zend Expressive framework with this latest tutorial showing you how to use configuration-driven routing instead of routes defined in just code.

Expressive 1 used configuration-driven pipelines and routing; Expressive 2 switches to use programmatic pipelines and routes instead. The programmatic approach was chosen as many developers have indicated they find it easier to understand and easier to read, and ensures they do not have any configuration conflicts.

However, there are times you may want to use configuration. For example, when you are writing re-usable modules, it's often easier to provide configuration for routed middleware, than to expect users to cut-and-paste examples, or use features such as delegator factories.

Fortunately, starting in Expressive 2, we offer a couple different mechanisms to support configuration-driven pipelines and routing.

They start by pointing out the result of the Expressive v1 to v2 migration tool (enabling v2's pipeline handling) and a warning that there could be issues as the programmatic declarations still remain. The tutorial then gets into some of the drawbacks of going configuration-only but shows how, with just a bit of extra code, those can be someone relieved. An example is included showing a configuration provider that, from the functionality itself, defines the routes and injects them into the current application (using injectRoutesFromConfig).

tagged: zendframework zendexpressive configuration route pipeline migration provider tutorial

Link: https://framework.zend.com/blog/2017-03-30-expressive-config-routes.html


Trending Topics: