An open API service indexing awesome lists of open source software.

https://github.com/alejandroherr/stack-subdomainmap

Middleware to map the kernels depending on the subdomain
https://github.com/alejandroherr/stack-subdomainmap

Last synced: about 2 months ago
JSON representation

Middleware to map the kernels depending on the subdomain

Awesome Lists containing this project

README

          

#SubdomainMap

[![Build Status](https://travis-ci.org/AlejandroHerr/stack-subdomainMap.svg?branch=develop)](https://travis-ci.org/AlejandroHerr/stack-subdomainMap)

Middleware to map the kernels depending on the subdomain.

**Heavily** inspired in [URL Map Stack Middleware](https://github.com/stackphp/url-map).

##HOW TO
###Installation
Via composer.json:
```json
{
"require": {
"alejandroherr/subdomainmap": "dev-master"
}
}
```
###Example using Silex Application
```php
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();
```

##Recommendations
When working with large apps/HttpKernelsInterfaces, try the [LazyHttpKernel](https://github.com/stackphp/LazyHttpKernel)

####Example
```php
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();
```