2017 © Pedro Peláez
 

library gin

a simple route based on yii2

image

exgalibas/gin

a simple route based on yii2

  • Wednesday, June 13, 2018
  • by exgalibas
  • Repository
  • 0 Watchers
  • 4 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Gin

A simple route for PHP based on yii2. You can get the source code easily by downloading file or using composer., (*1)

Composer

If you have composer, (*2)

    composer require exgalibas/gin

Using

Use the namaspace, (*3)

use \Exgalibas\Gin\Gin;

You can add the routing rules for specified http method like GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|ANY, (*4)

(new Gin)->get($pattern, $route)

Pattern

The Pattern can be ordinary string, formatting regex with name or original regular expression like:, (*5)

The name in pattern will be used to replace the route if it has <name> or transmit as params, (*6)

// formatting regex 
(new Gin)->get("<function:(post|comment)>/<action:(create|update|delete)>/<id:(\d+)>", "<function>")

This rule only match "exgalibas/gin/login" and call function named "login", (*7)

//ordinary string
(new Gin)->get("exgalibas/gin/login", "login")

Just be ordinary regular expression, match like "post/create/10" and call function named "create", (*8)

//original regular
(new Gin)->get("(post|comment)\/(create|delete)\/\d+", "create")

Route

The Route can be Closure, function name or formatting string like "class|function", (*9)

Example

use \Exgalibas\Gin\Gin;

$route = new Gin();

//example, match get url "post/10/create", call_user_func(["post", "create"], ["id" => 10])
$route->get("<class:(post|comment)>/<id:(\d+)>/<function:(create|update|delete)>", '<class>|<function>');

//delete route rule
$route->deleteRule("<class:(post|comment)>/<id:(\d+)>/<function:(create|update|delete)>");

//example, match post url "exgalibas/login/10", call closure function([id=>10])
$route->post("exgalibas/login/<id:(\d+)>", function($params){...})

//example, match get url "exgalibas/login/joker", call login(["name" => "joker"])
$route->get("exgalibas/login/<name:joker>", "login")

//parse the request
$route->dispatch();

Error

If dispatch error, exit "404", (*10)

The Versions

13/06 2018

dev-master

9999999-dev https://github.com/exgalibas/Gin

a simple route based on yii2

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

19/04 2017

1.0

1.0.0.0 https://github.com/exgalibas/Gin

a simple route based on yii2

  Sources   Download

MIT

The Requires

  • php >=5.3.0