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 * Bootstrap / Dependency Injection
*/ */
namespace AnimeClient; namespace Aviat\AnimeClient;
use \Whoops\Handler\PrettyPageHandler; use \Whoops\Handler\PrettyPageHandler;
use \Whoops\Handler\JsonResponseHandler; use \Whoops\Handler\JsonResponseHandler;

View File

@ -70,25 +70,6 @@ return [
'code' => '301' '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' => [ 'search' => [
'path' => '/anime/search', 'path' => '/anime/search',
'action' => ['search'], 'action' => ['search'],

View File

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

View File

@ -3,7 +3,7 @@
* Base Configuration class * Base Configuration class
*/ */
namespace AnimeClient\Base; namespace Aviat\AnimeClient\Base;
/** /**
* Wrapper for configuration values * 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 * Base Controller
*/ */
namespace AnimeClient\Base; namespace Aviat\AnimeClient\Base;
/** /**
* Base class for controllers, defines output methods * Base class for controllers, defines output methods
@ -116,7 +116,7 @@ class Controller {
$defaultHandler->addDataTable('Template Data', $data); $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)) if ( ! is_file($template_path))
{ {
@ -125,9 +125,9 @@ class Controller {
ob_start(); ob_start();
extract($data); extract($data);
include _dir(SRC_DIR, 'views', 'header.php'); include _dir(APP_DIR, 'views', 'header.php');
include $template_path; include $template_path;
include _dir(SRC_DIR, 'views', 'footer.php'); include _dir(APP_DIR, 'views', 'footer.php');
$buffer = ob_get_contents(); $buffer = ob_get_contents();
ob_end_clean(); ob_end_clean();

View File

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

View File

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

View File

@ -2,14 +2,14 @@
/** /**
* Base DB model * 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 * Base model for database interaction
*/ */
class DB extends \AnimeClient\Base\Model { class DB extends \Aviat\AnimeClient\Base\Model {
/** /**
* The query builder object * The query builder object
* @var object $db * @var object $db

View File

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

View File

@ -1,7 +1,13 @@
<?php <?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 { class RoutingBase {
/** /**
* Injection Container * Injection Container

View File

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

View File

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

View File

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

View File

@ -2,12 +2,12 @@
/** /**
* Manga Controller * Manga Controller
*/ */
namespace AnimeClient\Controller; namespace Aviat\AnimeClient\Controller;
use AnimeClient\Base\Container; use Aviat\AnimeClient\Base\Container;
use AnimeClient\Base\Controller; use Aviat\AnimeClient\Base\Controller;
use AnimeClient\Base\Config; use Aviat\AnimeClient\Base\Config;
use AnimeClient\Model\Manga as MangaModel; use Aviat\AnimeClient\Model\Manga as MangaModel;
/** /**
* Controller for manga list * Controller for manga list
@ -42,6 +42,8 @@ class Manga extends Controller {
/** /**
* Constructor * Constructor
*
* @param Container $container
*/ */
public function __construct(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 * 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 * Model for handling requests dealing with the anime list

View File

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

View File

@ -2,9 +2,9 @@
/** /**
* Manga API Model * 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 * Model for handling requests dealing with the manga list

View File

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

View File

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

View File

@ -1,9 +1,9 @@
<?php <?php
namespace AnimeClient\Base; namespace Aviat\Ion\Base;
/** /**
* Wrapper of Aura container to be in the anime client namespace * Dependency container
*/ */
class 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 <?php
use \AnimeClient\Base\Controller; use \Aviat\AnimeClient\Base\Controller;
use \Aura\Web\WebFactory; use \Aura\Web\WebFactory;
use \Aura\Router\RouterFactory; use \Aura\Router\RouterFactory;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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