From afced2339a276f3a45191b938176fe35b17337ef Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 13 Nov 2015 16:31:01 -0500 Subject: [PATCH] Poor style progress update commit --- .gitignore | 1 + app/bootstrap.php | 13 +++++++ app/config/menus.php | 1 + app/logs/.gitkeep | 0 app/views/manga/cover.php | 8 ++--- composer.json | 2 ++ index.php | 2 +- public/js/collection.js | 0 public/js/manga_edit.js | 14 ++++++-- src/Aviat/Ion/Di/Container.php | 47 ++++++++++++++++++++++++- src/Aviat/Ion/Di/ContainerInterface.php | 18 ++++++++++ tests/Ion/Di/ContainerTest.php | 26 ++++++++++++++ 12 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 app/logs/.gitkeep mode change 100644 => 100755 public/js/collection.js mode change 100644 => 100755 public/js/manga_edit.js diff --git a/.gitignore b/.gitignore index 1b60e1a6..06ef8db1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.workspace vendor app/cache/* +app/logs/* public/images/* public/js/cache/* composer.lock diff --git a/app/bootstrap.php b/app/bootstrap.php index ac7467f0..d993ec39 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -9,6 +9,10 @@ use Aura\Html\HelperLocatorFactory; use Aura\Web\WebFactory; use Aura\Router\RouterFactory; use Aura\Session\SessionFactory; +use Monolog\Logger; +use Monolog\Handler\RotatingFileHandler; +use Monolog\Handler\BrowserConsoleHandler; + use Aviat\Ion\Di\Container; use Aviat\AnimeClient\Auth\HummingbirdAuth; @@ -18,6 +22,15 @@ use Aviat\AnimeClient\Auth\HummingbirdAuth; return function(array $config_array = []) { $container = new Container(); + // ------------------------------------------------------------------------- + // Logging + // ------------------------------------------------------------------------- + + $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); + // ------------------------------------------------------------------------- // Injected Objects // ------------------------------------------------------------------------- diff --git a/app/config/menus.php b/app/config/menus.php index 788509b6..45c8c4a6 100644 --- a/app/config/menus.php +++ b/app/config/menus.php @@ -9,6 +9,7 @@ return [ 'on_hold' => '/on_hold', 'dropped' => '/dropped', 'completed' => '/completed', + //'collection' => '/collection/view', 'all' => '/all' ] ], diff --git a/app/logs/.gitkeep b/app/logs/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/app/views/manga/cover.php b/app/views/manga/cover.php index 79521f8d..a48f11c0 100644 --- a/app/views/manga/cover.php +++ b/app/views/manga/cover.php @@ -8,12 +8,12 @@
- + is_authenticated()): ?> - +
@@ -45,6 +45,6 @@ - +is_authenticated()): ?> - + diff --git a/composer.json b/composer.json index c447e9f6..72d4b27f 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,8 @@ "danielstjules/stringy": "~2.1", "filp/whoops": "dev-php7#fe32a402b086b21360e82013e8a0355575c7c6f4", "guzzlehttp/guzzle": "6.*", + "monolog/monolog": "1.*", + "psr/log": "~1.0", "robmorgan/phinx": "0.4.*", "szymach/c-pchart": "1.*" } diff --git a/index.php b/index.php index dc8cdcb4..fab73dbf 100644 --- a/index.php +++ b/index.php @@ -80,6 +80,6 @@ $container->set('error-handler', $defaultHandler); // ----------------------------------------------------------------------------- // Dispatch to the current route // ----------------------------------------------------------------------------- -$container->get('dispatcher')(); +$container->get('dispatcher')->__invoke(); // End of index.php \ No newline at end of file diff --git a/public/js/collection.js b/public/js/collection.js old mode 100644 new mode 100755 diff --git a/public/js/manga_edit.js b/public/js/manga_edit.js old mode 100644 new mode 100755 index ff96eda3..53e7dc59 --- a/public/js/manga_edit.js +++ b/public/js/manga_edit.js @@ -1,7 +1,9 @@ /** * Javascript for editing manga, if logged in */ -(function ($, undefined) { +(function ($) { + + "use strict"; if (CONTROLLER !== "manga") return; @@ -28,10 +30,18 @@ // Update the total count data[type + "s_read"] = ++completed; - $.post(BASE_URL + 'update', data, function(res) { + $.ajax({ + data: data, + dataType: 'json', + method: 'POST', + mimeType: 'application/json', + url: BASE_URL + '/' + CONTROLLER + '/update' + }).done(function(res) { console.table(res); parent_sel.find("."+type+"s_read").text(completed); add_message('success', "Sucessfully updated " + res.manga[0].romaji_title); + }).fail(function() { + add_message('error', "Failed to updated " + res.manga[0].romaji_title); }); }); diff --git a/src/Aviat/Ion/Di/Container.php b/src/Aviat/Ion/Di/Container.php index 55179ced..d2191a77 100644 --- a/src/Aviat/Ion/Di/Container.php +++ b/src/Aviat/Ion/Di/Container.php @@ -3,6 +3,7 @@ namespace Aviat\Ion\Di; use ArrayObject; +use Psr\Log\LoggerInterface; /** * Dependency container @@ -16,6 +17,13 @@ class Container implements ContainerInterface { */ protected $container = []; + /** + * Map of logger instances + * + * @var ArrayObject + */ + protected $loggers = []; + /** * Constructor * @@ -24,6 +32,7 @@ class Container implements ContainerInterface { public function __construct(array $values = []) { $this->container = new ArrayObject($values); + $this->loggers = new ArrayObject([]); } /** @@ -56,7 +65,7 @@ class Container implements ContainerInterface { * * @param string $id * @param mixed $value - * @return Container + * @return ContainerInterface */ public function set($id, $value) { @@ -76,5 +85,41 @@ class Container implements ContainerInterface { { return $this->container->offsetExists($id); } + + /** + * Determine whether a logger channel is registered + * @param string $key The logger channel + * @return boolean + */ + public function hasLogger($key = 'default') + { + return $this->loggers->offsetExists($key); + } + + /** + * Add a logger to the Container + * + * @param LoggerInterface $logger + * @param string $key The logger 'channel' + * @return ContainerInterface + */ + public function setLogger(LoggerInterface $logger, $key = 'default') + { + $this->loggers[$key] = $logger; + return $this; + } + + /** + * Retrieve a logger for the selected channel + * + * @param string $key The logger to retreive + * @return LoggerInterface|null + */ + public function getLogger($key = 'default') + { + return ($this->hasLogger($key)) + ? $this->loggers[$key] + : NULL; + } } // End of Container.php \ No newline at end of file diff --git a/src/Aviat/Ion/Di/ContainerInterface.php b/src/Aviat/Ion/Di/ContainerInterface.php index b902c923..364470bf 100644 --- a/src/Aviat/Ion/Di/ContainerInterface.php +++ b/src/Aviat/Ion/Di/ContainerInterface.php @@ -2,6 +2,8 @@ namespace Aviat\Ion\Di; +use Psr\Log\LoggerInterface; + /** * Interface for the Dependency Injection Container */ @@ -15,4 +17,20 @@ interface ContainerInterface extends \Interop\Container\ContainerInterface { * @return ContainerInterface */ public function set($key, $value); + + /** + * Add a logger to the Container + * + * @param LoggerInterface $logger + * @param string $key The logger 'channel' + */ + public function setLogger(LoggerInterface $logger, $key = 'default'); + + /** + * Retrieve a logger for the selected channel + * + * @param string $key The logger to retreive + * @return LoggerInterface|null + */ + public function getLogger($key = 'default'); } \ No newline at end of file diff --git a/tests/Ion/Di/ContainerTest.php b/tests/Ion/Di/ContainerTest.php index f01cca74..f4002582 100644 --- a/tests/Ion/Di/ContainerTest.php +++ b/tests/Ion/Di/ContainerTest.php @@ -2,6 +2,9 @@ use Aviat\Ion\Di\Container; use Aviat\Ion\Di\Exception\ContainerException; +use Monolog\Logger; +use Monolog\Handler\TestHandler; +use Monolog\Handler\NullHandler; class ContainerTest extends AnimeClient_TestCase { @@ -48,4 +51,27 @@ class ContainerTest extends AnimeClient_TestCase { } } + public function testLoggerMethods() + { + // Does the container have the default logger? + $this->assertFalse($this->container->hasLogger()); + $this->assertFalse($this->container->hasLogger('default')); + + $logger1 = new Logger('default'); + $logger2 = new Logger('testing'); + $logger1->pushHandler(new NullHandler()); + $logger2->pushHandler(new TestHandler()); + + // Set the logger channels + $this->container->setLogger($logger1); + $this->container->setLogger($logger2, 'test'); + + $this->assertEquals($logger1, $this->container->getLogger('default')); + $this->assertEquals($logger2, $this->container->getLogger('test')); + $this->assertNull($this->container->getLogger('foo')); + + $this->assertTrue($this->container->hasLogger()); + $this->assertTrue($this->container->hasLogger('default')); + $this->assertTrue($this->container->hasLogger('test')); + } } \ No newline at end of file