v.0.1
This commit is contained in:
32
vendor/craft-group/phroute/examples/route_filters.php
vendored
Normal file
32
vendor/craft-group/phroute/examples/route_filters.php
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
$collector = new RouteCollector();
|
||||
|
||||
$USER_SESSION = false;
|
||||
|
||||
$collector->filter('auth', function() use(&$USER_SESSION){
|
||||
if(!$USER_SESSION)
|
||||
{
|
||||
return "Nope! Must be authenticated";
|
||||
}
|
||||
});
|
||||
|
||||
$collector->group(array('before' => 'auth'), function(RouteCollector $collector){
|
||||
|
||||
$collector->get('/', function(){
|
||||
return 'Hurrah! Home Page';
|
||||
});
|
||||
});
|
||||
|
||||
$dispatcher = new Dispatcher($collector->getData());
|
||||
|
||||
echo $dispatcher->dispatch('GET', '/'), "\n"; // Nope! Must be authenticated
|
||||
|
||||
$USER_SESSION = true;
|
||||
|
||||
echo $dispatcher->dispatch('GET', '/'), "\n"; // Hurrah! Home Page
|
29
vendor/craft-group/phroute/examples/route_prefix.php
vendored
Normal file
29
vendor/craft-group/phroute/examples/route_prefix.php
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
$collector = new RouteCollector();
|
||||
|
||||
$collector->group(array('prefix' => 'admin'), function(RouteCollector $collector){
|
||||
|
||||
$collector->get('pages', function(){
|
||||
return 'page management';
|
||||
});
|
||||
|
||||
$collector->get('products', function(){
|
||||
return 'product management';
|
||||
});
|
||||
|
||||
$collector->get('orders', function(){
|
||||
return 'order management';
|
||||
});
|
||||
});
|
||||
|
||||
$dispatcher = new Dispatcher($collector->getData());
|
||||
|
||||
echo $dispatcher->dispatch('GET', '/admin/pages'), "\n"; // page management
|
||||
echo $dispatcher->dispatch('GET', '/admin/products'), "\n"; // product management
|
||||
echo $dispatcher->dispatch('GET', '/admin/orders'), "\n"; // order management
|
36
vendor/craft-group/phroute/examples/route_prefix_and_filter_nested.php
vendored
Normal file
36
vendor/craft-group/phroute/examples/route_prefix_and_filter_nested.php
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
$collector = new RouteCollector();
|
||||
|
||||
$collector->filter('auth', function(){
|
||||
return "Nope!";
|
||||
});
|
||||
|
||||
$collector->group(array('prefix' => 'admin'), function(RouteCollector $collector){
|
||||
|
||||
$collector->group(['before' => 'auth'], function(RouteCollector $collector){
|
||||
$collector->get('pages', function(){
|
||||
return 'page management';
|
||||
});
|
||||
|
||||
$collector->get('products', function(){
|
||||
return 'product management';
|
||||
});
|
||||
});
|
||||
|
||||
// Not inside auth group
|
||||
$collector->get('orders', function(){
|
||||
return 'Order management';
|
||||
});
|
||||
});
|
||||
|
||||
$dispatcher = new Dispatcher($collector->getData());
|
||||
|
||||
echo $dispatcher->dispatch('GET', '/admin/pages'), "\n"; // Nope!
|
||||
echo $dispatcher->dispatch('GET', '/admin/products'), "\n"; // Nope!
|
||||
echo $dispatcher->dispatch('GET', '/admin/orders'), "\n"; // order management
|
27
vendor/craft-group/phroute/examples/simple.php
vendored
Normal file
27
vendor/craft-group/phroute/examples/simple.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
error_reporting(-1);
|
||||
ini_set('display_errors', 1);
|
||||
include __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
use Phroute\Phroute\Dispatcher;
|
||||
|
||||
$collector = new RouteCollector();
|
||||
|
||||
$collector->get('/', function(){
|
||||
return 'Home Page';
|
||||
});
|
||||
|
||||
$collector->post('products', function(){
|
||||
return 'Create Product';
|
||||
});
|
||||
|
||||
$collector->put('items/{id}', function($id){
|
||||
return 'Amend Item ' . $id;
|
||||
});
|
||||
|
||||
$dispatcher = new Dispatcher($collector->getData());
|
||||
|
||||
echo $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); // Home Page
|
||||
//echo $dispatcher->dispatch('POST', '/products'), "\n"; // Create Product
|
||||
//echo $dispatcher->dispatch('PUT', '/items/123'), "\n"; // Amend Item 123
|
Reference in New Issue
Block a user