Version 5.1 - All the GraphQL #32
@ -53,7 +53,7 @@ return [
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
'anime.add.get' => [
|
'anime.add.get' => [
|
||||||
'path' => '/anime/add',
|
'path' => '/anime/add',
|
||||||
'action' => 'add_form',
|
'action' => 'addForm',
|
||||||
'verb' => 'get',
|
'verb' => 'get',
|
||||||
],
|
],
|
||||||
'anime.add.post' => [
|
'anime.add.post' => [
|
||||||
@ -82,7 +82,7 @@ return [
|
|||||||
],
|
],
|
||||||
'manga.add.get' => [
|
'manga.add.get' => [
|
||||||
'path' => '/manga/add',
|
'path' => '/manga/add',
|
||||||
'action' => 'add_form',
|
'action' => 'addForm',
|
||||||
'verb' => 'get',
|
'verb' => 'get',
|
||||||
],
|
],
|
||||||
'manga.add.post' => [
|
'manga.add.post' => [
|
||||||
@ -183,7 +183,7 @@ return [
|
|||||||
],
|
],
|
||||||
'update.post' => [
|
'update.post' => [
|
||||||
'path' => '/{controller}/update_form',
|
'path' => '/{controller}/update_form',
|
||||||
'action' => 'form_update',
|
'action' => 'formUpdate',
|
||||||
'verb' => 'post',
|
'verb' => 'post',
|
||||||
'tokens' => [
|
'tokens' => [
|
||||||
'controller' => '[a-z_]+',
|
'controller' => '[a-z_]+',
|
||||||
|
@ -36,5 +36,5 @@
|
|||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/anime_collection') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -86,5 +86,5 @@
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<?php if ($auth->is_authenticated()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/edit') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -107,5 +107,5 @@
|
|||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/edit') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -87,4 +87,4 @@
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<?php $group = ($auth->is_authenticated()) ? 'table_edit' : 'table' ?>
|
<?php $group = ($auth->is_authenticated()) ? 'table_edit' : 'table' ?>
|
||||||
<script src="<?= $urlGenerator->asset_url("js.php/g/{$group}") ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl("js.php/g/{$group}") ?>"></script>
|
@ -39,5 +39,5 @@
|
|||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/anime_collection') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -62,5 +62,5 @@
|
|||||||
</form>
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/anime_collection') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/anime_collection') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -1,6 +1,6 @@
|
|||||||
<main>
|
<main>
|
||||||
<?php if ($auth->is_authenticated()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<a class="bracketed" href="<?= $urlGenerator->full_url('collection/add', 'anime') ?>">Add Item</a>
|
<a class="bracketed" href="<?= $urlGenerator->fullUrl('collection/add', 'anime') ?>">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,8 +26,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<?php if($auth->is_authenticated()): ?>
|
<?php if($auth->is_authenticated()): ?>
|
||||||
<td>
|
<td>
|
||||||
<a class="bracketed" href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a>
|
<a class="bracketed" href="<?= $urlGenerator->fullUrl("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a>
|
||||||
<?php /*<a class="bracketed" href="<?= $urlGenerator->full_url("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a>*/ ?>
|
<?php /*<a class="bracketed" href="<?= $urlGenerator->fullUrl("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a>*/ ?>
|
||||||
</td>
|
</td>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<td class="align_left">
|
<td class="align_left">
|
||||||
@ -49,4 +49,4 @@
|
|||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/table') ?>"></script>
|
@ -1,3 +1,3 @@
|
|||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/event') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/event') ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -7,8 +7,8 @@
|
|||||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self'" />
|
<meta http-equiv="Content-Security-Policy" content="script-src 'self'" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0" />
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.ico" />
|
||||||
<link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php/g/base') ?>" />
|
<link rel="stylesheet" href="<?= $urlGenerator->assetUrl('css.php/g/base') ?>" />
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/base') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/base') ?>"></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="<?= $escape->attr($url_type) ?> list">
|
<body class="<?= $escape->attr($url_type) ?> list">
|
||||||
<header>
|
<header>
|
||||||
|
@ -2,19 +2,19 @@
|
|||||||
<h1 class="flex flex-align-end flex-wrap">
|
<h1 class="flex flex-align-end flex-wrap">
|
||||||
<span class="flex-no-wrap grow-1">
|
<span class="flex-no-wrap grow-1">
|
||||||
<?php if(strpos($route_path, 'collection') === FALSE): ?>
|
<?php if(strpos($route_path, 'collection') === FALSE): ?>
|
||||||
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
|
<a href="<?= $escape->attr($urlGenerator->defaultUrl($url_type)) ?>">
|
||||||
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
|
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
|
||||||
</a>
|
</a>
|
||||||
<?php if($config->get("show_{$url_type}_collection")): ?>
|
<?php if($config->get("show_{$url_type}_collection")): ?>
|
||||||
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
|
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
[<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
|
[<a href="<?= $urlGenerator->defaultUrl($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<a href="<?= $urlGenerator->url('collection/view') ?>">
|
<a href="<?= $urlGenerator->url('collection/view') ?>">
|
||||||
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
|
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
|
||||||
</a>
|
</a>
|
||||||
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
|
[<a href="<?= $urlGenerator->defaultUrl('anime') ?>">Anime List</a>]
|
||||||
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
|
[<a href="<?= $urlGenerator->defaultUrl('manga') ?>">Manga List</a>]
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</span>
|
</span>
|
||||||
<?php if ($auth->is_authenticated()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
|
@ -36,5 +36,5 @@
|
|||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/manga_collection') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/manga_collection') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -56,5 +56,5 @@
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<?php if ($auth->is_authenticated()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/edit') ?>"></script>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
@ -1,7 +1,7 @@
|
|||||||
<main>
|
<main>
|
||||||
<?php /*if ($auth->is_authenticated()): ?>
|
<?php if ($auth->is_authenticated()): ?>
|
||||||
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
|
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">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>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
@ -47,4 +47,4 @@
|
|||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</main>
|
</main>
|
||||||
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
|
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/table') ?>"></script>
|
@ -125,7 +125,7 @@ class Controller {
|
|||||||
public function redirectToDefaultRoute()
|
public function redirectToDefaultRoute()
|
||||||
{
|
{
|
||||||
$default_type = $this->config->get(['routes', 'route_config', 'default_list']);
|
$default_type = $this->config->get(['routes', 'route_config', 'default_list']);
|
||||||
$this->redirect($this->urlGenerator->default_url($default_type), 303);
|
$this->redirect($this->urlGenerator->defaultUrl($default_type), 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
namespace Aviat\AnimeClient\Controller;
|
namespace Aviat\AnimeClient\Controller;
|
||||||
|
|
||||||
use Aviat\AnimeClient\Controller as BaseController;
|
use Aviat\AnimeClient\Controller as BaseController;
|
||||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
use Aviat\AnimeClient\Model\{
|
||||||
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
|
Anime as AnimeModel,
|
||||||
|
AnimeCollection as AnimeCollectionModel
|
||||||
|
};
|
||||||
use Aviat\AnimeClient\UrlGenerator;
|
use Aviat\AnimeClient\UrlGenerator;
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ class Collection extends BaseController {
|
|||||||
|
|
||||||
$this->outputHTML('collection/' . strtolower($action), [
|
$this->outputHTML('collection/' . strtolower($action), [
|
||||||
'action' => $action,
|
'action' => $action,
|
||||||
'action_url' => $this->urlGenerator->full_url('collection/' . strtolower($action)),
|
'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)),
|
||||||
'title' => $this->config->get('whose_list') . " Anime Collection · {$action}",
|
'title' => $this->config->get('whose_list') . " Anime Collection · {$action}",
|
||||||
'media_items' => $this->animeCollectionModel->get_media_type_list(),
|
'media_items' => $this->animeCollectionModel->get_media_type_list(),
|
||||||
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
|
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
namespace Aviat\AnimeClient;
|
namespace Aviat\AnimeClient;
|
||||||
|
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UrlGenerator class.
|
* UrlGenerator class.
|
||||||
@ -45,33 +46,16 @@ class UrlGenerator extends RoutingBase {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function asset_url()
|
public function assetUrl(...$args)
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$baseUrl = rtrim($this->url(""), '/');
|
||||||
$base_url = rtrim($this->url(""), '/');
|
$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
|
||||||
|
|
||||||
$base_url = "{$base_url}" . $this->__get("asset_path");
|
array_unshift($args, $baseUrl);
|
||||||
|
|
||||||
array_unshift($args, $base_url);
|
|
||||||
|
|
||||||
return implode("/", $args);
|
return implode("/", $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the base url from the config
|
|
||||||
*
|
|
||||||
* @param string $type - (optional) The controller
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function base_url($type = "anime")
|
|
||||||
{
|
|
||||||
$config_path = trim($this->__get("{$type}_path"), "/");
|
|
||||||
|
|
||||||
$path = ($config_path !== '') ? $config_path : "";
|
|
||||||
|
|
||||||
return implode("/", ['/', $this->host, $path]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a proper url from the path
|
* Generate a proper url from the path
|
||||||
*
|
*
|
||||||
@ -108,20 +92,20 @@ class UrlGenerator extends RoutingBase {
|
|||||||
* Full default path for the list pages
|
* Full default path for the list pages
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function default_url($type)
|
public function defaultUrl($type)
|
||||||
{
|
{
|
||||||
$type = trim($type);
|
$type = trim($type);
|
||||||
$default_path = $this->__get("default_{$type}_list_path");
|
$defaultPath = $this->__get("default_{$type}_list_path");
|
||||||
|
|
||||||
if ( ! is_null($default_path))
|
if ( ! is_null($defaultPath))
|
||||||
{
|
{
|
||||||
return $this->url("{$type}/{$default_path}");
|
return $this->url("{$type}/{$defaultPath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException("Invalid default type: '{$type}'");
|
throw new InvalidArgumentException("Invalid default type: '{$type}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,7 +115,7 @@ class UrlGenerator extends RoutingBase {
|
|||||||
* @param string $type - (optional) The controller (anime or manga), defaults to anime
|
* @param string $type - (optional) The controller (anime or manga), defaults to anime
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function full_url($path = "", $type = "anime")
|
public function fullUrl($path = "", $type = "anime")
|
||||||
{
|
{
|
||||||
$config_default_route = $this->__get("default_{$type}_path");
|
$config_default_route = $this->__get("default_{$type}_path");
|
||||||
|
|
||||||
|
@ -190,11 +190,11 @@ class DispatcherTest extends AnimeClient_TestCase {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$this->doSetUp($config, "/", "localhost");
|
$this->doSetUp($config, "/", "localhost");
|
||||||
$this->assertEquals('//localhost/manga/all', $this->urlGenerator->default_url('manga'), "Incorrect default url");
|
$this->assertEquals('//localhost/manga/all', $this->urlGenerator->defaultUrl('manga'), "Incorrect default url");
|
||||||
$this->assertEquals('//localhost/anime/watching', $this->urlGenerator->default_url('anime'), "Incorrect default url");
|
$this->assertEquals('//localhost/anime/watching', $this->urlGenerator->defaultUrl('anime'), "Incorrect default url");
|
||||||
|
|
||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$this->urlGenerator->default_url('foo');
|
$this->urlGenerator->defaultUrl('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataGetControllerList()
|
public function dataGetControllerList()
|
||||||
|
@ -32,8 +32,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
|
|||||||
{
|
{
|
||||||
$urlGenerator = new UrlGenerator($this->container);
|
$urlGenerator = new UrlGenerator($this->container);
|
||||||
|
|
||||||
$result = call_user_func_array([$urlGenerator, 'asset_url'], $args);
|
$result = $urlGenerator->assetUrl(...$args);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,51 +87,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
|
|||||||
$this->container->setInstance('config', $config);
|
$this->container->setInstance('config', $config);
|
||||||
$urlGenerator = new UrlGenerator($this->container);
|
$urlGenerator = new UrlGenerator($this->container);
|
||||||
|
|
||||||
$result = $urlGenerator->full_url($path, $type);
|
$result = $urlGenerator->fullUrl($path, $type);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataBaseUrl()
|
|
||||||
{
|
|
||||||
$config = [
|
|
||||||
'routes' => [
|
|
||||||
'routes' => [],
|
|
||||||
'route_config' => [
|
|
||||||
'anime_path' => 'anime',
|
|
||||||
'manga_path' => 'manga',
|
|
||||||
'default_list' => 'manga',
|
|
||||||
'default_anime_path' => '/watching',
|
|
||||||
'default_manga_path' => '/all',
|
|
||||||
'default_to_list_view' => TRUE,
|
|
||||||
],
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
return [
|
|
||||||
'path_based_routing_anime' => [
|
|
||||||
'config' => $config,
|
|
||||||
'type' => 'anime',
|
|
||||||
'expected' => '//localhost/anime'
|
|
||||||
],
|
|
||||||
'path_based_routing_manga' => [
|
|
||||||
'config' => $config,
|
|
||||||
'type' => 'manga',
|
|
||||||
'expected' => '//localhost/manga'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider dataBaseUrl
|
|
||||||
*/
|
|
||||||
public function testBaseUrl($config, $type, $expected)
|
|
||||||
{
|
|
||||||
$config = new Config($config);
|
|
||||||
$this->container->setInstance('config', $config);
|
|
||||||
$urlGenerator = new UrlGenerator($this->container);
|
|
||||||
|
|
||||||
$result = $urlGenerator->base_url($type);
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user