2017 © Pedro PelĂĄez
 

library simple-router

A simple router for small php projects

image

intec/simple-router

A simple router for small php projects

  • Thursday, May 17, 2018
  • by incluirtecnologia
  • Repository
  • 3 Watchers
  • 0 Stars
  • 319 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 74 % Grown

The README.md

Simple Router for php >= 5.6.

Build Status, (*1)

How to Install:

composer require 'intec/simple-router';, (*2)

How to Use:

use LibrasSAC\Router\SimpleRouter;

// add route '/hello'
SimpleRouter::add('/hello', function(){
    echo 'Hello!';
});

// match route hello
SimpleRouter::match('/hello');

// add route '/hello/<string>'
SimpleRouter::add('/hello/([a-zA-Z]*)', function($request){
    $name = request->getUrlParams()[0];
    echo "Hello $name!";
});

// match route hello/<string>. It Will print 'Hello Jorge!'
SimpleRouter::match('/hello/jorge');

// add multiple routes once
SimpleRouter::setRoutes([
    [
        'pattern' => '/my/name/is/([a-zA-Z]*)',
            'middlewares' => [
            function(request) {
            // middleware stuff
            // if you want to block the request at this point
            // you will need to use a redirect or exit.
            // Otherwise the router will call the next middleware
            },
            function($request) {
            // middleware 2
            // if you want to block the request at this point
            // you will need to use a redirect or exit
            }
        ]
        'callback' => function($request) {
            $name = request->getUrlParams()[0];
            echo $name;
        }
    ],
    [
        'pattern' => '/my/id/([0-9+])',
        'callback' => function($request) {
            $id = request->getUrlParams()[0];
            echo $id;
        }
    ]
]);

The Versions

17/05 2018

dev-master

9999999-dev

A simple router for small php projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by MĂĄrcio Dias

php small router