Remove errorhandler, and replace with logger
This commit is contained in:
parent
b85ddb9464
commit
816a309f18
@ -38,7 +38,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
|
|||||||
|
|
||||||
### Installation
|
### 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
|
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
|
3. Create the following directories if they don't exist, and make sure they are world writable
|
||||||
* app/cache
|
* app/cache
|
||||||
@ -51,7 +51,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
|
|||||||
* For importing anime:
|
* For importing anime:
|
||||||
1. Login
|
1. Login
|
||||||
2. Use the form to select your media
|
2. Use the form to select your media
|
||||||
3. Save & Repeat as needed
|
3. Save & Repeat as needed
|
||||||
* For bulk importing anime:
|
* 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=`
|
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
|
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
|
||||||
|
@ -29,8 +29,7 @@ return function(array $config_array = []) {
|
|||||||
|
|
||||||
$app_logger = new Logger('animeclient');
|
$app_logger = new Logger('animeclient');
|
||||||
$app_logger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
|
$app_logger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
|
||||||
$app_logger->pushHandler(new BrowserConsoleHandler(Logger::DEBUG));
|
$container->setLogger($app_logger, 'default');
|
||||||
$container->setLogger($app_logger);
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Injected Objects
|
// Injected Objects
|
||||||
|
@ -7,16 +7,15 @@
|
|||||||
"aura/html": "2.*",
|
"aura/html": "2.*",
|
||||||
"aura/router": "2.2.*",
|
"aura/router": "2.2.*",
|
||||||
"aura/session": "2.*",
|
"aura/session": "2.*",
|
||||||
"aura/web": "2.0.*",
|
"aura/web": "2.*",
|
||||||
"aviat4ion/query": "2.5.*",
|
"aviat4ion/query": "2.5.*",
|
||||||
"container-interop/container-interop": "1.*",
|
"container-interop/container-interop": "1.*",
|
||||||
"danielstjules/stringy": "~2.1",
|
"danielstjules/stringy": "~2.1",
|
||||||
"filp/whoops": "1.1.*",
|
"filp/whoops": "1.1.*",
|
||||||
"guzzlehttp/guzzle": "6.*",
|
"guzzlehttp/guzzle": "6.*",
|
||||||
"monolog/monolog": "1.*",
|
"monolog/monolog": "1.*",
|
||||||
"mustache/mustache": "*",
|
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
"robmorgan/phinx": "0.4.*",
|
"robmorgan/phinx": "0.4.*",
|
||||||
"szymach/c-pchart": "1.*"
|
"yosymfony/toml": "0.3.*"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -86,7 +86,6 @@ unset($SRC_DIR);
|
|||||||
unset($CONF_DIR);
|
unset($CONF_DIR);
|
||||||
|
|
||||||
$container = $di($config_array);
|
$container = $di($config_array);
|
||||||
$container->set('error-handler', $defaultHandler);
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Dispatch to the current route
|
// Dispatch to the current route
|
||||||
|
@ -197,8 +197,6 @@ class Controller {
|
|||||||
*/
|
*/
|
||||||
protected 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);
|
|
||||||
$router = $this->container->get('dispatcher');
|
$router = $this->container->get('dispatcher');
|
||||||
|
|
||||||
if (isset($this->base_data))
|
if (isset($this->base_data))
|
||||||
|
@ -62,14 +62,15 @@ class Dispatcher extends RoutingBase {
|
|||||||
*/
|
*/
|
||||||
public function get_route()
|
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);
|
$raw_route = $this->request->url->get(PHP_URL_PATH);
|
||||||
$route_path = "/" . trim($raw_route, '/');
|
$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
|
'route_path' => $route_path
|
||||||
]);
|
], TRUE));
|
||||||
|
|
||||||
return $this->router->match($route_path, $_SERVER);
|
return $this->router->match($route_path, $_SERVER);
|
||||||
}
|
}
|
||||||
@ -93,12 +94,14 @@ class Dispatcher extends RoutingBase {
|
|||||||
*/
|
*/
|
||||||
public function __invoke($route = NULL)
|
public function __invoke($route = NULL)
|
||||||
{
|
{
|
||||||
$error_handler = $this->container->get('error-handler');
|
$logger = $this->container->getLogger('default');
|
||||||
|
|
||||||
if (is_null($route))
|
if (is_null($route))
|
||||||
{
|
{
|
||||||
$route = $this->get_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)
|
if($route)
|
||||||
@ -233,12 +236,13 @@ class Dispatcher extends RoutingBase {
|
|||||||
*/
|
*/
|
||||||
protected function call($controller_name, $method, array $params)
|
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);
|
$controller = new $controller_name($this->container);
|
||||||
|
|
||||||
// Run the appropriate controller method
|
// 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);
|
call_user_func_array([$controller, $method], $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,9 +254,12 @@ class Dispatcher extends RoutingBase {
|
|||||||
*/
|
*/
|
||||||
protected function get_error_params()
|
protected function get_error_params()
|
||||||
{
|
{
|
||||||
|
$logger = $this->container->getLogger('default');
|
||||||
$failure = $this->router->getFailedRoute();
|
$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;
|
$action_method = AnimeClient::ERROR_MESSAGE_METHOD;
|
||||||
|
|
||||||
$params = [];
|
$params = [];
|
||||||
|
@ -149,7 +149,7 @@ class Anime extends API {
|
|||||||
*/
|
*/
|
||||||
public function search($name)
|
public function search($name)
|
||||||
{
|
{
|
||||||
$errorHandler = $this->container->get('error-handler');
|
$logger = $this->container->getLogger('default');
|
||||||
|
|
||||||
$config = [
|
$config = [
|
||||||
'query' => [
|
'query' => [
|
||||||
@ -158,10 +158,12 @@ class Anime extends API {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$response = $this->get('search/anime', $config);
|
$response = $this->get('search/anime', $config);
|
||||||
$errorHandler->addDataTable('anime_search_response', (array)$response);
|
|
||||||
|
|
||||||
if ($response->getStatusCode() != 200)
|
if ($response->getStatusCode() != 200)
|
||||||
{
|
{
|
||||||
|
$logger->addWarning("Non 200 response for search api call");
|
||||||
|
$logger->addWarning($response->getBody());
|
||||||
|
|
||||||
throw new RuntimeException($response->getEffectiveUrl());
|
throw new RuntimeException($response->getEffectiveUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Aura\Web\WebFactory;
|
||||||
|
use Aura\Router\RouterFactory;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\Handler\TestHandler;
|
||||||
|
|
||||||
use Aviat\Ion\Di\Container;
|
use Aviat\Ion\Di\Container;
|
||||||
use Aviat\AnimeClient\Dispatcher;
|
use Aviat\AnimeClient\Dispatcher;
|
||||||
use Aviat\AnimeClient\Config;
|
use Aviat\AnimeClient\Config;
|
||||||
use Aviat\AnimeClient\UrlGenerator;
|
use Aviat\AnimeClient\UrlGenerator;
|
||||||
use Aura\Web\WebFactory;
|
|
||||||
use Aura\Router\RouterFactory;
|
|
||||||
|
|
||||||
class DispatcherTest extends AnimeClient_TestCase {
|
class DispatcherTest extends AnimeClient_TestCase {
|
||||||
|
|
||||||
@ -35,15 +39,19 @@ class DispatcherTest extends AnimeClient_TestCase {
|
|||||||
|
|
||||||
$old_config = $this->container->get('config');
|
$old_config = $this->container->get('config');
|
||||||
|
|
||||||
|
$logger = new Logger('test_logger');
|
||||||
|
$logger->pushHandler(new TestHandler(Logger::DEBUG));
|
||||||
|
|
||||||
// Add the appropriate objects to the container
|
// Add the appropriate objects to the container
|
||||||
$this->container = new Container([
|
$this->container = new Container([
|
||||||
'config' => $old_config,
|
'config' => $old_config,
|
||||||
'request' => $web_factory->newRequest(),
|
'request' => $web_factory->newRequest(),
|
||||||
'response' => $web_factory->newResponse(),
|
'response' => $web_factory->newResponse(),
|
||||||
'aura-router' => $router_factory->newInstance(),
|
'aura-router' => $router_factory->newInstance()
|
||||||
'error-handler' => new MockErrorHandler()
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->container->setLogger($logger, 'default');
|
||||||
|
|
||||||
if ( ! empty($config))
|
if ( ! empty($config))
|
||||||
{
|
{
|
||||||
$config = new Config($config);
|
$config = new Config($config);
|
||||||
|
@ -75,7 +75,6 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
|
|||||||
// Set up DI container
|
// Set up DI container
|
||||||
$di = require _dir($APP_DIR, 'bootstrap.php');
|
$di = require _dir($APP_DIR, 'bootstrap.php');
|
||||||
$container = $di($config_array);
|
$container = $di($config_array);
|
||||||
$container->set('error-handler', new MockErrorHandler());
|
|
||||||
$container->set('session-handler', self::$session_handler);
|
$container->set('session-handler', self::$session_handler);
|
||||||
|
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
Loading…
Reference in New Issue
Block a user