Code style improvements

This commit is contained in:
Timothy Warren 2015-10-06 11:38:20 -04:00
parent aedabd6eda
commit d53524ed86
17 changed files with 81 additions and 36 deletions

View File

@ -20,7 +20,7 @@
</thead> </thead>
<tbody> <tbody>
<?php foreach($items as $item): ?> <?php foreach($items as $item): ?>
<tr id="a-<?= $item['anime']['id'] ?>"> <tr id="a-<?= $item['id'] ?>">
<td class="align_left"> <td class="align_left">
<a href="<?= $item['anime']['url'] ?>"> <a href="<?= $item['anime']['url'] ?>">
<?= $item['anime']['title'] ?> <?= $item['anime']['title'] ?>

View File

@ -13,7 +13,7 @@
<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">
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>"> <a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
<?= $config->whose_list ?>'s <?= ucfirst($url_type) ?> <?= (strpos($route_path, 'collection') !== FALSE) ? 'Collection' : 'List' ?> <?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> <?= (strpos($route_path, 'collection') !== FALSE) ? 'Collection' : 'List' ?>
</a> [<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>] </a> [<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
</span> </span>
<span class="flex-no-wrap small-font"> <span class="flex-no-wrap small-font">

View File

@ -16,9 +16,9 @@
</thead> </thead>
<tbody> <tbody>
<?php foreach($items as $item): ?> <?php foreach($items as $item): ?>
<tr id="manga-<?= $item['manga']['id'] ?>"> <tr id="manga-<?= $item['id'] ?>">
<td class="align_left"> <td class="align_left">
<a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>"> <a href="<?= $item['manga']['url'] ?>">
<?= $item['manga']['title'] ?> <?= $item['manga']['title'] ?>
</a> </a>
<?= ( ! is_null($item['manga']['alternate_title'])) ? " &middot; " . $item['manga']['alternate_title'] : "" ?> <?= ( ! is_null($item['manga']['alternate_title'])) ? " &middot; " . $item['manga']['alternate_title'] : "" ?>

View File

@ -7,6 +7,9 @@ namespace Aviat\AnimeClient;
/** /**
* Wrapper for configuration values * Wrapper for configuration values
*
* @property Database Config $database
* @property Menu Config $menus
*/ */
class Config { class Config {
@ -39,12 +42,12 @@ class Config {
} }
/** /**
* Getter for config values * Get a config value
* *
* @param string $key * @param string $key
* @return mixed * @return mixed
*/ */
public function __get($key) public function get($key)
{ {
if (isset($this->config[$key])) if (isset($this->config[$key]))
{ {
@ -53,5 +56,18 @@ class Config {
return NULL; return NULL;
} }
/**
* Set a config value
*
* @param string $key
* @param mixed $value
* @return Config
*/
public function set($key, $value)
{
$this->config[$key] = $value;
return $this;
}
} }
// End of config.php // End of config.php

View File

@ -25,6 +25,12 @@ class Controller {
*/ */
protected $config; protected $config;
/**
* Request object
* @var object $request
*/
protected $request;
/** /**
* Response object * Response object
* @var object $response * @var object $response
@ -90,7 +96,7 @@ class Controller {
/** /**
* Get the string output of a partial template * Get the string output of a partial template
* *
* @param HTMLView $view * @param HtmlView $view
* @param string $template * @param string $template
* @param array|object $data * @param array|object $data
* @return string * @return string
@ -110,7 +116,7 @@ class Controller {
$data['route_path'] = ($route) ? $router->get_route()->path : ""; $data['route_path'] = ($route) ? $router->get_route()->path : "";
$template_path = _dir($this->config->__get('view_path'), "{$template}.php"); $template_path = _dir($this->config->get('view_path'), "{$template}.php");
if ( ! is_file($template_path)) if ( ! is_file($template_path))
{ {
@ -198,7 +204,6 @@ class Controller {
*/ */
public function logout() public function logout()
{ {
session_destroy();
$this->response->redirect->seeOther($this->urlGenerator->full_url('')); $this->response->redirect->seeOther($this->urlGenerator->full_url(''));
} }

View File

@ -57,7 +57,7 @@ class Anime extends BaseController {
{ {
parent::__construct($container); parent::__construct($container);
if ($this->config->show_anime_collection === FALSE) if ($this->config->get('show_anime_collection') === FALSE)
{ {
unset($this->nav_routes['Collection']); unset($this->nav_routes['Collection']);
} }
@ -73,6 +73,13 @@ class Anime extends BaseController {
]); ]);
} }
/**
* Show a portion, or all of the anime list
*
* @param string $type - The section of the list
* @param string $view - List or cover view
* @return void
*/
public function index($type = "watching", $view = '') public function index($type = "watching", $view = '')
{ {
return $this->anime_list($type, $view); return $this->anime_list($type, $view);
@ -116,7 +123,7 @@ class Anime extends BaseController {
'completed' => AnimeWatchingStatus::COMPLETED 'completed' => AnimeWatchingStatus::COMPLETED
]; ];
$title = $this->config->whose_list . "'s Anime List &middot; {$type_title_map[$type]}"; $title = $this->config->get('whose_list') . "'s Anime List &middot; {$type_title_map[$type]}";
$view_map = [ $view_map = [
'' => 'cover', '' => 'cover',

View File

@ -58,7 +58,7 @@ class Collection extends BaseController {
{ {
parent::__construct($container); parent::__construct($container);
if ($this->config->show_anime_collection === FALSE) if ($this->config->get('show_anime_collection') === FALSE)
{ {
unset($this->nav_routes['Collection']); unset($this->nav_routes['Collection']);
} }
@ -101,7 +101,7 @@ class Collection extends BaseController {
$data = $this->collection_model->get_collection(); $data = $this->collection_model->get_collection();
$this->outputHTML('collection/' . $view_map[$view], [ $this->outputHTML('collection/' . $view_map[$view], [
'title' => $this->config->whose_list . "'s Anime Collection", 'title' => $this->config->get('whose_list') . "'s Anime Collection",
'sections' => $data, 'sections' => $data,
'genres' => $this->collection_model->get_genre_list() 'genres' => $this->collection_model->get_genre_list()
]); ]);

View File

@ -58,6 +58,13 @@ class Manga extends Controller {
]); ]);
} }
/**
* Get a section of the manga list
*
* @param string $status
* @param string $view
* @return void
*/
public function index($status = "all", $view = "") public function index($status = "all", $view = "")
{ {
return $this->manga_list($status, $view); return $this->manga_list($status, $view);
@ -91,7 +98,7 @@ class Manga extends Controller {
'on_hold' => MangaModel::ON_HOLD 'on_hold' => MangaModel::ON_HOLD
]; ];
$title = $this->config->whose_list . "'s Manga List &middot; {$map[$status]}"; $title = $this->config->get('whose_list') . "'s Manga List &middot; {$map[$status]}";
$view_map = [ $view_map = [
'' => 'cover', '' => 'cover',

View File

@ -22,7 +22,7 @@ class Model {
/** /**
* The container object * The container object
* @var Container * @var ContainerInterface
*/ */
protected $container; protected $container;
@ -61,8 +61,9 @@ class Model {
// Failsafe for weird urls // Failsafe for weird urls
if (strlen($ext) > 3) return $api_path; if (strlen($ext) > 3) return $api_path;
$img_cache_path = $this->config->get('img_cache_path');
$cached_image = "{$series_slug}.{$ext}"; $cached_image = "{$series_slug}.{$ext}";
$cached_path = "{$this->config->img_cache_path}/{$type}/{$cached_image}"; $cached_path = "{$img_cache_path}/{$type}/{$cached_image}";
// Cache the file if it doesn't already exist // Cache the file if it doesn't already exist
if ( ! file_exists($cached_path)) if ( ! file_exists($cached_path))

View File

@ -47,7 +47,8 @@ class Anime extends API {
*/ */
public function update($data) public function update($data)
{ {
$data['auth_token'] = $_SESSION['hummingbird_anime_token']; // @TODO use Hummingbird Auth class
$data['auth_token'] = '';
$result = $this->client->post("libraries/{$data['id']}", [ $result = $this->client->post("libraries/{$data['id']}", [
'body' => $data 'body' => $data
@ -168,7 +169,8 @@ class Anime extends API {
$config['query']['status'] = $status; $config['query']['status'] = $status;
} }
$response = $this->client->get("users/{$this->config->hummingbird_username}/library", $config); $username = $this->config->get('hummingbird_username');
$response = $this->client->get("users/{$username}/library", $config);
$output = $this->_check_cache($status, $response); $output = $this->_check_cache($status, $response);
foreach ($output as &$row) foreach ($output as &$row)
@ -189,8 +191,8 @@ class Anime extends API {
*/ */
protected function _check_cache($status, $response) protected function _check_cache($status, $response)
{ {
$cache_file = _dir($this->config->data_cache_path, "anime-{$status}.json"); $cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}.json");
$transformed_cache_file = _dir($this->config->data_cache_path, "anime-{$status}-transformed.json"); $transformed_cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}-transformed.json");
$cached = json_decode(file_get_contents($cache_file), TRUE); $cached = json_decode(file_get_contents($cache_file), TRUE);
$api_data = json_decode($response->getBody(), TRUE); $api_data = json_decode($response->getBody(), TRUE);

View File

@ -31,7 +31,7 @@ class DB extends BaseModel {
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
parent::__construct($container); parent::__construct($container);
$this->db_config = $this->config->database; $this->db_config = $this->config->get('database');
} }
} }
// End of BaseDBModel.php // End of BaseDBModel.php

View File

@ -48,8 +48,9 @@ class Manga extends API {
$id = $data['id']; $id = $data['id'];
unset($data['id']); unset($data['id']);
// @TODO update with auth key from auth class
$result = $this->client->put("manga_library_entries/{$id}", [ $result = $this->client->put("manga_library_entries/{$id}", [
'cookies' => ['token' => $_SESSION['hummingbird_anime_token']], 'cookies' => ['token' => ''],
'json' => ['manga_library_entry' => $data] 'json' => ['manga_library_entry' => $data]
]); ]);
@ -92,7 +93,7 @@ class Manga extends API {
$config = [ $config = [
'query' => [ 'query' => [
'user_id' => $this->config->hummingbird_username 'user_id' => $this->config->get('hummingbird_username')
], ],
'allow_redirects' => FALSE 'allow_redirects' => FALSE
]; ];
@ -117,8 +118,8 @@ class Manga extends API {
$api_data = json_decode($response->getBody(), TRUE); $api_data = json_decode($response->getBody(), TRUE);
if ( ! array_key_exists('manga', $api_data)) return []; if ( ! array_key_exists('manga', $api_data)) return [];
$cache_file = _dir($this->config->data_cache_path, 'manga.json'); $cache_file = _dir($this->config->get('data_cache_path'), 'manga.json');
$transformed_cache_file = _dir($this->config->data_cache_path, 'manga-transformed.json'); $transformed_cache_file = _dir($this->config->get('data_cache_path'), 'manga-transformed.json');
$cached_data = json_decode(file_get_contents($cache_file), TRUE); $cached_data = json_decode(file_get_contents($cache_file), TRUE);

View File

@ -168,10 +168,7 @@ class Router extends RoutingBase {
*/ */
public function get_controller() public function get_controller()
{ {
$error_handler = $this->container->get('error-handler');
$route_type = $this->__get('default_list'); $route_type = $this->__get('default_list');
$host = $this->request->server->get("HTTP_HOST");
$request_uri = $this->request->server->get('PATH_INFO'); $request_uri = $this->request->server->get('PATH_INFO');
$path = trim($request_uri, '/'); $path = trim($request_uri, '/');

View File

@ -38,7 +38,7 @@ class RoutingBase {
{ {
$this->container = $container; $this->container = $container;
$this->config = $container->get('config'); $this->config = $container->get('config');
$this->routes = $this->config->__get('routes'); $this->routes = $this->config->get('routes');
} }
/** /**
@ -49,7 +49,7 @@ class RoutingBase {
*/ */
public function __get($key) public function __get($key)
{ {
$routing_config = $this->config->routing; $routing_config = $this->config->get('routing');
if (array_key_exists($key, $routing_config)) if (array_key_exists($key, $routing_config))
{ {

View File

@ -13,7 +13,16 @@ use BadMethodCallException;
*/ */
class Friend { class Friend {
/**
* Object to create a friend of
* @var object
*/
private $_friend_object_; private $_friend_object_;
/**
* Reflection class of the object
* @var object
*/
private $_reflection_friend_; private $_reflection_friend_;
/** /**

View File

@ -13,15 +13,15 @@ class ConfigTest extends AnimeClient_TestCase {
]); ]);
} }
public function testConfig__get() public function testConfigGet()
{ {
$this->assertEquals($this->config->foo, $this->config->__get('foo')); $this->assertEquals('bar', $this->config->get('foo'));
$this->assertEquals($this->config->bar, $this->config->__get('bar')); $this->assertEquals('baz', $this->config->get('bar'));
$this->assertEquals(NULL, $this->config->baz); $this->assertNull($this->config->get('baz'));
} }
public function testGetNonExistentConfigItem() public function testGetNonExistentConfigItem()
{ {
$this->assertEquals(NULL, $this->config->foobar); $this->assertNull($this->config->get('foobar'));
} }
} }

View File

@ -147,7 +147,7 @@ class RouterTest extends AnimeClient_TestCase {
// Check route setup // Check route setup
$this->assertEquals($config['routes'], $this->config->routes, "Incorrect route path"); $this->assertEquals($config['routes'], $this->config->get('routes'), "Incorrect route path");
$this->assertTrue(is_array($this->router->get_output_routes())); $this->assertTrue(is_array($this->router->get_output_routes()));
// Check environment variables // Check environment variables