PHP code example of inani / chibi

1. Go to this page and download the library: Download inani/chibi 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/ */

    

inani / chibi example snippets


$router->get('/users', 'App\Controllers\HomeController@views');

$router->post('/user/{user}/{name}', function($user, $name){
    
});

$router->post('/customers', function(Request $request, Response $respone) {

    $name = $request->only('name');
    
    return $response->withJson([
      'name' => $name
      ])->withStatus(200);
      
});


    public function views()
    {
        $array = [
            'one',
            'two',
            'three'
        ];
        return view('hello', [
            'name' => 'Houssain',
            'age' => 26,
            'array' => $array,
        ]);
    }



{{ $name }} is {{ $age}}

 $var = 30 


namespace App\Hurdles;

use Chibi\Hurdle\Wall;
use Chibi\Request;
use Chibi\Response;

class YearIsCurrent implements Wall{

	public function filter(Request $request, Response $response) {

		if($request->has('year') && $request->only('year') == 2018) {
			return true;
		}

		return false;
	}
}

$router->get('/users, 'App\Controllers\HomeController@views')->allow(App\Hurdles\YearIsCurrent::class);

return [
	'Csrf' => Chibi\Hurdle\CSRFTokenable::class,
	'YearIsCurrent' => App\Hurdles\YearIsCurrent::class,
];


<form action="  echo route('test_csrf') 



namespace App;

use Chibi\Auth\Authenticated;

class User extends Authenticated
{
    static $table = 'users';

    /**
     * The guard name
     *
     * @return string
     */
    function guard(): string
    {
        return 'users';
    }
}



$route->get('/onlyGuests', function() {
    return 'only Guests can enter';
})->allow('Guest');



$route->get('/onlyAuth', function() {
    return 'only Guests can enter';
})->allow('Auth');



$route->get('/onlyAdmins', function() {
    return 'only Guests can enter';
})->allow('Auth:admins');