2017 © Pedro Peláez
 

library jarvis

Jarvis is a PHP 7.1 micro-framework

image

eric-chau/jarvis

Jarvis is a PHP 7.1 micro-framework

  • Wednesday, September 27, 2017
  • by eric-chau
  • Repository
  • 1 Watchers
  • 7 Stars
  • 177 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Jarvis, a PHP 7.1 micro framework

Code Climate Test Coverage Build Status SensioLabsInsight Scrutinizer Code Quality, (*1)

Jarvis is a PHP 7.1 micro framework. It is designed to be simple and lightweight., (*2)

Note that if you want to use Jarvis with PHP 5.6, please switch on 0.1 branch or use the v0.1.* tag., (*3)

Jarvis requires php >= 7.1. it's based on its own dependency injection container, http foundation component from Symfony and nikic's fast route., (*4)

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute('default')
        ->setMethod('get')
        ->setPattern('/')
        ->setHandler(function () {
            return 'Hello world!';
        })
    ->end()
;

$response = $jarvis->run();

$response->send();

How Jarvis process incoming request

The schema below will sum up how Jarvis\Jarvis::run() treats any incoming request:, (*5)

INPUT: an instance of Request

|
|__ Step 1: broadcast RunEvent.
|
|__ Step 2: check if RunEvent has a response?
|_______
| NO    | YES
|       |
|       |_ RETURN Response
|
|__ Step 3: resolve URI
|
|__ Step 4: does request match any route?
|_______
| NO*   | YES
|       |
|       |_ Step 4a: broadcast ControllerEvent
|       |
|       |_ Step 4b: invoke callback to process the request
|       |
|<------
|
|_ Step 5: broadcast ResponseEvent
|
|_ RETURN Response

OUT: an instance of Response

*: note that if provided URI does not match any route run() will return an instance of Response with 404 or 406 status code., (*6)

Router skill

Jarvis' Router can handle anonymous and named routes. By default, a route is type of HTTP GET method and the pattern setted to /. You can find some example below:, (*7)

Anonymous route, GET HTTP method, / as pattern

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute()
        ->setHandler(function () {
            return 'foobar!';
        })
    ->end()
;

Named route, name: user_edit , http method: PUT, pattern: /user/{id}

Note that id must be a number. Let's see how to do so., (*8)

<?php

require_once __DIR__ . '/vendor/autoload.php';

$jarvis = new Jarvis\Jarvis();

$jarvis->router
    ->beginRoute('user_edit')
        ->setMethod('PUT')
        ->setPattern('/user/{id:\d+}')
        ->setHandler(function ($id) {
            // Do some stuff

            return "User $id informations are now up-to-date!";
        })
    ->end()
;

echo $jarvis->router->uri('user_edit', ['id' => 123]); // print '/user/123'

Dependency injection container skill

Container::alias()

Jarvis' DIC (dependency injection container) can deal with alias:, (*9)

<?php

$jarvis = new Jarvis\Jarvis();

$jarvis['foo'] = 'hello world';
$jarvis->alias('bar', 'foo');

$jarvis['foo'] === $jarvis['bar']; // = true

Container::find()

::find() is an another useful method provided by Jarvis' DIC:, (*10)

<?php

$jarvis = new Jarvis\Jarvis();

$jarvis['dicaprio_movie_1997'] = 'Titanic';
$jarvis['dicaprio_movie_2010'] = 'Inception';
$jarvis['dicaprio_movie_2014'] = 'The Wolf of Wall Street';

$jarvis->find('dicaprio_movie_*'); // = ['Titanic', 'Inception', 'The Wolf of Wall Street']
$jarvis->find('dicaprio_movie_19*'); // = ['Titanic']
$jarvis->find('dicaprio_movie_2015'); // = []

The Versions

27/09 2017

dev-master

9999999-dev

Jarvis is a PHP 7.1 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

07/06 2017

dev-test-atom

dev-test-atom

Jarvis is a PHP 7.1 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

21/01 2017

v2.0.0

2.0.0.0

Jarvis is a PHP 7 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

21/10 2016

1.0.x-dev

1.0.9999999.9999999-dev

Jarvis is a PHP 7 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

21/10 2016

v1.0.1

1.0.1.0

Jarvis is a PHP 7 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

26/09 2016

v1.0.0

1.0.0.0

Jarvis is a PHP 7 micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

10/01 2016

0.1.x-dev

0.1.9999999.9999999-dev

Jarvis is a PHP micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

10/01 2016

v0.1.1

0.1.1.0

Jarvis is a PHP micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires

20/10 2015

v0.1.0

0.1.0.0

Jarvis is a PHP micro-framework

  Sources   Download

MIT

The Requires

 

The Development Requires