A nano sized framework with the bare minimum for simple applications.

v2.0.0 2021-05-11 17:48 UTC

This package is auto-updated.

Last update: 2024-03-12 00:05:39 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 injection
  • Nano\PipeLine - A middleware bus
  • Nano\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