HummingBirdAnimeClient/app/appConf/routes.php

329 lines
7.5 KiB
PHP
Raw Normal View History

2017-02-15 16:13:32 -05:00
<?php declare(strict_types=1);
2015-11-16 11:40:01 -05:00
/**
2017-02-15 16:13:32 -05:00
* Hummingbird Anime List Client
2015-11-16 11:40:01 -05:00
*
2017-02-15 16:13:32 -05:00
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
2015-11-16 11:40:01 -05:00
*
2017-02-15 16:13:32 -05:00
* PHP version 7
2016-08-30 10:01:18 -04:00
*
2015-11-16 11:40:01 -05:00
* @package HummingbirdAnimeClient
2016-08-30 10:01:18 -04:00
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2018 Timothy J. Warren
2016-08-30 10:01:18 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2017-02-15 16:13:32 -05:00
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
2015-11-16 11:40:01 -05:00
*/
2015-05-22 12:36:26 -04:00
use const Aviat\AnimeClient\{
2018-11-01 22:01:09 -04:00
ALPHA_SLUG_PATTERN,
NUM_PATTERN,
SLUG_PATTERN,
DEFAULT_CONTROLLER_METHOD,
2017-03-31 13:37:53 -04:00
DEFAULT_CONTROLLER
};
2017-03-30 16:16:40 -04:00
// -------------------------------------------------------------------------
// Routing Config
//
// Maps paths to controllers and methods
2017-03-30 16:16:40 -04:00
// -------------------------------------------------------------------------
2018-11-01 22:01:09 -04:00
$routes = [
// ---------------------------------------------------------------------
// AJAX Routes
// ---------------------------------------------------------------------
'cache_purge' => [
'path' => '/cache_purge',
'action' => 'clearCache',
],
'heartbeat' => [
'path' => '/heartbeat',
'action' => 'heartbeat',
],
2017-03-30 16:16:40 -04:00
// ---------------------------------------------------------------------
// Anime List Routes
// ---------------------------------------------------------------------
'anime.add.get' => [
'path' => '/anime/add',
'action' => 'addForm',
],
'anime.add.post' => [
'path' => '/anime/add',
'action' => 'add',
'verb' => 'post',
],
'anime.random' => [
'path' => '/anime/details/random',
'action' => 'random',
],
2017-03-30 16:16:40 -04:00
'anime.details' => [
'path' => '/anime/details/{id}',
'action' => 'details',
'tokens' => [
2018-11-01 22:01:09 -04:00
'id' => SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'anime.delete' => [
'path' => '/anime/delete',
'action' => 'delete',
'verb' => 'post',
],
// ---------------------------------------------------------------------
// Manga Routes
// ---------------------------------------------------------------------
'manga.search' => [
'path' => '/manga/search',
'action' => 'search',
],
'manga.add.get' => [
'path' => '/manga/add',
'action' => 'addForm',
],
'manga.add.post' => [
'path' => '/manga/add',
'action' => 'add',
'verb' => 'post',
],
'manga.delete' => [
'path' => '/manga/delete',
'action' => 'delete',
'verb' => 'post',
],
'manga.random' => [
'path' => '/manga/details/random',
'action' => 'random',
],
2017-03-30 16:16:40 -04:00
'manga.details' => [
'path' => '/manga/details/{id}',
'action' => 'details',
'tokens' => [
2018-11-01 22:01:09 -04:00
'id' => SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
// ---------------------------------------------------------------------
// Anime Collection Routes
// ---------------------------------------------------------------------
'anime.collection.search' => [
'path' => '/anime-collection/search',
2017-03-30 16:16:40 -04:00
'action' => 'search',
],
'anime.collection.add.get' => [
'path' => '/anime-collection/add',
2017-03-30 16:16:40 -04:00
'action' => 'form',
],
'anime.collection.edit.get' => [
'path' => '/anime-collection/edit/{id}',
2017-03-30 16:16:40 -04:00
'action' => 'form',
'tokens' => [
2018-11-01 22:01:09 -04:00
'id' => NUM_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'anime.collection.add.post' => [
'path' => '/anime-collection/add',
2017-03-30 16:16:40 -04:00
'action' => 'add',
'verb' => 'post',
],
'anime.collection.edit.post' => [
'path' => '/anime-collection/edit',
2017-03-30 16:16:40 -04:00
'action' => 'edit',
'verb' => 'post',
],
'anime.collection.view' => [
'path' => '/anime-collection/view{/view}',
'action' => 'view',
2017-03-30 16:16:40 -04:00
'tokens' => [
2018-11-01 22:01:09 -04:00
'view' => ALPHA_SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'anime.collection.delete' => [
'path' => '/anime-collection/delete',
2017-03-30 16:16:40 -04:00
'action' => 'delete',
'verb' => 'post',
],
'anime.collection.redirect' => [
'path' => '/anime-collection',
],
'anime.collection.redirect2' => [
'path' => '/anime-collection/',
],
2017-03-30 16:16:40 -04:00
// ---------------------------------------------------------------------
// Manga Collection Routes
// ---------------------------------------------------------------------
'manga.collection.search' => [
'path' => '/manga-collection/search',
'action' => 'search',
],
'manga.collection.add.get' => [
'path' => '/manga-collection/add',
'action' => 'form',
],
'manga.collection.edit.get' => [
'path' => '/manga-collection/edit/{id}',
'action' => 'form',
'tokens' => [
2018-11-01 22:01:09 -04:00
'id' => NUM_PATTERN,
],
],
'manga.collection.add.post' => [
'path' => '/manga-collection/add',
'action' => 'add',
'verb' => 'post',
],
'manga.collection.edit.post' => [
'path' => '/manga-collection/edit',
'action' => 'edit',
'verb' => 'post',
],
'manga.collection.view' => [
'path' => '/manga-collection/view{/view}',
'tokens' => [
2018-11-01 22:01:09 -04:00
'view' => ALPHA_SLUG_PATTERN,
],
],
'manga.collection.delete' => [
'path' => '/manga-collection/delete',
'action' => 'delete',
'verb' => 'post',
],
2017-03-30 16:16:40 -04:00
// ---------------------------------------------------------------------
// Other Routes
// ---------------------------------------------------------------------
'character' => [
'path' => '/character/{slug}',
'tokens' => [
2018-11-01 22:01:09 -04:00
'slug' => SLUG_PATTERN
2017-03-30 16:16:40 -04:00
]
],
'person' => [
'path' => '/people/{slug}',
'tokens' => [
'slug' => SLUG_PATTERN,
]
],
2018-11-01 22:01:09 -04:00
'default_user_info' => [
'path' => '/me',
'action' => 'me',
'controller' => 'user',
],
2017-03-30 16:16:40 -04:00
'user_info' => [
2018-11-01 22:01:09 -04:00
'path' => '/user/{username}',
'controller' => 'user',
'action' => 'about',
2018-10-30 11:42:32 -04:00
'tokens' => [
2018-11-01 22:01:09 -04:00
'username' => '.*?'
2018-10-30 11:42:32 -04:00
]
2017-03-30 16:16:40 -04:00
],
// ---------------------------------------------------------------------
// Default / Shared routes
// ---------------------------------------------------------------------
'anilist-redirect' => [
'path' => '/anilist-redirect',
'action' => 'anilistRedirect',
'controller' => 'settings',
],
'anilist-callback' => [
'path' => '/anilist-oauth',
'action' => 'anilistCallback',
'controller' => 'settings',
],
'image_proxy' => [
'path' => '/public/images/{type}/{file}',
2018-11-01 22:01:09 -04:00
'action' => 'cache',
'controller' => 'images',
'tokens' => [
2018-11-01 22:01:09 -04:00
'type' => SLUG_PATTERN,
'file' => '[a-z0-9\-]+\.[a-z]{3,4}'
]
],
2018-08-15 08:51:37 -04:00
'settings' => [
'path' => '/settings',
],
2018-08-24 14:23:01 -04:00
'settings-post' => [
2018-11-01 22:01:09 -04:00
'path' => '/settings/update',
'action' => 'update',
2018-08-24 14:23:01 -04:00
'verb' => 'post',
],
2017-03-30 16:16:40 -04:00
'login' => [
'path' => '/login',
'action' => 'login',
],
'login.post' => [
'path' => '/login',
'action' => 'loginAction',
'verb' => 'post',
],
'logout' => [
'path' => '/logout',
'action' => 'logout',
],
'increment' => [
'path' => '/{controller}/increment',
'action' => 'increment',
'verb' => 'post',
'tokens' => [
2018-11-01 22:01:09 -04:00
'controller' => ALPHA_SLUG_PATTERN,
],
],
2017-03-30 16:16:40 -04:00
'update' => [
'path' => '/{controller}/update',
'action' => 'update',
'verb' => 'post',
'tokens' => [
2018-11-01 22:01:09 -04:00
'controller' => ALPHA_SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'update.post' => [
'path' => '/{controller}/update_form',
'action' => 'formUpdate',
'verb' => 'post',
'tokens' => [
2018-11-01 22:01:09 -04:00
'controller' => ALPHA_SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'edit' => [
'path' => '/{controller}/edit/{id}/{status}',
'action' => 'edit',
'tokens' => [
2018-11-01 22:01:09 -04:00
'id' => SLUG_PATTERN,
2017-03-30 16:16:40 -04:00
'status' => '([a-zA-Z\-_]|%20)+',
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'list' => [
'path' => '/{controller}/{type}{/view}',
'tokens' => [
2018-11-01 22:01:09 -04:00
'type' => ALPHA_SLUG_PATTERN,
'view' => ALPHA_SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
],
'history' => [
'controller' => 'history',
'path' => '/history/{type}',
'tokens' => [
'type' => SLUG_PATTERN
]
],
2017-03-30 16:16:40 -04:00
'index_redirect' => [
'path' => '/',
'action' => 'redirectToDefaultRoute',
],
2018-11-01 22:01:09 -04:00
];
$defaultMap = [
'action' => DEFAULT_CONTROLLER_METHOD,
'controller' => DEFAULT_CONTROLLER,
'params' => [],
'verb' => 'get',
];
foreach ($routes as &$route)
{
foreach($defaultMap as $key => $val)
{
if ( ! array_key_exists($key, $route))
{
$route[$key] = $val;
}
}
}
return $routes;