andrewbreksa/slim-action-helpers

A set of classes to make Slim 3 a bit easier to work with

1.0.1 2019-01-30 07:22 UTC

This package is auto-updated.

Last update: 2024-10-29 05:16:50 UTC


README

build-status license stars Coverage Status Latest Stable Version Total Downloads

Quick and dirty helper classes for RAD slim 3 development that fully support the __invoke Slim 3 middleware and callable paradigm.

Install

composer require andrewbreksa/slim-action-helpers

Examples

Action

<?php

namespace AndrewBreksa\SlimActionHelpers\Example\Actions;

use AndrewBreksa\SlimActionHelpers\AbstractAction;

class ExampleAction extends AbstractAction
{

    public function act()
    {
        // do some magic here
        return $this->json([
            'entity' => [
                'email' => 'andrew@andrewbreksa.com',
            ]
        ], 201);
    }
}

$app->post('/emails', \AndrewBreksa\SlimActionHelpers\Example\Actions\ExampleAction::class);

Middleware

<?php

namespace AndrewBreksa\SlimActionHelpers\Example\Middleware;

use AndrewBreksa\SlimActionHelpers\AbstractMiddleware;
use Psr\Log\LoggerInterface;

class RequestLoggingMiddleware extends AbstractMiddleware
{
    /**
     * Here, if a ResponseInterface is returned, the stack is ejected from, otherwise we continue on and automaically
     * call $next
     * @return mixed|void|null
     */
    public function act()
    {
        $this->getContainer()->get(LoggerInterface::class)->debug('request', [
            'method' => $this->getRequest()->getMethod(),
            'uri' => $this->getRequest()->getUri()->getPath(),
            'query' => $this->getRequest()->getQueryParams(),
            'headers' => $this->getRequest()->getHeaders()
        ]);
    }

}

$app->add(\AndrewBreksa\SlimActionHelpers\Example\Middleware\RequestLoggingMiddleware::class);

Docs

Eventually I may add very detailed docs, until then read the very simple source. It's literally 4 files.