2017 © Pedro Peláez
 

library wp-router

A simple router for WordPress plugins and themes

image

downshiftorg/wp-router

A simple router for WordPress plugins and themes

  • Monday, January 15, 2018
  • by DownShift
  • Repository
  • 3 Watchers
  • 11 Stars
  • 3,287 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 13 % Grown

The README.md

wp-router Build Status

A simple scoped router powered by query string parameters., (*1)

Though this has use outside of WordPress (for now), it is meant for use within the WordPress ecosystem as a means to add custom routes without specific page scripts., (*2)

usage

The router matches a get or post request to a responder. A responder is a function or an invokable class., (*3)

use DownShift\WordPress\Router;

$router = new Router('my_scope');

// matches ?my_scope=/myroute
$router->post('/myroute', function () {
  // do something here
});

// listen terminates via exit after route function executes
$router->listen();

You can also give a route definition an invokable class., (*4)

$router->post('/myroute', new InvokableClass());

// or a string if you prefer
$router->post('/myroute', 'DownShift\Responders\SomeClass');

service injection

Services in route functions are resolved using a PHP 5.3 friendly version of the Illuminate Container, (*5)

$container = new Container();
$container->bind('SomeInterface', 'SomeImplementation');
$router = new Router('my_scope');
$router->bind($container);

$router->get('/test', function (SomeInterface $service) {
  // do a thing with $service
});

If resolving a class, the constructor will have dependencies injected. Resolution of classes is only valid when using a string., (*6)

tests

Tests are written using peridot, and can be run like so:, (*7)

vendor/bin/peridot

The Versions

15/01 2018

dev-master

9999999-dev

A simple router for WordPress plugins and themes

  Sources   Download

MIT

The Requires

 

The Development Requires

15/01 2018

3.0.0

3.0.0.0

A simple router for WordPress plugins and themes

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2015

2.0.0

2.0.0.0

A simple router for WordPress plugins and themes

  Sources   Download

MIT

The Requires

 

The Development Requires

14/06 2015

1.0.0

1.0.0.0

A simple router for WordPress plugins and themes

  Sources   Download

MIT

The Requires

 

The Development Requires