More snake case to camel case

This commit is contained in:
Timothy Warren 2017-02-15 15:56:10 -05:00
parent 29c04e62be
commit 8cbfaf3646
19 changed files with 48 additions and 107 deletions

View File

@ -53,7 +53,7 @@ return [
// ---------------------------------------------------------------------
'anime.add.get' => [
'path' => '/anime/add',
'action' => 'add_form',
'action' => 'addForm',
'verb' => 'get',
],
'anime.add.post' => [
@ -82,7 +82,7 @@ return [
],
'manga.add.get' => [
'path' => '/manga/add',
'action' => 'add_form',
'action' => 'addForm',
'verb' => 'get',
],
'manga.add.post' => [
@ -183,7 +183,7 @@ return [
],
'update.post' => [
'path' => '/{controller}/update_form',
'action' => 'form_update',
'action' => 'formUpdate',
'verb' => 'post',
'tokens' => [
'controller' => '[a-z_]+',

View File

@ -36,5 +36,5 @@
</table>
</form>
</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 ?>

View File

@ -86,5 +86,5 @@
<?php endif ?>
</main>
<?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 ?>

View File

@ -107,5 +107,5 @@
</form>
</fieldset>
</main>
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/edit') ?>"></script>
<?php endif ?>

View File

@ -87,4 +87,4 @@
<?php endif ?>
</main>
<?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>

View File

@ -39,5 +39,5 @@
</table>
</form>
</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 ?>

View File

@ -62,5 +62,5 @@
</form>
</fieldset>
</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 ?>

View File

@ -1,6 +1,6 @@
<main>
<?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 if (empty($sections)): ?>
<h3>There's nothing here!</h3>
@ -26,8 +26,8 @@
<tr>
<?php if($auth->is_authenticated()): ?>
<td>
<a class="bracketed" href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a>
<?php /*<a class="bracketed" href="<?= $urlGenerator->full_url("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a>*/ ?>
<a class="bracketed" href="<?= $urlGenerator->fullUrl("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a>
<?php /*<a class="bracketed" href="<?= $urlGenerator->fullUrl("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a>*/ ?>
</td>
<?php endif ?>
<td class="align_left">
@ -49,4 +49,4 @@
<?php endforeach ?>
<?php endif ?>
</main>
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/table') ?>"></script>

View File

@ -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>
</html>

View File

@ -7,8 +7,8 @@
<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" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php/g/base') ?>" />
<script src="<?= $urlGenerator->asset_url('js.php/g/base') ?>"></script>
<link rel="stylesheet" href="<?= $urlGenerator->assetUrl('css.php/g/base') ?>" />
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/base') ?>"></script>
</head>
<body class="<?= $escape->attr($url_type) ?> list">
<header>

View File

@ -2,19 +2,19 @@
<h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1">
<?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
</a>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
<?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: ?>
<a href="<?= $urlGenerator->url('collection/view') ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
</a>
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
[<a href="<?= $urlGenerator->defaultUrl('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->defaultUrl('manga') ?>">Manga List</a>]
<?php endif ?>
</span>
<?php if ($auth->is_authenticated()): ?>

View File

@ -36,5 +36,5 @@
</table>
</form>
</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 ?>

View File

@ -56,5 +56,5 @@
<?php endif ?>
</main>
<?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 ?>

View File

@ -1,7 +1,7 @@
<main>
<?php /*if ($auth->is_authenticated()): ?>
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url('manga/add') ?>">Add Item</a>
<?php endif*/ ?>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
<?php else: ?>
@ -47,4 +47,4 @@
<?php endforeach ?>
<?php endif ?>
</main>
<script src="<?= $urlGenerator->asset_url('js.php/g/table') ?>"></script>
<script defer="defer" src="<?= $urlGenerator->assetUrl('js.php/g/table') ?>"></script>

View File

@ -125,7 +125,7 @@ class Controller {
public function redirectToDefaultRoute()
{
$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);
}
/**

View File

@ -17,8 +17,10 @@
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
use Aviat\AnimeClient\Model\{
Anime as AnimeModel,
AnimeCollection as AnimeCollectionModel
};
use Aviat\AnimeClient\UrlGenerator;
use Aviat\Ion\Di\ContainerInterface;
@ -119,7 +121,7 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . strtolower($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 &middot; {$action}",
'media_items' => $this->animeCollectionModel->get_media_type_list(),
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []

View File

@ -17,6 +17,7 @@
namespace Aviat\AnimeClient;
use Aviat\Ion\Di\ContainerInterface;
use InvalidArgumentException;
/**
* UrlGenerator class.
@ -45,33 +46,16 @@ class UrlGenerator extends RoutingBase {
*
* @return string
*/
public function asset_url()
public function assetUrl(...$args)
{
$args = func_get_args();
$base_url = rtrim($this->url(""), '/');
$baseUrl = rtrim($this->url(""), '/');
$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
$base_url = "{$base_url}" . $this->__get("asset_path");
array_unshift($args, $base_url);
array_unshift($args, $baseUrl);
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
*
@ -108,20 +92,20 @@ class UrlGenerator extends RoutingBase {
* Full default path for the list pages
*
* @param string $type
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
* @return string
*/
public function default_url($type)
public function defaultUrl($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
* @return string
*/
public function full_url($path = "", $type = "anime")
public function fullUrl($path = "", $type = "anime")
{
$config_default_route = $this->__get("default_{$type}_path");

View File

@ -190,11 +190,11 @@ class DispatcherTest extends AnimeClient_TestCase {
];
$this->doSetUp($config, "/", "localhost");
$this->assertEquals('//localhost/manga/all', $this->urlGenerator->default_url('manga'), "Incorrect default url");
$this->assertEquals('//localhost/anime/watching', $this->urlGenerator->default_url('anime'), "Incorrect default url");
$this->assertEquals('//localhost/manga/all', $this->urlGenerator->defaultUrl('manga'), "Incorrect default url");
$this->assertEquals('//localhost/anime/watching', $this->urlGenerator->defaultUrl('anime'), "Incorrect default url");
$this->expectException(\InvalidArgumentException::class);
$this->urlGenerator->default_url('foo');
$this->urlGenerator->defaultUrl('foo');
}
public function dataGetControllerList()

View File

@ -32,8 +32,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
{
$urlGenerator = new UrlGenerator($this->container);
$result = call_user_func_array([$urlGenerator, 'asset_url'], $args);
$result = $urlGenerator->assetUrl(...$args);
$this->assertEquals($expected, $result);
}
@ -88,51 +87,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
$this->container->setInstance('config', $config);
$urlGenerator = new UrlGenerator($this->container);
$result = $urlGenerator->full_url($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);
$result = $urlGenerator->fullUrl($path, $type);
$this->assertEquals($expected, $result);
}