Giter VIP home page Giter VIP logo

url-map's People

Contributors

anton-siardziuk avatar chh avatar digitalkaoz avatar fabpot avatar h4cc avatar harikt avatar henrikbjorn avatar igorw avatar jeromemacias avatar mbessolov avatar pborreli avatar simensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

url-map's Issues

Release 1.2

Hi,

Can anyone do a 1.2 release so it will support 3.x version of symfony ?

Make UrlMap behave like an App, not like a Middleware?

Rack::URLMap doesn't need an application for constructing an URLMap. Though the UrlMap isn't a real middleware anymore, it has the benefit that it's more usable as a micro framework, because it behaves like an app. In the case that no prefix was matched the UrlMap returns a response with status code 404, which can be handled by a middleware which inspects response codes.

Pro:

  • Fixes that requiring an app when using UrlMap standalone is kind of weird
  • More in line with Rack::URLMap
  • Behaves more like an app, makes sense when adding a ->map() functionality to Stack\Builder

Contra:

  • Not directly usable as Middleware anymore (but could be worked around by wrapping it in an Inline Middleware, or if we think it's a common use case we could make the UrlMap directly usable as Inline Middleware by implementing __invoke)
<?php

use Stack\CallableHttpKernel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

function app(callable $callback)
{
     return new CallableHttpKernel($callback);
}

$urlMap = new Stack\UrlMap([
    '/' => app(function ($request) {
        return new Response("Hello World!");
    }),
    '/lobster' => app(function ($request) {
        return new Response("Lobster!");
    })
]);

$urlMap->handle(Request::createFromGlobals())->send();

Using an UrlMap in a Middleware Stack by wrapping in an inline middleware:

<?php

use Stack\CallableHttpKernel;
use Stack\Builder;
use Stack\UrlMap;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$urlMap = new UrlMap([
    '/lobster' => new CallableHttpKernel(function() {
        return new Response("Lobster!");
    })
]);

$stack = (new Builder)
    ->push("Stack\Inline", function($app, $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) use ($urlMap) {
        $response = $urlMap->handle($request, $type, $catch);

        if ($response->isNotFound()) {
            return $app->handle($request, $type, $catch);
        }

        return $response;
    });

Handling 404 from UrlMap:

<?php

use Stack\CallableHttpKernel;
use Stack\Builder;
use Stack\UrlMap;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$urlMap = new UrlMap([
    '/lobster' => new CallableHttpKernel(function() {
        return new Response("Lobster!");
    })
]);

$app = (new Builder)
    ->push("Stack\Inline", function($app, $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {
        $response = $app->handle($request, $type, $catch);

        if ($response->isNotFound()) {
            // Handle 404
        }

        return $response;
    }),
    ->resolve($urlMap);

$request = Request::createFromGlobals();
$response = $app->handle($request);
$response->send();

$app->terminate($request, $response);

UrlMap not interpreting REQUEST_URI correctly

In situations where there is a file prefix in the REQUEST_URI, UrlMap incorrectly includes it as part of the intended route.

For example, in Symfony during development, you usually visit the app through local.dev/app_dev.php/my/action and Symfony is smart enough to compute the /my/action route automatically, chopping off the app_dev.php.

StackPHP does not chop off this file prefix. It seems to me that this should be the expected behavior.

You can easily reproduce this issue by using two middlewares and UrlMap through a file in the URL.

Stable release for Symfony v3?

Hey is it possible to make a release for Symfony 3 please? Thanks in advance.

Issue
1.1.0 release requires ~2.1 in the composer, however the code has been done to allow Symfony v3 see v1.1.0...master

Solution for now

"stack/url-map": "dev-master#7788a63a3a1d293b1fc7c46f0208c9a7ed8a7835 as 1.2.0"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.