Patika

Patika is a routing package which you don't have to define the routes.

View the Project on GitHub ozziest/patika

Why?

There are a lot of cool routing packages in PHP World. But you have to define all routes that you need it. But sometimes like creating an API, it is time waste. When you use the Patika, you don't have to define any route. All routes are parsed by the Patika according to your Controller definitions.

For Example

1. Simple Routing
GET localhost/users/all    
# Namespace: App\Controllers\Users
# Method: all
# Arguments: []
2. Long Routing
GET localhost/admin/manager/users/all
# Namespace: App\Controllers\Admin\Manage\Users
# Method: all
# Arguments: []
3. Routing with Arguments
GET localhost/admin/manage/users/get/1 
# Namespace: App\Controllers\Admin\Manage\Users
# Method: get
# Arguments: [1]
namespace App\Controllers\Admin\Manage;

class Users {

    public function get($id)
    {
        echo $id;
    }

}
4. Routing with Multiple Arguments
GET localhost/admin/manage/users/getByArgument/1/2/3/foo/bar 
# Namespace: App\Controllers\Admin\Manage\Users
# Method: get
# Arguments: [1, 2, 3, 'foo', 'bar']
namespace App\Controllers\Admin\Manage;

class Users {

    public function get($one, $two, $three, $foo, $bar)
    {
        echo $id;
    }

}

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require": {
        "ozziest/patika": "dev-master"
    }
}
$ composer update

Configurations

First of all, you should define .htaccess file so that handle all request and send it to index.php file.

.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

index.php file must be defined like this;

// Including composer autoload file
include 'vendor/autoload.php';

// First of all, you should use try-catch block for handling routing errors
try {
    // You must create a new instance of Manager Class with the app argument.
    $patika = new Ozziest\Patika\Manager(['app' => 'App\Controllers']);
    // And calling the route!
    $patika->call();
} catch (Ozziest\Patika\Exceptions\PatikaException $e) {
    // If the controller or method aren't found, you can handle the error.
    echo $e->getMessage();
}

That's all! Patika Router is active now. Now, you can define your controller which what you want.

Exceptions

Authors and Contributors

Support or Contact

Having trouble with The Patika? Check out our issue page and we’ll help you sort it out.