Some minor refactoring

This commit is contained in:
Timothy Warren 2015-11-04 16:36:54 -05:00
parent 9b38242f9d
commit beb127c06c
7 changed files with 101 additions and 73 deletions

33
.gitignore vendored
View File

@ -1,14 +1,19 @@
.codelite .codelite
*.phprj *.phprj
*.workspace *.workspace
vendor vendor
app/cache/* app/cache/*
public/images/* public/images/*
public/js/cache/* public/js/cache/*
composer.lock composer.lock
*.sqlite *.sqlite
*.db *.db
*.sqlite3 *.sqlite3
docs/* docs/*
coverage/* coverage/*
tests/test_data/sessions/* tests/test_data/sessions/*
build/coverage/*
build/logs/*
build/pdepend/*
build/phpdox/*
cache.properties

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="true"
checkForUnintentionallyCoveredCode="true"
>
<filter>
<whitelist>
<directory suffix=".php">src/Aviat/Ion</directory>
<directory suffix=".php">src/Aviat/AnimeClient</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Ion">
<directory>tests/Ion</directory>
</testsuite>
<testsuite name="AnimeClient">
<directory>tests/AnimeClient</directory>
</testsuite>
</testsuites>
<php>
<server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" />
<server name="HTTP_HOST" value="localhost" />
<server name="SERVER_NAME" value="localhost" />
<server name="REQUEST_URI" value="/" />
<server name="REQUEST_METHOD" value="GET" />
</php>
</phpunit>

View File

@ -72,6 +72,8 @@ class Controller {
$this->request = $container->get('request'); $this->request = $container->get('request');
$this->response = $container->get('response'); $this->response = $container->get('response');
$this->base_data['urlGenerator'] = $urlGenerator; $this->base_data['urlGenerator'] = $urlGenerator;
$this->base_data['auth'] = $container->get('auth');
$this->base_data['config'] = $this->config;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
@ -110,7 +112,7 @@ class Controller {
* @param array $data * @param array $data
* @return string * @return string
*/ */
public function load_partial($view, $template, array $data = []) protected function load_partial($view, $template, array $data = [])
{ {
$errorHandler = $this->container->get('error-handler'); $errorHandler = $this->container->get('error-handler');
$errorHandler->addDataTable('Template Data', $data); $errorHandler->addDataTable('Template Data', $data);
@ -143,23 +145,69 @@ class Controller {
* @param array $data * @param array $data
* @return void * @return void
*/ */
public function render_full_page($view, $template, array $data) protected function render_full_page($view, $template, array $data)
{ {
$view->appendOutput($this->load_partial($view, 'header', $data)); $view->appendOutput($this->load_partial($view, 'header', $data));
$view->appendOutput($this->load_partial($view, $template, $data)); $view->appendOutput($this->load_partial($view, $template, $data));
$view->appendOutput($this->load_partial($view, 'footer', $data)); $view->appendOutput($this->load_partial($view, 'footer', $data));
} }
/**
* Show the login form
*
* @codeCoverageIgnore
* @param string $status
* @return void
*/
public function login($status="")
{
$message = "";
$view = new HtmlView($this->container);
if ($status != "")
{
$message = $this->show_message($view, 'error', $status);
}
$this->outputHTML('login', [
'title' => 'Api login',
'message' => $message
], $view);
}
/**
* Add a message box to the page
*
* @codeCoverageIgnore
* @param HtmlView $view
* @param string $type
* @param string $message
* @return string
*/
protected function show_message($view, $type, $message)
{
return $this->load_partial($view, 'message', [
'stat_class' => $type,
'message' => $message
]);
}
/** /**
* Output a template to HTML, using the provided data * Output a template to HTML, using the provided data
* *
* @param string $template * @param string $template
* @param array $data * @param array $data
* @param HtmlView $view
* @return void * @return void
*/ */
public function outputHTML($template, array $data = []) protected function outputHTML($template, array $data = [], $view = NULL)
{ {
$view = new HtmlView($this->container); if (is_null($view))
{
$view = new HtmlView($this->container);
}
$this->render_full_page($view, $template, $data); $this->render_full_page($view, $template, $data);
} }
@ -169,7 +217,7 @@ class Controller {
* @param mixed $data * @param mixed $data
* @return void * @return void
*/ */
public function outputJSON($data = []) protected function outputJSON($data = [])
{ {
$view = new JsonView($this->container); $view = new JsonView($this->container);
$view->setOutput($data); $view->setOutput($data);
@ -182,7 +230,7 @@ class Controller {
* @param int $code * @param int $code
* @return void * @return void
*/ */
public function redirect($url, $code) protected function redirect($url, $code)
{ {
$http = new HttpView($this->container); $http = new HttpView($this->container);
$http->redirect($url, $code); $http->redirect($url, $code);

View File

@ -73,8 +73,15 @@ class Anime extends BaseController {
'completed' => AnimeWatchingStatus::COMPLETED 'completed' => AnimeWatchingStatus::COMPLETED
]; ];
$title = $this->config->get('whose_list') . if (array_key_exists($type, $type_title_map))
"'s Anime List &middot; {$type_title_map[$type]}"; {
$title = $this->config->get('whose_list') .
"'s Anime List &middot; {$type_title_map[$type]}";
}
else
{
$title = '';
}
$view_map = [ $view_map = [
'' => 'cover', '' => 'cover',

View File

@ -60,6 +60,12 @@ class Dispatcher extends RoutingBase {
'action' => 'redirect_to_default' 'action' => 'redirect_to_default'
]); ]);
$this->output_routes[] = $this->router->add('login', '/{controller}/login')
->setValues([
'controller' => $this->routes['convention']['default_controller'],
'action' => 'login'
]);
$this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}') $this->output_routes[] = $this->router->add('list', '/{controller}/{type}{/view}')
->setValues([ ->setValues([
'controller' => $this->routes['convention']['default_controller'], 'controller' => $this->routes['convention']['default_controller'],
@ -68,13 +74,6 @@ class Dispatcher extends RoutingBase {
'type' => '[a-z_]+', 'type' => '[a-z_]+',
'view' => '[a-z_]+' 'view' => '[a-z_]+'
]); ]);
$this->output_routes[] = $this->router->add('generic', '{/controller,action,view}')
->setValues([
'controller' => $this->routes['convention']['default_controller'],
'action' => $this->routes['convention']['default_method'],
'view' => '',
]);
} }
/** /**

View File

@ -180,8 +180,7 @@ class Manga extends API {
*/ */
private function zipper_lists($raw_data) private function zipper_lists($raw_data)
{ {
$zipper = new Transformer\MangaListsZipper($raw_data); return (new Transformer\MangaListsZipper($raw_data))->transform();
return $zipper->transform();
} }
/** /**

View File

@ -17,13 +17,13 @@ class Friend {
* Object to create a friend of * Object to create a friend of
* @var object * @var object
*/ */
private $_friend_object_; private $_friend_;
/** /**
* Reflection class of the object * Reflection class of the object
* @var object * @var object
*/ */
private $_reflection_friend_; private $_reflect_;
/** /**
* Create a friend object * Create a friend object
@ -37,8 +37,8 @@ class Friend {
throw new InvalidArgumentException("Friend must be an object"); throw new InvalidArgumentException("Friend must be an object");
} }
$this->_friend_object_ = $obj; $this->_friend_ = $obj;
$this->_reflection_friend_ = new ReflectionClass($obj); $this->_reflect_ = new ReflectionClass($obj);
} }
/** /**
@ -49,10 +49,10 @@ class Friend {
*/ */
public function __get($key) public function __get($key)
{ {
if ($this->_reflection_friend_->hasProperty($key)) if ($this->_reflect_->hasProperty($key))
{ {
$property = $this->_get_property($key); $property = $this->_get_property($key);
return $property->getValue($this->_friend_object_); return $property->getValue($this->_friend_);
} }
return NULL; return NULL;
@ -67,10 +67,10 @@ class Friend {
*/ */
public function __set($key, $value) public function __set($key, $value)
{ {
if ($this->_reflection_friend_->hasProperty($key)) if ($this->_reflect_->hasProperty($key))
{ {
$property = $this->_get_property($key); $property = $this->_get_property($key);
$property->setValue($this->_friend_object_, $value); $property->setValue($this->_friend_, $value);
} }
} }
@ -83,14 +83,14 @@ class Friend {
*/ */
public function __call($method, $args) public function __call($method, $args)
{ {
if ( ! $this->_reflection_friend_->hasMethod($method)) if ( ! $this->_reflect_->hasMethod($method))
{ {
throw new BadMethodCallException("Method '{$method}' does not exist"); throw new BadMethodCallException("Method '{$method}' does not exist");
} }
$friendMethod = new ReflectionMethod($this->_friend_object_, $method); $friendMethod = new ReflectionMethod($this->_friend_, $method);
$friendMethod->setAccessible(TRUE); $friendMethod->setAccessible(TRUE);
return $friendMethod->invokeArgs($this->_friend_object_, $args); return $friendMethod->invokeArgs($this->_friend_, $args);
} }
/** /**
@ -104,7 +104,7 @@ class Friend {
{ {
try try
{ {
$property = $this->_reflection_friend_->getProperty($name); $property = $this->_reflect_->getProperty($name);
$property->setAccessible(TRUE); $property->setAccessible(TRUE);
return $property; return $property;
} }