HummingBirdAnimeClient/app/appConf/routes.php

325 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
*
2021-02-23 15:38:29 -05:00
* An API client for Kitsu to manage anime and manga watch lists
2015-11-16 11:40:01 -05:00
*
2021-02-23 15:38:29 -05:00
* PHP version 8
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>
2021-02-23 15:38:29 -05:00
* @copyright 2015 - 2021 Timothy J. Warren
2016-08-30 10:01:18 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2021-02-23 15:38:29 -05:00
* @version 5.2
* @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,
2022-03-03 18:19:02 -05:00
DEFAULT_CONTROLLER,
DEFAULT_CONTROLLER_METHOD,
KITSU_SLUG_PATTERN,
2022-03-03 18:19:02 -05:00
NUM_PATTERN,
2023-06-28 14:30:30 -04:00
SLUG_PATTERN,
};
2017-03-30 16:16:40 -04:00
// -------------------------------------------------------------------------
// Routing Config
//
// Maps paths to controllers and methods
2017-03-30 16:16:40 -04:00
// -------------------------------------------------------------------------
$base_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' => [
'id' => KITSU_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' => [
'id' => KITSU_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' => [
'slug' => KITSU_SLUG_PATTERN,
2022-03-03 18:19:02 -05:00
],
2017-03-30 16:16:40 -04:00
],
'person' => [
'path' => '/people/{slug}',
'tokens' => [
'slug' => KITSU_SLUG_PATTERN,
2022-03-03 18:19:02 -05:00
],
],
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' => [
2022-03-03 18:19:02 -05:00
'username' => '.*?',
],
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,
2022-03-03 18:19:02 -05:00
'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',
],
2020-12-10 15:59:37 -05:00
'history' => [
'controller' => 'history',
'path' => '/history/{type}',
'tokens' => [
2022-03-03 18:19:02 -05:00
'type' => SLUG_PATTERN,
],
2020-12-10 15:59:37 -05:00
],
'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' => [
'id' => KITSU_SLUG_PATTERN,
'status' => SLUG_PATTERN,
2016-01-06 11:08:56 -05:00
],
2017-03-30 16:16:40 -04:00
],
'list' => [
2020-12-10 15:59:37 -05:00
'path' => '/{controller}/{status}{/view}',
2017-03-30 16:16:40 -04:00
'tokens' => [
2020-12-10 15:59:37 -05:00
'status' => ALPHA_SLUG_PATTERN,
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
'index_redirect' => [
'path' => '/',
'action' => 'redirectToDefaultRoute',
],
2018-11-01 22:01:09 -04:00
];
$defaultMap = [
'action' => DEFAULT_CONTROLLER_METHOD,
'controller' => DEFAULT_CONTROLLER,
'params' => [],
'verb' => 'get',
];
$routes = [];
foreach ($base_routes as $name => $route)
2018-11-01 22:01:09 -04:00
{
$routes[$name] = array_merge($defaultMap, $route);
2018-11-01 22:01:09 -04:00
}
return $routes;