2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-04-19 13:02:50 -04:00
|
|
|
/**
|
2016-12-20 12:58:37 -05:00
|
|
|
* Anime List Client
|
2016-04-19 13:02:50 -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-04-19 13:02:50 -04:00
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2016-12-20 12:58:37 -05:00
|
|
|
* @package AnimeListClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2017-01-11 10:30:53 -05:00
|
|
|
* @copyright 2015 - 2017 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
|
2016-04-19 13:02:50 -04:00
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
2017-01-11 10:30:53 -05:00
|
|
|
*/namespace Aviat\AnimeClient\Command;
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
use Aura\Session\SessionFactory;
|
|
|
|
use Aviat\AnimeClient\AnimeClient;
|
|
|
|
use Aviat\AnimeClient\Auth\HummingbirdAuth;
|
|
|
|
use Aviat\AnimeClient\Model;
|
2016-07-28 10:44:13 -04:00
|
|
|
use Aviat\AnimeClient\Util;
|
2016-10-20 22:32:17 -04:00
|
|
|
use Aviat\Ion\Cache\CacheManager;
|
|
|
|
use Aviat\Ion\Config;
|
|
|
|
use Aviat\Ion\Di\Container;
|
|
|
|
use ConsoleKit\Command;
|
|
|
|
use ConsoleKit\Widgets\Box;
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for console command setup
|
|
|
|
*/
|
2016-04-19 14:51:58 -04:00
|
|
|
class BaseCommand extends Command {
|
2016-04-19 13:02:50 -04:00
|
|
|
use \Aviat\Ion\Di\ContainerAware;
|
|
|
|
|
2016-04-19 14:51:58 -04:00
|
|
|
/**
|
|
|
|
* Echo text in a box
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function echoBox($message)
|
|
|
|
{
|
|
|
|
echo "\n";
|
|
|
|
$box = new Box($this->getConsole(), $message);
|
|
|
|
$box->write();
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the Di container
|
|
|
|
*
|
|
|
|
* @return Container
|
|
|
|
*/
|
2016-04-19 13:02:50 -04:00
|
|
|
protected function setupContainer()
|
|
|
|
{
|
2016-08-29 16:36:13 -04:00
|
|
|
$CONF_DIR = realpath(__DIR__ . '/../../app/config/');
|
2016-04-19 13:02:50 -04:00
|
|
|
require_once $CONF_DIR . '/base_config.php'; // $base_config
|
|
|
|
|
2016-12-20 12:58:37 -05:00
|
|
|
$config = AnimeClient::loadToml($CONF_DIR);
|
2016-04-19 13:02:50 -04:00
|
|
|
$config_array = array_merge($base_config, $config);
|
|
|
|
|
|
|
|
$di = function ($config_array) {
|
|
|
|
$container = new Container();
|
|
|
|
|
|
|
|
// Create Config Object
|
2016-08-29 15:36:36 -04:00
|
|
|
$container->set('config', function() {
|
|
|
|
return new Config();
|
|
|
|
});
|
|
|
|
$container->setInstance('config', $config_array);
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
// Create Cache Object
|
2016-08-29 15:36:36 -04:00
|
|
|
$container->set('cache', function($container) {
|
|
|
|
return new CacheManager($container->get('config'));
|
|
|
|
});
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
// Create session Object
|
2016-08-29 15:36:36 -04:00
|
|
|
$container->set('session', function() {
|
|
|
|
return (new SessionFactory())->newInstance($_COOKIE);
|
|
|
|
});
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
// Models
|
2016-08-29 15:36:36 -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('auth', function($container) {
|
|
|
|
return new HummingbirdAuth($container);
|
|
|
|
});
|
|
|
|
$container->set('util', function($container) {
|
|
|
|
return new Util($container);
|
|
|
|
});
|
2016-04-19 13:02:50 -04:00
|
|
|
|
|
|
|
return $container;
|
|
|
|
};
|
|
|
|
|
|
|
|
return $di($config_array);
|
|
|
|
}
|
|
|
|
}
|