PHP code example of eric-chau / jarvis

1. Go to this page and download the library: Download eric-chau/jarvis library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eric-chau / jarvis example snippets




is = new Jarvis\Jarvis();

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

$response = $jarvis->run();

$response->send();



is = new Jarvis\Jarvis();

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



is = 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'



$jarvis = new Jarvis\Jarvis();

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

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



$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'); // = []