1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* Hummingbird Anime Client |
4
|
|
|
* |
5
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists |
6
|
|
|
* |
7
|
|
|
* PHP version 7 |
8
|
|
|
* |
9
|
|
|
* @package HummingbirdAnimeClient |
10
|
|
|
* @author Timothy J. Warren <[email protected]> |
11
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
13
|
|
|
* @version 3.1 |
14
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Aviat\AnimeClient; |
18
|
|
|
|
19
|
|
|
use Aviat\Ion\ConfigInterface; |
20
|
|
|
use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; |
21
|
|
|
use DomainException; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Utility method class |
25
|
|
|
*/ |
26
|
|
|
class Util { |
27
|
|
|
|
28
|
|
|
use ContainerAware; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Routes that don't require a second navigation level |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private static $form_pages = [ |
35
|
|
|
'edit', |
36
|
|
|
'add', |
37
|
|
|
'update', |
38
|
|
|
'update_form', |
39
|
|
|
'login', |
40
|
|
|
'logout', |
41
|
|
|
'details' |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The config manager |
46
|
|
|
* @var ConfigInterface |
47
|
|
|
*/ |
48
|
|
|
private $config; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Set up the Util class |
52
|
|
|
* |
53
|
|
|
* @param ContainerInterface $container |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
public function __construct(ContainerInterface $container) |
56
|
|
|
{ |
57
|
|
|
$this->setContainer($container); |
58
|
|
|
$this->config = $container->get('config'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* HTML selection helper function |
63
|
|
|
* |
64
|
|
|
* @param string $a - First item to compare |
65
|
|
|
* @param string $b - Second item to compare |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public static function is_selected($a, $b) |
69
|
|
|
{ |
70
|
|
|
return ($a === $b) ? 'selected' : ''; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Inverse of selected helper function |
75
|
|
|
* |
76
|
|
|
* @param string $a - First item to compare |
77
|
|
|
* @param string $b - Second item to compare |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public static function is_not_selected($a, $b) |
81
|
|
|
{ |
82
|
|
|
return ($a !== $b) ? 'selected' : ''; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Determine whether to show the sub-menu |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function is_view_page() |
91
|
|
|
{ |
92
|
|
|
$url = $this->container->get('request') |
93
|
|
|
->getUri(); |
94
|
|
|
$page_segments = explode("/", (string) $url); |
95
|
|
|
|
96
|
|
|
$intersect = array_intersect($page_segments, self::$form_pages); |
97
|
|
|
|
98
|
|
|
return empty($intersect); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Determine whether the page is a page with a form, and |
103
|
|
|
* not suitable for redirection |
104
|
|
|
* |
105
|
|
|
* @return boolean |
106
|
|
|
*/ |
107
|
|
|
public function is_form_page() |
108
|
|
|
{ |
109
|
|
|
return ! $this->is_view_page(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.