stack/builder
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
symfony/http-foundation | v5.4.39 | - | MIT | prod dev | |
symfony/http-kernel | v5.4.39 | - | MIT | prod dev |
Stack/Builder is a compact library that assists developers in constructing a nested HttpKernelInterface decorator tree, effectively modeling it as a stack of middlewares. This gives developers the ability to handle complex software environments by simplifying the process of arranging layers within them. Stack/Builder works as a middleware on top of PHP applications, making HTTP requests more manageable.
To effectively use the Stack/Builder in your projects, the library first needs to be instantiated. Here's an example of how to use Stack/Builder to simplify and manage HTTP requests as a stack of middlewares.
First, decorate a silex app with session and cache middlewares:
$app = new Silex\Application();
$app->get('/', function () {
return 'Hello World!';
});
$app = new Stack\Session(
new Symfony\Component\HttpKernel\HttpCache\HttpCache($app, new Store(__DIR__.'/cache'))
);
To use Stack/Builder to simplify that:
$stack = (new Stack\Builder())
->push('Stack\Session')
->push('Symfony\Component\HttpKernel\HttpCache\HttpCache', new Store(__DIR__.'/cache'));
$app = $stack->resolve($app);
Next, create a serve request:
$request = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);
Stack/Builder also allows you to use a callable
for more complex middleware instantiation situations:
$stack = (new Stack\Builder())
->push('Stack\Session')
->push(function ($app) {
$cache = new HttpCache($app, new Store(__DIR__.'/cache'));
return $cache;
});
The documentation for Stack/Builder could be found within the README file available on the GitHub repository at https://github.com/stackphp/builder.git. It provides useful examples and clear instructions on how to use the library to handle complex HTTP requests effortlessly. Until now, there doesn't appear to be a separate, dedicated documentation site or document outside of the README file in the repository.