franksacco/nano-framework

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple, fast and secure PHP framework

dev-master 2022-01-18 08:54 UTC

This package is auto-updated.

Last update: 2022-02-18 08:56:03 UTC


README

Logo

Build Status Latest Stable Version PHP Versions Supported License

[Archived]

Due to lack of time, this project is no longer under development.

About

A simple, light and fast PHP framework based on middlewares.

Create an app

In order to create your application based on Nano Framework, you have to extend the AbstractApplication class and setup the middlewares queue of the application. The method AbstractApplication::middleware(MiddlewareQueue $middleware) must be overwritten in order to setup the middlewares queue used to process the server request and create the response. Note that the order in which the middlewares are added defines the order in which they are executed.
A basic example:

class YourApplication extends AbstractApplication {
    public function middleware(MiddlewareQueue $middleware)
    {
        $middleware
            ->add(ErrorHandlerMiddleware::class)     // Error/Exception handling.
            ->add(ResponseEmitterMiddleware::class)  // Send response to the user.
            ->add(BufferOutputMiddleware::class)     // Output buffering and compressing.
            ->add(RoutingMiddleware::class);         // Routing engine.
    }
}

The AbstractApplication class implements MiddlewareInterface as it is always the last middleware in the queue. Its job is to dispatch the server request to an action in order to produce a response. The action to be executed is a callable set as attribute in the server request. In this example, this is automatically made by the RoutingMiddleware.
Now, you have to start your application from your index.php file:

require dirname(__DIR__) . '/vendor/autoload.php';

$config = require dirname(__DIR__) . '/config/config.php';

$app = new \App\YourApplication($config);
$app->run();

That's it. Now you have to implement the logic of your application.

Requirements

  • PHP >= 7.2
  • JSON PHP Extension
  • PDO PHP Extension

Documentation

Documentation for this project is available in the docs folder.

License

The Nano Framework is open-sourced software licensed under the MIT license.

Author