Skip to content

Tomiwa-Ot/php-router

Repository files navigation

PHP Router

Latest Stable Version Total Downloads Latest Unstable Version License

Features

  • Static routes
  • Dynamic routes
  • Pass variables in the URI
  • Multiple HTTP methods
  • Custom error handling
  • Enable/Disable error reporting
  • Request logging

Usage

Routes

Routes are defined in app.php

$route->get('/users', function() {
    Index::get();
});

$route->post('/user/<string:name>', function() {
    Index::post();
});

$route->delete('/user/<int:id>', function() {
    Index::delete();
});

Defining Controllers

Controllers are defined in Controllers/

class User extends BaseController
{
    public static function get()
    {
        render('index.php', array('title' => 'Index Page'));
    }

    public static function post()
    {
        json(reqVar('name'), 200);
    }

    public static function delete()
    {
        xml('Delete Request', 200);
    }
}

Installation

Via Git

git clone https://github.com/Tomiwa-Ot/php-router.git
cd php-router
composer install

Via Composer

composer create-project grephq/php-router
cd php-router
composer install

Docs

Example

https://github.com/Tomiwa-Ot/php-router/wiki/Usage#example

License

MIT License

Copyright (c) 2023 Olorunfemi-Ojo Tomiwa

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.