2017 © Pedro Peláez
 

library router

a php router base on Macaw

image

mombol/router

a php router base on Macaw

  • Friday, April 22, 2016
  • by mombol
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Router

Router is a simple, open source PHP router base on macaw. It's super small (~150 LOC), fast, and has some great annotated source code. This class allows you to just throw it into your project and start using it immediately., (*1)

Install

If you have Composer, just include Router as a project dependency in your composer.json. If you don't just install it by downloading the .ZIP file and extracting it to your project directory., (*2)

require: {
    "mombol/router": "^1.0"
}

Examples

First, use the Router namespace:, (*3)

use \Mombol\Router\Router;

Router is not an object, so you can just make direct operations to the class. Here's the Hello World:, (*4)

Router::get('/', function() {
  return 'Hello world!';
});

Router also supports lambda URIs, such as:, (*5)

Router::get('/(:any)', function($slug) {
  return 'The slug is: ' . $slug;
});

You can also make requests for HTTP methods in Router, so you could also do:, (*6)

Router::get('/', function() {
  return 'I <3 GET commands!';
});

Router::post('/', function() {
  return  'I <3 POST commands!';
});

Lastly, if there is no route defined for a certain location, you can make Router run a custom callback, like:, (*7)

Router::error(function() {
  return '404 :: Not Found';
});

If you don't specify an error callback, Router will just echo 404., (*8)

After call Router function do this:, (*9)

Router::dispatch(function($content){
  if (!empty($content) && is_string($content)) {
    echo $content;
  }
});

, (*10)


Orther

See https://github.com/noahbuscher/Macaw, (*11)

The Versions

22/04 2016

dev-master

9999999-dev

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol

22/04 2016

1.0.4

1.0.4.0

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol

22/04 2016

1.0.3

1.0.3.0

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol

22/04 2016

1.0.2

1.0.2.0

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol

22/04 2016

1.0.1

1.0.1.0

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol

22/04 2016

v1.0.0

1.0.0.0

a php router base on Macaw

  Sources   Download

MIT

by Avatar mombol