Skip to content
A minimal middleware based micro framework using PHP Framework Interop Group - PSR, with the goal is to achive the best combination of flexibility and simplicity by using standards.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
src add CallbackMiddleware Aug 23, 2019
tests add CallbackMiddleware Aug 23, 2019
.gitignore add infection testing Apr 26, 2019
.php_cs drop simplified_null_return Jul 17, 2019
.scrutinizer.yml initial commit Apr 6, 2019
.travis.yml v2 Aug 16, 2019
LICENSE initial commit Apr 6, 2019
README.md add CallbackMiddleware Aug 23, 2019
composer.json add CallbackMiddleware Aug 23, 2019
infection.json.dist add infection testing Apr 26, 2019
phpinsights.php add nunomaduro/phpinsights Jul 21, 2019
phpstan.neon phpstan fix Aug 9, 2019
phpunit.xml.dist try to get infection testing running on travis Apr 26, 2019

README.md

chubbyphp-framework

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Monthly Downloads Latest Stable Version Latest Unstable Version

Description

A minimal middleware based micro framework using PHP Framework Interop Group - PSR, with the goal is to achive the best combination of flexibility and simplicity by using standards.

Requirements

Suggest

Router

Any Router which implements Chubbyphp\Framework\Router\RouterInterface can be used.

PSR 7 / PSR 17

Installation

Through Composer as chubbyphp/chubbyphp-framework.

Usage

Aura.Router

composer require chubbyphp/chubbyphp-framework "^2.1" \
    aura/router "^3.1" zendframework/zend-diactoros "^2.0"
<?php

declare(strict_types=1);

namespace App;

use Chubbyphp\Framework\Application;
use Chubbyphp\Framework\ErrorHandler;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\RouterMiddleware;
use Chubbyphp\Framework\RequestHandler\CallbackRequestHandler;
use Chubbyphp\Framework\Router\AuraRouter;
use Chubbyphp\Framework\Router\Route;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\ResponseFactory;
use Zend\Diactoros\ServerRequestFactory;

$loader = require __DIR__.'/vendor/autoload.php';

set_error_handler([ErrorHandler::class, 'handle']);

$responseFactory = new ResponseFactory();

$route = Route::get('/hello/{name}', 'hello', new CallbackRequestHandler(
    function (ServerRequestInterface $request) use ($responseFactory) {
        $name = $request->getAttribute('name');
        $response = $responseFactory->createResponse();
        $response->getBody()->write(sprintf('Hello, %s', $name));

        return $response;
    }
))->pathOptions(['tokens' => ['name' => '[a-z]+']]);

$app = new Application([
    new ExceptionMiddleware($responseFactory, true),
    new RouterMiddleware(new AuraRouter([$route]), $responseFactory),
]);

$app->send($app->handle(ServerRequestFactory::fromGlobals()));

FastRoute

composer require chubbyphp/chubbyphp-framework "^2.1" \
    nikic/fast-route "^1.3" zendframework/zend-diactoros "^2.0"
<?php

declare(strict_types=1);

namespace App;

use Chubbyphp\Framework\Application;
use Chubbyphp\Framework\ErrorHandler;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\RouterMiddleware;
use Chubbyphp\Framework\RequestHandler\CallbackRequestHandler;
use Chubbyphp\Framework\Router\FastRouteRouter;
use Chubbyphp\Framework\Router\Route;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\ResponseFactory;
use Zend\Diactoros\ServerRequestFactory;

$loader = require __DIR__.'/vendor/autoload.php';

set_error_handler([ErrorHandler::class, 'handle']);

$responseFactory = new ResponseFactory();

$route = Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler(
    function (ServerRequestInterface $request) use ($responseFactory) {
        $name = $request->getAttribute('name');
        $response = $responseFactory->createResponse();
        $response->getBody()->write(sprintf('Hello, %s', $name));

        return $response;
    }
));

$app = new Application([
    new ExceptionMiddleware($responseFactory, true),
    new RouterMiddleware(new FastRouteRouter([$route]), $responseFactory),
]);

$app->send($app->handle(ServerRequestFactory::fromGlobals()));

Middleware

RequestHandler

Router

Webserver

Skeleton

Migration

Replace the code from the first block with the code of the second ones.

use Chubbyphp\Framework\Application;
use Chubbyphp\Framework\ExceptionHandler;
use Chubbyphp\Framework\Middleware\MiddlewareDispatcher;
use Chubbyphp\Framework\Router\FastRouteRouter;

$app = new Application(
    new FastRouteRouter([$route]),
    new MiddlewareDispatcher(),
    new ExceptionHandler($responseFactory, true)
);
use Chubbyphp\Framework\Application;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\RouterMiddleware;
use Chubbyphp\Framework\Router\FastRouteRouter;

$app = new Application([
    new ExceptionMiddleware($responseFactory, true),
    new RouterMiddleware(new FastRouteRouter([$route]), $responseFactory),
]);

Copyright

Dominik Zogg 2019

You can’t perform that action at this time.