Philae
RESTFul, modern and minimal framework for PHP, built on top of PSR-7 and PSR-15 components.
This project is compliant with PSR-1, PSR-2, PSR-4, PSR-7, PSR-11 and PSR-15. If you notice compliance oversights, please send a patch via pull request.
Goals
- Simple: Keep the core source code as reduced as possible.
- Flexible: Keep dependencies as minimum as possible.
- Predictable: Be the glue of essential modern components, following standards and with proper documentation.
- Powerful: Well tested and robust code, suitable for any scenario and environment.
Components
- League Container as the application core. It comes with PSR-11 Container support.
- Zend Diactoros as the PSR-7 HTTP Messages implementation.
- Some PSR-15 Middlewares like error-handler and others.
- FastRoute as the core routing engine.
Install
Via Composer
$ composer require itsjavi/philaeVia Git
$ git clone https://github.com/itsjavi/philae.gitCreate a project skeleton with philae-skeleton
$ composer create-project itsjavi/philae-skeleton myprojectUsage
<?php
use Middlewares\ErrorHandlerDefault;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
include __DIR__ . '/vendor/autoload.php';
// Initialize the app with the default dependencies and some essential middleware.
$app = new Philae\Application();
$app->addServiceProvider(new \Philae\DefaultServiceProvider());
$app->setMiddlewares(
[
// error handler
(new Middlewares\ErrorHandler(ErrorHandlerDefault::class))->catchExceptions(true),
// dispatch the request
new Philae\Middlewares\RouteDispatcher(),
// transform the handler response
new Philae\Middlewares\ResponseTransformer(),
// execute the request handler
(new Philae\Middlewares\RequestHandler())->arguments($app->getResponse()),
]
);
// Define the routes
$router = $app->getRouter();
$router->get('/', function (ServerRequestInterface $req, ResponseInterface $res) {
$res->getBody()->write('<h1>Hello, World!</h1>' . PHP_EOL);
return $res;
});
$router->get('/{name}', function (ServerRequestInterface $req, ResponseInterface $res, array $params) {
$res->getBody()->write('<h1>Hello, ' . $params['name'] . '!</h1>' . PHP_EOL);
return $res;
});
$router->get('/foo', MyController::class); // Compatible also with callable objects implementing __invoke
$router->post('/foo/{id}', MyController::class . '::create'); // and with any other callable definition
$router->put('/foo/{id}', [MyController::class, 'edit']);
// Process the middlewares and send the response:
$app->execute();Testing
$ composer testor
$ vendor/bin/phpunit
$ vendor/bin/phpcsContributing
Please see CONTRIBUTING for details.
Credits
- Nikita Popov (FastRoute)
- Oscar Otero (PSR-7 Middlewares)
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
