2017 © Pedro Peláez
 

library router-cached

A simple request router with cached

image

vakata/router-cached

A simple request router with cached

  • Thursday, October 27, 2016
  • by vakata
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

routerCached

Latest Version on Packagist ![Software License][ico-license] Build Status Code Climate ![Tests Coverage][ico-cc-coverage], (*1)

A simple request router with cache., (*2)

Install

Via Composer, (*3)

``` bash $ composer require vakata/router-cached, (*4)


## Usage ``` php // Usage is the same as with the non-cached router // you only need to supply a class implementing the \vakata\cache\CacheInterface $router = new \vakata\routerCached\RouterCached( new \vakata\cache\Filecache(__DIR__), // where will cached pages be stored 60, // cache validity in seconds - by default it is 1440 seconds function ($request, $verb) { // return a key for each request return md5($verb . ' ' . $request); // this is the default }, [ 'GET', 'POST' ], // which verbs to cache 'routeCache' // a namespace (allowing easy clearing of all cached routes) ); // everything else is exactly the same as with the non-caching router: $router ->get('/', function () { echo 'homepage'; }) ->get('/profile', function () { echo 'user profile'; }) ->with('/books/') // specify a prefix for all future routes ->get('read/{i:id}', function ($matches) { // this method uses a named placeholder // provided the user visits /books/read/10 matches will contain: var_dump($matches); // 0 => books, 1 => read, 2 => 10, id => 10 // placeholders are wrapped in curly braces {...} and can be: // - i - an integer // - a - any letter (a-z) // - h - any letter or integer // - * - anything (up to the next slash (/)) // - ** - anything (to the end of the URL) // placeholders can be named too by using the syntax: // {placeholder:name} // placeholders can also be optional // {?optional} }) // for advanced users - you can use any regex as a placeholder: ->get('{(delete|update):action}/{(\d+):id}', function ($matches) { }) // you can also use any HTTP verb ->post('delete/{i:id}', function ($matches) { }) // here is how you reset the prefix ->with('') // you can also bind multiple HTTP verbs in one go ->add(['GET', 'HEAD'], '/path', function () { }) // you can also use with() statements to execute some code if the begging of the URL is a match to the prefix ->with('user', function () { echo 1; }) ->get('view', function () { /* 1 will be echoed */ }) ->post('chat', function () { /* 1 will be echoed */ }); // there is no need to chain the method calls - this works too: $router->post('123', function () { }); $router->post('456', function () { }); // you finally run the router try { $router->run($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']); } catch (\vakata\router\RouterException $e) { // thrown if no matching route is found }

Read more in the API docs, (*5)

Testing

bash $ composer test, (*6)

Contributing

Please see CONTRIBUTING for details., (*7)

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker., (*8)

Credits

License

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

The Versions

27/10 2016

dev-master

9999999-dev https://github.com/vakata/router-cached

A simple request router with cached

  Sources   Download

MIT

The Requires

 

The Development Requires

vakata routercached

27/10 2016

1.0.1

1.0.1.0 https://github.com/vakata/router-cached

A simple request router with cached

  Sources   Download

MIT

The Requires

 

The Development Requires

vakata routercached

10/12 2015

1.0.0

1.0.0.0 https://github.com/vakata/router-cached

A simple request router with cached

  Sources   Download

MIT

The Requires

 

The Development Requires

vakata routercached