alejandroherr / subdomainmap

根据子域名映射内核的中间件

v1.0 2014-06-09 16:06 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:47:49 UTC


README

#SubdomainMap

Build Status

根据子域名映射内核的中间件。

强烈URL Map Stack Middleware 启发。

##如何通过 composer.json 安装

{
    "require": {
        "alejandroherr/subdomainmap": "dev-master"
    }
}

###使用 Silex 应用程序的示例

<?php
$loader = require ROOT . "/vendor/autoload.php";

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

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

$appA=new Application();
$appA->get('/', function () use ($appA) {
    return 'appA';
});
$appB=new Application();
$appB->get('/', function () use ($appB) {
    return 'appB';
});

$map = array(
    'appa' => $appA,
    'appb' => $appB
);

$app = new AlejandroHerr\Stack\SubdomainMap($app,$map);

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

##当与大型应用程序/HttpKernelsInterfaces 一起工作时,建议尝试 LazyHttpKernel

####示例

<?php
$loader = require ROOT . "/vendor/autoload.php";

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

$app=new Application();
$app->get('/', function () use ($app) {
    return 'Nothing here';
});

$appA=new Application();
$appA->get('/', function () use ($appA) {
    return 'I am appA';
});
$appA = lazy(function () use ($appA) {
    return $appA;
});

$app = new AlejandroHerr\Stack\SubdomainMap(
    $app,
    array('appa' => $appA)
);

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