HummingBirdAnimeClient/src/Util.php

114 lines
2.2 KiB
PHP
Raw Normal View History

2016-10-20 22:09:36 -04:00
<?php declare(strict_types=1);
2016-08-30 10:57:41 -04:00
/**
* Hummingbird Anime List Client
2016-08-30 10:57:41 -04:00
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
2016-08-30 10:57:41 -04:00
*
2016-10-20 22:09:36 -04:00
* PHP version 7
2016-08-30 10:57:41 -04:00
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2018-01-15 14:43:15 -05:00
* @copyright 2015 - 2018 Timothy J. Warren
2016-08-30 10:57:41 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
2016-08-30 10:57:41 -04:00
*/
namespace Aviat\AnimeClient;
use Aviat\Ion\ConfigInterface;
2016-12-20 12:58:37 -05:00
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use DomainException;
2016-08-30 10:57:41 -04:00
/**
* Utility method class
*/
class Util {
2016-12-20 12:58:37 -05:00
use ContainerAware;
2016-08-30 10:57:41 -04:00
/**
* Routes that don't require a second navigation level
* @var array
*/
2017-02-16 14:30:06 -05:00
private static $formPages = [
2016-08-30 10:57:41 -04:00
'edit',
'add',
'update',
'update_form',
'login',
'logout',
2017-03-08 12:55:49 -05:00
'details',
2017-03-08 13:46:50 -05:00
'character',
'me'
2016-08-30 10:57:41 -04:00
];
/**
* The config manager
* @var ConfigInterface
*/
private $config;
/**
* Set up the Util class
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->setContainer($container);
$this->config = $container->get('config');
}
/**
* HTML selection helper function
*
* @param string $a - First item to compare
* @param string $b - Second item to compare
* @return string
*/
2017-02-16 14:30:06 -05:00
public static function isSelected($a, $b)
2016-08-30 10:57:41 -04:00
{
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
*/
2017-02-16 14:30:06 -05:00
public static function isNotSelected($a, $b)
2016-08-30 10:57:41 -04:00
{
return ($a !== $b) ? 'selected' : '';
}
/**
* Determine whether to show the sub-menu
*
* @return bool
*/
2017-02-16 14:30:06 -05:00
public function isViewPage()
2016-08-30 10:57:41 -04:00
{
2017-03-22 11:15:40 -04:00
$url = $this->container->get('request')->getUri();
2017-02-16 14:30:06 -05:00
$pageSegments = explode("/", (string) $url);
2016-08-30 10:57:41 -04:00
2017-02-16 14:30:06 -05:00
$intersect = array_intersect($pageSegments, self::$formPages);
2016-08-30 10:57:41 -04:00
return empty($intersect);
}
/**
* Determine whether the page is a page with a form, and
* not suitable for redirection
*
* @return boolean
*/
2017-02-16 14:30:06 -05:00
public function isFormPage()
2016-08-30 10:57:41 -04:00
{
2017-02-16 14:30:06 -05:00
return ! $this->isViewPage();
2016-08-30 10:57:41 -04:00
}
}
2016-08-30 10:57:41 -04:00