1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
ar_pinp::allow( 'ar_url'); |
4
|
|
|
ar_pinp::allow( 'ar_urlQuery' ); |
5
|
|
|
use \arc\url; |
|
|
|
|
6
|
|
|
|
7
|
|
|
class ar_url extends arBase implements arKeyValueStoreInterface { |
8
|
|
|
|
9
|
|
|
private $url, $query; |
|
|
|
|
10
|
|
|
|
11
|
|
|
public function __construct( $url ) { |
12
|
|
|
$query = new \arc\url\PHPQuery(); |
13
|
|
|
$this->url = new \arc\url\Url($url, $query); |
14
|
|
|
$this->query = new ar_urlQuery($query); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function __get($var) { |
18
|
|
|
if ($var=='password') { |
19
|
|
|
$var = 'pass'; |
20
|
|
|
} |
21
|
|
|
if ($var=='query') { |
22
|
|
|
return $this->query; |
23
|
|
|
} else if ( isset( $this->url->{$var} ) ) { |
24
|
|
|
return $this->url->{$var}; |
25
|
|
|
} else { |
26
|
|
|
return null; |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __set($var, $value) { |
31
|
|
|
switch($var) { |
32
|
|
|
case 'query' : |
|
|
|
|
33
|
|
|
if (is_string($value)) { |
34
|
|
|
$this->url->query = $value; |
35
|
|
|
$this->query = new ar_urlQuery($this->url->query); |
36
|
|
|
} else if ($value instanceof ar_urlQuery) { |
37
|
|
|
$this->url->query = (string) $value; |
38
|
|
|
} else if (is_object($value) && method_exists($value, '__toString') ) { |
39
|
|
|
$this->url->query = (string)$value; |
40
|
|
|
} |
41
|
|
|
break; |
42
|
|
|
case 'password' : |
|
|
|
|
43
|
|
|
$var = 'pass'; |
44
|
|
|
case 'path' : |
|
|
|
|
45
|
|
|
case 'scheme': |
46
|
|
|
case 'host' : |
|
|
|
|
47
|
|
|
case 'port' : |
|
|
|
|
48
|
|
|
case 'user' : |
|
|
|
|
49
|
|
|
case 'pass' : |
|
|
|
|
50
|
|
|
case 'fragment' : |
|
|
|
|
51
|
|
|
return $this->url->{$var} = $value; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function __toString() { |
57
|
|
|
return (string)$this->url; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getvar( $name ) { |
61
|
|
|
return $this->query->$name; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function putvar( $name, $value ) { |
65
|
|
|
$this->query->{$name} = $value; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function import( $values ) { |
69
|
|
|
$this->query->import( $values ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
class ar_urlQuery implements arKeyValueStoreInterface, ArrayAccess /*, ArrayAcces, IteratorAggregate, .. */ { |
|
|
|
|
75
|
|
|
private $query; |
76
|
|
|
|
77
|
|
|
public function __construct( $query ) { |
78
|
|
|
if ( $query instanceof \arc\url\Query ){ |
79
|
|
|
$this->query = $query; |
80
|
|
|
} else { |
81
|
|
|
$this->query = new \arc\url\PHPQuery($query); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function __setQuery($url, $query) { |
86
|
|
|
if ( $url->query === $this->query ) { |
87
|
|
|
$url->query = $this->query = $query->query; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public function __call( $name, $arguments ) { |
|
|
|
|
92
|
|
|
if (($name[0]==='_')) { |
93
|
|
|
$realName = substr($name, 1); |
94
|
|
|
if (ar_pinp::isAllowed($this, $realName)) { |
95
|
|
|
return call_user_func_array(array($this, $realName), $arguments); |
96
|
|
|
} else { |
97
|
|
|
trigger_error("Method $realName not found in class ".get_class($this), E_USER_WARNING); |
98
|
|
|
} |
99
|
|
|
} else { |
100
|
|
|
trigger_error("Method $name not found in class ".get_class($this), E_USER_WARNING); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function __get( $name ) { |
105
|
|
|
return $this->query->{$name}; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function __set( $name, $value ) { |
109
|
|
|
$this->query->{$name} = $value; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getvar( $name ) { |
113
|
|
|
return $this->query->{$name}; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function putvar( $name, $value ) { |
117
|
|
|
$this->query->{$name} = $value; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function __toString() { |
121
|
|
|
return (string)$this->query; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function import( $values ) { |
125
|
|
|
$this->query->import( $values ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function offsetExists($name){ |
129
|
|
|
return isset($this->query->{$name}); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function offsetGet($name) { |
133
|
|
|
return $this->query->{$name}; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function offsetSet($name, $value) { |
137
|
|
|
$this->query->{$name} = $value; |
138
|
|
|
} |
139
|
|
|
public function offsetUnset($name) { |
140
|
|
|
unset($this->query->{$name}); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.