ichhabrecht/psr7-middleware-yaml-parser

PSR-7 middleware that parses Yaml files to ServerRequest attribute

1.1.0 2016-05-05 17:22 UTC

This package is auto-updated.

Last update: 2024-10-11 14:58:03 UTC


README

PSR-7 middleware that parses Yaml files to ServerRequest attribute.

Latest Stable Version Build Status

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;
});