Last active
August 29, 2015 14:15
-
-
Save NigelGreenway/001c920e26979978cff1 to your computer and use it in GitHub Desktop.
Example code for Route/FastRoute config...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'demo' => [ | |
'prefix' => '/demo', | |
'routes' => require realpath(__DIR__ . '/Demo/routing.php'), | |
], | |
'security' => [ | |
'prefix' => '', | |
'routes' => require realpath(__DIR__ . '/Security/routing.php'), | |
], | |
'separated_routes' => require realpath(__DIR__ . '/SeparatedRoutesDemo/Resource/routing.php'), | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is simplistic code to illustrate how routing config files could be implemented. | |
*/ | |
public function addRoutesFromConfig( | |
array $routes = [], | |
$namedRoutes = false, | |
Strategy\StrategyInterface $strategy = null | |
) { | |
foreach ($modules as $moduleName => $moduleConfig) { | |
if (true === isset($moduleConfig['routes'])) { | |
foreach ($moduleConfig['routes'] as $routeName => $routeConfig) { | |
$route = sprintf('%s%s', $moduleConfig['prefix'], $routeConfig['pattern']); | |
$this->addRoute($method, $route, $handler, $name); | |
} | |
} else { | |
foreach ($moduleConfig as $moduleName => $moduleConfig) { | |
foreach($moduleConfig['routes'] as $routeName => $routeConfig) { | |
$route = sprintf('%s%s', $moduleConfig['prefix'], $routeConfig['pattern']); | |
$this->addRoute($method, $route, $handler, $name); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'demo_one' => [ | |
'pattern' => '/hello/{name:word}', | |
'handler' => 'Demo\Controller\DemoController::helloPerson', | |
'method' => 'GET', | |
], | |
'demo_two' => [ | |
'pattern' => '/bye/{name:word}', | |
'handler' => 'Demo\Controller\DemoController::byePerson', | |
'method' => 'GET', | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'login' => [ | |
'pattern' => '/login', | |
'handler' => 'Security\Controller\AuthenticationController::login', | |
'method' => 'POST', | |
], | |
'logout' => [ | |
'pattern' => '/logout', | |
'handler' => 'Security\Controller\AuthenticationController::logout', | |
'method' => 'POST', | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'route_one' => [ | |
'pattern' => '/route/first', | |
'handler' => 'One\Controller\OneController::first', | |
'method' => 'GET', | |
], | |
'route_two' => [ | |
'pattern' => '/route/second', | |
'handler' => 'One\Controller\OneController::second', | |
'method' => 'POST', | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'one' => [ | |
'prefix' => '/one', | |
'routes' => require realpath(__DIR__ . '/one.php'), | |
], | |
'two' => [ | |
'prefix' => '/two', | |
'routes' => require realpath(__DIR__ . '/two.php'), | |
] | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'route_one' => [ | |
'pattern' => '/route/first', | |
'handler' => 'One\Controller\OneController::first', | |
'method' => 'GET', | |
], | |
'route_two' => [ | |
'pattern' => '/route/second', | |
'handler' => 'One\Controller\OneController::second', | |
'method' => 'POST', | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment