From fde0a3dabd43f7412207b6304a1cfbd9dd0992b9 Mon Sep 17 00:00:00 2001 From: Ben Scholzen Date: Tue, 2 Feb 2016 01:29:38 +0100 Subject: [PATCH 1/3] Split router interface into consumer-only and runtime-configurable versions --- src/RouterInterface.php | 25 ++------------ src/RuntimeConfigurableRouterInterface.php | 38 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 src/RuntimeConfigurableRouterInterface.php diff --git a/src/RouterInterface.php b/src/RouterInterface.php index fcc4938..16e1e7b 100644 --- a/src/RouterInterface.php +++ b/src/RouterInterface.php @@ -16,26 +16,6 @@ */ interface RouterInterface { - /** - * Add a route. - * - * This method adds a route against which the underlying implementation may - * match. Implementations MUST aggregate route instances, but MUST NOT use - * the details to inject the underlying router until `match()` and/or - * `generateUri()` is called. This is required to allow consumers to - * modify route instances before matching (e.g., to provide route options, - * inject a name, etc.). - * - * The method MUST raise Exception\RuntimeException if called after either `match()` - * or `generateUri()` have already been called, to ensure integrity of the - * router between invocations of either of those methods. - * - * @param Route $route - * @throws Exception\RuntimeException when called after match() or - * generateUri() have been called. - */ - public function addRoute(Route $route); - /** * Match a request against the known routes. * @@ -53,7 +33,7 @@ public function match(Request $request); * Generate a URI from the named route. * * Takes the named route and any substitutions, and attempts to generate a - * URI from it. + * URI from it. Additional router-dependent options may be passed. * * The URI generated MUST NOT be escaped. If you wish to escape any part of * the URI, this should be performed afterwards; consider passing the URI @@ -63,8 +43,9 @@ public function match(Request $request); * @see http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html * @param string $name * @param array $substitutions + * @param array $options * @return string * @throws Exception\RuntimeException if unable to generate the given URI. */ - public function generateUri($name, array $substitutions = []); + public function generateUri($name, array $substitutions = [], array $options = []); } diff --git a/src/RuntimeConfigurableRouterInterface.php b/src/RuntimeConfigurableRouterInterface.php new file mode 100644 index 0000000..cceb278 --- /dev/null +++ b/src/RuntimeConfigurableRouterInterface.php @@ -0,0 +1,38 @@ + Date: Mon, 3 Oct 2016 21:47:21 -0400 Subject: [PATCH 2/3] RouterInterface tweaks Removed the RuntimeConfigurableRouterInterface and put addRoute back into the RouterInterface. We'll allow the `$options` to be passed on to the actual routers via the new third `$options` parameter. This approach does break BC as well, but it will be released with a new major version to avoid surprising library users. --- src/RouterInterface.php | 20 ++++++++++++ src/RuntimeConfigurableRouterInterface.php | 38 ---------------------- 2 files changed, 20 insertions(+), 38 deletions(-) delete mode 100644 src/RuntimeConfigurableRouterInterface.php diff --git a/src/RouterInterface.php b/src/RouterInterface.php index 16e1e7b..c72ac6b 100644 --- a/src/RouterInterface.php +++ b/src/RouterInterface.php @@ -16,6 +16,26 @@ */ interface RouterInterface { + /** + * Add a route. + * + * This method adds a route against which the underlying implementation may + * match. Implementations MUST aggregate route instances, but MUST NOT use + * the details to inject the underlying router until `match()` and/or + * `generateUri()` is called. This is required to allow consumers to + * modify route instances before matching (e.g., to provide route options, + * inject a name, etc.). + * + * The method MUST raise Exception\RuntimeException if called after either `match()` + * or `generateUri()` have already been called, to ensure integrity of the + * router between invocations of either of those methods. + * + * @param Route $route + * @throws Exception\RuntimeException when called after match() or + * generateUri() have been called. + */ + public function addRoute(Route $route); + /** * Match a request against the known routes. * diff --git a/src/RuntimeConfigurableRouterInterface.php b/src/RuntimeConfigurableRouterInterface.php deleted file mode 100644 index cceb278..0000000 --- a/src/RuntimeConfigurableRouterInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - Date: Mon, 3 Oct 2016 21:56:50 -0400 Subject: [PATCH 3/3] Add CHANGELOG for #6 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4de775..b5b20f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#6](https://github.com/zendframework/zend-expressive-router/pull/6) modifies `RouterInterface::generateUri` to + support an `$options` parameter, which may pass additional configuration options to the actual router. ### Deprecated