ichhabrecht / psr7-middleware-yaml-parser
PSR-7 middleware that parses Yaml files to ServerRequest attribute
1.1.0
2016-05-05 17:22 UTC
Requires
- psr/http-message: ^1.0
- symfony/yaml: ^3.0
Requires (Dev)
- mikey179/vfsstream: ~1.6.0
- phpunit/phpunit: ~4.8.0
README
PSR-7 middleware that parses Yaml files to ServerRequest attribute.
This middleware parses Yaml files or strings. The result is stored in an own ServerRequest attribute for further usage.
Installation
It's recommended that you use Composer to install the Yaml parser.
$ composer require ichhabrecht/psr7-middleware-yaml-parser
Usage
In Slim 3:
$app->add(new \IchHabRecht\Psr7MiddlewareYamlParser\YamlParser(__DIR__ . '/settings.yml')); $app->get('/', function ($request, $response, $args) { $settings = $request->getAttribute('yaml'); return $response; });
Change attribute name
It is possible to adjust the ServerRequest attribute name to your own needs.
$app->add(new \IchHabRecht\Psr7MiddlewareYamlParser\YamlParser(__DIR__ . '/settings.yml', 'settings')); $app->get('/', function ($request, $response, $args) { $settings = $request->getAttribute('settings'); return $response; });