Some minor refactoring
This commit is contained in:
parent
9b38242f9d
commit
beb127c06c
5
.gitignore
vendored
5
.gitignore
vendored
@ -12,3 +12,8 @@ composer.lock
|
||||
docs/*
|
||||
coverage/*
|
||||
tests/test_data/sessions/*
|
||||
build/coverage/*
|
||||
build/logs/*
|
||||
build/pdepend/*
|
||||
build/phpdox/*
|
||||
cache.properties
|
30
phpunit.xml
30
phpunit.xml
@ -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>
|
@ -72,6 +72,8 @@ class Controller {
|
||||
$this->request = $container->get('request');
|
||||
$this->response = $container->get('response');
|
||||
$this->base_data['urlGenerator'] = $urlGenerator;
|
||||
$this->base_data['auth'] = $container->get('auth');
|
||||
$this->base_data['config'] = $this->config;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ class Controller {
|
||||
* @param array $data
|
||||
* @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->addDataTable('Template Data', $data);
|
||||
@ -143,23 +145,69 @@ class Controller {
|
||||
* @param array $data
|
||||
* @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, $template, $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
|
||||
*
|
||||
* @param string $template
|
||||
* @param array $data
|
||||
* @param HtmlView $view
|
||||
* @return void
|
||||
*/
|
||||
public function outputHTML($template, array $data = [])
|
||||
protected function outputHTML($template, array $data = [], $view = NULL)
|
||||
{
|
||||
if (is_null($view))
|
||||
{
|
||||
$view = new HtmlView($this->container);
|
||||
}
|
||||
|
||||
$this->render_full_page($view, $template, $data);
|
||||
}
|
||||
|
||||
@ -169,7 +217,7 @@ class Controller {
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function outputJSON($data = [])
|
||||
protected function outputJSON($data = [])
|
||||
{
|
||||
$view = new JsonView($this->container);
|
||||
$view->setOutput($data);
|
||||
@ -182,7 +230,7 @@ class Controller {
|
||||
* @param int $code
|
||||
* @return void
|
||||
*/
|
||||
public function redirect($url, $code)
|
||||
protected function redirect($url, $code)
|
||||
{
|
||||
$http = new HttpView($this->container);
|
||||
$http->redirect($url, $code);
|
||||
|
@ -73,8 +73,15 @@ class Anime extends BaseController {
|
||||
'completed' => AnimeWatchingStatus::COMPLETED
|
||||
];
|
||||
|
||||
if (array_key_exists($type, $type_title_map))
|
||||
{
|
||||
$title = $this->config->get('whose_list') .
|
||||
"'s Anime List · {$type_title_map[$type]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = '';
|
||||
}
|
||||
|
||||
$view_map = [
|
||||
'' => 'cover',
|
||||
|
@ -60,6 +60,12 @@ class Dispatcher extends RoutingBase {
|
||||
'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}')
|
||||
->setValues([
|
||||
'controller' => $this->routes['convention']['default_controller'],
|
||||
@ -68,13 +74,6 @@ class Dispatcher extends RoutingBase {
|
||||
'type' => '[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' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,8 +180,7 @@ class Manga extends API {
|
||||
*/
|
||||
private function zipper_lists($raw_data)
|
||||
{
|
||||
$zipper = new Transformer\MangaListsZipper($raw_data);
|
||||
return $zipper->transform();
|
||||
return (new Transformer\MangaListsZipper($raw_data))->transform();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,13 +17,13 @@ class Friend {
|
||||
* Object to create a friend of
|
||||
* @var object
|
||||
*/
|
||||
private $_friend_object_;
|
||||
private $_friend_;
|
||||
|
||||
/**
|
||||
* Reflection class of the object
|
||||
* @var object
|
||||
*/
|
||||
private $_reflection_friend_;
|
||||
private $_reflect_;
|
||||
|
||||
/**
|
||||
* Create a friend object
|
||||
@ -37,8 +37,8 @@ class Friend {
|
||||
throw new InvalidArgumentException("Friend must be an object");
|
||||
}
|
||||
|
||||
$this->_friend_object_ = $obj;
|
||||
$this->_reflection_friend_ = new ReflectionClass($obj);
|
||||
$this->_friend_ = $obj;
|
||||
$this->_reflect_ = new ReflectionClass($obj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,10 +49,10 @@ class Friend {
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if ($this->_reflection_friend_->hasProperty($key))
|
||||
if ($this->_reflect_->hasProperty($key))
|
||||
{
|
||||
$property = $this->_get_property($key);
|
||||
return $property->getValue($this->_friend_object_);
|
||||
return $property->getValue($this->_friend_);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -67,10 +67,10 @@ class Friend {
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
if ($this->_reflection_friend_->hasProperty($key))
|
||||
if ($this->_reflect_->hasProperty($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)
|
||||
{
|
||||
if ( ! $this->_reflection_friend_->hasMethod($method))
|
||||
if ( ! $this->_reflect_->hasMethod($method))
|
||||
{
|
||||
throw new BadMethodCallException("Method '{$method}' does not exist");
|
||||
}
|
||||
|
||||
$friendMethod = new ReflectionMethod($this->_friend_object_, $method);
|
||||
$friendMethod = new ReflectionMethod($this->_friend_, $method);
|
||||
$friendMethod->setAccessible(TRUE);
|
||||
return $friendMethod->invokeArgs($this->_friend_object_, $args);
|
||||
return $friendMethod->invokeArgs($this->_friend_, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class Friend {
|
||||
{
|
||||
try
|
||||
{
|
||||
$property = $this->_reflection_friend_->getProperty($name);
|
||||
$property = $this->_reflect_->getProperty($name);
|
||||
$property->setAccessible(TRUE);
|
||||
return $property;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user