From 2391ca14ca3676eefd7af335ad834d0590c81843 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Mon, 11 Jan 2016 14:39:53 -0500 Subject: [PATCH] Remove errorhandler, and replace with logger --- README.md | 4 ++-- app/bootstrap.php | 3 +-- composer.json | 5 ++--- index.php | 1 - src/Aviat/AnimeClient/Controller.php | 2 -- src/Aviat/AnimeClient/Dispatcher.php | 25 ++++++++++++++++--------- src/Aviat/AnimeClient/Model/Anime.php | 6 ++++-- tests/AnimeClient/DispatcherTest.php | 16 ++++++++++++---- tests/AnimeClient_TestCase.php | 1 - 9 files changed, 37 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ec2ce21b..4d97aa44 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird ### Installation -1. Install dependencies via composer: `composer install` +1. Install via composer: `composer create-project timw4mail/hummingbird-anime-client` 2. Configure settings in `app/config/config.php` to your liking 3. Create the following directories if they don't exist, and make sure they are world writable * app/cache @@ -51,7 +51,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird * For importing anime: 1. Login 2. Use the form to select your media - 3. Save & Repeat as needed + 3. Save & Repeat as needed * For bulk importing anime: 1. Find the anime you are looking for on the hummingbird search api page: `https://hummingbird.me/api/v1/search/anime?query=` 2. Create an `import.json` file in the root of the app, with an array of objects from the search page that you want to import diff --git a/app/bootstrap.php b/app/bootstrap.php index eaec9c1d..ee55977e 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -29,8 +29,7 @@ return function(array $config_array = []) { $app_logger = new Logger('animeclient'); $app_logger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE)); - $app_logger->pushHandler(new BrowserConsoleHandler(Logger::DEBUG)); - $container->setLogger($app_logger); + $container->setLogger($app_logger, 'default'); // ------------------------------------------------------------------------- // Injected Objects diff --git a/composer.json b/composer.json index 70880894..5a94dc29 100644 --- a/composer.json +++ b/composer.json @@ -7,16 +7,15 @@ "aura/html": "2.*", "aura/router": "2.2.*", "aura/session": "2.*", - "aura/web": "2.0.*", + "aura/web": "2.*", "aviat4ion/query": "2.5.*", "container-interop/container-interop": "1.*", "danielstjules/stringy": "~2.1", "filp/whoops": "1.1.*", "guzzlehttp/guzzle": "6.*", "monolog/monolog": "1.*", - "mustache/mustache": "*", "psr/log": "~1.0", "robmorgan/phinx": "0.4.*", - "szymach/c-pchart": "1.*" + "yosymfony/toml": "0.3.*" } } \ No newline at end of file diff --git a/index.php b/index.php index 244b4982..ad7e532a 100644 --- a/index.php +++ b/index.php @@ -86,7 +86,6 @@ unset($SRC_DIR); unset($CONF_DIR); $container = $di($config_array); -$container->set('error-handler', $defaultHandler); // ----------------------------------------------------------------------------- // Dispatch to the current route diff --git a/src/Aviat/AnimeClient/Controller.php b/src/Aviat/AnimeClient/Controller.php index 3bb5b3a6..5344e75b 100644 --- a/src/Aviat/AnimeClient/Controller.php +++ b/src/Aviat/AnimeClient/Controller.php @@ -197,8 +197,6 @@ class Controller { */ protected function load_partial($view, $template, array $data = []) { - $errorHandler = $this->container->get('error-handler'); - $errorHandler->addDataTable('Template Data', $data); $router = $this->container->get('dispatcher'); if (isset($this->base_data)) diff --git a/src/Aviat/AnimeClient/Dispatcher.php b/src/Aviat/AnimeClient/Dispatcher.php index 43470b33..c22f6b8d 100644 --- a/src/Aviat/AnimeClient/Dispatcher.php +++ b/src/Aviat/AnimeClient/Dispatcher.php @@ -62,14 +62,15 @@ class Dispatcher extends RoutingBase { */ public function get_route() { - $error_handler = $this->container->get('error-handler'); + $logger = $this->container->getLogger('default'); $raw_route = $this->request->url->get(PHP_URL_PATH); $route_path = "/" . trim($raw_route, '/'); - $error_handler->addDataTable('Route Info', [ + $logger->addDebug('Dispatcher - Routing data from get_route method'); + $logger->addDebug(print_r([ 'route_path' => $route_path - ]); + ], TRUE)); return $this->router->match($route_path, $_SERVER); } @@ -93,12 +94,14 @@ class Dispatcher extends RoutingBase { */ public function __invoke($route = NULL) { - $error_handler = $this->container->get('error-handler'); + $logger = $this->container->getLogger('default'); if (is_null($route)) { $route = $this->get_route(); - $error_handler->addDataTable('route_args', (array)$route); + + $logger->addDebug('Dispatcher - Route invoke arguments'); + $logger->addDebug(print_r($route, TRUE)); } if($route) @@ -233,12 +236,13 @@ class Dispatcher extends RoutingBase { */ protected function call($controller_name, $method, array $params) { - $error_handler = $this->container->get('error-handler'); + $logger = $this->container->getLogger('default'); $controller = new $controller_name($this->container); // Run the appropriate controller method - $error_handler->addDataTable('controller_args', $params); + $logger->addDebug('Dispatcher - controller arguments'); + $logger->addDebug(print_r($params, TRUE)); call_user_func_array([$controller, $method], $params); } @@ -250,9 +254,12 @@ class Dispatcher extends RoutingBase { */ protected function get_error_params() { + $logger = $this->container->getLogger('default'); $failure = $this->router->getFailedRoute(); - $error_handler = $this->container->get('error-handler'); - $error_handler->addDataTable('failed_route', (array)$failure); + + $logger->info('Dispatcher - failed route'); + $logger->info(print_r($failure, TRUE)); + $action_method = AnimeClient::ERROR_MESSAGE_METHOD; $params = []; diff --git a/src/Aviat/AnimeClient/Model/Anime.php b/src/Aviat/AnimeClient/Model/Anime.php index 58685326..af002a2c 100644 --- a/src/Aviat/AnimeClient/Model/Anime.php +++ b/src/Aviat/AnimeClient/Model/Anime.php @@ -149,7 +149,7 @@ class Anime extends API { */ public function search($name) { - $errorHandler = $this->container->get('error-handler'); + $logger = $this->container->getLogger('default'); $config = [ 'query' => [ @@ -158,10 +158,12 @@ class Anime extends API { ]; $response = $this->get('search/anime', $config); - $errorHandler->addDataTable('anime_search_response', (array)$response); if ($response->getStatusCode() != 200) { + $logger->addWarning("Non 200 response for search api call"); + $logger->addWarning($response->getBody()); + throw new RuntimeException($response->getEffectiveUrl()); } diff --git a/tests/AnimeClient/DispatcherTest.php b/tests/AnimeClient/DispatcherTest.php index 564568df..bf7d39af 100644 --- a/tests/AnimeClient/DispatcherTest.php +++ b/tests/AnimeClient/DispatcherTest.php @@ -1,11 +1,15 @@ container->get('config'); + $logger = new Logger('test_logger'); + $logger->pushHandler(new TestHandler(Logger::DEBUG)); + // Add the appropriate objects to the container $this->container = new Container([ 'config' => $old_config, 'request' => $web_factory->newRequest(), 'response' => $web_factory->newResponse(), - 'aura-router' => $router_factory->newInstance(), - 'error-handler' => new MockErrorHandler() + 'aura-router' => $router_factory->newInstance() ]); + $this->container->setLogger($logger, 'default'); + if ( ! empty($config)) { $config = new Config($config); diff --git a/tests/AnimeClient_TestCase.php b/tests/AnimeClient_TestCase.php index 8c25ed08..2c7e0c6b 100644 --- a/tests/AnimeClient_TestCase.php +++ b/tests/AnimeClient_TestCase.php @@ -75,7 +75,6 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase { // Set up DI container $di = require _dir($APP_DIR, 'bootstrap.php'); $container = $di($config_array); - $container->set('error-handler', new MockErrorHandler()); $container->set('session-handler', self::$session_handler); $this->container = $container;