diff --git a/app/bootstrap.php b/app/bootstrap.php index 82f615bc..38ea40fe 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -3,7 +3,7 @@ * Bootstrap / Dependency Injection */ -namespace AnimeClient; +namespace Aviat\AnimeClient; use \Whoops\Handler\PrettyPageHandler; use \Whoops\Handler\JsonResponseHandler; diff --git a/app/config/routes.php b/app/config/routes.php index 1060ddf2..92e46c47 100644 --- a/app/config/routes.php +++ b/app/config/routes.php @@ -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'], diff --git a/src/views/404.php b/app/views/404.php similarity index 100% rename from src/views/404.php rename to app/views/404.php diff --git a/src/views/anime/cover.php b/app/views/anime/cover.php similarity index 100% rename from src/views/anime/cover.php rename to app/views/anime/cover.php diff --git a/src/views/anime/edit.php b/app/views/anime/edit.php similarity index 100% rename from src/views/anime/edit.php rename to app/views/anime/edit.php diff --git a/src/views/anime/list.php b/app/views/anime/list.php similarity index 100% rename from src/views/anime/list.php rename to app/views/anime/list.php diff --git a/src/views/collection/add.php b/app/views/collection/add.php similarity index 100% rename from src/views/collection/add.php rename to app/views/collection/add.php diff --git a/src/views/collection/cover.php b/app/views/collection/cover.php similarity index 100% rename from src/views/collection/cover.php rename to app/views/collection/cover.php diff --git a/src/views/collection/edit.php b/app/views/collection/edit.php similarity index 100% rename from src/views/collection/edit.php rename to app/views/collection/edit.php diff --git a/src/views/collection/list.php b/app/views/collection/list.php similarity index 100% rename from src/views/collection/list.php rename to app/views/collection/list.php diff --git a/src/views/footer.php b/app/views/footer.php similarity index 100% rename from src/views/footer.php rename to app/views/footer.php diff --git a/src/views/header.php b/app/views/header.php similarity index 100% rename from src/views/header.php rename to app/views/header.php diff --git a/src/views/login.php b/app/views/login.php similarity index 100% rename from src/views/login.php rename to app/views/login.php diff --git a/src/views/manga/cover.php b/app/views/manga/cover.php similarity index 100% rename from src/views/manga/cover.php rename to app/views/manga/cover.php diff --git a/src/views/manga/list.php b/app/views/manga/list.php similarity index 100% rename from src/views/manga/list.php rename to app/views/manga/list.php diff --git a/src/views/message.php b/app/views/message.php similarity index 100% rename from src/views/message.php rename to app/views/message.php diff --git a/index.php b/index.php index 87e8c089..243a05e1 100644 --- a/index.php +++ b/index.php @@ -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)) diff --git a/src/Base/Config.php b/src/Aviat/AnimeClient/Base/Config.php similarity index 96% rename from src/Base/Config.php rename to src/Aviat/AnimeClient/Base/Config.php index 5f9a0bc6..3f1cd40a 100644 --- a/src/Base/Config.php +++ b/src/Aviat/AnimeClient/Base/Config.php @@ -3,7 +3,7 @@ * Base Configuration class */ -namespace AnimeClient\Base; +namespace Aviat\AnimeClient\Base; /** * Wrapper for configuration values diff --git a/src/Aviat/AnimeClient/Base/Container.php b/src/Aviat/AnimeClient/Base/Container.php new file mode 100644 index 00000000..8c6bdcd2 --- /dev/null +++ b/src/Aviat/AnimeClient/Base/Container.php @@ -0,0 +1,11 @@ +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(); diff --git a/src/Base/Model.php b/src/Aviat/AnimeClient/Base/Model.php similarity index 98% rename from src/Base/Model.php rename to src/Aviat/AnimeClient/Base/Model.php index 76896170..8b320608 100644 --- a/src/Base/Model.php +++ b/src/Aviat/AnimeClient/Base/Model.php @@ -2,7 +2,7 @@ /** * Base for base models */ -namespace AnimeClient\Base; +namespace Aviat\AnimeClient\Base; use abeautifulsite\SimpleImage; diff --git a/src/Base/Model/API.php b/src/Aviat/AnimeClient/Base/Model/API.php similarity index 91% rename from src/Base/Model/API.php rename to src/Aviat/AnimeClient/Base/Model/API.php index b8a2f748..4ab4fd17 100644 --- a/src/Base/Model/API.php +++ b/src/Aviat/AnimeClient/Base/Model/API.php @@ -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 diff --git a/src/Base/Model/DB.php b/src/Aviat/AnimeClient/Base/Model/DB.php similarity index 78% rename from src/Base/Model/DB.php rename to src/Aviat/AnimeClient/Base/Model/DB.php index 7992e91b..be7b506d 100644 --- a/src/Base/Model/DB.php +++ b/src/Aviat/AnimeClient/Base/Model/DB.php @@ -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 diff --git a/src/Base/Router.php b/src/Aviat/AnimeClient/Base/Router.php similarity index 94% rename from src/Base/Router.php rename to src/Aviat/AnimeClient/Base/Router.php index c33413f2..b448109c 100644 --- a/src/Base/Router.php +++ b/src/Aviat/AnimeClient/Base/Router.php @@ -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); diff --git a/src/Base/RoutingBase.php b/src/Aviat/AnimeClient/Base/RoutingBase.php similarity index 82% rename from src/Base/RoutingBase.php rename to src/Aviat/AnimeClient/Base/RoutingBase.php index 1887ae30..e19e82d5 100644 --- a/src/Base/RoutingBase.php +++ b/src/Aviat/AnimeClient/Base/RoutingBase.php @@ -1,7 +1,13 @@ 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 diff --git a/src/Controller/Stats.php b/src/Controller/Stats.php deleted file mode 100644 index 5bf95e06..00000000 --- a/src/Controller/Stats.php +++ /dev/null @@ -1,11 +0,0 @@ -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); diff --git a/tests/Base/Model/BaseDBModelTest.php b/tests/Base/Model/BaseDBModelTest.php index 1b1f37ef..6a600aeb 100644 --- a/tests/Base/Model/BaseDBModelTest.php +++ b/tests/Base/Model/BaseDBModelTest.php @@ -1,6 +1,6 @@