HummingBirdAnimeClient/app/bootstrap.php

68 lines
2.0 KiB
PHP
Raw Normal View History

2015-06-29 09:46:49 -04:00
<?php
/**
* Bootstrap / Dependency Injection
*/
2015-06-29 09:46:49 -04:00
2015-09-14 19:54:34 -04:00
namespace Aviat\AnimeClient;
2015-06-29 09:46:49 -04:00
use Aura\Html\HelperLocatorFactory;
2015-10-09 14:34:55 -04:00
use Aura\Web\WebFactory;
use Aura\Router\RouterFactory;
use Aura\Session\SessionFactory;
2015-09-17 23:11:18 -04:00
use Aviat\Ion\Di\Container;
2015-10-15 09:25:30 -04:00
use Aviat\AnimeClient\Auth\HummingbirdAuth;
// -----------------------------------------------------------------------------
// 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();
// -------------------------------------------------------------------------
// 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 Aura Router Object
$aura_router = (new RouterFactory())->newInstance();
$container->set('aura-router', $aura_router);
// 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
$web_factory = new WebFactory([
'_GET' => $_GET,
'_POST' => $_POST,
'_COOKIE' => $_COOKIE,
'_SERVER' => $_SERVER,
'_FILES' => $_FILES
]);
$container->set('request', $web_factory->newRequest());
$container->set('response', $web_factory->newResponse());
// Create session Object
$session = (new SessionFactory())->newInstance($_COOKIE);
$container->set('session', $session);
$container->set('url-generator', new UrlGenerator($container));
2015-10-15 09:25:30 -04:00
$container->set('auth', new HummingbirdAuth($container));
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