itsjavi / philae
This package is abandoned and no longer maintained.
No replacement package was suggested.
RESTFul, modern and minimal framework for PHP, built on top of PSR-7 and PSR-15 components.
0.7.0
2017-05-27 07:38 UTC
Requires
- php: ^7.0
- http-interop/http-middleware: ^0.4
- league/container: ~2.4.1
- middlewares/error-handler: ~0.6.0
- middlewares/utils: ~0.11.1
- nikic/fast-route: ~1.2.0
- zendframework/zend-diactoros: ~1.4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2020-01-17 00:49:45 UTC
README
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/philae
Via Git
$ git clone https://github.com/itsjavi/philae.git
Create a project skeleton with philae-skeleton
$ composer create-project itsjavi/philae-skeleton myproject
Usage
<?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 test
or
$ vendor/bin/phpunit $ vendor/bin/phpcs
Contributing
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.