2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-08-30 10:01:18 -04:00
|
|
|
/**
|
|
|
|
* Hummingbird Anime Client
|
|
|
|
*
|
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists
|
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 3.1
|
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
2015-12-08 14:52:59 -05:00
|
|
|
|
2015-09-14 19:54:34 -04: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;
|
2015-11-13 16:31:01 -05:00
|
|
|
use Monolog\Logger;
|
|
|
|
use Monolog\Handler\RotatingFileHandler;
|
2016-02-16 16:28:44 -05:00
|
|
|
use Zend\Diactoros\ServerRequestFactory;
|
|
|
|
use Zend\Diactoros\Response;
|
2015-11-13 16:31:01 -05:00
|
|
|
|
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-04-05 13:19:35 -04:00
|
|
|
use Aviat\Ion\Cache\CacheManager;
|
2015-10-15 09:25:30 -04:00
|
|
|
use Aviat\AnimeClient\Auth\HummingbirdAuth;
|
2015-12-08 16:39:49 -05:00
|
|
|
use Aviat\AnimeClient\Model;
|
2015-09-14 10:54:50 -04:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Setup DI container
|
|
|
|
// -----------------------------------------------------------------------------
|
2015-10-09 14:34:55 -04:00
|
|
|
return function(array $config_array = []) {
|
2015-09-17 23:11:18 -04:00
|
|
|
$container = new Container();
|
|
|
|
|
2015-11-13 16:31:01 -05:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Logging
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
$app_logger = new Logger('animeclient');
|
2015-11-16 10:33:30 -05:00
|
|
|
$app_logger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
|
2016-01-11 14:39:53 -05:00
|
|
|
$container->setLogger($app_logger, 'default');
|
2015-11-13 16:31:01 -05:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Injected Objects
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Create Config Object
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('config', function() {
|
|
|
|
return new Config();
|
|
|
|
});
|
|
|
|
$container->setInstance('config', new Config($config_array));
|
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) {
|
|
|
|
return new CacheManager($container->get('config'));
|
|
|
|
});
|
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) {
|
|
|
|
$html_helper = (new HelperLocatorFactory)->newInstance();
|
|
|
|
$html_helper->set('menu', function() use ($container) {
|
|
|
|
$menu_helper = new Helper\Menu();
|
|
|
|
$menu_helper->setContainer($container);
|
|
|
|
return $menu_helper;
|
|
|
|
});
|
|
|
|
|
|
|
|
return $html_helper;
|
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-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);
|
|
|
|
});
|
2015-12-08 16:39:49 -05:00
|
|
|
|
2016-04-08 18:05:52 -04:00
|
|
|
// Miscellaneous Classes
|
2016-08-29 14:51:32 -04:00
|
|
|
$container->set('auth', function($container) {
|
|
|
|
return new HummingbirdAuth($container);
|
|
|
|
});
|
|
|
|
$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
|