Remove loose functions file

This commit is contained in:
Timothy Warren 2015-11-16 19:30:04 -05:00
parent 49b3f507a6
commit 5d2cad4690
9 changed files with 104 additions and 94 deletions

View File

@ -70,6 +70,11 @@ return function(array $config_array = []) {
$container->set('url-generator', new UrlGenerator($container)); $container->set('url-generator', new UrlGenerator($container));
$container->set('auth', new HummingbirdAuth($container)); $container->set('auth', new HummingbirdAuth($container));
// Miscellaneous helper methods
$anime_client = new AnimeClient();
$anime_client->setContainer($container);
$container->set('anime_client', $anime_client);
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Dispatcher // Dispatcher
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------

View File

@ -1,3 +1,4 @@
<?php namespace Aviat\AnimeClient ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -26,11 +27,11 @@
</h1> </h1>
<nav> <nav>
<?= $helper->menu($menu_name) ?> <?= $helper->menu($menu_name) ?>
<?php if (is_view_page()): ?> <?php if ($container->get('anime_client')->is_view_page()): ?>
<br /> <br />
<ul> <ul>
<li class="<?= is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li> <li class="<?= AnimeClient::is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li> <li class="<?= AnimeClient::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul> </ul>
<?php endif ?> <?php endif ?>
</nav> </nav>

View File

@ -56,7 +56,6 @@ spl_autoload_register(function($class) {
}); });
require _dir(ROOT_DIR, '/vendor/autoload.php'); require _dir(ROOT_DIR, '/vendor/autoload.php');
require _dir(SRC_DIR, '/functions.php');
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Setup error handling // Setup error handling

View File

@ -0,0 +1,61 @@
<?php
/**
* Hummingbird Anime Client
*
* An API client for Hummingbird to manage anime and manga watch lists
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren
* @copyright Copyright (c) 2015
* @link https://github.com/timw4mail/HummingBirdAnimeClient
* @license MIT
*/
namespace Aviat\AnimeClient;
class AnimeClient {
use \Aviat\Ion\Di\ContainerAware;
/**
* HTML selection helper function
*
* @param string $a - First item to compare
* @param string $b - Second item to compare
* @return string
*/
public static function is_selected($a, $b)
{
return ($a === $b) ? 'selected' : '';
}
/**
* Inverse of selected helper function
*
* @param string $a - First item to compare
* @param string $b - Second item to compare
* @return string
*/
public static function is_not_selected($a, $b)
{
return ($a !== $b) ? 'selected' : '';
}
/**
* Determine whether to show the sub-menu
*
* @return bool
*/
public function is_view_page()
{
$url = $this->container->get('request')
->server->get('REQUEST_URI');
$blacklist = ['edit', 'add', 'update', 'login', 'logout'];
$page_segments = explode("/", $url);
$intersect = array_intersect($page_segments, $blacklist);
return empty($intersect);
}
}
// End of anime_client.php

View File

@ -56,6 +56,7 @@ class HtmlView extends HttpView {
{ {
$data['helper'] = $this->helper; $data['helper'] = $this->helper;
$data['escape'] = $this->helper->escape(); $data['escape'] = $this->helper->escape();
$data['container'] = $this->container;
ob_start(); ob_start();
extract($data); extract($data);

View File

@ -1,57 +0,0 @@
<?php
/**
* Hummingbird Anime Client
*
* An API client for Hummingbird to manage anime and manga watch lists
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren
* @copyright Copyright (c) 2015
* @link https://github.com/timw4mail/HummingBirdAnimeClient
* @license MIT
*/
/**
* Global functions
*/
/**
* HTML selection helper function
*
* @param string $a - First item to compare
* @param string $b - Second item to compare
* @return string
*/
function is_selected($a, $b)
{
return ($a === $b) ? 'selected' : '';
}
/**
* Inverse of selected helper function
*
* @param string $a - First item to compare
* @param string $b - Second item to compare
* @return string
*/
function is_not_selected($a, $b)
{
return ($a !== $b) ? 'selected' : '';
}
/**
* Determine whether to show the sub-menu
*
* @return bool
*/
function is_view_page()
{
$blacklist = ['edit', 'add', 'update', 'login', 'logout'];
$page_segments = explode("/", $_SERVER['REQUEST_URI']);
$intersect = array_intersect($page_segments, $blacklist);
return empty($intersect);
}
// End of functions.php

View File

@ -0,0 +1,33 @@
<?php
use Aviat\AnimeClient\AnimeClient;
class AnimeClientTest extends AnimeClient_TestCase {
/**
* Basic sanity test for _dir function
*/
public function testDir()
{
$this->assertEquals('foo' . DIRECTORY_SEPARATOR . 'bar', \_dir('foo', 'bar'));
}
public function testIsSelected()
{
// Failure to match
$this->assertEquals('', AnimeClient::is_selected('foo', 'bar'));
// Matches
$this->assertEquals('selected', AnimeClient::is_selected('foo', 'foo'));
}
public function testIsNotSelected()
{
// Failure to match
$this->assertEquals('selected', AnimeClient::is_not_selected('foo', 'bar'));
// Matches
$this->assertEquals('', AnimeClient::is_not_selected('foo', 'foo'));
}
}

View File

@ -1,32 +0,0 @@
<?php
use \AnimeClient\Config;
class FunctionsTest extends AnimeClient_TestCase {
/**
* Basic sanity test for _dir function
*/
public function testDir()
{
$this->assertEquals('foo' . DIRECTORY_SEPARATOR . 'bar', _dir('foo', 'bar'));
}
public function testIsSelected()
{
// Failure to match
$this->assertEquals('', is_selected('foo', 'bar'));
// Matches
$this->assertEquals('selected', is_selected('foo', 'foo'));
}
public function testIsNotSelected()
{
// Failure to match
$this->assertEquals('selected', is_not_selected('foo', 'bar'));
// Matches
$this->assertEquals('', is_not_selected('foo', 'foo'));
}
}

View File

@ -27,7 +27,6 @@ define('BASE_DIR', _dir(SRC_DIR, 'Base'));
define('TEST_DATA_DIR', _dir(__DIR__, 'test_data')); define('TEST_DATA_DIR', _dir(__DIR__, 'test_data'));
define('TEST_VIEW_DIR', _dir(__DIR__, 'test_views')); define('TEST_VIEW_DIR', _dir(__DIR__, 'test_views'));
require _dir(ROOT_DIR, '/vendor/autoload.php'); require _dir(ROOT_DIR, '/vendor/autoload.php');
require _dir(SRC_DIR, '/functions.php');
/** /**
* Set up autoloaders * Set up autoloaders