{"id":13678272,"url":"https://github.com/akiyamaSM/chibi","last_synced_at":"2025-04-29T12:34:28.445Z","repository":{"id":56990804,"uuid":"106802940","full_name":"akiyamaSM/chibi","owner":"akiyamaSM","description":"A mini PHP framework","archived":false,"fork":false,"pushed_at":"2019-05-11T21:46:24.000Z","size":460,"stargazers_count":36,"open_issues_count":3,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-02T13:21:42.345Z","etag":null,"topics":["chibi","framework","mini-php-framework","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akiyamaSM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-13T09:10:56.000Z","updated_at":"2024-07-11T14:05:54.000Z","dependencies_parsed_at":"2022-08-21T10:10:35.301Z","dependency_job_id":null,"html_url":"https://github.com/akiyamaSM/chibi","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fchibi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fchibi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fchibi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akiyamaSM%2Fchibi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akiyamaSM","download_url":"https://codeload.github.com/akiyamaSM/chibi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224173692,"owners_count":17268158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chibi","framework","mini-php-framework","php"],"created_at":"2024-08-02T13:00:51.788Z","updated_at":"2024-11-11T20:31:16.331Z","avatar_url":"https://github.com/akiyamaSM.png","language":"PHP","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Chibi\nChibi is a mini PHP framework to work on small projects, containing the following elements.\n\n# Routing\nWith Chibi its really easy to make your routes\n\n## Route to Controller\n```php\n$router-\u003eget('/users', 'App\\Controllers\\HomeController@views');\n```\n## Route to closure\n```php\n$router-\u003epost('/user/{user}/{name}', function($user, $name){\n    \n});\n```\n## A Response \u0026 Request instances are allways passed for you out of the box you just need to type hint it\n```php\n$router-\u003epost('/customers', function(Request $request, Response $respone) {\n\n    $name = $request-\u003eonly('name');\n    \n    return $response-\u003ewithJson([\n      'name' =\u003e $name\n      ])-\u003ewithStatus(200);\n      \n});\n```\n\n# Controllers\n\nEvery Controller used in the app should extends the Chibi\\Controller\\Controller Controller.\n\n# Views\nYou can pass data from controllers to the view via the view method\n\n```php\n\n    public function views()\n    {\n        $array = [\n            'one',\n            'two',\n            'three'\n        ];\n        return view('hello', [\n            'name' =\u003e 'Houssain',\n            'age' =\u003e 26,\n            'array' =\u003e $array,\n        ]);\n    }\n\n```\n\nThe views are in the View folder with a Chibi.php extenstion.\n\nA simple templete engin is provided.\n\n```php\n\n{{ $name }} is {{ $age}}\n\n\u003c?php $var = 30 ?\u003e \n\n@when( $age \u003c= 10 )\n\tYou are a kid\n@or( $age \u003e 10 )\n\tYou are growing!\n@done\n\n\n@foreach($array as $arr)\n\t\u003ch1\u003e{{ $arr }}\u003c/h1\u003e\n@endforeach\n\n\n\u003ch3\u003e{{ $var }}\u003c/h3\u003e\n\n\n```\n\n# Hurdles\n\n\nDo 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\n## Create a Hurdle\nA hurdle Object should implement the Wall Interface\n```php\n\nnamespace App\\Hurdles;\n\nuse Chibi\\Hurdle\\Wall;\nuse Chibi\\Request;\nuse Chibi\\Response;\n\nclass YearIsCurrent implements Wall{\n\n\tpublic function filter(Request $request, Response $response) {\n\n\t\tif($request-\u003ehas('year') \u0026\u0026 $request-\u003eonly('year') == 2018) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n}\n```\n## Use the Hurdle in the route as follow\n\n```php\n$router-\u003eget('/users, 'App\\Controllers\\HomeController@views')-\u003eallow(App\\Hurdles\\YearIsCurrent::class);\n```\n## Apply a Hurdle for all routes\nWell its easy, Just fill the register file in the App\\Hurdles Folder\n\n```php\nreturn [\n\t'Csrf' =\u003e Chibi\\Hurdle\\CSRFTokenable::class,\n\t'YearIsCurrent' =\u003e App\\Hurdles\\YearIsCurrent::class,\n];\n```\n\n## CSRF Token\n\nA 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.\n\n```php\n\n\u003cform action=\" \u003c?php echo route('test_csrf') ?\u003e\" method=\"POST\"\u003e\n    \u003clabel for=\"name\"\u003eName\u003c/label\u003e\n    \u003cinput type=\"text\" name=\"name\" /\u003e\n    @csrf_field\n    \u003cinput type=\"submit\"\u003e\n\u003c/form\u003e\n```\n\n\n# Katana ORM\nThe 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:\n\n- Model::find($id); // get the model or null\n- Model::findOrFail($id); // get the model or ModelNotFoundException is thrown\n- $model_instance-\u003eproperty = 'new Value'; // set the value\n- $model_instance-\u003eproperty; // get the value\n- $model_instance-\u003eupdate(); // make persist the changes\n- $model_instance-\u003esave(); // create a new instance if not exist, otherwise update it\n- $model_instance-\u003edelete(); // remove the model\n- Model::destory($ids); // you can pass an id or array of ids to destroy\n\n# Authentication system out of the box\n\nWith Chibi framework you will do practicaly nothing to build a system of authentication.\n\n## Set up the Model\n\nYour Katana model should extend the Authenticated class where you should set up the name of the guard.\n\n```php\n\n\nnamespace App;\n\nuse Chibi\\Auth\\Authenticated;\n\nclass User extends Authenticated\n{\n    static $table = 'users';\n\n    /**\n     * The guard name\n     *\n     * @return string\n     */\n    function guard(): string\n    {\n        return 'users';\n    }\n}\n\n```\n## Connexion\n\nYou can use the following methods:\n- $user-\u003eforceLogging(); // To force the selected user to login \n- $user-\u003elogout(); // to logout\n- $user-\u003echeck(); // check if the current user is logged in\n- Auth::against('users')-\u003eloginWith(1); // force to log specific use against a guard\n- Auth::against('users')-\u003euser(); // get the Katana instance of the connected user or null\n- Auth::logOut(); // logout the connected user\n- Auth::against('users')-\u003ecanLogin($username, $password, $extra); // check if the user can be logged in\n\n### Hurdles\nChibi framework ships with some useful hurdles that will help you to protect your routes depending on the situation\n\n#### GUEST\n\n```php\n\n$route-\u003eget('/onlyGuests', function() {\n    return 'only Guests can enter';\n})-\u003eallow('Guest');\n\n```\n\n#### Auth\n\n```php\n\n$route-\u003eget('/onlyAuth', function() {\n    return 'only Guests can enter';\n})-\u003eallow('Auth');\n\n```\n\nYou can pass the name of the guard as an option to check against it\n\n\n```php\n\n$route-\u003eget('/onlyAdmins', function() {\n    return 'only Guests can enter';\n})-\u003eallow('Auth:admins');\n\n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FakiyamaSM%2Fchibi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FakiyamaSM%2Fchibi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FakiyamaSM%2Fchibi/lists"}