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
- Host: GitHub
- URL: https://github.com/alejandroherr/stack-subdomainmap
- Owner: AlejandroHerr
- License: mit
- Created: 2014-06-08T14:44:08.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-09T16:08:15.000Z (almost 12 years ago)
- Last Synced: 2025-01-13T15:15:16.025Z (over 1 year ago)
- Language: PHP
- Size: 207 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#SubdomainMap
[](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();
```