tsoffereins / nano
A nano sized framework with the bare minimum for simple applications.
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 1
Type:framework
Requires
- php: ^8.0
- ext-pdo: *
Requires (Dev)
- phpspec/prophecy: ^1.8
- phpunit/phpunit: ^7.3
- vimeo/psalm: ^3.0
This package is auto-updated.
Last update: 2024-11-12 01:40:27 UTC
README
Nano is a teeny tiny framework that offers the bare minimum for you to create, for example, a very slim and super quick API.
Installation
Installation can be done using Composer to download and install Nano framework as well as its dependencies.
composer require nano/framework
Building blocks
The Nano framework contains the following classes:
Nano\Container
- An IoC container for dependency injectionNano\PipeLine
- A middleware busNano\Router
- A router for defining endpoints
Container
Using the container:
$container = new Container(); $container->bind('abstract', 'concrete'); $instance = $container->make('abstract');
Binding a callback:
$container->bind('abstract', function() { return new Concrete('config'); });
Binding as a singleton:
$container->singleton('abstract', function() { return new Concrete('config'); });
PipeLine
Using the PipeLine:
$pipe = $container->make('Nano\PipeLine'); $pipe->addMiddleare(['Middleware']); $pipe->fire(function() { return 'Hello world!'; }, $request);
Defining middleware:
class Middleware { public function handle($request, $next) { // Do something with request $response = $next($request); // Do something with response return $response; } }
Router
Using the Router:
$router = $container->make('Nano\Router'); $router->addRoutes(['/home', 'Controller@index']); echo $router->match($_SERVER['REQUEST_URI']);
Defining a controller:
class Controller { public function index() { return 'Hello world!'; } }
Route parameters:
$router->addRoutes(['/user/:id', 'Controller@user']);
Request methods:
$router->addRoutes([ '/home', 'Controller@index', // defaults to GET 'POST=/user/', 'GET=/user/:id', 'PUT=/user/:id', 'DELETE=/user/:id' ]);
Support
Please file issues here at Github