2017 © Pedro Peláez
 

library sail

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

image

funnyitselmo/sail

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  • Sunday, July 9, 2017
  • by FunnyItsElmo
  • Repository
  • 1 Watchers
  • 2 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Sail [Discontinued]

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs., (*2)

Installation

composer require funnyitselmo/sail

Hello World

use Sail\Sail;
use Sail\Tree;
use Sail\Middleware;
use Sail\Exceptions\NoSuchRouteException;
use Sail\Exceptions\NoMiddlewareException;
use Sail\Exceptions\NoCallableException;

require '../vendor/autoload.php';

/**
 * The very first step is to create the Sail object
 */
$sail = new Sail();

/**
 * This will display 'Hello World!' if you send a simple GET request
 * GET $sail->get()
 * POST $sail->post()
 * PUT $sail->put()
 * PATCH $sail->patch()
 * DELETE $sail->delete()
 * OPTIONS $sail->options()
 */
$sail->get('/', function  ($request, $response) {
        $response->setData('Hello World!');
});

/**
 * Lets create a new sub tree which will handle all request that start
 * with test or any other route we will specifiy later
 * NOTE: Sail also extends Tree
 */
class TestTree extends Tree {

        public function build () {

                $this->get('/', function  ($request, $response) {
                        $response->setData('You can see me if you request /test');
                });

                //everything that is in curly braces is a variable
                $this->get('/{id}', function  ($request, $response, $id) {
                        $data = array('I can also handle variables! request /test/42', '{id} is ' . $id);

                        $response->setHeaders(array(
                                'Content-Type' => 'application/json'
                         ));

                        $response->setData(json_encode($data));
                });

        }

}

/**
 * It is time to create our first middleare.
 */
class AuthMiddleware implements Middleware {

        public function call() {
                //check if the user is allowed to view the route
                return true;
        }

}

/**
 * The following code part adds the route test to the router.
 * The Route links to a tree and just passes the request if the
 * middleware, in this case the AuthMiddleware, allows the request.
 */
$sail->tree('/test', new AuthMiddleware(), new TestTree());

/**
 * Now we just need to run the code and catch the 
 * perhaps occurring exceptions
 */
try {
        $sail->run();
} catch (NoSuchRouteException $e) {
        echo $e->getMessage();
} catch (NoMiddlewareException $e) {
        echo $e->getMessage();
} catch (NoCallableException $e) {
        echo $e->getMessage();
}

The Versions

09/07 2017

dev-master

9999999-dev

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

09/07 2017

1.0.5

1.0.5.0

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

31/07 2016

1.0.4

1.0.4.0

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

31/07 2016

1.0.3

1.0.3.0

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

26/03 2016

1.0.2

1.0.2.0

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

25/03 2016

1.0.1

1.0.1.0

Sail is a lightweight object-oriented micro-framework written in PHP to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router

24/03 2016

1.0.0

1.0.0.0

Sail is a lightweight micro-framework to create quick and simple yet powerful APIs.

  Sources   Download

BSD

by Julian Spravil

api micro framework lightweight restful router