Add php namespaces
This commit is contained in:
parent
24fb6b9815
commit
4785b82208
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Base API Model
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
use \GuzzleHttp\Client;
|
||||
use \GuzzleHttp\Cookie\CookieJar;
|
||||
@ -63,7 +64,7 @@ class BaseApiModel extends BaseModel {
|
||||
{
|
||||
$result = $this->client->post('https://hummingbird.me/api/v1/users/authenticate', [
|
||||
'body' => [
|
||||
'username' => $this->config->hummingbird_username,
|
||||
'username' => $username,
|
||||
'password' => $password
|
||||
]
|
||||
]);
|
||||
|
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Base Controller
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
use Aura\Web\WebFactory;
|
||||
|
||||
@ -28,6 +29,18 @@ class BaseController {
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* The api model for the current controller
|
||||
* @var object
|
||||
*/
|
||||
protected $model;
|
||||
|
||||
/**
|
||||
* Common data to be sent to views
|
||||
* @var array
|
||||
*/
|
||||
protected $base_data = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -77,7 +90,6 @@ class BaseController {
|
||||
if ( ! is_file($template_path))
|
||||
{
|
||||
throw new Exception("Invalid template : {$path}");
|
||||
die();
|
||||
}
|
||||
|
||||
ob_start();
|
||||
@ -198,10 +210,14 @@ class BaseController {
|
||||
*/
|
||||
public function login_action()
|
||||
{
|
||||
if ($this->model->authenticate($this->config->hummingbird_username, $this->request->post->get('password')))
|
||||
if (
|
||||
$this->model->authenticate(
|
||||
$this->config->hummingbird_username,
|
||||
$this->request->post->get('password')
|
||||
)
|
||||
)
|
||||
{
|
||||
$this->response->redirect->afterPost(full_url('', $this->base_data['url_type']));
|
||||
$this->output();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -227,7 +243,15 @@ class BaseController {
|
||||
// cookies
|
||||
foreach($this->response->cookies->get() as $name => $cookie)
|
||||
{
|
||||
@setcookie($name, $cookie['value'], $cookie['expire'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly']);
|
||||
@setcookie(
|
||||
$name,
|
||||
$cookie['value'],
|
||||
$cookie['expire'],
|
||||
$cookie['path'],
|
||||
$cookie['domain'],
|
||||
$cookie['secure'],
|
||||
$cookie['httponly']
|
||||
);
|
||||
}
|
||||
|
||||
// send the actual response
|
||||
|
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Base DB model
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Base model for database interaction
|
||||
|
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Base for base models
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
use abeautifulsite\SimpleImage;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Wrapper for configuration values
|
||||
*/
|
||||
@ -22,22 +24,16 @@ class Config {
|
||||
// @codeCoverageIgnoreStart
|
||||
if (empty($config_files))
|
||||
{
|
||||
/* $config = */require_once _dir(CONF_DIR, 'config.php');
|
||||
/* $base_config = */require_once _dir(CONF_DIR, 'base_config.php');
|
||||
require_once _dir(CONF_DIR, 'config.php'); // $config
|
||||
require_once _dir(CONF_DIR, 'base_config.php'); // $base_config
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
else
|
||||
else // @codeCoverageIgnoreEnd
|
||||
{
|
||||
$config = $config_files['config'];
|
||||
$base_config = $config_files['base_config'];
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
|
||||
foreach($base_config as $key => $val)
|
||||
{
|
||||
$this->config[$key] = $val;
|
||||
}
|
||||
$this->config = array_merge($config, $base_config);
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Routing logic
|
||||
*/
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
use Aura\Router\RouterFactory;
|
||||
|
||||
/**
|
||||
@ -120,8 +122,8 @@ class Router {
|
||||
private function _setup_routes()
|
||||
{
|
||||
$route_map = [
|
||||
'anime' => 'AnimeController',
|
||||
'manga' => 'MangaController',
|
||||
'anime' => '\\AnimeClient\\AnimeController',
|
||||
'manga' => '\\AnimeClient\\MangaController',
|
||||
];
|
||||
$route_type = "anime";
|
||||
|
||||
|
@ -25,6 +25,9 @@ function _setup_autoloaders()
|
||||
{
|
||||
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
||||
spl_autoload_register(function ($class) {
|
||||
$class_parts = explode('\\', $class);
|
||||
$class = end($class_parts);
|
||||
|
||||
$dirs = ["base", "controllers", "models"];
|
||||
|
||||
foreach($dirs as $dir)
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Anime Controller
|
||||
*/
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Controller for Anime-related pages
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Manga Controller
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Controller for manga list
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Anime Collection DB Model
|
||||
*/
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Model for getting anime collection data
|
||||
*/
|
||||
@ -27,7 +29,7 @@ class AnimeCollectionModel extends BaseDBModel {
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->db = Query($this->db_config['collection']);
|
||||
$this->db = \Query($this->db_config['collection']);
|
||||
$this->anime_model = new AnimeModel();
|
||||
|
||||
// Is database valid? If not, set a flag so the
|
||||
@ -82,7 +84,7 @@ class AnimeCollectionModel extends BaseDBModel {
|
||||
->order_by('title')
|
||||
->get();
|
||||
|
||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $query->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Anime API Model
|
||||
*/
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Model for handling requests dealing with the anime list
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
/**
|
||||
* Manga API Model
|
||||
*/
|
||||
namespace AnimeClient;
|
||||
|
||||
/**
|
||||
* Model for handling requests dealing with the manga list
|
||||
@ -9,17 +10,11 @@
|
||||
class MangaModel extends BaseApiModel {
|
||||
|
||||
/**
|
||||
* @var string $base_url - The base url for api requests
|
||||
* The base url for api requests
|
||||
* @var string
|
||||
*/
|
||||
protected $base_url = "https://hummingbird.me/";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the selected manga
|
||||
@ -112,9 +107,9 @@ class MangaModel extends BaseApiModel {
|
||||
$raw_data = $response->json();
|
||||
|
||||
// Attempt to create the cache dir if it doesn't exist
|
||||
if ( ! is_dir($config->data_cache_path))
|
||||
if ( ! is_dir($this->config->data_cache_path))
|
||||
{
|
||||
mkdir($config->data_cache_path);
|
||||
mkdir($this->config->data_cache_path);
|
||||
}
|
||||
|
||||
// Cache data in case of downtime
|
||||
|
@ -5,10 +5,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Alternate Title</th>
|
||||
<th>Rating</th>
|
||||
<th>Chapters</th>
|
||||
<!-- <th>Volumes</th> -->
|
||||
<th>Volumes</th>
|
||||
<th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -19,11 +18,11 @@
|
||||
<a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>">
|
||||
<?= $item['manga']['romaji_title'] ?>
|
||||
</a>
|
||||
<?= (array_key_exists('english_title', $item['manga'])) ? " · " . $item['manga']['english_title'] : "" ?>
|
||||
</td>
|
||||
<td class="align_left"><?= (array_key_exists('english_title', $item['manga'])) ? $item['manga']['english_title'] : "" ?></td>
|
||||
<td><?= ($item['rating'] > 0) ? (int)($item['rating'] * 2) : '-' ?> / 10</td>
|
||||
<td><?= $item['chapters_read'] ?> / <?= ($item['manga']['chapter_count'] > 0) ? $item['manga']['chapter_count'] : "-" ?></td>
|
||||
<!-- <td><?= $item['volumes_read'] ?> / <?= ($item['manga']['volume_count'] > 0) ? $item['manga']['volume_count'] : "-" ?></td> -->
|
||||
<td><?= $item['volumes_read'] ?> / <?= ($item['manga']['volume_count'] > 0) ? $item['manga']['volume_count'] : "-" ?></td>
|
||||
<td><?= $item['manga']['manga_type'] ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Here begins everything!
|
||||
*/
|
||||
|
||||
namespace AnimeClient;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! Start config
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -36,7 +38,7 @@ _setup_autoloaders();
|
||||
$config = new Config();
|
||||
require _dir(BASE_DIR, '/functions.php');
|
||||
|
||||
session_start();
|
||||
\session_start();
|
||||
|
||||
use \Whoops\Handler\PrettyPageHandler;
|
||||
use \Whoops\Handler\JsonResponseHandler;
|
||||
|
@ -35,6 +35,10 @@ tbody > tr:nth-child(odd) {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.flex-justify-space-around {
|
||||
jusify-content: space-around;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
|
@ -23,6 +23,7 @@ tbody > tr:nth-child(odd) {
|
||||
.flex-wrap {flex-wrap: wrap}
|
||||
.flex-no-wrap {flex-wrap: nowrap}
|
||||
.flex-align-end {align-items: flex-end}
|
||||
.flex-justify-space-around {jusify-content: space-around}
|
||||
.flex {display: flex}
|
||||
|
||||
.small-font {
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \AnimeClient\BaseApiModel;
|
||||
|
||||
class MockBaseApiModel extends BaseApiModel {
|
||||
|
||||
public function __construct()
|
||||
@ -20,8 +22,8 @@ class BaseApiModelTest extends AnimeClient_TestCase {
|
||||
$baseApiModel = new MockBaseApiModel();
|
||||
|
||||
// Some basic type checks for class memebers
|
||||
$this->assertInstanceOf('BaseModel', $baseApiModel);
|
||||
$this->assertInstanceOf('BaseApiModel', $baseApiModel);
|
||||
$this->assertInstanceOf('\AnimeClient\BaseModel', $baseApiModel);
|
||||
$this->assertInstanceOf('\AnimeClient\BaseApiModel', $baseApiModel);
|
||||
|
||||
$this->assertInstanceOf('\GuzzleHttp\Client', $baseApiModel->client);
|
||||
$this->assertInstanceOf('\GuzzleHttp\Cookie\CookieJar', $baseApiModel->cookieJar);
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \AnimeClient\BaseDBModel;
|
||||
|
||||
class BaseDBModelTest extends AnimeClient_TestCase {
|
||||
|
||||
public function testBaseDBModelSanity()
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \AnimeClient\BaseModel;
|
||||
|
||||
class BaseModelTest extends AnimeClient_TestCase {
|
||||
|
||||
public function testBaseModelSanity()
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \AnimeClient\Config;
|
||||
|
||||
class ConfigTest extends AnimeClient_TestCase {
|
||||
|
||||
public function setUp()
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use \AnimeClient\Config;
|
||||
|
||||
class FunctionsTest extends AnimeClient_TestCase {
|
||||
|
||||
public function setUp()
|
||||
|
@ -3,6 +3,8 @@
|
||||
* Global setup for unit tests
|
||||
*/
|
||||
|
||||
use \AnimeClient\Config;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Mock the default error handler
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user