1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class for rendering urls to be easily able to switch between clean urls and querystrings |
4
|
|
|
* |
5
|
|
|
* PHP version 5.5 |
6
|
|
|
* |
7
|
|
|
* @category OpCacheGUI |
8
|
|
|
* @package Presentation |
9
|
|
|
* @author Pieter Hordijk <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2014 Pieter Hordijk <https://github.com/PeeHaa> |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
12
|
|
|
* @version 1.0.0 |
13
|
|
|
*/ |
14
|
|
|
namespace OpCacheGUI\Presentation; |
15
|
|
|
|
16
|
|
|
use OpCacheGUI\Network\Router; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class for rendering urls to be easily able to switch between clean urls and querystrings |
20
|
|
|
* |
21
|
|
|
* @category OpCacheGUI |
22
|
|
|
* @package Presentation |
23
|
|
|
* @author Pieter Hordijk <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Url implements UrlRenderer |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* private int The type of the URIs |
29
|
|
|
*/ |
30
|
|
|
private $type; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates instance |
34
|
|
|
* |
35
|
|
|
* @param int $type The type of the URIs |
36
|
|
|
*/ |
37
|
5 |
|
public function __construct($type) |
38
|
|
|
{ |
39
|
5 |
|
$this->type = $type; |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Gets the URI based on the type |
44
|
|
|
* |
45
|
|
|
* @param string $identifier The identifier used for which to get the URI |
46
|
|
|
* |
47
|
|
|
* @return string The URI |
48
|
|
|
*/ |
49
|
4 |
|
public function get($identifier) |
50
|
|
|
{ |
51
|
4 |
|
if ($this->type === Router::URL_REWRITE) { |
52
|
2 |
|
return $this->getRewriteUrl($identifier); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
return $this->getQueryStringUrl($identifier); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Gets the URI based on the rewrite scheme |
60
|
|
|
* |
61
|
|
|
* @param string $identifier The identifier used for which to get the URI |
62
|
|
|
* |
63
|
|
|
* @return string The URI |
64
|
|
|
*/ |
65
|
2 |
|
private function getRewriteUrl($identifier) |
66
|
|
|
{ |
67
|
2 |
|
if ($identifier === 'status') { |
68
|
1 |
|
return '..'; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
return '/' . $identifier; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Gets the URI based on query strings |
76
|
|
|
* |
77
|
|
|
* @param string $identifier The identifier used for which to get the URI |
78
|
|
|
* |
79
|
|
|
* @return string The URI |
80
|
|
|
*/ |
81
|
2 |
|
private function getQueryStringUrl($identifier) |
82
|
|
|
{ |
83
|
2 |
|
if ($identifier === 'status') { |
84
|
1 |
|
return '?'; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
return '?' . $identifier; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|