diff --git a/.gitignore b/.gitignore index 3321b514..1b60e1a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,19 @@ -.codelite -*.phprj -*.workspace -vendor -app/cache/* -public/images/* -public/js/cache/* -composer.lock -*.sqlite -*.db -*.sqlite3 -docs/* -coverage/* -tests/test_data/sessions/* \ No newline at end of file +.codelite +*.phprj +*.workspace +vendor +app/cache/* +public/images/* +public/js/cache/* +composer.lock +*.sqlite +*.db +*.sqlite3 +docs/* +coverage/* +tests/test_data/sessions/* +build/coverage/* +build/logs/* +build/pdepend/* +build/phpdox/* +cache.properties \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 9ba29e12..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - src/Aviat/Ion - src/Aviat/AnimeClient - - - - - tests/Ion - - - tests/AnimeClient - - - - - - - - - - \ No newline at end of file diff --git a/src/Aviat/AnimeClient/Controller.php b/src/Aviat/AnimeClient/Controller.php index a40ae879..949b945a 100644 --- a/src/Aviat/AnimeClient/Controller.php +++ b/src/Aviat/AnimeClient/Controller.php @@ -72,6 +72,8 @@ class Controller { $this->request = $container->get('request'); $this->response = $container->get('response'); $this->base_data['urlGenerator'] = $urlGenerator; + $this->base_data['auth'] = $container->get('auth'); + $this->base_data['config'] = $this->config; $this->urlGenerator = $urlGenerator; } @@ -110,7 +112,7 @@ class Controller { * @param array $data * @return string */ - public function load_partial($view, $template, array $data = []) + protected function load_partial($view, $template, array $data = []) { $errorHandler = $this->container->get('error-handler'); $errorHandler->addDataTable('Template Data', $data); @@ -143,23 +145,69 @@ class Controller { * @param array $data * @return void */ - public function render_full_page($view, $template, array $data) + protected function render_full_page($view, $template, array $data) { $view->appendOutput($this->load_partial($view, 'header', $data)); $view->appendOutput($this->load_partial($view, $template, $data)); $view->appendOutput($this->load_partial($view, 'footer', $data)); } + /** + * Show the login form + * + * @codeCoverageIgnore + * @param string $status + * @return void + */ + public function login($status="") + { + $message = ""; + + $view = new HtmlView($this->container); + + if ($status != "") + { + $message = $this->show_message($view, 'error', $status); + } + + $this->outputHTML('login', [ + 'title' => 'Api login', + 'message' => $message + ], $view); + } + + /** + * Add a message box to the page + * + * @codeCoverageIgnore + * @param HtmlView $view + * @param string $type + * @param string $message + * @return string + */ + protected function show_message($view, $type, $message) + { + return $this->load_partial($view, 'message', [ + 'stat_class' => $type, + 'message' => $message + ]); + } + /** * Output a template to HTML, using the provided data * * @param string $template * @param array $data + * @param HtmlView $view * @return void */ - public function outputHTML($template, array $data = []) + protected function outputHTML($template, array $data = [], $view = NULL) { - $view = new HtmlView($this->container); + if (is_null($view)) + { + $view = new HtmlView($this->container); + } + $this->render_full_page($view, $template, $data); } @@ -169,7 +217,7 @@ class Controller { * @param mixed $data * @return void */ - public function outputJSON($data = []) + protected function outputJSON($data = []) { $view = new JsonView($this->container); $view->setOutput($data); @@ -182,7 +230,7 @@ class Controller { * @param int $code * @return void */ - public function redirect($url, $code) + protected function redirect($url, $code) { $http = new HttpView($this->container); $http->redirect($url, $code); diff --git a/src/Aviat/AnimeClient/Controller/Anime.php b/src/Aviat/AnimeClient/Controller/Anime.php index ad44486c..fc68b3cf 100644 --- a/src/Aviat/AnimeClient/Controller/Anime.php +++ b/src/Aviat/AnimeClient/Controller/Anime.php @@ -73,8 +73,15 @@ class Anime extends BaseController { 'completed' => AnimeWatchingStatus::COMPLETED ]; - $title = $this->config->get('whose_list') . - "'s Anime List · {$type_title_map[$type]}"; + if (array_key_exists($type, $type_title_map)) + { + $title = $this->config->get('whose_list') . + "'s Anime List · {$type_title_map[$type]}"; + } + else + { + $title = ''; + } $view_map = [ '' => 'cover', diff --git a/src/Aviat/AnimeClient/Dispatcher.php b/src/Aviat/AnimeClient/Dispatcher.php index 54e6ed46..777b3383 100644 --- a/src/Aviat/AnimeClient/Dispatcher.php +++ b/src/Aviat/AnimeClient/Dispatcher.php @@ -60,6 +60,12 @@ class Dispatcher extends RoutingBase { 'action' => 'redirect_to_default' ]); + $this->output_routes[] = $this->router->add('login', '/{controller}/login') + ->setValues([ + 'controller' => $this->routes['convention']['default_controller'], + 'action' => 'login' + ]); + $this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}') ->setValues([ 'controller' => $this->routes['convention']['default_controller'], @@ -68,13 +74,6 @@ class Dispatcher extends RoutingBase { 'type' => '[a-z_]+', 'view' => '[a-z_]+' ]); - - $this->output_routes[] = $this->router->add('generic', '{/controller,action,view}') - ->setValues([ - 'controller' => $this->routes['convention']['default_controller'], - 'action' => $this->routes['convention']['default_method'], - 'view' => '', - ]); } /** diff --git a/src/Aviat/AnimeClient/Model/Manga.php b/src/Aviat/AnimeClient/Model/Manga.php index e5a1de90..d80601b2 100644 --- a/src/Aviat/AnimeClient/Model/Manga.php +++ b/src/Aviat/AnimeClient/Model/Manga.php @@ -180,8 +180,7 @@ class Manga extends API { */ private function zipper_lists($raw_data) { - $zipper = new Transformer\MangaListsZipper($raw_data); - return $zipper->transform(); + return (new Transformer\MangaListsZipper($raw_data))->transform(); } /** diff --git a/src/Aviat/Ion/Friend.php b/src/Aviat/Ion/Friend.php index f479a3cf..6651910d 100644 --- a/src/Aviat/Ion/Friend.php +++ b/src/Aviat/Ion/Friend.php @@ -17,13 +17,13 @@ class Friend { * Object to create a friend of * @var object */ - private $_friend_object_; + private $_friend_; /** * Reflection class of the object * @var object */ - private $_reflection_friend_; + private $_reflect_; /** * Create a friend object @@ -37,8 +37,8 @@ class Friend { throw new InvalidArgumentException("Friend must be an object"); } - $this->_friend_object_ = $obj; - $this->_reflection_friend_ = new ReflectionClass($obj); + $this->_friend_ = $obj; + $this->_reflect_ = new ReflectionClass($obj); } /** @@ -49,10 +49,10 @@ class Friend { */ public function __get($key) { - if ($this->_reflection_friend_->hasProperty($key)) + if ($this->_reflect_->hasProperty($key)) { $property = $this->_get_property($key); - return $property->getValue($this->_friend_object_); + return $property->getValue($this->_friend_); } return NULL; @@ -67,10 +67,10 @@ class Friend { */ public function __set($key, $value) { - if ($this->_reflection_friend_->hasProperty($key)) + if ($this->_reflect_->hasProperty($key)) { $property = $this->_get_property($key); - $property->setValue($this->_friend_object_, $value); + $property->setValue($this->_friend_, $value); } } @@ -83,14 +83,14 @@ class Friend { */ public function __call($method, $args) { - if ( ! $this->_reflection_friend_->hasMethod($method)) + if ( ! $this->_reflect_->hasMethod($method)) { throw new BadMethodCallException("Method '{$method}' does not exist"); } - $friendMethod = new ReflectionMethod($this->_friend_object_, $method); + $friendMethod = new ReflectionMethod($this->_friend_, $method); $friendMethod->setAccessible(TRUE); - return $friendMethod->invokeArgs($this->_friend_object_, $args); + return $friendMethod->invokeArgs($this->_friend_, $args); } /** @@ -104,7 +104,7 @@ class Friend { { try { - $property = $this->_reflection_friend_->getProperty($name); + $property = $this->_reflect_->getProperty($name); $property->setAccessible(TRUE); return $property; }