PHP code example of artoodetoo / junc
1. Go to this page and download the library: Download artoodetoo/junc library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
artoodetoo / junc example snippets
= [
'/users' => 'get_all_users_handler',
'/user/{id:\d+}' => 'get_user_handler',
'/articles/{id:\d+}[/{title}]' => 'get_article_handler',
];
$dispatcher = FastRoute\simpleDispatcher(new R2\Junc\RouteMapper($map));
$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = rawurldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
case FastRoute\Dispatcher::NOT_FOUND:
header('HTTP/1.0 404 Not Found');
exit;
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
header("HTTP/1.0 405 Method Not Allowed");
exit;
case FastRoute\Dispatcher::FOUND:
$handler = $routeInfo[1]['do'];
$handler($routeInfo[2]);
break;
}
$map = [
'/' => 'index',
'/forum/{id:\d+}' => 'view_forums',
'/admin' => [
'allow' => 'ROLE_ADMIN',
'/' => 'admin_dashboard',
'/updates' => 'admin_updates',
'/user' => [
'/' => 'admin_user_list',
'/{id:\d+}' => 'admin_user_view',
'/new' => 'admin_user_new',
],
],
];
$map = [
'/' => 'index',
'/post/{id:\d+}' => [
['on' => 'GET', 'do' => 'read_post'],
['on' => 'POST', 'do' => 'write_post'],
],
];
$map = [
'/' => 'index',
[
'on' => 'GET',
'/forum/{id:\d+}' => 'view_forum',
'/topic/{id:\d+}' => 'view_topic',
],
[
'on' => 'POST',
'/new',
[
'/forum' => 'new_forum',
'/topic' => 'new_topic',
'/comment' => 'new_comment',
]
],
];
$dispatcher = FastRoute\cachedDispatcher(
new R2\Junc\RouteMapper($map),
[
'cacheFile' => __DIR__ . '/route.cache', /*