GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stackphp/url-map: URL Map Stack middleware.

This repository was archived by the owner on Jul 29, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

68 Commits
68 Commits

Folders and files

NameName
Last commit message
Last commit date
src/Stack
src/Stack
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
example.php
example.php
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

URL Map Stack Middleware

Build Status

The UrlMap class takes an array mapping paths to apps and dispatches accordingly. This class is insertable into a Middleware Stack Builder, like stack/builder.

Install

Install with Composer:

$ composer require stack/url-map

Example

Let's say we have a Silex app and want to map a blogging app which implements HttpKernelInterface at the sub path /blog:

<?php

use Symfony\Component\HttpFoundation\Request;
use Silex\Application;

$app = new Application();
$app->get('/', function () {
    return "Main Application!";
});

$blog = new Application();
$blog->get('/', function () {
    return "This is the blog!";
});

$map = [
    "/blog" => $blog
];

$app = (new Stack\Builder())
    ->push('Stack\UrlMap', $map)
    ->resolve($app);

$request = Request::createFromGlobals();

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

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

If you now navigate to /blog you should see This is the blog! in your browser.

The UrlMap overrides SCRIPT_NAME, SCRIPT_FILENAME and PHP_SELF to point at the mapped path. This also makes sure that the path is stripped from the path info.

This also means that apps which use the Symfony Routing component for Routing and URL Generation don't need any adaptions.

Apps using other means for routing should prepend the return value of the request's getBaseUrl() method to generated URLs. The URL Map also sets a stack.url_map.prefix request attribute, which can be used if you don't want to rely on the request base URL.

About

URL Map Stack middleware.

Resources

Readme
MIT license
Activity
Custom properties

Stars

45 stars

Watchers

3 watching

Forks

10 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.