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
|
|
|
$query = (array)$this->url->query; |
58
|
|
|
$url = clone($this->url); |
59
|
|
|
ar::untaint($query, FILTER_UNSAFE_RAW); |
60
|
|
|
$url->query->import($query); |
61
|
|
|
return (string)$url; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getvar( $name ) { |
65
|
|
|
return $this->query->$name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function putvar( $name, $value ) { |
69
|
|
|
$this->query->{$name} = $value; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function import( $values ) { |
73
|
|
|
$this->query->import( $values ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
class ar_urlQuery implements arKeyValueStoreInterface, ArrayAccess /*, ArrayAcces, IteratorAggregate, .. */ { |
79
|
|
|
private $query; |
80
|
|
|
|
81
|
|
|
public function __construct( $query ) { |
82
|
|
|
if ( $query instanceof \arc\url\Query ){ |
83
|
|
|
$this->query = $query; |
84
|
|
|
} else { |
85
|
|
|
$this->query = new \arc\url\PHPQuery($query); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function __setQuery($url, $query) { |
90
|
|
|
if ( $url->query === $this->query ) { |
91
|
|
|
$url->query = $this->query = $query->query; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
public function __call( $name, $arguments ) { |
96
|
|
|
if (($name[0]==='_')) { |
97
|
|
|
$realName = substr($name, 1); |
98
|
|
|
if (ar_pinp::isAllowed($this, $realName)) { |
99
|
|
|
return call_user_func_array(array($this, $realName), $arguments); |
100
|
|
|
} else { |
101
|
|
|
trigger_error("Method $realName not found in class ".get_class($this), E_USER_WARNING); |
102
|
|
|
} |
103
|
|
|
} else { |
104
|
|
|
trigger_error("Method $name not found in class ".get_class($this), E_USER_WARNING); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function &__get( $name ) { |
109
|
|
|
return $this->query->{$name}; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function __set( $name, $value ) { |
113
|
|
|
$this->query->{$name} = $value; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getvar( $name ) { |
117
|
|
|
return $this->query->{$name}; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function putvar( $name, $value ) { |
121
|
|
|
$this->query->{$name} = $value; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function __toString() { |
125
|
|
|
$q = clone $this->query; |
126
|
|
|
$qa = (array)$q; |
127
|
|
|
ar::untaint($qa, FILTER_UNSAFE_RAW); |
128
|
|
|
$q->import($qa); |
129
|
|
|
return (string)$q; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function import( $values ) { |
133
|
|
|
$this->query->import( $values ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function offsetExists($name){ |
137
|
|
|
return isset($this->query->{$name}); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function &offsetGet($name) { |
141
|
|
|
return $this->query->{$name}; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function offsetSet($name, $value) { |
145
|
|
|
$this->query->{$name} = $value; |
146
|
|
|
} |
147
|
|
|
public function offsetUnset($name) { |
148
|
|
|
unset($this->query->{$name}); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: