Namespace refactoring

This commit is contained in:
Timothy Warren 2015-09-14 19:54:34 -04:00
parent d93f5a82a0
commit 97a5abe665
46 changed files with 178 additions and 106 deletions

View File

@ -3,7 +3,7 @@
* Bootstrap / Dependency Injection
*/
namespace AnimeClient;
namespace Aviat\AnimeClient;
use \Whoops\Handler\PrettyPageHandler;
use \Whoops\Handler\JsonResponseHandler;

View File

@ -70,25 +70,6 @@ return [
'code' => '301'
]
],
'login_form' => [
'path' => '/anime/login',
'action' => ['login'],
'verb' => 'get'
],
'login_action' => [
'path' => '/anime/login',
'action' => ['login_action'],
'verb' => 'post'
],
'logout' => [
'path' => '/anime/logout',
'action' => ['logout']
],
'update' => [
'path' => '/anime/update',
'action' => ['update'],
'verb' => 'post'
],
'search' => [
'path' => '/anime/search',
'action' => ['search'],

View File

@ -54,7 +54,6 @@ function _setup_autoloaders()
require _dir(ROOT_DIR, '/vendor/autoload.php');
spl_autoload_register(function ($class) {
$class_parts = explode('\\', $class);
array_shift($class_parts);
$ns_path = SRC_DIR . '/' . implode('/', $class_parts) . ".php";
if (file_exists($ns_path))

View File

@ -3,7 +3,7 @@
* Base Configuration class
*/
namespace AnimeClient\Base;
namespace Aviat\AnimeClient\Base;
/**
* Wrapper for configuration values

View File

@ -0,0 +1,11 @@
<?php
namespace Aviat\AnimeClient\Base;
/**
* Dependency container
*/
class Container extends \Aviat\Ion\Base\Container {
}
// End of Container.php

View File

@ -2,7 +2,7 @@
/**
* Base Controller
*/
namespace AnimeClient\Base;
namespace Aviat\AnimeClient\Base;
/**
* Base class for controllers, defines output methods
@ -116,7 +116,7 @@ class Controller {
$defaultHandler->addDataTable('Template Data', $data);
$template_path = _dir(SRC_DIR, 'views', "{$template}.php");
$template_path = _dir(APP_DIR, 'views', "{$template}.php");
if ( ! is_file($template_path))
{
@ -125,9 +125,9 @@ class Controller {
ob_start();
extract($data);
include _dir(SRC_DIR, 'views', 'header.php');
include _dir(APP_DIR, 'views', 'header.php');
include $template_path;
include _dir(SRC_DIR, 'views', 'footer.php');
include _dir(APP_DIR, 'views', 'footer.php');
$buffer = ob_get_contents();
ob_end_clean();

View File

@ -2,7 +2,7 @@
/**
* Base for base models
*/
namespace AnimeClient\Base;
namespace Aviat\AnimeClient\Base;
use abeautifulsite\SimpleImage;

View File

@ -2,16 +2,16 @@
/**
* Base API Model
*/
namespace AnimeClient\Base\Model;
namespace Aviat\AnimeClient\Base\Model;
use \GuzzleHttp\Client;
use \GuzzleHttp\Cookie\CookieJar;
use \AnimeClient\Base\Container;
use \Aviat\AnimeClient\Base\Container;
/**
* Base model for api interaction
*/
class API extends \AnimeClient\Base\Model {
class API extends \Aviat\AnimeClient\Base\Model {
/**
* Base url for making api requests

View File

@ -2,14 +2,14 @@
/**
* Base DB model
*/
namespace AnimeClient\Base\Model;
namespace Aviat\AnimeClient\Base\Model;
use AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Container;
/**
* Base model for database interaction
*/
class DB extends \AnimeClient\Base\Model {
class DB extends \Aviat\AnimeClient\Base\Model {
/**
* The query builder object
* @var object $db

View File

@ -2,10 +2,10 @@
/**
* Routing logic
*/
namespace AnimeClient\Base;
namespace Aviat\AnimeClient\Base;
use \Aura\Web\Request;
use \Aura\Web\Response;
use Aura\Web\Request;
use Aura\Web\Response;
/**
* Basic routing/ dispatch
@ -39,10 +39,7 @@ class Router extends RoutingBase {
/**
* Constructor
*
* @param Config $config
* @param Router $router
* @param Request $request
* @param Response $response
* @param Container $container
*/
public function __construct(Container $container)
{
@ -179,7 +176,7 @@ class Router extends RoutingBase {
$path = $route['path'];
unset($route['path']);
$controller_class = '\\AnimeClient\\Controller\\' . ucfirst($route_type);
$controller_class = '\\Aviat\\AnimeClient\\Controller\\' . ucfirst($route_type);
// Prepend the controller to the route parameters
array_unshift($route['action'], $controller_class);

View File

@ -1,7 +1,13 @@
<?php
/**
* Base class for routing to make namespaced config settings
* easier to work with
*/
namespace Aviat\AnimeClient\Base;
namespace AnimeClient\Base;
/**
* Base for routing/url classes
*/
class RoutingBase {
/**
* Injection Container

View File

@ -1,6 +1,8 @@
<?php
namespace AnimeClient\Base;
/**
* Generate full urls from fragments
*/
namespace Aviat\AnimeClient\Base;
/**
* UrlGenerator class.

View File

@ -3,13 +3,13 @@
* Anime Controller
*/
namespace AnimeClient\Controller;
namespace Aviat\AnimeClient\Controller;
use AnimeClient\Base\Container;
use AnimeClient\Base\Controller as BaseController;
use AnimeClient\Base\Config;
use AnimeClient\Model\Anime as AnimeModel;
use AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Controller as BaseController;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
/**
* Controller for Anime-related pages

View File

@ -3,13 +3,13 @@
* Anime Collection Controller
*/
namespace AnimeClient\Controller;
namespace Aviat\AnimeClient\Controller;
use AnimeClient\Base\Container;
use AnimeClient\Base\Controller as BaseController;
use AnimeClient\Base\Config;
use AnimeClient\Model\Anime as AnimeModel;
use AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Controller as BaseController;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
/**
* Controller for Anime collection pages
@ -44,6 +44,8 @@ class Collection extends BaseController {
/**
* Constructor
*
* @param Container $container
*/
public function __construct(Container $container)
{
@ -78,6 +80,7 @@ class Collection extends BaseController {
/**
* Show the anime collection page
*
* @param string $view
* @return void
*/
public function index($view)

View File

@ -2,12 +2,12 @@
/**
* Manga Controller
*/
namespace AnimeClient\Controller;
namespace Aviat\AnimeClient\Controller;
use AnimeClient\Base\Container;
use AnimeClient\Base\Controller;
use AnimeClient\Base\Config;
use AnimeClient\Model\Manga as MangaModel;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Controller;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Model\Manga as MangaModel;
/**
* Controller for manga list
@ -42,6 +42,8 @@ class Manga extends Controller {
/**
* Constructor
*
* @param Container $container
*/
public function __construct(Container $container)
{

View File

@ -0,0 +1,11 @@
<?php
namespace Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Controller;
class Stats extends Controller {
}
// End of Stats.php

View File

@ -3,9 +3,9 @@
* Anime API Model
*/
namespace AnimeClient\Model;
namespace Aviat\AnimeClient\Model;
use AnimeClient\Base\Model\API;
use Aviat\AnimeClient\Base\Model\API;
/**
* Model for handling requests dealing with the anime list

View File

@ -3,11 +3,11 @@
* Anime Collection DB Model
*/
namespace AnimeClient\Model;
namespace Aviat\AnimeClient\Model;
use AnimeClient\Base\Model\DB;
use \AnimeClient\Base\Container;
use AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Base\Model\DB;
use \Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
/**
* Model for getting anime collection data

View File

@ -2,9 +2,9 @@
/**
* Manga API Model
*/
namespace AnimeClient\Model;
namespace Aviat\AnimeClient\Model;
use AnimeClient\Base\Model\API;
use Aviat\AnimeClient\Base\Model\API;
/**
* Model for handling requests dealing with the manga list

View File

@ -3,10 +3,10 @@
* Anime API Model
*/
namespace AnimeClient\Model;
namespace Aviat\AnimeClient\Model;
use AnimeClient\Base\Model\DB;
use AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Model\DB;
use Aviat\AnimeClient\Base\Container;
use StatsChartsTrait;

View File

@ -1,6 +1,6 @@
<?php
namespace AnimeClient\Model;
namespace Aviat\AnimeClient\Model;
use CpChart\Services\pChartFactory;

View File

@ -1,9 +1,9 @@
<?php
namespace AnimeClient\Base;
namespace Aviat\Ion\Base;
/**
* Wrapper of Aura container to be in the anime client namespace
* Dependency container
*/
class Container {

View File

@ -0,0 +1,72 @@
<?php
namespace Aviat\Ion\Base;
use Aura\Web\Request;
use Aura\Web\Response;
class Page {
/**
* @var Request
*/
protected $request;
/**
* @var Response
*/
protected $response;
/**
* __construct function.
*
* @param Request $request
* @param Response $response
*/
public function __construct(Request $request, Response $response)
{
$this->request = $request;
$this->response = $response;
}
/**
* __destruct function.
*/
public function __destruct()
{
$this->output();
}
/**
* Output the response to the client
*/
protected function output()
{
// send status
@header($this->response->status->get(), true, $this->response->status->getCode());
// headers
foreach($this->response->headers->get() as $label => $value)
{
@header("{$label}: {$value}");
}
// cookies
foreach($this->response->cookies->get() as $name => $cookie)
{
@setcookie(
$name,
$cookie['value'],
$cookie['expire'],
$cookie['path'],
$cookie['domain'],
$cookie['secure'],
$cookie['httponly']
);
}
// send the actual response
echo $this->response->content->get();
}
}
// End of Page.php

View File

@ -1,11 +0,0 @@
<?php
namespace AnimeClient\Controller;
use AnimeClient\Base\Container;
use AnimeClient\Base\Controller;
class Stats extends Controller {
}
// End of Stats.php

View File

@ -1,5 +1,5 @@
<?php
use \AnimeClient\Base\Controller;
use \Aviat\AnimeClient\Base\Controller;
use \Aura\Web\WebFactory;
use \Aura\Router\RouterFactory;

View File

@ -1,7 +1,7 @@
<?php
use AnimeClient\Base\Model as BaseModel;
use AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Model as BaseModel;
use Aviat\AnimeClient\Base\Container;
class BaseModelTest extends AnimeClient_TestCase {

View File

@ -1,6 +1,6 @@
<?php
use \AnimeClient\Base\Config;
use \Aviat\AnimeClient\Base\Config;
class ConfigTest extends AnimeClient_TestCase {

View File

@ -1,7 +1,7 @@
<?php
use AnimeClient\Base\Container;
use AnimeClient\Base\Model\API as BaseApiModel;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Model\API as BaseApiModel;
class MockBaseApiModel extends BaseApiModel {
@ -23,8 +23,8 @@ class BaseApiModelTest extends AnimeClient_TestCase {
$baseApiModel = new MockBaseApiModel($this->container);
// Some basic type checks for class memebers
$this->assertInstanceOf('\AnimeClient\Base\Model', $baseApiModel);
$this->assertInstanceOf('\AnimeClient\Base\Model\API', $baseApiModel);
$this->assertInstanceOf('\Aviat\AnimeClient\Base\Model', $baseApiModel);
$this->assertInstanceOf('\Aviat\AnimeClient\Base\Model\API', $baseApiModel);
$this->assertInstanceOf('\GuzzleHttp\Client', $baseApiModel->client);
$this->assertInstanceOf('\GuzzleHttp\Cookie\CookieJar', $baseApiModel->cookieJar);

View File

@ -1,6 +1,6 @@
<?php
use AnimeClient\Base\Model\DB as BaseDBModel;
use Aviat\AnimeClient\Base\Model\DB as BaseDBModel;
class BaseDBModelTest extends AnimeClient_TestCase {

View File

@ -1,9 +1,9 @@
<?php
use AnimeClient\Base\Router;
use AnimeClient\Base\Config;
use AnimeClient\Base\Container;
use AnimeClient\Base\UrlGenerator;
use Aviat\AnimeClient\Base\Router;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\UrlGenerator;
use Aura\Web\WebFactory;
use Aura\Router\RouterFactory;

View File

@ -1,8 +1,8 @@
<?php
use AnimeClient\Base\Config;
use AnimeClient\Base\Container;
use AnimeClient\Base\UrlGenerator;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\UrlGenerator;
class UrlGeneratorTest extends AnimeClient_TestCase {

View File

@ -3,8 +3,8 @@
* Global setup for unit tests
*/
use AnimeClient\Base\Config;
use AnimeClient\Base\Container;
use Aviat\AnimeClient\Base\Config;
use Aviat\AnimeClient\Base\Container;
// -----------------------------------------------------------------------------
// Mock the default error handler
@ -85,7 +85,6 @@ function _setup_autoloaders()
require _dir(ROOT_DIR, '/vendor/autoload.php');
spl_autoload_register(function ($class) {
$class_parts = explode('\\', $class);
array_shift($class_parts);
$ns_path = SRC_DIR . '/' . implode('/', $class_parts) . ".php";
if (file_exists($ns_path))