2017 © Pedro Peláez
 

library router

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

image

eylmz/router

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

  • Saturday, August 19, 2017
  • by eylmz
  • Repository
  • 2 Watchers
  • 11 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Router

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
Version : 1.0.0 * Installation * Simple Usage * Available Router Methods * Route Parameters * Controller and Method Parameters * Regular Expression Constraints * Named Routes * Route Groups * License, (*1)


Installation

You can download it and using it without any changes., (*2)

OR use Composer., (*3)

It's recommended that you use Composer to install Route., (*4)

$ composer require eylmz/router

Simple Usage

.htaccess

Options -Indexes
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

index.php

<?php
require 'vendor/autoload.php';
// or
// require 'src/eylmz/Router.php';

use eylmz/Router/Router;

Router::setControllerNamespace("App\\Controllers\\");
Router::setMiddlewareNamespace("App\\Middlewares\\");

// Routers
Router::any("/url","Controller@Method");
// or
Router::any("/url2",function() {

});
// #Routers

Router::routeNow(@$_GET["url"]);

Available Router Methods

Router::get($url, $callback);
Router::post($url, $callback);
Router::put($url, $callback);
Router::patch($url, $callback);
Router::delete($url, $callback);
Router::options($url, $callback);

Usage More Than One Routers

Router::match("GET|POST",$url,$callback);
//or
Router::match(["GET","POST"],$url,$callback);

Usage The Any Methods

Router::any($url,$callback);

Route Parameters

Required Parameters

Router::get("url\{id}",function($myID){
  echo "Hello " . $myID;
});

Optional Parameters

Router::get("url\{id?}",function($myID=0){
  echo $myID;
});

Controller and Method Parameters

// Controller -> First Parameter
// Method -> Second Parameter
Router::get("admin\{controller}\{method}","{?}@{?}");

// or

// Custom
Router::get("admin\{method}\{controller}","{controller}@{method}");


Regular Expression Constraints

Router::get('url/{id}', function ($myID) {

})->where('id', '[0-9]+');

Router::get('user/{id}/{name}', function ($myID, $name) {

})->where(['id' => '[0-9]+', 'name' => '[a-zA-Z]+']);

Named Routes

Router::get('user/profile', function () {
    //
})->name('profile');

Generating URLs To Named Routes

$url = Router::route("profile");

// Usage with parameters
Router::get('url/{id}/profile', function ($id) {

})->name('profile');

$url = Router::route('profile', ['id' => 1]);

Route Groups

Prefix URL

Router::prefix('admin')->group(function () {
    Router::get('users', function () {
        // new url -> /admin/users
    });
});

Middleware

Router::middleware("middleware")->group(function () {
    Router::get('/', function () {

    });

    Router::get('url/profile', function () {

    });
});

Usage More Than One Middlewares

Router::middleware(["middleware","middleware2"])->group(function () {
    Router::get('/', function () {

    });

    Router::get('url/profile', function () {

    });
});

License

The MIT License (MIT). Please see License File for more information., (*5)

The Versions

19/08 2017

dev-master

9999999-dev http://emre.pw

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

api php mvc restful router

19/08 2017

v1.0.0

1.0.0.0 http://emre.pw

Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

api php mvc restful router