Refactor a bit to prepare for manga collection

This commit is contained in:
Timothy Warren 2017-09-14 15:32:53 -04:00
parent 07152cc3be
commit a8e2049d08
8 changed files with 77 additions and 24 deletions

View File

@ -16,6 +16,7 @@
use const Aviat\AnimeClient\{ use const Aviat\AnimeClient\{
DEFAULT_CONTROLLER_NAMESPACE,
DEFAULT_CONTROLLER_METHOD, DEFAULT_CONTROLLER_METHOD,
DEFAULT_CONTROLLER DEFAULT_CONTROLLER
}; };
@ -85,48 +86,87 @@ return [
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Anime Collection Routes // Anime Collection Routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
'collection.search' => [ 'anime.collection.search' => [
'path' => '/collection/search', 'path' => '/anime-collection/search',
'action' => 'search', 'action' => 'search',
], ],
'collection.add.get' => [ 'anime.collection.add.get' => [
'path' => '/collection/add', 'path' => '/anime-collection/add',
'action' => 'form', 'action' => 'form',
'params' => [], 'params' => [],
], ],
'collection.edit.get' => [ 'anime.collection.edit.get' => [
'path' => '/collection/edit/{id}', 'path' => '/anime-collection/edit/{id}',
'action' => 'form', 'action' => 'form',
'tokens' => [ 'tokens' => [
'id' => '[0-9]+', 'id' => '[0-9]+',
], ],
], ],
'collection.add.post' => [ 'anime.collection.add.post' => [
'path' => '/collection/add', 'path' => '/anime-collection/add',
'action' => 'add', 'action' => 'add',
'verb' => 'post', 'verb' => 'post',
], ],
'collection.edit.post' => [ 'anime.collection.edit.post' => [
'path' => '/collection/edit', 'path' => '/anime-collection/edit',
'action' => 'edit', 'action' => 'edit',
'verb' => 'post', 'verb' => 'post',
], ],
'collection.view' => [ 'anime.collection.view' => [
'path' => '/collection/view{/view}', 'path' => '/anime-collection/view{/view}',
'action' => 'index', 'action' => 'index',
'params' => [], 'params' => [],
'tokens' => [ 'tokens' => [
'view' => '[a-z_]+', 'view' => '[a-z_]+',
], ],
], ],
'collection.delete' => [ 'anime.collection.delete' => [
'path' => '/collection/delete', 'path' => '/anime-collection/delete',
'action' => 'delete', 'action' => 'delete',
'verb' => 'post', 'verb' => 'post',
], ],
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Manga Collection Routes // Manga Collection Routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
'manga.collection.search' => [
'path' => '/manga-collection/search',
'action' => 'search',
],
'manga.collection.add.get' => [
'path' => '/manga-collection/add',
'action' => 'form',
'params' => [],
],
'manga.collection.edit.get' => [
'path' => '/manga-collection/edit/{id}',
'action' => 'form',
'tokens' => [
'id' => '[0-9]+',
],
],
'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}',
'action' => 'index',
'params' => [],
'tokens' => [
'view' => '[a-z_]+',
],
],
'manga.collection.delete' => [
'path' => '/manga-collection/delete',
'action' => 'delete',
'verb' => 'post',
],
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Other Routes // Other Routes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
<main> <main>
<?php if ($auth->isAuthenticated()): ?> <?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate('collection.add.get') ?>">Add Item</a> <a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
<?php endif ?> <?php endif ?>
<?php if (empty($sections)): ?> <?php if (empty($sections)): ?>
<h3>There's nothing here!</h3> <h3>There's nothing here!</h3>
@ -23,7 +23,7 @@
<?php if ($auth->isAuthenticated()): ?> <?php if ($auth->isAuthenticated()): ?>
<div class="row"> <div class="row">
<span class="edit"> <span class="edit">
<a class="bracketed" href="<?= $url->generate('collection.edit.get', [ <a class="bracketed" href="<?= $url->generate($collection_type . '.collection.edit.get', [
'id' => $item['hummingbird_id'] 'id' => $item['hummingbird_id']
]) ?>">Edit</a> ]) ?>">Edit</a>
</span> </span>

View File

@ -47,7 +47,7 @@
</form> </form>
<fieldset> <fieldset>
<legend>Danger Zone</legend> <legend>Danger Zone</legend>
<form class="js-delete" action="<?= $url->generate('collection.delete') ?>" method="post"> <form class="js-delete" action="<?= $url->generate($collection_type . '.collection.delete') ?>" method="post">
<table class="form invisible"> <table class="form invisible">
<tbody> <tbody>
<tr> <tr>

View File

@ -1,6 +1,6 @@
<main> <main>
<?php if ($auth->isAuthenticated()): ?> <?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate('collection.add.get') ?>">Add Item</a> <a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
<?php endif ?> <?php endif ?>
<?php if (empty($sections)): ?> <?php if (empty($sections)): ?>
<h3>There's nothing here!</h3> <h3>There's nothing here!</h3>
@ -26,7 +26,7 @@
<tr> <tr>
<?php if($auth->isAuthenticated()): ?> <?php if($auth->isAuthenticated()): ?>
<td> <td>
<a class="bracketed" href="<?= $url->generate('collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a> <a class="bracketed" href="<?= $url->generate($collection_type . '.collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a>
</td> </td>
<?php endif ?> <?php endif ?>
<td class="align_left"> <td class="align_left">

View File

@ -16,10 +16,16 @@ $extraSegment = $lastSegment === 'list' ? '/list' : '';
) ?> ) ?>
<?php if($config->get("show_{$url_type}_collection")): ?> <?php if($config->get("show_{$url_type}_collection")): ?>
[<?= $helper->a( [<?= $helper->a(
$url->generate('collection.view') . $extraSegment, $url->generate("{$url_type}.collection.view") . $extraSegment,
ucfirst($url_type) . ' Collection' ucfirst($url_type) . ' Collection'
) ?>] ) ?>]
<?php endif ?> <?php endif ?>
<?php if($config->get("show_{$other_type}_collection")): ?>
[<?= $helper->a(
$url->generate("{$other_type}.collection.view") . $extraSegment,
ucfirst($other_type) . ' Collection'
) ?>]
<?php endif ?>
[<?= $helper->a( [<?= $helper->a(
$urlGenerator->defaultUrl($other_type) . $extraSegment, $urlGenerator->defaultUrl($other_type) . $extraSegment,
ucfirst($other_type) . ' List' ucfirst($other_type) . ' List'

View File

@ -21,7 +21,7 @@
"aura/router": "^3.0", "aura/router": "^3.0",
"aura/session": "^2.0", "aura/session": "^2.0",
"aviat/banker": "^1.0.0", "aviat/banker": "^1.0.0",
"aviat/ion": "^2.1.0", "aviat/ion": "^2.2.0",
"monolog/monolog": "^1.0", "monolog/monolog": "^1.0",
"psr/http-message": "~1.0", "psr/http-message": "~1.0",
"psr/log": "~1.0", "psr/log": "~1.0",

View File

@ -27,7 +27,7 @@ use Aviat\Ion\Di\ContainerInterface;
/** /**
* Controller for Anime collection pages * Controller for Anime collection pages
*/ */
class Collection extends BaseController { class AnimeCollection extends BaseController {
/** /**
* The anime collection model * The anime collection model
@ -53,6 +53,7 @@ class Collection extends BaseController {
$this->animeModel = $container->get('anime-model'); $this->animeModel = $container->get('anime-model');
$this->animeCollectionModel = $container->get('anime-collection-model'); $this->animeCollectionModel = $container->get('anime-collection-model');
$this->baseData = array_merge($this->baseData, [ $this->baseData = array_merge($this->baseData, [
'collection_type' => 'anime',
'menu_name' => 'collection', 'menu_name' => 'collection',
'url_type' => 'anime', 'url_type' => 'anime',
'other_type' => 'manga', 'other_type' => 'manga',
@ -109,7 +110,7 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . $urlAction, [ $this->outputHTML('collection/' . $urlAction, [
'action' => $action, 'action' => $action,
'action_url' => $this->url->generate("collection.{$urlAction}.post"), 'action_url' => $this->url->generate("anime.collection.{$urlAction}.post"),
'title' => $this->formatTitle( 'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime Collection", $this->config->get('whose_list') . "'s Anime Collection",
$action $action

View File

@ -29,12 +29,15 @@ use function Aviat\Ion\_dir;
use Aviat\AnimeClient\API\FailedResponseException; use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\Ion\Di\ContainerInterface; use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Friend; use Aviat\Ion\Friend;
use Aviat\Ion\StringWrapper;
/** /**
* Basic routing/ dispatch * Basic routing/ dispatch
*/ */
class Dispatcher extends RoutingBase { class Dispatcher extends RoutingBase {
use StringWrapper;
/** /**
* The route-matching object * The route-matching object
* @var object $router * @var object $router
@ -208,6 +211,9 @@ class Dispatcher extends RoutingBase {
$segments = explode('/', $path); $segments = explode('/', $path);
$controller = reset($segments); $controller = reset($segments);
$logger = $this->container->getLogger('default');
$logger->info('Controller: ' . $controller);
if (empty($controller)) if (empty($controller))
{ {
$controller = $routeType; $controller = $routeType;
@ -235,7 +241,7 @@ class Dispatcher extends RoutingBase {
foreach ($classFiles as $file) foreach ($classFiles as $file)
{ {
$rawClassName = basename(str_replace(".php", "", $file)); $rawClassName = basename(str_replace(".php", "", $file));
$path = strtolower(basename($rawClassName)); $path = $this->string($rawClassName)->dasherize()->__toString();
$className = trim($defaultNamespace . '\\' . $rawClassName, '\\'); $className = trim($defaultNamespace . '\\' . $rawClassName, '\\');
$controllers[$path] = $className; $controllers[$path] = $className;