PHPackages                             inani/chibi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. inani/chibi

ActiveLibrary[Framework](/categories/framework)

inani/chibi
===========

The Chibi Framework.

2.0.0(7y ago)37183[3 issues](https://github.com/akiyamaSM/chibi/issues)MITPHP

Since Oct 16Pushed 7y ago4 watchersCompare

[ Source](https://github.com/akiyamaSM/chibi)[ Packagist](https://packagist.org/packages/inani/chibi)[ RSS](/packages/inani-chibi/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (5)Versions (15)Used By (0)

Chibi
=====

[](#chibi)

Chibi is a mini PHP framework to work on small projects, containing the following elements.

Routing
=======

[](#routing)

With Chibi its really easy to make your routes

Route to Controller
-------------------

[](#route-to-controller)

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

Route to closure
----------------

[](#route-to-closure)

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

});
```

A Response &amp; Request instances are allways passed for you out of the box you just need to type hint it
----------------------------------------------------------------------------------------------------------

[](#a-response--request-instances-are-allways-passed-for-you-out-of-the-box-you-just-need-to-type-hint-it)

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

    $name = $request->only('name');

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

});
```

Controllers
===========

[](#controllers)

Every Controller used in the app should extends the Chibi\\Controller\\Controller Controller.

Views
=====

[](#views)

You can pass data from controllers to the view via the view method

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

The views are in the View folder with a Chibi.php extenstion.

A simple templete engin is provided.

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

@when( $age  10 )
	You are growing!
@done

@foreach($array as $arr)
	{{ $arr }}
@endforeach

{{ $var }}
```

Hurdles
=======

[](#hurdles)

Do you want to protect some routes? To be able to access to it only if some conditions are verified, sure you can do! Just use Hurdles for your routes

Create a Hurdle
---------------

[](#create-a-hurdle)

A hurdle Object should implement the Wall Interface

```
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;
	}
}
```

Use the Hurdle in the route as follow
-------------------------------------

[](#use-the-hurdle-in-the-route-as-follow)

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

Apply a Hurdle for all routes
-----------------------------

[](#apply-a-hurdle-for-all-routes)

Well its easy, Just fill the register file in the App\\Hurdles Folder

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

CSRF Token
----------

[](#csrf-token)

A CSRFTokenable Hurdle will be run at each POST request to protect you from Cross-Site Request Forgery attacks, you only need to include the @csrf\_field in the form, otherwise an Exception will be thrown.

```
