2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-08-30 10:01:18 -04:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2016-12-20 12:58:37 -05:00
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-15 14:43:15 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2016-08-30 10:01:18 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2016-12-20 12:58:37 -05:00
|
|
|
* @version 4.0
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-01-11 10:34:24 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient;
|
2015-06-29 09:46:49 -04:00
|
|
|
|
2015-10-05 16:54:25 -04:00
|
|
|
use Aura\Html\HelperLocatorFactory;
|
2016-02-16 16:28:44 -05:00
|
|
|
use Aura\Router\RouterContainer;
|
2015-10-09 14:34:55 -04:00
|
|
|
use Aura\Session\SessionFactory;
|
2017-03-03 11:33:32 -05:00
|
|
|
use Aviat\AnimeClient\API\{
|
2018-08-10 20:10:19 -04:00
|
|
|
Anilist,
|
2017-03-03 11:33:32 -05:00
|
|
|
Kitsu,
|
2018-08-22 13:43:04 -04:00
|
|
|
Kitsu\KitsuRequestBuilder
|
2017-03-03 11:33:32 -05:00
|
|
|
};
|
2016-12-20 12:58:37 -05:00
|
|
|
use Aviat\AnimeClient\Model;
|
2016-12-22 21:36:23 -05:00
|
|
|
use Aviat\Banker\Pool;
|
2016-07-28 10:44:13 -04:00
|
|
|
use Aviat\Ion\Config;
|
2015-09-17 23:11:18 -04:00
|
|
|
use Aviat\Ion\Di\Container;
|
2016-12-20 12:58:37 -05:00
|
|
|
use Monolog\Handler\RotatingFileHandler;
|
|
|
|
use Monolog\Logger;
|
|
|
|
use Zend\Diactoros\{Response, ServerRequestFactory};
|
2015-09-14 10:54:50 -04:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Setup DI container
|
|
|
|
// -----------------------------------------------------------------------------
|
2018-01-16 14:58:07 -05:00
|
|
|
return function (array $configArray = []) {
|
2015-09-17 23:11:18 -04:00
|
|
|
$container = new Container();
|
|
|
|
|
2015-11-13 16:31:01 -05:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Logging
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
2017-03-03 11:33:32 -05:00
|
|
|
$appLogger = new Logger('animeclient');
|
|
|
|
$appLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
|
2018-08-10 20:10:19 -04:00
|
|
|
$anilistRequestLogger = new Logger('anilist-request');
|
|
|
|
$anilistRequestLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/anilist_request.log', Logger::NOTICE));
|
2017-03-03 11:33:32 -05:00
|
|
|
$kitsuRequestLogger = new Logger('kitsu-request');
|
|
|
|
$kitsuRequestLogger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/kitsu_request.log', Logger::NOTICE));
|
2018-01-16 14:58:07 -05:00
|
|
|
$container->setLogger($appLogger);
|
2018-08-10 20:10:19 -04:00
|
|
|
$container->setLogger($anilistRequestLogger, 'anilist-request');
|
2017-03-03 11:33:32 -05:00
|
|
|
$container->setLogger($kitsuRequestLogger, 'kitsu-request');
|
2015-11-13 16:31:01 -05:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Injected Objects
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Create Config Object
|
2017-03-03 11:33:32 -05:00
|
|
|
$container->set('config', function() use ($configArray) {
|
|
|
|
return new Config($configArray);
|
2016-08-29 14:51:32 -04:00
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2016-04-12 13:41:03 -04:00
|
|
|
// Create Cache Object
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('cache', function($container) {
|
2016-12-22 21:36:23 -05:00
|
|
|
$logger = $container->getLogger();
|
|
|
|
$config = $container->get('config')->get('cache');
|
|
|
|
return new Pool($config, $logger);
|
2016-08-29 14:51:32 -04:00
|
|
|
});
|
2016-04-12 13:41:03 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
// Create Aura Router Object
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('aura-router', function() {
|
|
|
|
return new RouterContainer;
|
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2015-10-05 16:54:25 -04:00
|
|
|
// Create Html helper Object
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('html-helper', function($container) {
|
2017-03-03 11:33:32 -05:00
|
|
|
$htmlHelper = (new HelperLocatorFactory)->newInstance();
|
|
|
|
$htmlHelper->set('menu', function() use ($container) {
|
|
|
|
$menuHelper = new Helper\Menu();
|
|
|
|
$menuHelper->setContainer($container);
|
|
|
|
return $menuHelper;
|
2016-08-29 14:51:32 -04:00
|
|
|
});
|
|
|
|
|
2017-03-03 11:33:32 -05:00
|
|
|
return $htmlHelper;
|
2015-10-05 16:54:25 -04:00
|
|
|
});
|
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
// Create Request/Response Objects
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('request', function() {
|
|
|
|
return ServerRequestFactory::fromGlobals(
|
|
|
|
$_SERVER,
|
|
|
|
$_GET,
|
|
|
|
$_POST,
|
|
|
|
$_COOKIE,
|
|
|
|
$_FILES
|
|
|
|
);
|
|
|
|
});
|
|
|
|
$container->set('response', function() {
|
|
|
|
return new Response;
|
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
|
|
|
// Create session Object
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('session', function() {
|
|
|
|
return (new SessionFactory())->newInstance($_COOKIE);
|
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2015-11-16 19:30:04 -05:00
|
|
|
// Miscellaneous helper methods
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('util', function($container) {
|
|
|
|
return new Util($container);
|
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2015-12-08 16:39:49 -05:00
|
|
|
// Models
|
2016-12-22 21:36:23 -05:00
|
|
|
$container->set('kitsu-model', function($container) {
|
2017-02-07 13:11:42 -05:00
|
|
|
$requestBuilder = new KitsuRequestBuilder();
|
|
|
|
$requestBuilder->setLogger($container->getLogger('kitsu-request'));
|
2017-02-08 15:48:20 -05:00
|
|
|
|
|
|
|
$listItem = new Kitsu\ListItem();
|
2017-01-06 21:39:01 -05:00
|
|
|
$listItem->setContainer($container);
|
2017-02-07 13:11:42 -05:00
|
|
|
$listItem->setRequestBuilder($requestBuilder);
|
2017-02-08 15:48:20 -05:00
|
|
|
|
|
|
|
$model = new Kitsu\Model($listItem);
|
2016-12-22 21:36:23 -05:00
|
|
|
$model->setContainer($container);
|
2017-02-07 13:11:42 -05:00
|
|
|
$model->setRequestBuilder($requestBuilder);
|
2017-02-08 15:48:20 -05:00
|
|
|
|
2017-01-13 16:53:56 -05:00
|
|
|
$cache = $container->get('cache');
|
|
|
|
$model->setCache($cache);
|
|
|
|
return $model;
|
|
|
|
});
|
2018-08-15 08:51:37 -04:00
|
|
|
$container->set('anilist-model', function($container) {
|
|
|
|
$requestBuilder = new Anilist\AnilistRequestBuilder();
|
|
|
|
$requestBuilder->setLogger($container->getLogger('anilist-request'));
|
|
|
|
|
|
|
|
$listItem = new Anilist\ListItem();
|
|
|
|
$listItem->setContainer($container);
|
|
|
|
$listItem->setRequestBuilder($requestBuilder);
|
|
|
|
|
|
|
|
$model = new Anilist\Model($listItem);
|
|
|
|
$model->setContainer($container);
|
|
|
|
$model->setRequestBuilder($requestBuilder);
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
});
|
2017-02-07 13:11:42 -05:00
|
|
|
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('api-model', function($container) {
|
|
|
|
return new Model\API($container);
|
|
|
|
});
|
|
|
|
$container->set('anime-model', function($container) {
|
|
|
|
return new Model\Anime($container);
|
|
|
|
});
|
|
|
|
$container->set('manga-model', function($container) {
|
|
|
|
return new Model\Manga($container);
|
|
|
|
});
|
|
|
|
$container->set('anime-collection-model', function($container) {
|
|
|
|
return new Model\AnimeCollection($container);
|
|
|
|
});
|
2017-09-14 16:18:13 -04:00
|
|
|
$container->set('manga-collection-model', function($container) {
|
|
|
|
return new Model\MangaCollection($container);
|
|
|
|
});
|
2015-12-08 16:39:49 -05:00
|
|
|
|
2016-04-08 18:05:52 -04:00
|
|
|
// Miscellaneous Classes
|
2017-01-05 13:41:32 -05:00
|
|
|
$container->set('auth', function($container) {
|
2017-02-08 15:48:20 -05:00
|
|
|
return new Kitsu\Auth($container);
|
2017-01-05 13:41:32 -05:00
|
|
|
});
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('url-generator', function($container) {
|
|
|
|
return new UrlGenerator($container);
|
|
|
|
});
|
2015-12-08 16:39:49 -05:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
// -------------------------------------------------------------------------
|
2015-10-09 14:34:55 -04:00
|
|
|
// Dispatcher
|
2015-09-17 23:11:18 -04:00
|
|
|
// -------------------------------------------------------------------------
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('dispatcher', function($container) {
|
|
|
|
return new Dispatcher($container);
|
|
|
|
});
|
2015-09-17 23:11:18 -04:00
|
|
|
|
|
|
|
return $container;
|
|
|
|
};
|
|
|
|
|
2015-10-05 16:54:25 -04:00
|
|
|
// End of bootstrap.php
|