stackphp / url-map Goto Github PK
View Code? Open in Web Editor NEWURL Map Stack middleware.
License: MIT License
URL Map Stack middleware.
License: MIT License
Hi,
Can anyone do a 1.2 release so it will support 3.x version of symfony ?
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:
->map()
functionality to Stack\BuilderContra:
__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);
There should be tagged a new stable release now it is 5.3 compatible.
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.
Mounted apps should be when possible aware of the prefix in which they are mounted into, so generated URLs include the prefix.
Some inspirations for possible solutions:
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"
The Readme in this repository says to run $ php composer.phar require chh/url-map:~1.0@dev
. However, the upstream package moved to https://packagist.org/packages/stack/url-map and installing stack/url-map
at the current version 1.1 with composer is as easy as running
$ composer require stack/url-map
This should be updated in the README.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.