Some code style fixes

This commit is contained in:
Timothy Warren 2015-12-08 16:39:49 -05:00
parent bfb8500386
commit 6ca086d85b
9 changed files with 42 additions and 13 deletions

View File

@ -15,6 +15,7 @@ use Monolog\Handler\BrowserConsoleHandler;
use Aviat\Ion\Di\Container; use Aviat\Ion\Di\Container;
use Aviat\AnimeClient\Auth\HummingbirdAuth; use Aviat\AnimeClient\Auth\HummingbirdAuth;
use Aviat\AnimeClient\Model;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Setup DI container // Setup DI container
@ -68,13 +69,21 @@ return function(array $config_array = []) {
$container->set('session', $session); $container->set('session', $session);
$container->set('url-generator', new UrlGenerator($container)); $container->set('url-generator', new UrlGenerator($container));
$container->set('auth', new HummingbirdAuth($container));
// Miscellaneous helper methods // Miscellaneous helper methods
$anime_client = new AnimeClient(); $anime_client = new AnimeClient();
$anime_client->setContainer($container); $anime_client->setContainer($container);
$container->set('anime_client', $anime_client); $container->set('anime_client', $anime_client);
// 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));
$container->set('auth', new HummingbirdAuth($container));
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Dispatcher // Dispatcher
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------

View File

@ -47,7 +47,7 @@ class HummingbirdAuth {
$this->setContainer($container); $this->setContainer($container);
$this->segment = $container->get('session') $this->segment = $container->get('session')
->getSegment(__NAMESPACE__); ->getSegment(__NAMESPACE__);
$this->model = new API($container); $this->model = $container->get('api-model');
} }
/** /**

View File

@ -44,7 +44,7 @@ class Anime extends BaseController {
{ {
parent::__construct($container); parent::__construct($container);
$this->model = new AnimeModel($container); $this->model = $container->get('anime-model');
$this->base_data = array_merge($this->base_data, [ $this->base_data = array_merge($this->base_data, [
'menu_name' => 'anime_list', 'menu_name' => 'anime_list',
'message' => '', 'message' => '',

View File

@ -53,8 +53,8 @@ class Collection extends BaseController {
parent::__construct($container); parent::__construct($container);
$this->urlGenerator = $container->get('url-generator'); $this->urlGenerator = $container->get('url-generator');
$this->anime_model = new AnimeModel($container); $this->anime_model = $container->get('anime-model');
$this->anime_collection_model = new AnimeCollectionModel($container); $this->anime_collection_model = $container->get('anime-collection-model');
$this->base_data = array_merge($this->base_data, [ $this->base_data = array_merge($this->base_data, [
'menu_name' => 'collection', 'menu_name' => 'collection',
'message' => '', 'message' => '',

View File

@ -43,7 +43,7 @@ class Manga extends Controller {
{ {
parent::__construct($container); parent::__construct($container);
$this->model = new MangaModel($container); $this->model = $container->get('manga-model');
$this->base_data = array_merge($this->base_data, [ $this->base_data = array_merge($this->base_data, [
'menu_name' => 'manga_list', 'menu_name' => 'manga_list',
'config' => $this->config, 'config' => $this->config,

View File

@ -60,6 +60,16 @@ class API extends BaseModel {
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
parent::__construct($container); parent::__construct($container);
$this->init();
}
/**
* Set up the class properties
*
* @return void
*/
protected function init()
{
$this->cookieJar = new CookieJar(); $this->cookieJar = new CookieJar();
$this->client = new Client([ $this->client = new Client([
'base_uri' => $this->base_url, 'base_uri' => $this->base_url,

View File

@ -51,7 +51,7 @@ class AnimeCollection extends DB {
$this->valid_database = FALSE; $this->valid_database = FALSE;
return FALSE; return FALSE;
} }
$this->anime_model = new AnimeModel($container); $this->anime_model = $container->get('anime-model');
// Is database valid? If not, set a flag so the // Is database valid? If not, set a flag so the
// app can be run without a valid database // app can be run without a valid database

View File

@ -12,7 +12,6 @@
namespace Aviat\Ion\Di; namespace Aviat\Ion\Di;
use ArrayObject;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
@ -41,8 +40,8 @@ class Container implements ContainerInterface {
*/ */
public function __construct(array $values = []) public function __construct(array $values = [])
{ {
$this->container = new ArrayObject($values); $this->container = $values;
$this->loggers = new ArrayObject([]); $this->loggers = [];
} }
/** /**
@ -93,7 +92,7 @@ class Container implements ContainerInterface {
*/ */
public function has($id) public function has($id)
{ {
return $this->container->offsetExists($id); return array_key_exists($id, $this->container);
} }
/** /**
@ -103,7 +102,7 @@ class Container implements ContainerInterface {
*/ */
public function hasLogger($key = 'default') public function hasLogger($key = 'default')
{ {
return $this->loggers->offsetExists($key); return array_key_exists($key, $this->loggers);
} }
/** /**

View File

@ -36,7 +36,18 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
'asset_path' => '//localhost/assets/', 'asset_path' => '//localhost/assets/',
'img_cache_path' => _dir(ROOT_DIR, 'public/images'), 'img_cache_path' => _dir(ROOT_DIR, 'public/images'),
'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'), 'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'),
'database' => [], 'database' => [
'collection' => [
'type' => 'sqlite',
'host' => '',
'user' => '',
'pass' => '',
'port' => '',
'name' => 'default',
'database' => '',
'file' => ':memory:',
]
],
'routing' => [ 'routing' => [
'asset_path' => '/assets' 'asset_path' => '/assets'
], ],