HummingBirdAnimeClient/app/bootstrap.php

96 lines
3.0 KiB
PHP
Raw Normal View History

2015-06-29 09:46:49 -04:00
<?php
2015-12-08 14:52:59 -05:00
/**
* Bootstrap / Dependency Injection
*/
2015-09-14 19:54:34 -04:00
namespace Aviat\AnimeClient;
2015-06-29 09:46:49 -04:00
use Aura\Html\HelperLocatorFactory;
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;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response;
2015-11-13 16:31:01 -05:00
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;
// -----------------------------------------------------------------------------
// 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');
$app_logger->pushHandler(new RotatingFileHandler(__DIR__ . '/logs/app.log', Logger::NOTICE));
$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
2015-10-09 14:34:55 -04:00
$config = new Config($config_array);
2015-09-17 23:11:18 -04:00
$container->set('config', $config);
// Create Cache Object
$container->set('cache', new CacheManager($container));
2015-09-17 23:11:18 -04:00
// Create Aura Router Object
$container->set('aura-router', new RouterContainer);
2015-09-17 23:11:18 -04:00
// Create Html helper Object
$html_helper = (new HelperLocatorFactory)->newInstance();
$html_helper->set('menu', function() use ($container) {
$menu_helper = new Helper\Menu();
$menu_helper->setContainer($container);
return $menu_helper;
});
$container->set('html-helper', $html_helper);
2015-09-17 23:11:18 -04:00
// Create Request/Response Objects
$request = ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$container->set('request', $request);
$container->set('response', new Response());
2015-09-17 23:11:18 -04:00
// Create session Object
$session = (new SessionFactory())->newInstance($_COOKIE);
$container->set('session', $session);
2015-11-16 19:30:04 -05:00
// Miscellaneous helper methods
$anime_client = new AnimeClient();
$anime_client->setContainer($container);
2016-01-04 10:53:03 -05:00
$container->set('anime-client', $anime_client);
2015-09-17 23:11:18 -04:00
2015-12-08 16:39:49 -05:00
// Models
$container->set('api-model', new Model\API($container));
$container->set('anime-model', new Model\Anime($container));
$container->set('manga-model', new Model\Manga($container));
$container->set('anime-collection-model', new Model\AnimeCollection($container));
2016-04-08 18:05:52 -04:00
// Miscellaneous Classes
2015-12-08 16:39:49 -05:00
$container->set('auth', new HummingbirdAuth($container));
2016-04-08 18:05:52 -04:00
$container->set('url-generator', 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
// -------------------------------------------------------------------------
2015-10-09 14:34:55 -04:00
$container->set('dispatcher', new Dispatcher($container));
2015-09-17 23:11:18 -04:00
return $container;
};
// End of bootstrap.php