2017 © Pedro Peláez
 

library routing

A library for simple routing in PHP

image

openclerk/routing

A library for simple routing in PHP

  • Monday, September 11, 2017
  • by soundasleep
  • Repository
  • 1 Watchers
  • 0 Stars
  • 140 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

openclerk/routing Build Status

A library for simple routing in PHP., (*1)

Using

This project uses openclerk/config for config management., (*2)

First configure the component with site-specific values:, (*3)

Openclerk\Config::merge(array(
  "absolute_url" => "http://localhost/path/",
));

Add a simple router file:, (*4)

getMessage());
}
?>

Add a .htaccess that translates paths to this router:, (*5)

RewriteEngine on

# Forbid access to any child PHP scripts
RewriteRule ^([^\.]+)/([^\.]+).php$   -                   [F]

RewriteRule ^([^\.]+)$                router.php?path=$1  [L,QSA]

Define site routes:, (*6)

// set up routes
\Openclerk\Router::addRoutes(array(
  "security/login/password" => "security/login.php?type=password",
  "security/login/:key" => "security/login-:key.php?type=:key",
  // by default any unmatched routes will require <module>.php
));

Now you can use url_for() and absolute_url_for():, (*7)

<a href="<?php echo htmlspecialchars(url_for('security/login/password')); ?>">Login with password</a>

Renderable objects

You can also pass along an object with a render($args) method, which will be called instead:, (*8)

class MyApi {
  function render($args) {
    // $args = array('code' => ...)
  }
}

\Openclerk\Router::addRoutes(array(
  "api/currency/:code" => new MyApi(),
));

Tests

composer update --dev
vendor/bin/phpunit

TODO

  1. Actual documentation
  2. Tests
  3. Publish on Packagist

The Versions

11/09 2017

dev-master

9999999-dev

A library for simple routing in PHP

  Sources   Download

The Requires

 

The Development Requires

11/09 2017

0.1.0

0.1.0.0

A library for simple routing in PHP

  Sources   Download

The Requires

 

The Development Requires