All Projects → akiyamaSM → Chibi

akiyamaSM / Chibi

A mini PHP framework

Labels

Projects that are alternatives of or similar to Chibi

Nuxt.js
The Intuitive Vue(2) Framework
Stars: ✭ 38,986 (+118039.39%)
Mutual labels:  framework
Dotlog
Simple and easy go log framework
Stars: ✭ 30 (-9.09%)
Mutual labels:  framework
Carrot
🥕 Build multi-device AR applications
Stars: ✭ 32 (-3.03%)
Mutual labels:  framework
Zinky
minimalist semi-opinionated modular framework.
Stars: ✭ 28 (-15.15%)
Mutual labels:  framework
Swiftyonboard
A swifty iOS framework that allows developers to create beautiful onboarding experiences.
Stars: ✭ 952 (+2784.85%)
Mutual labels:  framework
Fluent
Remove inconsistency of your view. Go Fluent
Stars: ✭ 31 (-6.06%)
Mutual labels:  framework
Newsreap
Usenet Framework that supports posting, indexing and retrieving
Stars: ✭ 21 (-36.36%)
Mutual labels:  framework
Jcnavigator
A decoupled navigator framework of jumping between modules or apps for iOS development.
Stars: ✭ 33 (+0%)
Mutual labels:  framework
Codefii
A micro-framework for web Ninjas
Stars: ✭ 30 (-9.09%)
Mutual labels:  framework
Asgineer
A really thin ASGI web framework
Stars: ✭ 32 (-3.03%)
Mutual labels:  framework
Whatsapp Framework
⚗️Whatsapp python api
Stars: ✭ 945 (+2763.64%)
Mutual labels:  framework
Hdphp
HDPHP V3.0版本是一个重构的高性能版本 http://www.hdphp.com
Stars: ✭ 29 (-12.12%)
Mutual labels:  framework
Core
Runn Me! core library
Stars: ✭ 31 (-6.06%)
Mutual labels:  framework
Sqliteef6migrations
System.Data.SQLite.EntityFramework.Migrations - Migrations for SQLite Entity Framework provider
Stars: ✭ 27 (-18.18%)
Mutual labels:  framework
Molten
A minimal, extensible, fast and productive framework for building HTTP APIs with Python 3.6 and later.
Stars: ✭ 964 (+2821.21%)
Mutual labels:  framework
Fastapi
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Stars: ✭ 39,588 (+119863.64%)
Mutual labels:  framework
Donerserializer
A C++14 JSON Serialization Library
Stars: ✭ 31 (-6.06%)
Mutual labels:  framework
Framework
The Lawoole framework
Stars: ✭ 33 (+0%)
Mutual labels:  framework
Alumna
[Alpha release of v3] Development platform for humans / Plataforma de desenvolvimento para humanos
Stars: ✭ 32 (-3.03%)
Mutual labels:  framework
Core Framework
REDHAWK is a software-defined radio (SDR) framework designed to support the development, deployment, and management of real-time software radio applications
Stars: ✭ 31 (-6.06%)
Mutual labels:  framework

Chibi

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

Routing

With Chibi its really easy to make your routes

Route to Controller

$router->get('/users', 'App\Controllers\[email protected]');

Route to closure

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

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

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

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

<?php $var = 30 ?> 

@when( $age <= 10 )
	You are a kid
@or( $age > 10 )
	You are growing!
@done


@foreach($array as $arr)
	<h1>{{ $arr }}</h1>
@endforeach


<h3>{{ $var }}</h3>


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

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

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

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

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.

<form action=" <?php echo route('test_csrf') ?>" method="POST">
    <label for="name">Name</label>
    <input type="text" name="name" />
    @csrf_field
    <input type="submit">
</form>

Katana ORM

The Chibi framework is using its simple Katana ORM, simple and easy to use, you don't have to make a lot of effor to handle your Models. for the time being it supports:

  • Model::find($id); // get the model or null
  • Model::findOrFail($id); // get the model or ModelNotFoundException is thrown
  • $model_instance->property = 'new Value'; // set the value
  • $model_instance->property; // get the value
  • $model_instance->update(); // make persist the changes
  • $model_instance->save(); // create a new instance if not exist, otherwise update it
  • $model_instance->delete(); // remove the model
  • Model::destory($ids); // you can pass an id or array of ids to destroy

Authentication system out of the box

With Chibi framework you will do practicaly nothing to build a system of authentication.

Set up the Model

Your Katana model should extend the Authenticated class where you should set up the name of the guard.

namespace App;

use Chibi\Auth\Authenticated;

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

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

Connexion

You can use the following methods:

  • $user->forceLogging(); // To force the selected user to login
  • $user->logout(); // to logout
  • $user->check(); // check if the current user is logged in
  • Auth::against('users')->loginWith(1); // force to log specific use against a guard
  • Auth::against('users')->user(); // get the Katana instance of the connected user or null
  • Auth::logOut(); // logout the connected user
  • Auth::against('users')->canLogin($username, $password, $extra); // check if the user can be logged in

Hurdles

Chibi framework ships with some useful hurdles that will help you to protect your routes depending on the situation

GUEST

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

Auth

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

You can pass the name of the guard as an option to check against it

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].