Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
/ kadalkesit Public archive

[POC] Another bare bone skeleton of zend-stratigility, zend-diactoros, and nikic/fast-route.

License

Notifications You must be signed in to change notification settings

simukti/kadalkesit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KADALKESIT

Kadalkesit is a skinny skeleton of PSR-7 middleware wrapper using Zend Diactoros, Zend Stratigility, and FastRoute. It will only dispatch a request to a callable action (should be small and fast enough), and the rest is yours.


USAGE

ROUTE DEFINITION

Each route definition contains only 3 required keys (method, path, action), here's the basic sample :

<?php
return [
    [
        'method'    => 'GET',
        'path'      => '/',
        'action'    => Action\Index::class,
    ],
    [
        'method'    => 'GET',
        'path'      => '/user',
        'action'    => Action\UserList::class,
    ],
    [
        'method'    => 'GET',
        'path'      => '/user/{username:[A-Za-z0-9_]{1,20}$}',
        'action'    => Action\UserView::class,
    ],
];

ACTION HANDLER

Action handler must be callable, this basic sample below is a invokable action class :

<?php
namespace Action;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\JsonResponse;

class Index
{
    /**
     * @param   RequestInterface    $request
     * @param   ResponseInterface   $response
     * @param   array               $routeParams
     */
    public function __invoke(RequestInterface $request, ResponseInterface $response, array $routeParams = [])
    {
        return new JsonResponse([__METHOD__, $routeParams]);
    }
}

HOW IT HAPPENS ?

Simple, routes handling managed by RouteManager middleware which implements Zend\Stratigility\MiddlewareInterface, attached to main pipe (Zend\Stratigility\MiddlewarePipe) and return Psr\Http\Message\ResponseInterface or throw an exception. Zend\Diactoros\Server will act as a server, listen to http request and set final handler.

TODO

  • group routing ?
  • optional route params ?
  • default value route params ?
  • routes cache ?
  • fix readme's spelling and its grammar 😊 ?

FEEL FREE TO CONTRIBUTE

LICENSE

BSD-3-Clause

Copyright (c) 2015 by Sarjono Mukti Aji.

Some rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * The names of the contributors may not be used to endorse or
      promote products derived from this software without specific
      prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

[POC] Another bare bone skeleton of zend-stratigility, zend-diactoros, and nikic/fast-route.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages