bapao / bapao
Tiny agnostic PSR-7 middleware micro framework
Installs: 119
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:framework
Requires
- php: >=5.5
- container-interop/container-interop: ^1.1
- psr/http-message: ^1.0
Requires (Dev)
- league/container: ^2.2
- mockery/mockery: ^0.9.5
- phpunit/phpunit: ^4.8
Suggests
- bapao/league-container-provider: As dependency container
This package is not auto-updated.
Last update: 2016-09-17 10:05:38 UTC
README
Tiny agnostic PSR-7 middleware micro framework.
Installation
Install Bapao via Composer:
$ composer require bapao/bapao
About
Bapao does not force you to use a specific DI container, routing or middleware package. At initialization of the Bapao application you can inject the DI container of your choice. Thereby the following services must be present in the container:
Service | Interface |
---|---|
request | Psr\Http\Message\ServerRequestInterface |
response | Psr\Http\Message\ResponseInterface |
response.emitter | Bapao\Bapao\Interfaces\ResponseEmitterInterface |
middleware.dispatcher | Bapao\Bapao\Interfaces\MiddlewareDispatcherInterface |
router | n.a. |
router.middleware | PSR-7 middleware compliant |
An example service provider based on The PHP League DI container is available for Bapao: League Container Provider. This service provider contains the following packages:
- Zend Diactoros for PSR-7 request/response and response emitter
- The PHP League Container for DI container
- The PHP League Route for routing
- Relay for middleware dispatching
- Oscarotero/Psr7-Middlewares for routing middleware
Simple example
Create a front controller (for instance index.php
) and add:
require_once __DIR__.'/vendor/autoload.php'; use Bapao\Bapao\Application; use Bapao\LeagueContainerProvider\LeagueContainerProvider; use League\Container\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; // create a DI container of your choice, based on container-interop $container = new Container(); $container->addServiceProvider(new LeagueContainerProvider()); // add more service providers... // init Bapao application $app = new Application($container); // add middleware // $app->addMiddleware(new SomeExampleMiddleware()); // add routing rules with router of your choice $router = $app->getRouter(); $router->get('/', function (Request $request, Response $response, array $arguments) { $response->getBody()->write('Welcome to Bapao!'); return $response; }); // run Bapao $app->run();
Service providers
Bapao relies heavily on service providers. The following service providers are available:
- Container Provider with The PHP League Container
Middleware
Bapao's internals are handled by PSR-7 based middleware. Bapao route handling is in fact the last of a given set middleware.
$app->addMiddleware(new ExampleMiddleware);
Oscarotero/Psr7Middlewares has a extended set of various middleware classes available.
Test
Run tests via phpunit:
$ php vendor/bin/phpunit
Side note
Bapao does not aim to compete with the well-known micro frameworks such as Slim, Silex and Lumen. They are great and well documented. Bapao is more or less an experiment to combine great PHP packages into a tiny wrapper framework.
License
Bapao is licensed under the MIT license.