Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - Decouple FastRoute RouteParser #2640

Merged
merged 5 commits into from Apr 21, 2019

Conversation

Projects
None yet
3 participants
@l0gicgate
Copy link
Contributor

commented Apr 21, 2019

This is pull 6 out of 7 to complete the goals set in #2604

This decouples the FastRoute route parser from RouteCollector. It introduces a new interface RouteParserInterface.

The new interface implements the following methods:

  • RouteParser::relativePathFor()
  • RouteParser::urlFor()
  • RouteParser::fullUrlFor()

A new method on RouteCollectorInterface is introduced:

  • RouteCollectorInterface::getRouteParser()

Example Usage:

use Slim\App;
use Slim\Http\Factory\DecoratedResponseFactory;
use Slim\Http\ServerRequest;
use Slim\Psr7\Factory\ResponseFactory;
use Slim\Psr7\Factory\ServerRequestFactory;
use Slim\Psr7\Factory\StreamFactory;

$responseFactory = new DecoratedResponseFactory(new ResponseFactory(), new StreamFactory());
$app = new App($responseFactory);
$routeCollector = $app->getRouteCollector();
$routeParser = $routeCollector->getRouteParser();

/**
 * The base app url would be for example:
 * http://example.com
 *
 * If you wanted to generate a fully qualified URL from within a route
 * you would do something like the following
 */
$route = $app->get('/hello/{name}', function ($request, $response, $args) use ($routeParser) {
    /** @var RouteInterface $route */
    $route = $request->getAttribute('route');
    $routeName = $route->getName();

    $uri = $request->getUri();

    /**
     * $fullyQualifiedUrl would be:
     * http://example.com/hello/world
     */
    $fullyQualifiedUrl = $routeParser->fullUrlFor($uri, $routeName, ['name' => 'world']);

    return $response;
});
$route->setName('test');

$request = new ServerRequest(ServerRequestFactory::createFromGlobals());
$app->run($request);

@l0gicgate l0gicgate added the Slim 4 label Apr 21, 2019

@l0gicgate l0gicgate added this to the 4.0 milestone Apr 21, 2019

@l0gicgate l0gicgate referenced this pull request Apr 21, 2019

Closed

[DRAFT] 4.x Refactor Routing #2604

7 of 7 tasks complete
@coveralls

This comment has been minimized.

Copy link

commented Apr 21, 2019

Coverage Status

Coverage increased (+0.009%) to 98.544% when pulling 0c267ec on l0gicgate:4.x-DecoupleFastRouteRouteParser into f1b45ef on slimphp:4.x.

@l0gicgate l0gicgate merged commit e65a4dc into slimphp:4.x Apr 21, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.009%) to 98.544%
Details

@l0gicgate l0gicgate deleted the l0gicgate:4.x-DecoupleFastRouteRouteParser branch Apr 21, 2019

@l0gicgate l0gicgate referenced this pull request Apr 25, 2019

Merged

Slim 4 Alpha Release #2665

@vlakoff

This comment has been minimized.

Copy link
Contributor

commented Apr 28, 2019

Just to point out relativePathFor() has been renamed to relativeUrlFor(), refs #2654.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.