Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Implement fromRoute() and getMatchedRoute() #23

Conversation

weierophinney
Copy link
Member

RouteResult::fromRoute() expects a Route instance, and, optionally, the parameters matched during routing, and returns an instance representing a successful route match. The various getters, other than getMatchedParams(), then proxy to the underlying Route instance. getMatchedRoute() returns the matched Route instance, allowing consumers to pull additional information from it, including the path, options, etc.

This patch also deprecates fromRouteMatch(), as it becomes redundant when the Route instance is present.

Finally, this patch would supercede #21 and fix #12, as the user could then perform the following to get the path:

$result = $request->getAttribute(RouteResult::class);
$path = $result->getRoute()->getPath();

(The user would also now be able to retrieve allowed methods for the given route, using the getAllowedMethods() method on either the RouteResult or composed Route, making this solution more flexible.)

This approach is completely backwards compatible, but, because it provides new functionality, would require a new minor version (1.3.0 is the target).

`RouteResult::fromRoute()` expects a `Route` instance, and, optionally,
the parameters matched during routing, and returns an instance
representing a successful route match. The various getters, other than
`getMatchedParams()`, then proxy to the underlying `Route` instance.
`getMatchedRoute()` returns the matched `Route` instance, allowing
consumers to pull additional information from it, including the path,
options, etc.

This patch also deprecates `fromRouteMatch()`, as it becomes redundant
when the `Route` instance is present.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling b800d23 on weierophinney:feature/result-compose-route into 908e910 on zendframework:develop.

@weierophinney weierophinney changed the title Implement fromRoute() and getMatchedRoute() Implement fromMatchedRoute() and getMatchedRoute() Dec 13, 2016
@weierophinney weierophinney changed the title Implement fromMatchedRoute() and getMatchedRoute() Implement fromRoute() and getMatchedRoute() Dec 13, 2016
@weierophinney weierophinney merged commit b800d23 into zendframework:develop Dec 13, 2016
weierophinney added a commit that referenced this pull request Dec 13, 2016
weierophinney added a commit that referenced this pull request Dec 13, 2016
@weierophinney weierophinney deleted the feature/result-compose-route branch December 13, 2016 14:29
weierophinney added a commit that referenced this pull request Dec 13, 2016
Forward ported changes from:

- #22
- #23
- #24
- #25

The changes in #23 allowed removing the changes introduced in #21, as
the route path is now accessible via the composed `Route` instance
(assuming that `fromRoute()` was used to create the `RouteResult`
instance).

Conflicts:
	src/RouteResultObserverInterface.php
	src/RouteResultSubjectInterface.php
	test/RouteResultTest.php
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants