@@ -140,6 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @param string id of this module |
143 | + * @param string $value |
|
143 | 144 | */ |
144 | 145 | public function setID($value) |
145 | 146 | { |
@@ -258,6 +259,7 @@ discard block |
||
258 | 259 | |
259 | 260 | /** |
260 | 261 | * Saves the current UrlManager instance to cache. |
262 | + * @param TUrlManager $manager |
|
261 | 263 | * @return boolean true if UrlManager instance was cached, false otherwise. |
262 | 264 | */ |
263 | 265 | protected function cacheUrlManager($manager) |
@@ -314,6 +316,7 @@ discard block |
||
314 | 316 | * by loading it as an application module and setting this property |
315 | 317 | * with the module ID. |
316 | 318 | * @param string the ID of the URL manager module |
319 | + * @param string $value |
|
317 | 320 | */ |
318 | 321 | public function setUrlManager($value) |
319 | 322 | { |
@@ -349,7 +352,7 @@ discard block |
||
349 | 352 | } |
350 | 353 | |
351 | 354 | /** |
352 | - * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get. |
|
355 | + * @return string the format of URLs. Defaults to THttpRequestUrlFormat::Get. |
|
353 | 356 | */ |
354 | 357 | public function getUrlFormat() |
355 | 358 | { |
@@ -379,6 +382,7 @@ discard block |
||
379 | 382 | |
380 | 383 | /** |
381 | 384 | * @param string separator used to separate GET variable name and value when URL format is Path. |
385 | + * @param string $value |
|
382 | 386 | * @throws TInvalidDataValueException if the separator is not a single character |
383 | 387 | */ |
384 | 388 | public function setUrlParamSeparator($value) |
@@ -620,6 +624,7 @@ discard block |
||
620 | 624 | |
621 | 625 | /** |
622 | 626 | * @param boolean whether cookies should be validated. |
627 | + * @param boolean $value |
|
623 | 628 | */ |
624 | 629 | public function setEnableCookieValidation($value) |
625 | 630 | { |
@@ -710,6 +715,7 @@ discard block |
||
710 | 715 | * @param array GET parameters, null if not needed |
711 | 716 | * @param boolean whether to encode the ampersand in URL, defaults to true. |
712 | 717 | * @param boolean whether to encode the GET parameters (their names and values), defaults to false. |
718 | + * @param string $serviceID |
|
713 | 719 | * @return string URL |
714 | 720 | * @see TUrlManager::constructUrl |
715 | 721 | */ |
@@ -915,6 +921,7 @@ discard block |
||
915 | 921 | * Returns whether there is an element at the specified offset. |
916 | 922 | * This method is required by the interface ArrayAccess. |
917 | 923 | * @param mixed the offset to check on |
924 | + * @param integer $offset |
|
918 | 925 | * @return boolean |
919 | 926 | */ |
920 | 927 | public function offsetExists($offset) |
@@ -926,6 +933,7 @@ discard block |
||
926 | 933 | * Returns the element at the specified offset. |
927 | 934 | * This method is required by the interface ArrayAccess. |
928 | 935 | * @param integer the offset to retrieve element. |
936 | + * @param integer $offset |
|
929 | 937 | * @return mixed the element at the offset, null if no element is found at the offset |
930 | 938 | */ |
931 | 939 | public function offsetGet($offset) |
@@ -938,6 +946,8 @@ discard block |
||
938 | 946 | * This method is required by the interface ArrayAccess. |
939 | 947 | * @param integer the offset to set element |
940 | 948 | * @param mixed the element value |
949 | + * @param integer $offset |
|
950 | + * @param string $item |
|
941 | 951 | */ |
942 | 952 | public function offsetSet($offset,$item) |
943 | 953 | { |
@@ -948,6 +958,7 @@ discard block |
||
948 | 958 | * Unsets the element at the specified offset. |
949 | 959 | * This method is required by the interface ArrayAccess. |
950 | 960 | * @param mixed the offset to unset element |
961 | + * @param integer $offset |
|
951 | 962 | */ |
952 | 963 | public function offsetUnset($offset) |
953 | 964 | { |
@@ -980,6 +991,7 @@ discard block |
||
980 | 991 | /** |
981 | 992 | * Constructor. |
982 | 993 | * @param mixed owner of this collection. |
994 | + * @param THttpResponse $owner |
|
983 | 995 | */ |
984 | 996 | public function __construct($owner=null) |
985 | 997 | { |
@@ -992,6 +1004,7 @@ discard block |
||
992 | 1004 | * operations for each newly added THttpCookie object. |
993 | 1005 | * @param integer the specified position. |
994 | 1006 | * @param mixed new item |
1007 | + * @param integer $index |
|
995 | 1008 | * @throws TInvalidDataTypeException if the item to be inserted is not a THttpCookie object. |
996 | 1009 | */ |
997 | 1010 | public function insertAt($index,$item) |
@@ -1011,6 +1024,7 @@ discard block |
||
1011 | 1024 | * This overrides the parent implementation by performing additional |
1012 | 1025 | * cleanup work when removing a TCookie object. |
1013 | 1026 | * @param integer the index of the item to be removed. |
1027 | + * @param integer $index |
|
1014 | 1028 | * @return mixed the removed item. |
1015 | 1029 | */ |
1016 | 1030 | public function removeAt($index) |
@@ -1109,6 +1123,7 @@ discard block |
||
1109 | 1123 | |
1110 | 1124 | /** |
1111 | 1125 | * @param string the domain to associate the cookie with |
1126 | + * @param string $value |
|
1112 | 1127 | */ |
1113 | 1128 | public function setDomain($value) |
1114 | 1129 | { |
@@ -1125,6 +1140,7 @@ discard block |
||
1125 | 1140 | |
1126 | 1141 | /** |
1127 | 1142 | * @param integer the time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. |
1143 | + * @param integer $value |
|
1128 | 1144 | */ |
1129 | 1145 | public function setExpire($value) |
1130 | 1146 | { |
@@ -1157,6 +1173,7 @@ discard block |
||
1157 | 1173 | |
1158 | 1174 | /** |
1159 | 1175 | * @param string the name of the cookie |
1176 | + * @param string $value |
|
1160 | 1177 | */ |
1161 | 1178 | public function setName($value) |
1162 | 1179 | { |
@@ -1173,6 +1190,7 @@ discard block |
||
1173 | 1190 | |
1174 | 1191 | /** |
1175 | 1192 | * @param string the value of the cookie |
1193 | + * @param string $value |
|
1176 | 1194 | */ |
1177 | 1195 | public function setValue($value) |
1178 | 1196 | { |
@@ -1189,6 +1207,7 @@ discard block |
||
1189 | 1207 | |
1190 | 1208 | /** |
1191 | 1209 | * @param string the path on the server in which the cookie will be available on |
1210 | + * @param string $value |
|
1192 | 1211 | */ |
1193 | 1212 | public function setPath($value) |
1194 | 1213 | { |
@@ -1205,6 +1224,7 @@ discard block |
||
1205 | 1224 | |
1206 | 1225 | /** |
1207 | 1226 | * @param boolean ether the cookie should only be transmitted over a secure HTTPS connection |
1227 | + * @param boolean $value |
|
1208 | 1228 | */ |
1209 | 1229 | public function setSecure($value) |
1210 | 1230 | { |
@@ -1287,6 +1307,7 @@ discard block |
||
1287 | 1307 | * Constructor. |
1288 | 1308 | * Decomposes the specified URI into parts. |
1289 | 1309 | * @param string URI to be represented |
1310 | + * @param string $uri |
|
1290 | 1311 | * @throws TInvalidDataValueException if URI is of bad format |
1291 | 1312 | */ |
1292 | 1313 | public function __construct($uri) |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | * @package System.Web |
67 | 67 | * @since 3.0 |
68 | 68 | */ |
69 | -class THttpRequest extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule |
|
69 | +class THttpRequest extends TApplicationComponent implements IteratorAggregate, ArrayAccess, Countable, IModule |
|
70 | 70 | { |
71 | - const CGIFIX__PATH_INFO = 1; |
|
72 | - const CGIFIX__SCRIPT_NAME = 2; |
|
71 | + const CGIFIX__PATH_INFO = 1; |
|
72 | + const CGIFIX__SCRIPT_NAME = 2; |
|
73 | 73 | /** |
74 | 74 | * @var TUrlManager the URL manager module |
75 | 75 | */ |
76 | - private $_urlManager=null; |
|
76 | + private $_urlManager = null; |
|
77 | 77 | /** |
78 | 78 | * @var string the ID of the URL manager module |
79 | 79 | */ |
80 | - private $_urlManagerID=''; |
|
80 | + private $_urlManagerID = ''; |
|
81 | 81 | /** |
82 | 82 | * @var string Separator used to separate GET variable name and value when URL format is Path. |
83 | 83 | */ |
84 | - private $_separator=','; |
|
84 | + private $_separator = ','; |
|
85 | 85 | /** |
86 | 86 | * @var string requested service ID |
87 | 87 | */ |
88 | - private $_serviceID=null; |
|
88 | + private $_serviceID = null; |
|
89 | 89 | /** |
90 | 90 | * @var string requested service parameter |
91 | 91 | */ |
92 | - private $_serviceParam=null; |
|
92 | + private $_serviceParam = null; |
|
93 | 93 | /** |
94 | 94 | * @var THttpCookieCollection cookies sent from user |
95 | 95 | */ |
96 | - private $_cookies=null; |
|
96 | + private $_cookies = null; |
|
97 | 97 | /** |
98 | 98 | * @var string requested URI (URL w/o host info) |
99 | 99 | */ |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * @var boolean whether the session ID should be kept in cookie only |
107 | 107 | */ |
108 | - private $_cookieOnly=null; |
|
109 | - private $_urlFormat=THttpRequestUrlFormat::Get; |
|
108 | + private $_cookieOnly = null; |
|
109 | + private $_urlFormat = THttpRequestUrlFormat::Get; |
|
110 | 110 | private $_services; |
111 | - private $_requestResolved=false; |
|
112 | - private $_enableCookieValidation=false; |
|
113 | - private $_cgiFix=0; |
|
111 | + private $_requestResolved = false; |
|
112 | + private $_enableCookieValidation = false; |
|
113 | + private $_cgiFix = 0; |
|
114 | 114 | /** |
115 | 115 | * @var boolean whether to cache the TUrlManager class (useful with a lot of TUrlMappings) |
116 | 116 | */ |
117 | - private $_enableCache=false; |
|
117 | + private $_enableCache = false; |
|
118 | 118 | /** |
119 | 119 | * @var string request URL |
120 | 120 | */ |
121 | - private $_url=null; |
|
121 | + private $_url = null; |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @var string module id |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | /** |
129 | 129 | * @var array contains all request variables |
130 | 130 | */ |
131 | - private $_items=array(); |
|
131 | + private $_items = array(); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return string id of this module |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function setID($value) |
145 | 145 | { |
146 | - $this->_id=$value; |
|
146 | + $this->_id = $value; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | public function init($config) |
155 | 155 | { |
156 | 156 | // Fill in default request info when the script is run in command line |
157 | - if(php_sapi_name()==='cli') |
|
157 | + if (php_sapi_name() === 'cli') |
|
158 | 158 | { |
159 | - $_SERVER['REMOTE_ADDR']='127.0.0.1'; |
|
160 | - $_SERVER['REQUEST_METHOD']='GET'; |
|
161 | - $_SERVER['SERVER_NAME']='localhost'; |
|
162 | - $_SERVER['SERVER_PORT']=80; |
|
163 | - $_SERVER['HTTP_USER_AGENT']=''; |
|
159 | + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
|
160 | + $_SERVER['REQUEST_METHOD'] = 'GET'; |
|
161 | + $_SERVER['SERVER_NAME'] = 'localhost'; |
|
162 | + $_SERVER['SERVER_PORT'] = 80; |
|
163 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | // Info about server variables: |
@@ -169,30 +169,30 @@ discard block |
||
169 | 169 | // QUERY_STRING is the string following the '?' in the ur (eg the a=x part in http://foo/bar?a=x) |
170 | 170 | // REQUEST_URI contains the URI part entered in the browser address bar |
171 | 171 | // SCRIPT_FILENAME is the file path to the executing script |
172 | - if(isset($_SERVER['REQUEST_URI'])) |
|
173 | - $this->_requestUri=$_SERVER['REQUEST_URI']; |
|
172 | + if (isset($_SERVER['REQUEST_URI'])) |
|
173 | + $this->_requestUri = $_SERVER['REQUEST_URI']; |
|
174 | 174 | else // TBD: in this case, SCRIPT_NAME need to be escaped |
175 | - $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
|
176 | - |
|
177 | - if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
178 | - $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
179 | - elseif(isset($_SERVER['PATH_INFO'])) |
|
180 | - $this->_pathInfo=$_SERVER['PATH_INFO']; |
|
181 | - else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
182 | - $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
175 | + $this->_requestUri = $_SERVER['SCRIPT_NAME'] . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']); |
|
176 | + |
|
177 | + if ($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
178 | + $this->_pathInfo = substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
179 | + elseif (isset($_SERVER['PATH_INFO'])) |
|
180 | + $this->_pathInfo = $_SERVER['PATH_INFO']; |
|
181 | + else if (strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) === 0 && $_SERVER['PHP_SELF'] !== $_SERVER['SCRIPT_NAME']) |
|
182 | + $this->_pathInfo = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
|
183 | 183 | else |
184 | - $this->_pathInfo=''; |
|
184 | + $this->_pathInfo = ''; |
|
185 | 185 | |
186 | - if(get_magic_quotes_gpc()) |
|
186 | + if (get_magic_quotes_gpc()) |
|
187 | 187 | { |
188 | - if(isset($_GET)) |
|
189 | - $_GET=$this->stripSlashes($_GET); |
|
190 | - if(isset($_POST)) |
|
191 | - $_POST=$this->stripSlashes($_POST); |
|
192 | - if(isset($_REQUEST)) |
|
193 | - $_REQUEST=$this->stripSlashes($_REQUEST); |
|
194 | - if(isset($_COOKIE)) |
|
195 | - $_COOKIE=$this->stripSlashes($_COOKIE); |
|
188 | + if (isset($_GET)) |
|
189 | + $_GET = $this->stripSlashes($_GET); |
|
190 | + if (isset($_POST)) |
|
191 | + $_POST = $this->stripSlashes($_POST); |
|
192 | + if (isset($_REQUEST)) |
|
193 | + $_REQUEST = $this->stripSlashes($_REQUEST); |
|
194 | + if (isset($_COOKIE)) |
|
195 | + $_COOKIE = $this->stripSlashes($_COOKIE); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $this->getApplication()->setRequest($this); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function stripSlashes(&$data) |
208 | 208 | { |
209 | - return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); |
|
209 | + return is_array($data) ? array_map(array($this, 'stripSlashes'), $data) : stripslashes($data); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -214,21 +214,21 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function getUrl() |
216 | 216 | { |
217 | - if($this->_url===null) |
|
217 | + if ($this->_url === null) |
|
218 | 218 | { |
219 | - $secure=$this->getIsSecureConnection(); |
|
220 | - $url=$secure?'https://':'http://'; |
|
221 | - if(empty($_SERVER['HTTP_HOST'])) |
|
219 | + $secure = $this->getIsSecureConnection(); |
|
220 | + $url = $secure ? 'https://' : 'http://'; |
|
221 | + if (empty($_SERVER['HTTP_HOST'])) |
|
222 | 222 | { |
223 | - $url.=$_SERVER['SERVER_NAME']; |
|
224 | - $port=$_SERVER['SERVER_PORT']; |
|
225 | - if(($port!=80 && !$secure) || ($port!=443 && $secure)) |
|
226 | - $url.=':'.$port; |
|
223 | + $url .= $_SERVER['SERVER_NAME']; |
|
224 | + $port = $_SERVER['SERVER_PORT']; |
|
225 | + if (($port != 80 && !$secure) || ($port != 443 && $secure)) |
|
226 | + $url .= ':' . $port; |
|
227 | 227 | } |
228 | 228 | else |
229 | - $url.=$_SERVER['HTTP_HOST']; |
|
230 | - $url.=$this->getRequestUri(); |
|
231 | - $this->_url=new TUri($url); |
|
229 | + $url .= $_SERVER['HTTP_HOST']; |
|
230 | + $url .= $this->getRequestUri(); |
|
231 | + $this->_url = new TUri($url); |
|
232 | 232 | } |
233 | 233 | return $this->_url; |
234 | 234 | } |
@@ -262,16 +262,16 @@ discard block |
||
262 | 262 | */ |
263 | 263 | protected function cacheUrlManager($manager) |
264 | 264 | { |
265 | - if($this->getEnableCache()) |
|
265 | + if ($this->getEnableCache()) |
|
266 | 266 | { |
267 | 267 | $cache = $this->getApplication()->getCache(); |
268 | - if($cache !== null) |
|
268 | + if ($cache !== null) |
|
269 | 269 | { |
270 | 270 | $dependencies = null; |
271 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
271 | + if ($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
272 | 272 | if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
273 | 273 | { |
274 | - $fn = Prado::getPathOfNamespace($fn,$this->getApplication()->getConfigurationFileExt()); |
|
274 | + $fn = Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); |
|
275 | 275 | $dependencies = new TFileCacheDependency($fn); |
276 | 276 | } |
277 | 277 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
@@ -286,13 +286,13 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function loadCachedUrlManager() |
288 | 288 | { |
289 | - if($this->getEnableCache()) |
|
289 | + if ($this->getEnableCache()) |
|
290 | 290 | { |
291 | 291 | $cache = $this->getApplication()->getCache(); |
292 | - if($cache !== null) |
|
292 | + if ($cache !== null) |
|
293 | 293 | { |
294 | 294 | $manager = $cache->get($this->getCacheKey()); |
295 | - if($manager instanceof TUrlManager) |
|
295 | + if ($manager instanceof TUrlManager) |
|
296 | 296 | return $manager; |
297 | 297 | } |
298 | 298 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function setUrlManager($value) |
319 | 319 | { |
320 | - $this->_urlManagerID=$value; |
|
320 | + $this->_urlManagerID = $value; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -325,22 +325,22 @@ discard block |
||
325 | 325 | */ |
326 | 326 | public function getUrlManagerModule() |
327 | 327 | { |
328 | - if($this->_urlManager===null) |
|
328 | + if ($this->_urlManager === null) |
|
329 | 329 | { |
330 | - if(($this->_urlManager = $this->loadCachedUrlManager())===null) |
|
330 | + if (($this->_urlManager = $this->loadCachedUrlManager()) === null) |
|
331 | 331 | { |
332 | - if(empty($this->_urlManagerID)) |
|
332 | + if (empty($this->_urlManagerID)) |
|
333 | 333 | { |
334 | - $this->_urlManager=new TUrlManager; |
|
334 | + $this->_urlManager = new TUrlManager; |
|
335 | 335 | $this->_urlManager->init(null); |
336 | 336 | } |
337 | 337 | else |
338 | 338 | { |
339 | - $this->_urlManager=$this->getApplication()->getModule($this->_urlManagerID); |
|
340 | - if($this->_urlManager===null) |
|
341 | - throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
342 | - if(!($this->_urlManager instanceof TUrlManager)) |
|
343 | - throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
339 | + $this->_urlManager = $this->getApplication()->getModule($this->_urlManagerID); |
|
340 | + if ($this->_urlManager === null) |
|
341 | + throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
|
342 | + if (!($this->_urlManager instanceof TUrlManager)) |
|
343 | + throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
|
344 | 344 | } |
345 | 345 | $this->cacheUrlManager($this->_urlManager); |
346 | 346 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public function setUrlFormat($value) |
368 | 368 | { |
369 | - $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat'); |
|
369 | + $this->_urlFormat = TPropertyValue::ensureEnum($value, 'THttpRequestUrlFormat'); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -383,8 +383,8 @@ discard block |
||
383 | 383 | */ |
384 | 384 | public function setUrlParamSeparator($value) |
385 | 385 | { |
386 | - if(strlen($value)===1) |
|
387 | - $this->_separator=$value; |
|
386 | + if (strlen($value) === 1) |
|
387 | + $this->_separator = $value; |
|
388 | 388 | else |
389 | 389 | throw new TInvalidDataValueException('httprequest_separator_invalid'); |
390 | 390 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function getRequestType() |
396 | 396 | { |
397 | - return isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:null; |
|
397 | + return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -403,10 +403,10 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public function getContentType($mimetypeOnly = true) |
405 | 405 | { |
406 | - if(!isset($_SERVER['CONTENT_TYPE'])) |
|
406 | + if (!isset($_SERVER['CONTENT_TYPE'])) |
|
407 | 407 | return null; |
408 | 408 | |
409 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
409 | + if ($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
410 | 410 | return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
411 | 411 | |
412 | 412 | return $_SERVER['CONTENT_TYPE']; |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | */ |
418 | 418 | public function getIsSecureConnection() |
419 | 419 | { |
420 | - return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); |
|
420 | + return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off'); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public function getQueryString() |
435 | 435 | { |
436 | - return isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:null; |
|
436 | + return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | /** |
@@ -441,30 +441,30 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function getHttpProtocolVersion() |
443 | 443 | { |
444 | - return isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:null; |
|
444 | + return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
448 | 448 | * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default) |
449 | 449 | * @return array |
450 | 450 | */ |
451 | - public function getHeaders($case=null) |
|
451 | + public function getHeaders($case = null) |
|
452 | 452 | { |
453 | 453 | static $result; |
454 | 454 | |
455 | - if($result === null && function_exists('apache_request_headers')) { |
|
455 | + if ($result === null && function_exists('apache_request_headers')) { |
|
456 | 456 | $result = apache_request_headers(); |
457 | 457 | } |
458 | - elseif($result === null) { |
|
458 | + elseif ($result === null) { |
|
459 | 459 | $result = array(); |
460 | - foreach($_SERVER as $key=>$value) { |
|
461 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
462 | - $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); |
|
460 | + foreach ($_SERVER as $key=>$value) { |
|
461 | + if (strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
462 | + $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); |
|
463 | 463 | $result[$key] = $value; |
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | - if($case !== null) |
|
467 | + if ($case !== null) |
|
468 | 468 | return array_change_key_case($result, $case); |
469 | 469 | |
470 | 470 | return $result; |
@@ -485,13 +485,13 @@ discard block |
||
485 | 485 | * false - force http |
486 | 486 | * @return string schema and hostname of the requested URL |
487 | 487 | */ |
488 | - public function getBaseUrl($forceSecureConnection=null) |
|
488 | + public function getBaseUrl($forceSecureConnection = null) |
|
489 | 489 | { |
490 | - $url=$this->getUrl(); |
|
491 | - $scheme=($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
|
492 | - $host=$url->getHost(); |
|
493 | - if (($port=$url->getPort())) $host.=':'.$port; |
|
494 | - return $scheme.'://'.$host; |
|
490 | + $url = $this->getUrl(); |
|
491 | + $scheme = ($forceSecureConnection) ? "https" : (($forceSecureConnection === null) ? $url->getScheme() : 'http'); |
|
492 | + $host = $url->getHost(); |
|
493 | + if (($port = $url->getPort())) $host .= ':' . $port; |
|
494 | + return $scheme . '://' . $host; |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -499,10 +499,10 @@ discard block |
||
499 | 499 | */ |
500 | 500 | public function getApplicationUrl() |
501 | 501 | { |
502 | - if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
502 | + if ($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
503 | 503 | return $_SERVER['ORIG_SCRIPT_NAME']; |
504 | 504 | |
505 | - return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
|
505 | + return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | * false - force http |
513 | 513 | * @return string entry script URL (w/ host part) |
514 | 514 | */ |
515 | - public function getAbsoluteApplicationUrl($forceSecureConnection=null) |
|
515 | + public function getAbsoluteApplicationUrl($forceSecureConnection = null) |
|
516 | 516 | { |
517 | 517 | return $this->getBaseUrl($forceSecureConnection) . $this->getApplicationUrl(); |
518 | 518 | } |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | */ |
523 | 523 | public function getApplicationFilePath() |
524 | 524 | { |
525 | - return realpath(isset($_SERVER['SCRIPT_FILENAME'])?$_SERVER['SCRIPT_FILENAME']:null); |
|
525 | + return realpath(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | */ |
531 | 531 | public function getServerName() |
532 | 532 | { |
533 | - return isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:null; |
|
533 | + return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | */ |
539 | 539 | public function getServerPort() |
540 | 540 | { |
541 | - return isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:null; |
|
541 | + return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | */ |
547 | 547 | public function getUrlReferrer() |
548 | 548 | { |
549 | - return isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:null; |
|
549 | + return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | { |
560 | 560 | return get_browser(); |
561 | 561 | } |
562 | - catch(TPhpErrorException $e) |
|
562 | + catch (TPhpErrorException $e) |
|
563 | 563 | { |
564 | 564 | throw new TConfigurationException('httprequest_browscap_required'); |
565 | 565 | } |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | */ |
571 | 571 | public function getUserAgent() |
572 | 572 | { |
573 | - return isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null; |
|
573 | + return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | */ |
579 | 579 | public function getUserHostAddress() |
580 | 580 | { |
581 | - return isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:null; |
|
581 | + return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | */ |
587 | 587 | public function getUserHost() |
588 | 588 | { |
589 | - return isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:null; |
|
589 | + return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | public function getAcceptTypes() |
596 | 596 | { |
597 | 597 | // TBD: break it into array?? |
598 | - return isset($_SERVER['HTTP_ACCEPT'])?$_SERVER['HTTP_ACCEPT']:null; |
|
598 | + return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | */ |
624 | 624 | public function setEnableCookieValidation($value) |
625 | 625 | { |
626 | - $this->_enableCookieValidation=TPropertyValue::ensureBoolean($value); |
|
626 | + $this->_enableCookieValidation = TPropertyValue::ensureBoolean($value); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | /** |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | */ |
644 | 644 | public function setCgiFix($value) |
645 | 645 | { |
646 | - $this->_cgiFix=TPropertyValue::ensureInteger($value); |
|
646 | + $this->_cgiFix = TPropertyValue::ensureInteger($value); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -651,22 +651,22 @@ discard block |
||
651 | 651 | */ |
652 | 652 | public function getCookies() |
653 | 653 | { |
654 | - if($this->_cookies===null) |
|
654 | + if ($this->_cookies === null) |
|
655 | 655 | { |
656 | - $this->_cookies=new THttpCookieCollection; |
|
657 | - if($this->getEnableCookieValidation()) |
|
656 | + $this->_cookies = new THttpCookieCollection; |
|
657 | + if ($this->getEnableCookieValidation()) |
|
658 | 658 | { |
659 | - $sm=$this->getApplication()->getSecurityManager(); |
|
660 | - foreach($_COOKIE as $key=>$value) |
|
659 | + $sm = $this->getApplication()->getSecurityManager(); |
|
660 | + foreach ($_COOKIE as $key=>$value) |
|
661 | 661 | { |
662 | - if(($value=$sm->validateData($value))!==false) |
|
663 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
662 | + if (($value = $sm->validateData($value)) !== false) |
|
663 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
664 | 664 | } |
665 | 665 | } |
666 | 666 | else |
667 | 667 | { |
668 | - foreach($_COOKIE as $key=>$value) |
|
669 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
668 | + foreach ($_COOKIE as $key=>$value) |
|
669 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | return $this->_cookies; |
@@ -713,13 +713,13 @@ discard block |
||
713 | 713 | * @return string URL |
714 | 714 | * @see TUrlManager::constructUrl |
715 | 715 | */ |
716 | - public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) |
|
716 | + public function constructUrl($serviceID, $serviceParam, $getItems = null, $encodeAmpersand = true, $encodeGetItems = true) |
|
717 | 717 | { |
718 | - if ($this->_cookieOnly===null) |
|
719 | - $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
720 | - $url=$this->getUrlManagerModule()->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
|
721 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
722 | - return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
718 | + if ($this->_cookieOnly === null) |
|
719 | + $this->_cookieOnly = (int) ini_get('session.use_cookies') && (int) ini_get('session.use_only_cookies'); |
|
720 | + $url = $this->getUrlManagerModule()->constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
|
721 | + if (defined('SID') && SID != '' && !$this->_cookieOnly) |
|
722 | + return $url . (strpos($url, '?') === false ? '?' : ($encodeAmpersand ? '&' : '&')) . SID; |
|
723 | 723 | else |
724 | 724 | return $url; |
725 | 725 | } |
@@ -747,15 +747,15 @@ discard block |
||
747 | 747 | */ |
748 | 748 | public function resolveRequest($serviceIDs) |
749 | 749 | { |
750 | - Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'],'System.Web.THttpRequest'); |
|
751 | - $getParams=$this->parseUrl(); |
|
752 | - foreach($getParams as $name=>$value) |
|
753 | - $_GET[$name]=$value; |
|
754 | - $this->_items=array_merge($_GET,$_POST); |
|
755 | - $this->_requestResolved=true; |
|
756 | - foreach($serviceIDs as $serviceID) |
|
750 | + Prado::trace("Resolving request from " . $_SERVER['REMOTE_ADDR'], 'System.Web.THttpRequest'); |
|
751 | + $getParams = $this->parseUrl(); |
|
752 | + foreach ($getParams as $name=>$value) |
|
753 | + $_GET[$name] = $value; |
|
754 | + $this->_items = array_merge($_GET, $_POST); |
|
755 | + $this->_requestResolved = true; |
|
756 | + foreach ($serviceIDs as $serviceID) |
|
757 | 757 | { |
758 | - if($this->contains($serviceID)) |
|
758 | + if ($this->contains($serviceID)) |
|
759 | 759 | { |
760 | 760 | $this->setServiceID($serviceID); |
761 | 761 | $this->setServiceParameter($this->itemAt($serviceID)); |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | */ |
788 | 788 | public function setServiceID($value) |
789 | 789 | { |
790 | - $this->_serviceID=$value; |
|
790 | + $this->_serviceID = $value; |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | /** |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | */ |
805 | 805 | public function setServiceParameter($value) |
806 | 806 | { |
807 | - $this->_serviceParam=$value; |
|
807 | + $this->_serviceParam = $value; |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | //------ The following methods enable THttpRequest to be TMap-like ----- |
@@ -862,9 +862,9 @@ discard block |
||
862 | 862 | * @param mixed key |
863 | 863 | * @param mixed value |
864 | 864 | */ |
865 | - public function add($key,$value) |
|
865 | + public function add($key, $value) |
|
866 | 866 | { |
867 | - $this->_items[$key]=$value; |
|
867 | + $this->_items[$key] = $value; |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | /** |
@@ -875,9 +875,9 @@ discard block |
||
875 | 875 | */ |
876 | 876 | public function remove($key) |
877 | 877 | { |
878 | - if(isset($this->_items[$key]) || array_key_exists($key,$this->_items)) |
|
878 | + if (isset($this->_items[$key]) || array_key_exists($key, $this->_items)) |
|
879 | 879 | { |
880 | - $value=$this->_items[$key]; |
|
880 | + $value = $this->_items[$key]; |
|
881 | 881 | unset($this->_items[$key]); |
882 | 882 | return $value; |
883 | 883 | } |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | */ |
891 | 891 | public function clear() |
892 | 892 | { |
893 | - foreach(array_keys($this->_items) as $key) |
|
893 | + foreach (array_keys($this->_items) as $key) |
|
894 | 894 | $this->remove($key); |
895 | 895 | } |
896 | 896 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | */ |
901 | 901 | public function contains($key) |
902 | 902 | { |
903 | - return isset($this->_items[$key]) || array_key_exists($key,$this->_items); |
|
903 | + return isset($this->_items[$key]) || array_key_exists($key, $this->_items); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -939,9 +939,9 @@ discard block |
||
939 | 939 | * @param integer the offset to set element |
940 | 940 | * @param mixed the element value |
941 | 941 | */ |
942 | - public function offsetSet($offset,$item) |
|
942 | + public function offsetSet($offset, $item) |
|
943 | 943 | { |
944 | - $this->add($offset,$item); |
|
944 | + $this->add($offset, $item); |
|
945 | 945 | } |
946 | 946 | |
947 | 947 | /** |
@@ -981,9 +981,9 @@ discard block |
||
981 | 981 | * Constructor. |
982 | 982 | * @param mixed owner of this collection. |
983 | 983 | */ |
984 | - public function __construct($owner=null) |
|
984 | + public function __construct($owner = null) |
|
985 | 985 | { |
986 | - $this->_o=$owner; |
|
986 | + $this->_o = $owner; |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | /** |
@@ -994,12 +994,12 @@ discard block |
||
994 | 994 | * @param mixed new item |
995 | 995 | * @throws TInvalidDataTypeException if the item to be inserted is not a THttpCookie object. |
996 | 996 | */ |
997 | - public function insertAt($index,$item) |
|
997 | + public function insertAt($index, $item) |
|
998 | 998 | { |
999 | - if($item instanceof THttpCookie) |
|
999 | + if ($item instanceof THttpCookie) |
|
1000 | 1000 | { |
1001 | - parent::insertAt($index,$item); |
|
1002 | - if($this->_o instanceof THttpResponse) |
|
1001 | + parent::insertAt($index, $item); |
|
1002 | + if ($this->_o instanceof THttpResponse) |
|
1003 | 1003 | $this->_o->addCookie($item); |
1004 | 1004 | } |
1005 | 1005 | else |
@@ -1015,8 +1015,8 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | public function removeAt($index) |
1017 | 1017 | { |
1018 | - $item=parent::removeAt($index); |
|
1019 | - if($this->_o instanceof THttpResponse) |
|
1018 | + $item = parent::removeAt($index); |
|
1019 | + if ($this->_o instanceof THttpResponse) |
|
1020 | 1020 | $this->_o->removeCookie($item); |
1021 | 1021 | return $item; |
1022 | 1022 | } |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | */ |
1028 | 1028 | public function itemAt($index) |
1029 | 1029 | { |
1030 | - if(is_integer($index)) |
|
1030 | + if (is_integer($index)) |
|
1031 | 1031 | return parent::itemAt($index); |
1032 | 1032 | else |
1033 | 1033 | return $this->findCookieByName($index); |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | */ |
1041 | 1041 | public function findCookieByName($name) |
1042 | 1042 | { |
1043 | - foreach($this as $cookie) |
|
1044 | - if($cookie->getName()===$name) |
|
1043 | + foreach ($this as $cookie) |
|
1044 | + if ($cookie->getName() === $name) |
|
1045 | 1045 | return $cookie; |
1046 | 1046 | return null; |
1047 | 1047 | } |
@@ -1062,7 +1062,7 @@ discard block |
||
1062 | 1062 | /** |
1063 | 1063 | * @var string domain of the cookie |
1064 | 1064 | */ |
1065 | - private $_domain=''; |
|
1065 | + private $_domain = ''; |
|
1066 | 1066 | /** |
1067 | 1067 | * @var string name of the cookie |
1068 | 1068 | */ |
@@ -1070,33 +1070,33 @@ discard block |
||
1070 | 1070 | /** |
1071 | 1071 | * @var string value of the cookie |
1072 | 1072 | */ |
1073 | - private $_value=''; |
|
1073 | + private $_value = ''; |
|
1074 | 1074 | /** |
1075 | 1075 | * @var integer expire of the cookie |
1076 | 1076 | */ |
1077 | - private $_expire=0; |
|
1077 | + private $_expire = 0; |
|
1078 | 1078 | /** |
1079 | 1079 | * @var string path of the cookie |
1080 | 1080 | */ |
1081 | - private $_path='/'; |
|
1081 | + private $_path = '/'; |
|
1082 | 1082 | /** |
1083 | 1083 | * @var boolean whether cookie should be sent via secure connection |
1084 | 1084 | */ |
1085 | - private $_secure=false; |
|
1085 | + private $_secure = false; |
|
1086 | 1086 | /** |
1087 | 1087 | * @var boolean if true the cookie value will be unavailable to JavaScript |
1088 | 1088 | */ |
1089 | - private $_httpOnly=false; |
|
1089 | + private $_httpOnly = false; |
|
1090 | 1090 | |
1091 | 1091 | /** |
1092 | 1092 | * Constructor. |
1093 | 1093 | * @param string name of this cookie |
1094 | 1094 | * @param string value of this cookie |
1095 | 1095 | */ |
1096 | - public function __construct($name,$value) |
|
1096 | + public function __construct($name, $value) |
|
1097 | 1097 | { |
1098 | - $this->_name=$name; |
|
1099 | - $this->_value=$value; |
|
1098 | + $this->_name = $name; |
|
1099 | + $this->_value = $value; |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | /** |
@@ -1112,7 +1112,7 @@ discard block |
||
1112 | 1112 | */ |
1113 | 1113 | public function setDomain($value) |
1114 | 1114 | { |
1115 | - $this->_domain=$value; |
|
1115 | + $this->_domain = $value; |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | /** |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | */ |
1129 | 1129 | public function setExpire($value) |
1130 | 1130 | { |
1131 | - $this->_expire=TPropertyValue::ensureInteger($value); |
|
1131 | + $this->_expire = TPropertyValue::ensureInteger($value); |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | /** |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | */ |
1161 | 1161 | public function setName($value) |
1162 | 1162 | { |
1163 | - $this->_name=$value; |
|
1163 | + $this->_name = $value; |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
1176 | 1176 | */ |
1177 | 1177 | public function setValue($value) |
1178 | 1178 | { |
1179 | - $this->_value=$value; |
|
1179 | + $this->_value = $value; |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
@@ -1192,7 +1192,7 @@ discard block |
||
1192 | 1192 | */ |
1193 | 1193 | public function setPath($value) |
1194 | 1194 | { |
1195 | - $this->_path=$value; |
|
1195 | + $this->_path = $value; |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | /** |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | */ |
1209 | 1209 | public function setSecure($value) |
1210 | 1210 | { |
1211 | - $this->_secure=TPropertyValue::ensureBoolean($value); |
|
1211 | + $this->_secure = TPropertyValue::ensureBoolean($value); |
|
1212 | 1212 | } |
1213 | 1213 | } |
1214 | 1214 | |
@@ -1236,7 +1236,7 @@ discard block |
||
1236 | 1236 | /** |
1237 | 1237 | * @var array list of default ports for known schemes |
1238 | 1238 | */ |
1239 | - private static $_defaultPort=array( |
|
1239 | + private static $_defaultPort = array( |
|
1240 | 1240 | 'ftp'=>21, |
1241 | 1241 | 'gopher'=>70, |
1242 | 1242 | 'http'=>80, |
@@ -1291,22 +1291,22 @@ discard block |
||
1291 | 1291 | */ |
1292 | 1292 | public function __construct($uri) |
1293 | 1293 | { |
1294 | - if(($ret=@parse_url($uri))!==false) |
|
1294 | + if (($ret = @parse_url($uri)) !== false) |
|
1295 | 1295 | { |
1296 | 1296 | // decoding??? |
1297 | - $this->_scheme=isset($ret['scheme'])?$ret['scheme']:''; |
|
1298 | - $this->_host=isset($ret['host'])?$ret['host']:''; |
|
1299 | - $this->_port=isset($ret['port'])?$ret['port']:''; |
|
1300 | - $this->_user=isset($ret['user'])?$ret['user']:''; |
|
1301 | - $this->_pass=isset($ret['pass'])?$ret['pass']:''; |
|
1302 | - $this->_path=isset($ret['path'])?$ret['path']:''; |
|
1303 | - $this->_query=isset($ret['query'])?$ret['query']:''; |
|
1304 | - $this->_fragment=isset($ret['fragment'])?$ret['fragment']:''; |
|
1305 | - $this->_uri=$uri; |
|
1297 | + $this->_scheme = isset($ret['scheme']) ? $ret['scheme'] : ''; |
|
1298 | + $this->_host = isset($ret['host']) ? $ret['host'] : ''; |
|
1299 | + $this->_port = isset($ret['port']) ? $ret['port'] : ''; |
|
1300 | + $this->_user = isset($ret['user']) ? $ret['user'] : ''; |
|
1301 | + $this->_pass = isset($ret['pass']) ? $ret['pass'] : ''; |
|
1302 | + $this->_path = isset($ret['path']) ? $ret['path'] : ''; |
|
1303 | + $this->_query = isset($ret['query']) ? $ret['query'] : ''; |
|
1304 | + $this->_fragment = isset($ret['fragment']) ? $ret['fragment'] : ''; |
|
1305 | + $this->_uri = $uri; |
|
1306 | 1306 | } |
1307 | 1307 | else |
1308 | 1308 | { |
1309 | - throw new TInvalidDataValueException('uri_format_invalid',$uri); |
|
1309 | + throw new TInvalidDataValueException('uri_format_invalid', $uri); |
|
1310 | 1310 | } |
1311 | 1311 | } |
1312 | 1312 | |
@@ -1399,8 +1399,8 @@ discard block |
||
1399 | 1399 | */ |
1400 | 1400 | class THttpRequestUrlFormat extends TEnumerable |
1401 | 1401 | { |
1402 | - const Get='Get'; |
|
1403 | - const Path='Path'; |
|
1404 | - const HiddenPath='HiddenPath'; |
|
1402 | + const Get = 'Get'; |
|
1403 | + const Path = 'Path'; |
|
1404 | + const HiddenPath = 'HiddenPath'; |
|
1405 | 1405 | } |
1406 | 1406 |
@@ -169,30 +169,37 @@ discard block |
||
169 | 169 | // QUERY_STRING is the string following the '?' in the ur (eg the a=x part in http://foo/bar?a=x) |
170 | 170 | // REQUEST_URI contains the URI part entered in the browser address bar |
171 | 171 | // SCRIPT_FILENAME is the file path to the executing script |
172 | - if(isset($_SERVER['REQUEST_URI'])) |
|
173 | - $this->_requestUri=$_SERVER['REQUEST_URI']; |
|
174 | - else // TBD: in this case, SCRIPT_NAME need to be escaped |
|
172 | + if(isset($_SERVER['REQUEST_URI'])) { |
|
173 | + $this->_requestUri=$_SERVER['REQUEST_URI']; |
|
174 | + } else { |
|
175 | + // TBD: in this case, SCRIPT_NAME need to be escaped |
|
175 | 176 | $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
177 | + } |
|
176 | 178 | |
177 | - if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
178 | - $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
179 | - elseif(isset($_SERVER['PATH_INFO'])) |
|
180 | - $this->_pathInfo=$_SERVER['PATH_INFO']; |
|
181 | - else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
182 | - $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
183 | - else |
|
184 | - $this->_pathInfo=''; |
|
179 | + if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) { |
|
180 | + $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
181 | + } elseif(isset($_SERVER['PATH_INFO'])) { |
|
182 | + $this->_pathInfo=$_SERVER['PATH_INFO']; |
|
183 | + } else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) { |
|
184 | + $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
185 | + } else { |
|
186 | + $this->_pathInfo=''; |
|
187 | + } |
|
185 | 188 | |
186 | 189 | if(get_magic_quotes_gpc()) |
187 | 190 | { |
188 | - if(isset($_GET)) |
|
189 | - $_GET=$this->stripSlashes($_GET); |
|
190 | - if(isset($_POST)) |
|
191 | - $_POST=$this->stripSlashes($_POST); |
|
192 | - if(isset($_REQUEST)) |
|
193 | - $_REQUEST=$this->stripSlashes($_REQUEST); |
|
194 | - if(isset($_COOKIE)) |
|
195 | - $_COOKIE=$this->stripSlashes($_COOKIE); |
|
191 | + if(isset($_GET)) { |
|
192 | + $_GET=$this->stripSlashes($_GET); |
|
193 | + } |
|
194 | + if(isset($_POST)) { |
|
195 | + $_POST=$this->stripSlashes($_POST); |
|
196 | + } |
|
197 | + if(isset($_REQUEST)) { |
|
198 | + $_REQUEST=$this->stripSlashes($_REQUEST); |
|
199 | + } |
|
200 | + if(isset($_COOKIE)) { |
|
201 | + $_COOKIE=$this->stripSlashes($_COOKIE); |
|
202 | + } |
|
196 | 203 | } |
197 | 204 | |
198 | 205 | $this->getApplication()->setRequest($this); |
@@ -222,11 +229,12 @@ discard block |
||
222 | 229 | { |
223 | 230 | $url.=$_SERVER['SERVER_NAME']; |
224 | 231 | $port=$_SERVER['SERVER_PORT']; |
225 | - if(($port!=80 && !$secure) || ($port!=443 && $secure)) |
|
226 | - $url.=':'.$port; |
|
232 | + if(($port!=80 && !$secure) || ($port!=443 && $secure)) { |
|
233 | + $url.=':'.$port; |
|
234 | + } |
|
235 | + } else { |
|
236 | + $url.=$_SERVER['HTTP_HOST']; |
|
227 | 237 | } |
228 | - else |
|
229 | - $url.=$_SERVER['HTTP_HOST']; |
|
230 | 238 | $url.=$this->getRequestUri(); |
231 | 239 | $this->_url=new TUri($url); |
232 | 240 | } |
@@ -268,10 +276,11 @@ discard block |
||
268 | 276 | if($cache !== null) |
269 | 277 | { |
270 | 278 | $dependencies = null; |
271 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
272 | - if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
279 | + if($this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
280 | + if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
273 | 281 | { |
274 | 282 | $fn = Prado::getPathOfNamespace($fn,$this->getApplication()->getConfigurationFileExt()); |
283 | + } |
|
275 | 284 | $dependencies = new TFileCacheDependency($fn); |
276 | 285 | } |
277 | 286 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
@@ -292,8 +301,9 @@ discard block |
||
292 | 301 | if($cache !== null) |
293 | 302 | { |
294 | 303 | $manager = $cache->get($this->getCacheKey()); |
295 | - if($manager instanceof TUrlManager) |
|
296 | - return $manager; |
|
304 | + if($manager instanceof TUrlManager) { |
|
305 | + return $manager; |
|
306 | + } |
|
297 | 307 | } |
298 | 308 | } |
299 | 309 | return null; |
@@ -333,14 +343,15 @@ discard block |
||
333 | 343 | { |
334 | 344 | $this->_urlManager=new TUrlManager; |
335 | 345 | $this->_urlManager->init(null); |
336 | - } |
|
337 | - else |
|
346 | + } else |
|
338 | 347 | { |
339 | 348 | $this->_urlManager=$this->getApplication()->getModule($this->_urlManagerID); |
340 | - if($this->_urlManager===null) |
|
341 | - throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
342 | - if(!($this->_urlManager instanceof TUrlManager)) |
|
343 | - throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
349 | + if($this->_urlManager===null) { |
|
350 | + throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
351 | + } |
|
352 | + if(!($this->_urlManager instanceof TUrlManager)) { |
|
353 | + throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
354 | + } |
|
344 | 355 | } |
345 | 356 | $this->cacheUrlManager($this->_urlManager); |
346 | 357 | } |
@@ -383,10 +394,11 @@ discard block |
||
383 | 394 | */ |
384 | 395 | public function setUrlParamSeparator($value) |
385 | 396 | { |
386 | - if(strlen($value)===1) |
|
387 | - $this->_separator=$value; |
|
388 | - else |
|
389 | - throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
397 | + if(strlen($value)===1) { |
|
398 | + $this->_separator=$value; |
|
399 | + } else { |
|
400 | + throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
401 | + } |
|
390 | 402 | } |
391 | 403 | |
392 | 404 | /** |
@@ -403,11 +415,13 @@ discard block |
||
403 | 415 | */ |
404 | 416 | public function getContentType($mimetypeOnly = true) |
405 | 417 | { |
406 | - if(!isset($_SERVER['CONTENT_TYPE'])) |
|
407 | - return null; |
|
418 | + if(!isset($_SERVER['CONTENT_TYPE'])) { |
|
419 | + return null; |
|
420 | + } |
|
408 | 421 | |
409 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
410 | - return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
422 | + if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) { |
|
423 | + return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
424 | + } |
|
411 | 425 | |
412 | 426 | return $_SERVER['CONTENT_TYPE']; |
413 | 427 | } |
@@ -454,18 +468,20 @@ discard block |
||
454 | 468 | |
455 | 469 | if($result === null && function_exists('apache_request_headers')) { |
456 | 470 | $result = apache_request_headers(); |
457 | - } |
|
458 | - elseif($result === null) { |
|
471 | + } elseif($result === null) { |
|
459 | 472 | $result = array(); |
460 | 473 | foreach($_SERVER as $key=>$value) { |
461 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
474 | + if(strncasecmp($key, 'HTTP_', 5) !== 0) { |
|
475 | + continue; |
|
476 | + } |
|
462 | 477 | $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); |
463 | 478 | $result[$key] = $value; |
464 | 479 | } |
465 | 480 | } |
466 | 481 | |
467 | - if($case !== null) |
|
468 | - return array_change_key_case($result, $case); |
|
482 | + if($case !== null) { |
|
483 | + return array_change_key_case($result, $case); |
|
484 | + } |
|
469 | 485 | |
470 | 486 | return $result; |
471 | 487 | } |
@@ -490,7 +506,9 @@ discard block |
||
490 | 506 | $url=$this->getUrl(); |
491 | 507 | $scheme=($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
492 | 508 | $host=$url->getHost(); |
493 | - if (($port=$url->getPort())) $host.=':'.$port; |
|
509 | + if (($port=$url->getPort())) { |
|
510 | + $host.=':'.$port; |
|
511 | + } |
|
494 | 512 | return $scheme.'://'.$host; |
495 | 513 | } |
496 | 514 | |
@@ -499,8 +517,9 @@ discard block |
||
499 | 517 | */ |
500 | 518 | public function getApplicationUrl() |
501 | 519 | { |
502 | - if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
503 | - return $_SERVER['ORIG_SCRIPT_NAME']; |
|
520 | + if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) { |
|
521 | + return $_SERVER['ORIG_SCRIPT_NAME']; |
|
522 | + } |
|
504 | 523 | |
505 | 524 | return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
506 | 525 | } |
@@ -558,8 +577,7 @@ discard block |
||
558 | 577 | try |
559 | 578 | { |
560 | 579 | return get_browser(); |
561 | - } |
|
562 | - catch(TPhpErrorException $e) |
|
580 | + } catch(TPhpErrorException $e) |
|
563 | 581 | { |
564 | 582 | throw new TConfigurationException('httprequest_browscap_required'); |
565 | 583 | } |
@@ -659,14 +677,15 @@ discard block |
||
659 | 677 | $sm=$this->getApplication()->getSecurityManager(); |
660 | 678 | foreach($_COOKIE as $key=>$value) |
661 | 679 | { |
662 | - if(($value=$sm->validateData($value))!==false) |
|
663 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
680 | + if(($value=$sm->validateData($value))!==false) { |
|
681 | + $this->_cookies->add(new THttpCookie($key,$value)); |
|
682 | + } |
|
664 | 683 | } |
665 | - } |
|
666 | - else |
|
684 | + } else |
|
667 | 685 | { |
668 | - foreach($_COOKIE as $key=>$value) |
|
669 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
686 | + foreach($_COOKIE as $key=>$value) { |
|
687 | + $this->_cookies->add(new THttpCookie($key,$value)); |
|
688 | + } |
|
670 | 689 | } |
671 | 690 | } |
672 | 691 | return $this->_cookies; |
@@ -715,13 +734,15 @@ discard block |
||
715 | 734 | */ |
716 | 735 | public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) |
717 | 736 | { |
718 | - if ($this->_cookieOnly===null) |
|
719 | - $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
737 | + if ($this->_cookieOnly===null) { |
|
738 | + $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
739 | + } |
|
720 | 740 | $url=$this->getUrlManagerModule()->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
721 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
722 | - return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
723 | - else |
|
724 | - return $url; |
|
741 | + if(defined('SID') && SID != '' && !$this->_cookieOnly) { |
|
742 | + return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
743 | + } else { |
|
744 | + return $url; |
|
745 | + } |
|
725 | 746 | } |
726 | 747 | |
727 | 748 | /** |
@@ -749,8 +770,9 @@ discard block |
||
749 | 770 | { |
750 | 771 | Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'],'System.Web.THttpRequest'); |
751 | 772 | $getParams=$this->parseUrl(); |
752 | - foreach($getParams as $name=>$value) |
|
753 | - $_GET[$name]=$value; |
|
773 | + foreach($getParams as $name=>$value) { |
|
774 | + $_GET[$name]=$value; |
|
775 | + } |
|
754 | 776 | $this->_items=array_merge($_GET,$_POST); |
755 | 777 | $this->_requestResolved=true; |
756 | 778 | foreach($serviceIDs as $serviceID) |
@@ -880,9 +902,9 @@ discard block |
||
880 | 902 | $value=$this->_items[$key]; |
881 | 903 | unset($this->_items[$key]); |
882 | 904 | return $value; |
905 | + } else { |
|
906 | + return null; |
|
883 | 907 | } |
884 | - else |
|
885 | - return null; |
|
886 | 908 | } |
887 | 909 | |
888 | 910 | /** |
@@ -890,8 +912,9 @@ discard block |
||
890 | 912 | */ |
891 | 913 | public function clear() |
892 | 914 | { |
893 | - foreach(array_keys($this->_items) as $key) |
|
894 | - $this->remove($key); |
|
915 | + foreach(array_keys($this->_items) as $key) { |
|
916 | + $this->remove($key); |
|
917 | + } |
|
895 | 918 | } |
896 | 919 | |
897 | 920 | /** |
@@ -999,11 +1022,12 @@ discard block |
||
999 | 1022 | if($item instanceof THttpCookie) |
1000 | 1023 | { |
1001 | 1024 | parent::insertAt($index,$item); |
1002 | - if($this->_o instanceof THttpResponse) |
|
1003 | - $this->_o->addCookie($item); |
|
1025 | + if($this->_o instanceof THttpResponse) { |
|
1026 | + $this->_o->addCookie($item); |
|
1027 | + } |
|
1028 | + } else { |
|
1029 | + throw new TInvalidDataTypeException('httpcookiecollection_httpcookie_required'); |
|
1004 | 1030 | } |
1005 | - else |
|
1006 | - throw new TInvalidDataTypeException('httpcookiecollection_httpcookie_required'); |
|
1007 | 1031 | } |
1008 | 1032 | |
1009 | 1033 | /** |
@@ -1016,8 +1040,9 @@ discard block |
||
1016 | 1040 | public function removeAt($index) |
1017 | 1041 | { |
1018 | 1042 | $item=parent::removeAt($index); |
1019 | - if($this->_o instanceof THttpResponse) |
|
1020 | - $this->_o->removeCookie($item); |
|
1043 | + if($this->_o instanceof THttpResponse) { |
|
1044 | + $this->_o->removeCookie($item); |
|
1045 | + } |
|
1021 | 1046 | return $item; |
1022 | 1047 | } |
1023 | 1048 | |
@@ -1027,10 +1052,11 @@ discard block |
||
1027 | 1052 | */ |
1028 | 1053 | public function itemAt($index) |
1029 | 1054 | { |
1030 | - if(is_integer($index)) |
|
1031 | - return parent::itemAt($index); |
|
1032 | - else |
|
1033 | - return $this->findCookieByName($index); |
|
1055 | + if(is_integer($index)) { |
|
1056 | + return parent::itemAt($index); |
|
1057 | + } else { |
|
1058 | + return $this->findCookieByName($index); |
|
1059 | + } |
|
1034 | 1060 | } |
1035 | 1061 | |
1036 | 1062 | /** |
@@ -1040,9 +1066,10 @@ discard block |
||
1040 | 1066 | */ |
1041 | 1067 | public function findCookieByName($name) |
1042 | 1068 | { |
1043 | - foreach($this as $cookie) |
|
1044 | - if($cookie->getName()===$name) |
|
1069 | + foreach($this as $cookie) { |
|
1070 | + if($cookie->getName()===$name) |
|
1045 | 1071 | return $cookie; |
1072 | + } |
|
1046 | 1073 | return null; |
1047 | 1074 | } |
1048 | 1075 | } |
@@ -1303,8 +1330,7 @@ discard block |
||
1303 | 1330 | $this->_query=isset($ret['query'])?$ret['query']:''; |
1304 | 1331 | $this->_fragment=isset($ret['fragment'])?$ret['fragment']:''; |
1305 | 1332 | $this->_uri=$uri; |
1306 | - } |
|
1307 | - else |
|
1333 | + } else |
|
1308 | 1334 | { |
1309 | 1335 | throw new TInvalidDataValueException('uri_format_invalid',$uri); |
1310 | 1336 | } |
@@ -181,6 +181,7 @@ discard block |
||
181 | 181 | |
182 | 182 | /** |
183 | 183 | * @param integer time-to-live for cached session pages in minutes, this has no effect for nocache limiter. |
184 | + * @param integer $value |
|
184 | 185 | */ |
185 | 186 | public function setCacheExpire($value) |
186 | 187 | { |
@@ -198,6 +199,7 @@ discard block |
||
198 | 199 | /** |
199 | 200 | * @param string cache control method to use for session pages. Valid values |
200 | 201 | * include none/nocache/private/private_no_expire/public |
202 | + * @param string $value |
|
201 | 203 | */ |
202 | 204 | public function setCacheControl($value) |
203 | 205 | { |
@@ -223,7 +225,7 @@ discard block |
||
223 | 225 | } |
224 | 226 | |
225 | 227 | /** |
226 | - * @return string|boolean output charset. |
|
228 | + * @return string output charset. |
|
227 | 229 | */ |
228 | 230 | public function getCharset() |
229 | 231 | { |
@@ -232,6 +234,7 @@ discard block |
||
232 | 234 | |
233 | 235 | /** |
234 | 236 | * @param string|boolean output charset. |
237 | + * @param string $charset |
|
235 | 238 | */ |
236 | 239 | public function setCharset($charset) |
237 | 240 | { |
@@ -248,6 +251,7 @@ discard block |
||
248 | 251 | |
249 | 252 | /** |
250 | 253 | * @param boolean whether to enable output buffer |
254 | + * @param boolean $value |
|
251 | 255 | * @throws TInvalidOperationException if session is started already |
252 | 256 | */ |
253 | 257 | public function setBufferOutput($value) |
@@ -604,6 +608,7 @@ discard block |
||
604 | 608 | * Sends a header. |
605 | 609 | * @param string header |
606 | 610 | * @param boolean whether the header should replace a previous similar header, or add a second header of the same type |
611 | + * @param string $value |
|
607 | 612 | */ |
608 | 613 | public function appendHeader($value, $replace=true) |
609 | 614 | { |
@@ -629,6 +634,7 @@ discard block |
||
629 | 634 | * Sends a cookie. |
630 | 635 | * Do not call this method directly. Operate with the result of {@link getCookies} instead. |
631 | 636 | * @param THttpCookie cook to be sent |
637 | + * @param THttpCookie $cookie |
|
632 | 638 | */ |
633 | 639 | public function addCookie($cookie) |
634 | 640 | { |
@@ -713,6 +719,7 @@ discard block |
||
713 | 719 | * This method is used internally. Please use {@link createHtmlWriter} instead. |
714 | 720 | * @param string type of HTML writer to be created. |
715 | 721 | * @param ITextWriter text writer holding the contents. |
722 | + * @param THttpResponse $writer |
|
716 | 723 | */ |
717 | 724 | public function createNewHtmlWriter($type, $writer) |
718 | 725 | { |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | */ |
65 | 65 | class THttpResponse extends TModule implements ITextWriter |
66 | 66 | { |
67 | - const DEFAULT_CONTENTTYPE = 'text/html'; |
|
68 | - const DEFAULT_CHARSET = 'UTF-8'; |
|
67 | + const DEFAULT_CONTENTTYPE = 'text/html'; |
|
68 | + const DEFAULT_CHARSET = 'UTF-8'; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616} |
@@ -81,35 +81,35 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * @var boolean whether to buffer output |
83 | 83 | */ |
84 | - private $_bufferOutput=true; |
|
84 | + private $_bufferOutput = true; |
|
85 | 85 | /** |
86 | 86 | * @var boolean if the application is initialized |
87 | 87 | */ |
88 | - private $_initialized=false; |
|
88 | + private $_initialized = false; |
|
89 | 89 | /** |
90 | 90 | * @var THttpCookieCollection list of cookies to return |
91 | 91 | */ |
92 | - private $_cookies=null; |
|
92 | + private $_cookies = null; |
|
93 | 93 | /** |
94 | 94 | * @var integer response status code |
95 | 95 | */ |
96 | - private $_status=200; |
|
96 | + private $_status = 200; |
|
97 | 97 | /** |
98 | 98 | * @var string reason correspond to status code |
99 | 99 | */ |
100 | - private $_reason='OK'; |
|
100 | + private $_reason = 'OK'; |
|
101 | 101 | /** |
102 | 102 | * @var string HTML writer type |
103 | 103 | */ |
104 | - private $_htmlWriterType='System.Web.UI.THtmlWriter'; |
|
104 | + private $_htmlWriterType = 'System.Web.UI.THtmlWriter'; |
|
105 | 105 | /** |
106 | 106 | * @var string content type |
107 | 107 | */ |
108 | - private $_contentType=null; |
|
108 | + private $_contentType = null; |
|
109 | 109 | /** |
110 | 110 | * @var string|boolean character set, e.g. UTF-8 or false if no character set should be send to client |
111 | 111 | */ |
112 | - private $_charset=''; |
|
112 | + private $_charset = ''; |
|
113 | 113 | /** |
114 | 114 | * @var THttpResponseAdapter adapter. |
115 | 115 | */ |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function setAdapter(THttpResponseAdapter $adapter) |
140 | 140 | { |
141 | - $this->_adapter=$adapter; |
|
141 | + $this->_adapter = $adapter; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function getHasAdapter() |
156 | 156 | { |
157 | - return $this->_adapter!==null; |
|
157 | + return $this->_adapter !== null; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function init($config) |
167 | 167 | { |
168 | - if($this->_bufferOutput) |
|
168 | + if ($this->_bufferOutput) |
|
169 | 169 | ob_start(); |
170 | - $this->_initialized=true; |
|
170 | + $this->_initialized = true; |
|
171 | 171 | $this->getApplication()->setResponse($this); |
172 | 172 | } |
173 | 173 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function setCacheControl($value) |
203 | 203 | { |
204 | - session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public'))); |
|
204 | + session_cache_limiter(TPropertyValue::ensureEnum($value, array('none', 'nocache', 'private', 'private_no_expire', 'public'))); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | */ |
236 | 236 | public function setCharset($charset) |
237 | 237 | { |
238 | - $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset; |
|
238 | + $this->_charset = (strToLower($charset) === 'false') ? false : (string) $charset; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function setBufferOutput($value) |
254 | 254 | { |
255 | - if($this->_initialized) |
|
255 | + if ($this->_initialized) |
|
256 | 256 | throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
257 | 257 | else |
258 | - $this->_bufferOutput=TPropertyValue::ensureBoolean($value); |
|
258 | + $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -274,24 +274,24 @@ discard block |
||
274 | 274 | * @param integer HTTP status code |
275 | 275 | * @param string HTTP status reason, defaults to standard HTTP reasons |
276 | 276 | */ |
277 | - public function setStatusCode($status, $reason=null) |
|
277 | + public function setStatusCode($status, $reason = null) |
|
278 | 278 | { |
279 | 279 | if ($this->_httpHeaderSent) |
280 | 280 | throw new Exception('Unable to alter response as HTTP header already sent'); |
281 | - $status=TPropertyValue::ensureInteger($status); |
|
282 | - if(isset(self::$HTTP_STATUS_CODES[$status])) { |
|
283 | - $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
|
284 | - }else{ |
|
285 | - if($reason===null || $reason==='') { |
|
281 | + $status = TPropertyValue::ensureInteger($status); |
|
282 | + if (isset(self::$HTTP_STATUS_CODES[$status])) { |
|
283 | + $this->_reason = self::$HTTP_STATUS_CODES[$status]; |
|
284 | + } else { |
|
285 | + if ($reason === null || $reason === '') { |
|
286 | 286 | throw new TInvalidDataValueException("response_status_reason_missing"); |
287 | 287 | } |
288 | - $reason=TPropertyValue::ensureString($reason); |
|
289 | - if(strpos($reason, "\r")!=false || strpos($reason, "\n")!=false) { |
|
288 | + $reason = TPropertyValue::ensureString($reason); |
|
289 | + if (strpos($reason, "\r") != false || strpos($reason, "\n") != false) { |
|
290 | 290 | throw new TInvalidDataValueException("response_status_reason_barchars"); |
291 | 291 | } |
292 | - $this->_reason=$reason; |
|
292 | + $this->_reason = $reason; |
|
293 | 293 | } |
294 | - $this->_status=$status; |
|
294 | + $this->_status = $status; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function getCookies() |
308 | 308 | { |
309 | - if($this->_cookies===null) |
|
310 | - $this->_cookies=new THttpCookieCollection($this); |
|
309 | + if ($this->_cookies === null) |
|
310 | + $this->_cookies = new THttpCookieCollection($this); |
|
311 | 311 | return $this->_cookies; |
312 | 312 | } |
313 | 313 | |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect. |
337 | 337 | * @throws TInvalidDataValueException if the file cannot be found |
338 | 338 | */ |
339 | - public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null) |
|
339 | + public function writeFile($fileName, $content = null, $mimeType = null, $headers = null, $forceDownload = true, $clientFileName = null, $fileSize = null) |
|
340 | 340 | { |
341 | - static $defaultMimeTypes=array( |
|
341 | + static $defaultMimeTypes = array( |
|
342 | 342 | 'css'=>'text/css', |
343 | 343 | 'gif'=>'image/gif', |
344 | 344 | 'png'=>'image/png', |
@@ -351,31 +351,31 @@ discard block |
||
351 | 351 | 'xls'=>'application/vnd.ms-excel', |
352 | 352 | ); |
353 | 353 | |
354 | - if($mimeType===null) |
|
354 | + if ($mimeType === null) |
|
355 | 355 | { |
356 | - $mimeType='text/plain'; |
|
357 | - if(function_exists('mime_content_type')) |
|
358 | - $mimeType=mime_content_type($fileName); |
|
359 | - else if(($ext=strrchr($fileName,'.'))!==false) |
|
356 | + $mimeType = 'text/plain'; |
|
357 | + if (function_exists('mime_content_type')) |
|
358 | + $mimeType = mime_content_type($fileName); |
|
359 | + else if (($ext = strrchr($fileName, '.')) !== false) |
|
360 | 360 | { |
361 | - $ext=substr($ext,1); |
|
362 | - if(isset($defaultMimeTypes[$ext])) |
|
363 | - $mimeType=$defaultMimeTypes[$ext]; |
|
361 | + $ext = substr($ext, 1); |
|
362 | + if (isset($defaultMimeTypes[$ext])) |
|
363 | + $mimeType = $defaultMimeTypes[$ext]; |
|
364 | 364 | } |
365 | 365 | } |
366 | 366 | |
367 | - if($clientFileName===null) |
|
368 | - $clientFileName=basename($fileName); |
|
367 | + if ($clientFileName === null) |
|
368 | + $clientFileName = basename($fileName); |
|
369 | 369 | else |
370 | - $clientFileName=basename($clientFileName); |
|
370 | + $clientFileName = basename($clientFileName); |
|
371 | 371 | |
372 | - if($fileSize===null || $fileSize < 0) |
|
373 | - $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
372 | + if ($fileSize === null || $fileSize < 0) |
|
373 | + $fileSize = ($content === null ? filesize($fileName) : strlen($content)); |
|
374 | 374 | |
375 | 375 | $this->sendHttpHeader(); |
376 | - if(is_array($headers)) |
|
376 | + if (is_array($headers)) |
|
377 | 377 | { |
378 | - foreach($headers as $h) |
|
378 | + foreach ($headers as $h) |
|
379 | 379 | header($h); |
380 | 380 | } |
381 | 381 | else |
@@ -387,10 +387,10 @@ discard block |
||
387 | 387 | $this->_contentTypeHeaderSent = true; |
388 | 388 | } |
389 | 389 | |
390 | - header('Content-Length: '.$fileSize); |
|
390 | + header('Content-Length: ' . $fileSize); |
|
391 | 391 | header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
392 | 392 | header('Content-Transfer-Encoding: binary'); |
393 | - if($content===null) |
|
393 | + if ($content === null) |
|
394 | 394 | readfile($fileName); |
395 | 395 | else |
396 | 396 | echo $content; |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | */ |
405 | 405 | public function redirect($url) |
406 | 406 | { |
407 | - if($this->getHasAdapter()) |
|
407 | + if ($this->getHasAdapter()) |
|
408 | 408 | $this->_adapter->httpRedirect($url); |
409 | 409 | else |
410 | 410 | $this->httpRedirect($url); |
@@ -426,15 +426,15 @@ discard block |
||
426 | 426 | { |
427 | 427 | $this->ensureHeadersSent(); |
428 | 428 | |
429 | - if($url[0]==='/') |
|
430 | - $url=$this->getRequest()->getBaseUrl().$url; |
|
429 | + if ($url[0] === '/') |
|
430 | + $url = $this->getRequest()->getBaseUrl() . $url; |
|
431 | 431 | if ($this->_status >= 300 && $this->_status < 400) |
432 | 432 | // The status code has been modified to a valid redirection status, send it |
433 | - header('Location: '.str_replace('&','&',$url), true, $this->_status); |
|
433 | + header('Location: ' . str_replace('&', '&', $url), true, $this->_status); |
|
434 | 434 | else |
435 | - header('Location: '.str_replace('&','&',$url)); |
|
435 | + header('Location: ' . str_replace('&', '&', $url)); |
|
436 | 436 | |
437 | - if(!$this->getApplication()->getRequestCompleted()) |
|
437 | + if (!$this->getApplication()->getRequestCompleted()) |
|
438 | 438 | $this->getApplication()->onEndRequest(); |
439 | 439 | |
440 | 440 | exit(); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | */ |
456 | 456 | public function flush($continueBuffering = true) |
457 | 457 | { |
458 | - if($this->getHasAdapter()) |
|
458 | + if ($this->getHasAdapter()) |
|
459 | 459 | $this->_adapter->flushContent($continueBuffering); |
460 | 460 | else |
461 | 461 | $this->flushContent($continueBuffering); |
@@ -477,12 +477,12 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function flushContent($continueBuffering = true) |
479 | 479 | { |
480 | - Prado::trace("Flushing output",'System.Web.THttpResponse'); |
|
480 | + Prado::trace("Flushing output", 'System.Web.THttpResponse'); |
|
481 | 481 | $this->ensureHeadersSent(); |
482 | - if($this->_bufferOutput) |
|
482 | + if ($this->_bufferOutput) |
|
483 | 483 | { |
484 | 484 | // avoid forced send of http headers (ob_flush() does that) if there's no output yet |
485 | - if (ob_get_length()>0) |
|
485 | + if (ob_get_length() > 0) |
|
486 | 486 | { |
487 | 487 | if (!$continueBuffering) |
488 | 488 | { |
@@ -512,14 +512,14 @@ discard block |
||
512 | 512 | */ |
513 | 513 | protected function sendHttpHeader() |
514 | 514 | { |
515 | - $protocol=$this->getRequest()->getHttpProtocolVersion(); |
|
516 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
517 | - $protocol='HTTP/1.1'; |
|
515 | + $protocol = $this->getRequest()->getHttpProtocolVersion(); |
|
516 | + if ($this->getRequest()->getHttpProtocolVersion() === null) |
|
517 | + $protocol = 'HTTP/1.1'; |
|
518 | 518 | |
519 | 519 | $phpSapiName = substr(php_sapi_name(), 0, 3); |
520 | 520 | $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; |
521 | 521 | |
522 | - header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
522 | + header(($cgi ? 'Status:' : $protocol) . ' ' . $this->_status . ' ' . $this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
523 | 523 | |
524 | 524 | $this->_httpHeaderSent = true; |
525 | 525 | } |
@@ -538,18 +538,18 @@ discard block |
||
538 | 538 | */ |
539 | 539 | protected function sendContentTypeHeader() |
540 | 540 | { |
541 | - $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
542 | - $charset=$this->getCharset(); |
|
543 | - if($charset === false) { |
|
544 | - $this->appendHeader('Content-Type: '.$contentType); |
|
541 | + $contentType = $this->_contentType === null ? self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
542 | + $charset = $this->getCharset(); |
|
543 | + if ($charset === false) { |
|
544 | + $this->appendHeader('Content-Type: ' . $contentType); |
|
545 | 545 | return; |
546 | 546 | } |
547 | 547 | |
548 | - if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
|
549 | - $charset=$globalization->getCharset(); |
|
548 | + if ($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
549 | + $charset = $globalization->getCharset(); |
|
550 | 550 | |
551 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
552 | - $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
|
551 | + if ($charset === '') $charset = self::DEFAULT_CHARSET; |
|
552 | + $this->appendHeader('Content-Type: ' . $contentType . ';charset=' . $charset); |
|
553 | 553 | |
554 | 554 | $this->_contentTypeHeaderSent = true; |
555 | 555 | } |
@@ -562,8 +562,8 @@ discard block |
||
562 | 562 | */ |
563 | 563 | public function getContents() |
564 | 564 | { |
565 | - Prado::trace("Retrieving output",'System.Web.THttpResponse'); |
|
566 | - return $this->_bufferOutput?ob_get_contents():''; |
|
565 | + Prado::trace("Retrieving output", 'System.Web.THttpResponse'); |
|
566 | + return $this->_bufferOutput ? ob_get_contents() : ''; |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -571,30 +571,30 @@ discard block |
||
571 | 571 | */ |
572 | 572 | public function clear() |
573 | 573 | { |
574 | - if($this->_bufferOutput) |
|
574 | + if ($this->_bufferOutput) |
|
575 | 575 | ob_clean(); |
576 | - Prado::trace("Clearing output",'System.Web.THttpResponse'); |
|
576 | + Prado::trace("Clearing output", 'System.Web.THttpResponse'); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | 580 | * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default) |
581 | 581 | * @return array |
582 | 582 | */ |
583 | - public function getHeaders($case=null) |
|
583 | + public function getHeaders($case = null) |
|
584 | 584 | { |
585 | 585 | $result = array(); |
586 | 586 | $headers = headers_list(); |
587 | - foreach($headers as $header) { |
|
587 | + foreach ($headers as $header) { |
|
588 | 588 | $tmp = explode(':', $header); |
589 | 589 | $key = trim(array_shift($tmp)); |
590 | 590 | $value = trim(implode(':', $tmp)); |
591 | - if(isset($result[$key])) |
|
591 | + if (isset($result[$key])) |
|
592 | 592 | $result[$key] .= ', ' . $value; |
593 | 593 | else |
594 | 594 | $result[$key] = $value; |
595 | 595 | } |
596 | 596 | |
597 | - if($case !== null) |
|
597 | + if ($case !== null) |
|
598 | 598 | return array_change_key_case($result, $case); |
599 | 599 | |
600 | 600 | return $result; |
@@ -605,9 +605,9 @@ discard block |
||
605 | 605 | * @param string header |
606 | 606 | * @param boolean whether the header should replace a previous similar header, or add a second header of the same type |
607 | 607 | */ |
608 | - public function appendHeader($value, $replace=true) |
|
608 | + public function appendHeader($value, $replace = true) |
|
609 | 609 | { |
610 | - Prado::trace("Sending header '$value'",'System.Web.THttpResponse'); |
|
610 | + Prado::trace("Sending header '$value'", 'System.Web.THttpResponse'); |
|
611 | 611 | header($value, $replace); |
612 | 612 | } |
613 | 613 | |
@@ -620,9 +620,9 @@ discard block |
||
620 | 620 | * @param string The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does. |
621 | 621 | * @see http://us2.php.net/manual/en/function.error-log.php |
622 | 622 | */ |
623 | - public function appendLog($message,$messageType=0,$destination='',$extraHeaders='') |
|
623 | + public function appendLog($message, $messageType = 0, $destination = '', $extraHeaders = '') |
|
624 | 624 | { |
625 | - error_log($message,$messageType,$destination,$extraHeaders); |
|
625 | + error_log($message, $messageType, $destination, $extraHeaders); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -632,10 +632,10 @@ discard block |
||
632 | 632 | */ |
633 | 633 | public function addCookie($cookie) |
634 | 634 | { |
635 | - $request=$this->getRequest(); |
|
636 | - if($request->getEnableCookieValidation()) |
|
635 | + $request = $this->getRequest(); |
|
636 | + if ($request->getEnableCookieValidation()) |
|
637 | 637 | { |
638 | - $value=$this->getApplication()->getSecurityManager()->hashData($cookie->getValue()); |
|
638 | + $value = $this->getApplication()->getSecurityManager()->hashData($cookie->getValue()); |
|
639 | 639 | setcookie( |
640 | 640 | $cookie->getName(), |
641 | 641 | $value, |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | */ |
691 | 691 | public function setHtmlWriterType($value) |
692 | 692 | { |
693 | - $this->_htmlWriterType=$value; |
|
693 | + $this->_htmlWriterType = $value; |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -698,11 +698,11 @@ discard block |
||
698 | 698 | * If the type of the HTML writer is not supplied, {@link getHtmlWriterType HtmlWriterType} will be assumed. |
699 | 699 | * @param string type of the HTML writer to be created. If null, {@link getHtmlWriterType HtmlWriterType} will be assumed. |
700 | 700 | */ |
701 | - public function createHtmlWriter($type=null) |
|
701 | + public function createHtmlWriter($type = null) |
|
702 | 702 | { |
703 | - if($type===null) |
|
704 | - $type=$this->getHtmlWriterType(); |
|
705 | - if($this->getHasAdapter()) |
|
703 | + if ($type === null) |
|
704 | + $type = $this->getHtmlWriterType(); |
|
705 | + if ($this->getHasAdapter()) |
|
706 | 706 | return $this->_adapter->createNewHtmlWriter($type, $this); |
707 | 707 | else |
708 | 708 | return $this->createNewHtmlWriter($type, $this); |
@@ -165,8 +165,9 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function init($config) |
167 | 167 | { |
168 | - if($this->_bufferOutput) |
|
169 | - ob_start(); |
|
168 | + if($this->_bufferOutput) { |
|
169 | + ob_start(); |
|
170 | + } |
|
170 | 171 | $this->_initialized=true; |
171 | 172 | $this->getApplication()->setResponse($this); |
172 | 173 | } |
@@ -209,8 +210,9 @@ discard block |
||
209 | 210 | */ |
210 | 211 | public function setContentType($type) |
211 | 212 | { |
212 | - if ($this->_contentTypeHeaderSent) |
|
213 | - throw new Exception('Unable to alter content-type as it has been already sent'); |
|
213 | + if ($this->_contentTypeHeaderSent) { |
|
214 | + throw new Exception('Unable to alter content-type as it has been already sent'); |
|
215 | + } |
|
214 | 216 | $this->_contentType = $type; |
215 | 217 | } |
216 | 218 | |
@@ -252,10 +254,11 @@ discard block |
||
252 | 254 | */ |
253 | 255 | public function setBufferOutput($value) |
254 | 256 | { |
255 | - if($this->_initialized) |
|
256 | - throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
257 | - else |
|
258 | - $this->_bufferOutput=TPropertyValue::ensureBoolean($value); |
|
257 | + if($this->_initialized) { |
|
258 | + throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
259 | + } else { |
|
260 | + $this->_bufferOutput=TPropertyValue::ensureBoolean($value); |
|
261 | + } |
|
259 | 262 | } |
260 | 263 | |
261 | 264 | /** |
@@ -276,12 +279,13 @@ discard block |
||
276 | 279 | */ |
277 | 280 | public function setStatusCode($status, $reason=null) |
278 | 281 | { |
279 | - if ($this->_httpHeaderSent) |
|
280 | - throw new Exception('Unable to alter response as HTTP header already sent'); |
|
282 | + if ($this->_httpHeaderSent) { |
|
283 | + throw new Exception('Unable to alter response as HTTP header already sent'); |
|
284 | + } |
|
281 | 285 | $status=TPropertyValue::ensureInteger($status); |
282 | 286 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
283 | 287 | $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
284 | - }else{ |
|
288 | + } else{ |
|
285 | 289 | if($reason===null || $reason==='') { |
286 | 290 | throw new TInvalidDataValueException("response_status_reason_missing"); |
287 | 291 | } |
@@ -306,8 +310,9 @@ discard block |
||
306 | 310 | */ |
307 | 311 | public function getCookies() |
308 | 312 | { |
309 | - if($this->_cookies===null) |
|
310 | - $this->_cookies=new THttpCookieCollection($this); |
|
313 | + if($this->_cookies===null) { |
|
314 | + $this->_cookies=new THttpCookieCollection($this); |
|
315 | + } |
|
311 | 316 | return $this->_cookies; |
312 | 317 | } |
313 | 318 | |
@@ -319,8 +324,9 @@ discard block |
||
319 | 324 | public function write($str) |
320 | 325 | { |
321 | 326 | // when starting output make sure we send the headers first |
322 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
323 | - $this->ensureHeadersSent(); |
|
327 | + if (!$this->_bufferOutput and !$this->_httpHeaderSent) { |
|
328 | + $this->ensureHeadersSent(); |
|
329 | + } |
|
324 | 330 | echo $str; |
325 | 331 | } |
326 | 332 | |
@@ -354,31 +360,34 @@ discard block |
||
354 | 360 | if($mimeType===null) |
355 | 361 | { |
356 | 362 | $mimeType='text/plain'; |
357 | - if(function_exists('mime_content_type')) |
|
358 | - $mimeType=mime_content_type($fileName); |
|
359 | - else if(($ext=strrchr($fileName,'.'))!==false) |
|
363 | + if(function_exists('mime_content_type')) { |
|
364 | + $mimeType=mime_content_type($fileName); |
|
365 | + } else if(($ext=strrchr($fileName,'.'))!==false) |
|
360 | 366 | { |
361 | 367 | $ext=substr($ext,1); |
362 | - if(isset($defaultMimeTypes[$ext])) |
|
363 | - $mimeType=$defaultMimeTypes[$ext]; |
|
368 | + if(isset($defaultMimeTypes[$ext])) { |
|
369 | + $mimeType=$defaultMimeTypes[$ext]; |
|
370 | + } |
|
364 | 371 | } |
365 | 372 | } |
366 | 373 | |
367 | - if($clientFileName===null) |
|
368 | - $clientFileName=basename($fileName); |
|
369 | - else |
|
370 | - $clientFileName=basename($clientFileName); |
|
374 | + if($clientFileName===null) { |
|
375 | + $clientFileName=basename($fileName); |
|
376 | + } else { |
|
377 | + $clientFileName=basename($clientFileName); |
|
378 | + } |
|
371 | 379 | |
372 | - if($fileSize===null || $fileSize < 0) |
|
373 | - $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
380 | + if($fileSize===null || $fileSize < 0) { |
|
381 | + $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
382 | + } |
|
374 | 383 | |
375 | 384 | $this->sendHttpHeader(); |
376 | 385 | if(is_array($headers)) |
377 | 386 | { |
378 | - foreach($headers as $h) |
|
379 | - header($h); |
|
380 | - } |
|
381 | - else |
|
387 | + foreach($headers as $h) { |
|
388 | + header($h); |
|
389 | + } |
|
390 | + } else |
|
382 | 391 | { |
383 | 392 | header('Pragma: public'); |
384 | 393 | header('Expires: 0'); |
@@ -390,10 +399,11 @@ discard block |
||
390 | 399 | header('Content-Length: '.$fileSize); |
391 | 400 | header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
392 | 401 | header('Content-Transfer-Encoding: binary'); |
393 | - if($content===null) |
|
394 | - readfile($fileName); |
|
395 | - else |
|
396 | - echo $content; |
|
402 | + if($content===null) { |
|
403 | + readfile($fileName); |
|
404 | + } else { |
|
405 | + echo $content; |
|
406 | + } |
|
397 | 407 | } |
398 | 408 | |
399 | 409 | /** |
@@ -404,10 +414,11 @@ discard block |
||
404 | 414 | */ |
405 | 415 | public function redirect($url) |
406 | 416 | { |
407 | - if($this->getHasAdapter()) |
|
408 | - $this->_adapter->httpRedirect($url); |
|
409 | - else |
|
410 | - $this->httpRedirect($url); |
|
417 | + if($this->getHasAdapter()) { |
|
418 | + $this->_adapter->httpRedirect($url); |
|
419 | + } else { |
|
420 | + $this->httpRedirect($url); |
|
421 | + } |
|
411 | 422 | } |
412 | 423 | |
413 | 424 | /** |
@@ -426,16 +437,19 @@ discard block |
||
426 | 437 | { |
427 | 438 | $this->ensureHeadersSent(); |
428 | 439 | |
429 | - if($url[0]==='/') |
|
430 | - $url=$this->getRequest()->getBaseUrl().$url; |
|
431 | - if ($this->_status >= 300 && $this->_status < 400) |
|
432 | - // The status code has been modified to a valid redirection status, send it |
|
440 | + if($url[0]==='/') { |
|
441 | + $url=$this->getRequest()->getBaseUrl().$url; |
|
442 | + } |
|
443 | + if ($this->_status >= 300 && $this->_status < 400) { |
|
444 | + // The status code has been modified to a valid redirection status, send it |
|
433 | 445 | header('Location: '.str_replace('&','&',$url), true, $this->_status); |
434 | - else |
|
435 | - header('Location: '.str_replace('&','&',$url)); |
|
446 | + } else { |
|
447 | + header('Location: '.str_replace('&','&',$url)); |
|
448 | + } |
|
436 | 449 | |
437 | - if(!$this->getApplication()->getRequestCompleted()) |
|
438 | - $this->getApplication()->onEndRequest(); |
|
450 | + if(!$this->getApplication()->getRequestCompleted()) { |
|
451 | + $this->getApplication()->onEndRequest(); |
|
452 | + } |
|
439 | 453 | |
440 | 454 | exit(); |
441 | 455 | } |
@@ -455,10 +469,11 @@ discard block |
||
455 | 469 | */ |
456 | 470 | public function flush($continueBuffering = true) |
457 | 471 | { |
458 | - if($this->getHasAdapter()) |
|
459 | - $this->_adapter->flushContent($continueBuffering); |
|
460 | - else |
|
461 | - $this->flushContent($continueBuffering); |
|
472 | + if($this->getHasAdapter()) { |
|
473 | + $this->_adapter->flushContent($continueBuffering); |
|
474 | + } else { |
|
475 | + $this->flushContent($continueBuffering); |
|
476 | + } |
|
462 | 477 | } |
463 | 478 | |
464 | 479 | /** |
@@ -488,14 +503,14 @@ discard block |
||
488 | 503 | { |
489 | 504 | $this->_bufferOutput = false; |
490 | 505 | ob_end_flush(); |
506 | + } else { |
|
507 | + ob_flush(); |
|
491 | 508 | } |
492 | - else |
|
493 | - ob_flush(); |
|
494 | 509 | flush(); |
495 | 510 | } |
511 | + } else { |
|
512 | + flush(); |
|
496 | 513 | } |
497 | - else |
|
498 | - flush(); |
|
499 | 514 | } |
500 | 515 | |
501 | 516 | /** |
@@ -503,8 +518,9 @@ discard block |
||
503 | 518 | */ |
504 | 519 | protected function ensureHttpHeaderSent() |
505 | 520 | { |
506 | - if (!$this->_httpHeaderSent) |
|
507 | - $this->sendHttpHeader(); |
|
521 | + if (!$this->_httpHeaderSent) { |
|
522 | + $this->sendHttpHeader(); |
|
523 | + } |
|
508 | 524 | } |
509 | 525 | |
510 | 526 | /** |
@@ -513,8 +529,9 @@ discard block |
||
513 | 529 | protected function sendHttpHeader() |
514 | 530 | { |
515 | 531 | $protocol=$this->getRequest()->getHttpProtocolVersion(); |
516 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
517 | - $protocol='HTTP/1.1'; |
|
532 | + if($this->getRequest()->getHttpProtocolVersion() === null) { |
|
533 | + $protocol='HTTP/1.1'; |
|
534 | + } |
|
518 | 535 | |
519 | 536 | $phpSapiName = substr(php_sapi_name(), 0, 3); |
520 | 537 | $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; |
@@ -529,8 +546,9 @@ discard block |
||
529 | 546 | */ |
530 | 547 | protected function ensureContentTypeHeaderSent() |
531 | 548 | { |
532 | - if (!$this->_contentTypeHeaderSent) |
|
533 | - $this->sendContentTypeHeader(); |
|
549 | + if (!$this->_contentTypeHeaderSent) { |
|
550 | + $this->sendContentTypeHeader(); |
|
551 | + } |
|
534 | 552 | } |
535 | 553 | |
536 | 554 | /** |
@@ -545,10 +563,13 @@ discard block |
||
545 | 563 | return; |
546 | 564 | } |
547 | 565 | |
548 | - if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
|
549 | - $charset=$globalization->getCharset(); |
|
566 | + if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) { |
|
567 | + $charset=$globalization->getCharset(); |
|
568 | + } |
|
550 | 569 | |
551 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
570 | + if($charset==='') { |
|
571 | + $charset = self::DEFAULT_CHARSET; |
|
572 | + } |
|
552 | 573 | $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
553 | 574 | |
554 | 575 | $this->_contentTypeHeaderSent = true; |
@@ -571,8 +592,9 @@ discard block |
||
571 | 592 | */ |
572 | 593 | public function clear() |
573 | 594 | { |
574 | - if($this->_bufferOutput) |
|
575 | - ob_clean(); |
|
595 | + if($this->_bufferOutput) { |
|
596 | + ob_clean(); |
|
597 | + } |
|
576 | 598 | Prado::trace("Clearing output",'System.Web.THttpResponse'); |
577 | 599 | } |
578 | 600 | |
@@ -588,14 +610,16 @@ discard block |
||
588 | 610 | $tmp = explode(':', $header); |
589 | 611 | $key = trim(array_shift($tmp)); |
590 | 612 | $value = trim(implode(':', $tmp)); |
591 | - if(isset($result[$key])) |
|
592 | - $result[$key] .= ', ' . $value; |
|
593 | - else |
|
594 | - $result[$key] = $value; |
|
613 | + if(isset($result[$key])) { |
|
614 | + $result[$key] .= ', ' . $value; |
|
615 | + } else { |
|
616 | + $result[$key] = $value; |
|
617 | + } |
|
595 | 618 | } |
596 | 619 | |
597 | - if($case !== null) |
|
598 | - return array_change_key_case($result, $case); |
|
620 | + if($case !== null) { |
|
621 | + return array_change_key_case($result, $case); |
|
622 | + } |
|
599 | 623 | |
600 | 624 | return $result; |
601 | 625 | } |
@@ -645,8 +669,7 @@ discard block |
||
645 | 669 | $cookie->getSecure(), |
646 | 670 | $cookie->getHttpOnly() |
647 | 671 | ); |
648 | - } |
|
649 | - else { |
|
672 | + } else { |
|
650 | 673 | setcookie( |
651 | 674 | $cookie->getName(), |
652 | 675 | $cookie->getValue(), |
@@ -700,12 +723,14 @@ discard block |
||
700 | 723 | */ |
701 | 724 | public function createHtmlWriter($type=null) |
702 | 725 | { |
703 | - if($type===null) |
|
704 | - $type=$this->getHtmlWriterType(); |
|
705 | - if($this->getHasAdapter()) |
|
706 | - return $this->_adapter->createNewHtmlWriter($type, $this); |
|
707 | - else |
|
708 | - return $this->createNewHtmlWriter($type, $this); |
|
726 | + if($type===null) { |
|
727 | + $type=$this->getHtmlWriterType(); |
|
728 | + } |
|
729 | + if($this->getHasAdapter()) { |
|
730 | + return $this->_adapter->createNewHtmlWriter($type, $this); |
|
731 | + } else { |
|
732 | + return $this->createNewHtmlWriter($type, $this); |
|
733 | + } |
|
709 | 734 | } |
710 | 735 | |
711 | 736 | /** |
@@ -31,6 +31,7 @@ |
||
31 | 31 | /** |
32 | 32 | * Constructor. Attach a response to be adapted. |
33 | 33 | * @param THttpResponse the response object the adapter is to attach to. |
34 | + * @param THttpResponse $response |
|
34 | 35 | */ |
35 | 36 | public function __construct($response) |
36 | 37 | { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct($response) |
36 | 36 | { |
37 | - $this->_response=$response; |
|
37 | + $this->_response = $response; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function createNewHtmlWriter($type, $writer) |
73 | 73 | { |
74 | - return $this->_response->createNewHtmlWriter($type,$writer); |
|
74 | + return $this->_response->createNewHtmlWriter($type, $writer); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 |
@@ -265,6 +265,7 @@ discard block |
||
265 | 265 | * If true, make sure the methods {@link _open}, {@link _close}, {@link _read}, |
266 | 266 | * {@link _write}, {@link _destroy}, and {@link _gc} are overridden in child |
267 | 267 | * class, because they will be used as the callback handlers. |
268 | + * @param boolean $value |
|
268 | 269 | */ |
269 | 270 | public function setUseCustomStorage($value) |
270 | 271 | { |
@@ -527,6 +528,7 @@ discard block |
||
527 | 528 | * Returns the session variable value with the session variable name. |
528 | 529 | * This method is exactly the same as {@link offsetGet}. |
529 | 530 | * @param mixed the session variable name |
531 | + * @param string $key |
|
530 | 532 | * @return mixed the session variable value, null if no such variable exists |
531 | 533 | */ |
532 | 534 | public function itemAt($key) |
@@ -539,6 +541,7 @@ discard block |
||
539 | 541 | * Note, if the specified name already exists, the old value will be removed first. |
540 | 542 | * @param mixed session variable name |
541 | 543 | * @param mixed session variable value |
544 | + * @param string $key |
|
542 | 545 | */ |
543 | 546 | public function add($key,$value) |
544 | 547 | { |
@@ -306,10 +306,10 @@ |
||
306 | 306 | { |
307 | 307 | $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode'); |
308 | 308 | if($value===THttpSessionCookieMode::None) |
309 | - { |
|
309 | + { |
|
310 | 310 | ini_set('session.use_cookies','0'); |
311 | 311 | ini_set('session.use_only_cookies','0'); |
312 | - } |
|
312 | + } |
|
313 | 313 | else if($value===THttpSessionCookieMode::Allow) |
314 | 314 | { |
315 | 315 | ini_set('session.use_cookies','1'); |
@@ -67,24 +67,24 @@ discard block |
||
67 | 67 | * @package System.Web |
68 | 68 | * @since 3.0 |
69 | 69 | */ |
70 | -class THttpSession extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule |
|
70 | +class THttpSession extends TApplicationComponent implements IteratorAggregate, ArrayAccess, Countable, IModule |
|
71 | 71 | { |
72 | 72 | /** |
73 | 73 | * @var boolean whether this module has been initialized |
74 | 74 | */ |
75 | - private $_initialized=false; |
|
75 | + private $_initialized = false; |
|
76 | 76 | /** |
77 | 77 | * @var boolean whether the session has started |
78 | 78 | */ |
79 | - private $_started=false; |
|
79 | + private $_started = false; |
|
80 | 80 | /** |
81 | 81 | * @var boolean whether the session should be started when the module is initialized |
82 | 82 | */ |
83 | - private $_autoStart=false; |
|
83 | + private $_autoStart = false; |
|
84 | 84 | /** |
85 | 85 | * @var THttpCookie cookie to be used to store session ID and other data |
86 | 86 | */ |
87 | - private $_cookie=null; |
|
87 | + private $_cookie = null; |
|
88 | 88 | /** |
89 | 89 | * @var string module id |
90 | 90 | */ |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @var boolean |
94 | 94 | */ |
95 | - private $_customStorage=false; |
|
95 | + private $_customStorage = false; |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return string id of this module |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function setID($value) |
109 | 109 | { |
110 | - $this->_id=$value; |
|
110 | + $this->_id = $value; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function init($config) |
120 | 120 | { |
121 | - if($this->_autoStart) |
|
121 | + if ($this->_autoStart) |
|
122 | 122 | $this->open(); |
123 | - $this->_initialized=true; |
|
123 | + $this->_initialized = true; |
|
124 | 124 | $this->getApplication()->setSession($this); |
125 | 125 | register_shutdown_function(array($this, "close")); |
126 | 126 | } |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function open() |
132 | 132 | { |
133 | - if(!$this->_started) |
|
133 | + if (!$this->_started) |
|
134 | 134 | { |
135 | - if($this->_customStorage) |
|
136 | - session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); |
|
137 | - if($this->_cookie!==null) |
|
138 | - session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); |
|
139 | - if(ini_get('session.auto_start')!=='1') |
|
135 | + if ($this->_customStorage) |
|
136 | + session_set_save_handler(array($this, '_open'), array($this, '_close'), array($this, '_read'), array($this, '_write'), array($this, '_destroy'), array($this, '_gc')); |
|
137 | + if ($this->_cookie !== null) |
|
138 | + session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
|
139 | + if (ini_get('session.auto_start') !== '1') |
|
140 | 140 | session_start(); |
141 | - $this->_started=true; |
|
141 | + $this->_started = true; |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function close() |
149 | 149 | { |
150 | - if($this->_started) |
|
150 | + if ($this->_started) |
|
151 | 151 | { |
152 | 152 | session_write_close(); |
153 | - $this->_started=false; |
|
153 | + $this->_started = false; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function destroy() |
161 | 161 | { |
162 | - if($this->_started) |
|
162 | + if ($this->_started) |
|
163 | 163 | { |
164 | 164 | session_destroy(); |
165 | - $this->_started=false; |
|
165 | + $this->_started = false; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @return string old session id |
174 | 174 | * @link http://php.net/manual/en/function.session-regenerate-id.php |
175 | 175 | */ |
176 | - public function regenerate($deleteOld=false) |
|
176 | + public function regenerate($deleteOld = false) |
|
177 | 177 | { |
178 | 178 | $old = $this->getSessionID(); |
179 | 179 | session_regenerate_id($deleteOld); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function setSessionID($value) |
204 | 204 | { |
205 | - if($this->_started) |
|
205 | + if ($this->_started) |
|
206 | 206 | throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
207 | 207 | else |
208 | 208 | session_id($value); |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function setSessionName($value) |
224 | 224 | { |
225 | - if($this->_started) |
|
225 | + if ($this->_started) |
|
226 | 226 | throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
227 | - else if(ctype_alnum($value)) |
|
227 | + else if (ctype_alnum($value)) |
|
228 | 228 | session_name($value); |
229 | 229 | else |
230 | - throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value); |
|
230 | + throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -244,12 +244,12 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function setSavePath($value) |
246 | 246 | { |
247 | - if($this->_started) |
|
247 | + if ($this->_started) |
|
248 | 248 | throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
249 | - else if(is_dir($value)) |
|
249 | + else if (is_dir($value)) |
|
250 | 250 | session_save_path($value); |
251 | 251 | else |
252 | - throw new TInvalidDataValueException('httpsession_savepath_invalid',$value); |
|
252 | + throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public function setUseCustomStorage($value) |
270 | 270 | { |
271 | - $this->_customStorage=TPropertyValue::ensureBoolean($value); |
|
271 | + $this->_customStorage = TPropertyValue::ensureBoolean($value); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function getCookie() |
278 | 278 | { |
279 | - if($this->_cookie===null) |
|
280 | - $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID()); |
|
279 | + if ($this->_cookie === null) |
|
280 | + $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
|
281 | 281 | return $this->_cookie; |
282 | 282 | } |
283 | 283 | |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function getCookieMode() |
288 | 288 | { |
289 | - if(ini_get('session.use_cookies')==='0') |
|
289 | + if (ini_get('session.use_cookies') === '0') |
|
290 | 290 | return THttpSessionCookieMode::None; |
291 | - else if(ini_get('session.use_only_cookies')==='0') |
|
291 | + else if (ini_get('session.use_only_cookies') === '0') |
|
292 | 292 | return THttpSessionCookieMode::Allow; |
293 | 293 | else |
294 | 294 | return THttpSessionCookieMode::Only; |
@@ -300,25 +300,25 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function setCookieMode($value) |
302 | 302 | { |
303 | - if($this->_started) |
|
303 | + if ($this->_started) |
|
304 | 304 | throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
305 | 305 | else |
306 | 306 | { |
307 | - $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode'); |
|
308 | - if($value===THttpSessionCookieMode::None) |
|
307 | + $value = TPropertyValue::ensureEnum($value, 'THttpSessionCookieMode'); |
|
308 | + if ($value === THttpSessionCookieMode::None) |
|
309 | 309 | { |
310 | - ini_set('session.use_cookies','0'); |
|
311 | - ini_set('session.use_only_cookies','0'); |
|
310 | + ini_set('session.use_cookies', '0'); |
|
311 | + ini_set('session.use_only_cookies', '0'); |
|
312 | 312 | } |
313 | - else if($value===THttpSessionCookieMode::Allow) |
|
313 | + else if ($value === THttpSessionCookieMode::Allow) |
|
314 | 314 | { |
315 | - ini_set('session.use_cookies','1'); |
|
316 | - ini_set('session.use_only_cookies','0'); |
|
315 | + ini_set('session.use_cookies', '1'); |
|
316 | + ini_set('session.use_only_cookies', '0'); |
|
317 | 317 | } |
318 | 318 | else |
319 | 319 | { |
320 | - ini_set('session.use_cookies','1'); |
|
321 | - ini_set('session.use_only_cookies','1'); |
|
320 | + ini_set('session.use_cookies', '1'); |
|
321 | + ini_set('session.use_only_cookies', '1'); |
|
322 | 322 | ini_set('session.use_trans_sid', 0); |
323 | 323 | } |
324 | 324 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public function setAutoStart($value) |
340 | 340 | { |
341 | - if($this->_initialized) |
|
341 | + if ($this->_initialized) |
|
342 | 342 | throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
343 | 343 | else |
344 | - $this->_autoStart=TPropertyValue::ensureBoolean($value); |
|
344 | + $this->_autoStart = TPropertyValue::ensureBoolean($value); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -359,18 +359,18 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function setGCProbability($value) |
361 | 361 | { |
362 | - if($this->_started) |
|
362 | + if ($this->_started) |
|
363 | 363 | throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
364 | 364 | else |
365 | 365 | { |
366 | - $value=TPropertyValue::ensureInteger($value); |
|
367 | - if($value>=0 && $value<=100) |
|
366 | + $value = TPropertyValue::ensureInteger($value); |
|
367 | + if ($value >= 0 && $value <= 100) |
|
368 | 368 | { |
369 | - ini_set('session.gc_probability',$value); |
|
370 | - ini_set('session.gc_divisor','100'); |
|
369 | + ini_set('session.gc_probability', $value); |
|
370 | + ini_set('session.gc_divisor', '100'); |
|
371 | 371 | } |
372 | 372 | else |
373 | - throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value); |
|
373 | + throw new TInvalidDataValueException('httpsession_gcprobability_invalid', $value); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function getUseTransparentSessionID() |
381 | 381 | { |
382 | - return ini_get('session.use_trans_sid')==='1'; |
|
382 | + return ini_get('session.use_trans_sid') === '1'; |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | */ |
388 | 388 | public function setUseTransparentSessionID($value) |
389 | 389 | { |
390 | - if($this->_started) |
|
390 | + if ($this->_started) |
|
391 | 391 | throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
392 | 392 | else |
393 | 393 | { |
394 | - $value=TPropertyValue::ensureBoolean($value); |
|
395 | - if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only) |
|
394 | + $value = TPropertyValue::ensureBoolean($value); |
|
395 | + if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) |
|
396 | 396 | throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
397 | - ini_set('session.use_trans_sid',$value?'1':'0'); |
|
397 | + ini_set('session.use_trans_sid', $value ? '1' : '0'); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | */ |
413 | 413 | public function setTimeout($value) |
414 | 414 | { |
415 | - if($this->_started) |
|
415 | + if ($this->_started) |
|
416 | 416 | throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
417 | 417 | else |
418 | - ini_set('session.gc_maxlifetime',$value); |
|
418 | + ini_set('session.gc_maxlifetime', $value); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | * @param string session name |
426 | 426 | * @return boolean whether session is opened successfully |
427 | 427 | */ |
428 | - public function _open($savePath,$sessionName) |
|
428 | + public function _open($savePath, $sessionName) |
|
429 | 429 | { |
430 | 430 | return true; |
431 | 431 | } |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @param string session data |
459 | 459 | * @return boolean whether session write is successful |
460 | 460 | */ |
461 | - public function _write($id,$data) |
|
461 | + public function _write($id, $data) |
|
462 | 462 | { |
463 | 463 | return true; |
464 | 464 | } |
@@ -540,9 +540,9 @@ discard block |
||
540 | 540 | * @param mixed session variable name |
541 | 541 | * @param mixed session variable value |
542 | 542 | */ |
543 | - public function add($key,$value) |
|
543 | + public function add($key, $value) |
|
544 | 544 | { |
545 | - $_SESSION[$key]=$value; |
|
545 | + $_SESSION[$key] = $value; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -552,9 +552,9 @@ discard block |
||
552 | 552 | */ |
553 | 553 | public function remove($key) |
554 | 554 | { |
555 | - if(isset($_SESSION[$key])) |
|
555 | + if (isset($_SESSION[$key])) |
|
556 | 556 | { |
557 | - $value=$_SESSION[$key]; |
|
557 | + $value = $_SESSION[$key]; |
|
558 | 558 | unset($_SESSION[$key]); |
559 | 559 | return $value; |
560 | 560 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function clear() |
569 | 569 | { |
570 | - foreach(array_keys($_SESSION) as $key) |
|
570 | + foreach (array_keys($_SESSION) as $key) |
|
571 | 571 | unset($_SESSION[$key]); |
572 | 572 | } |
573 | 573 | |
@@ -613,9 +613,9 @@ discard block |
||
613 | 613 | * @param integer the offset to set element |
614 | 614 | * @param mixed the element value |
615 | 615 | */ |
616 | - public function offsetSet($offset,$item) |
|
616 | + public function offsetSet($offset, $item) |
|
617 | 617 | { |
618 | - $_SESSION[$offset]=$item; |
|
618 | + $_SESSION[$offset] = $item; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | /** |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | */ |
658 | 658 | public function __construct() |
659 | 659 | { |
660 | - $this->_keys=array_keys($_SESSION); |
|
660 | + $this->_keys = array_keys($_SESSION); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | */ |
667 | 667 | public function rewind() |
668 | 668 | { |
669 | - $this->_key=reset($this->_keys); |
|
669 | + $this->_key = reset($this->_keys); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | */ |
687 | 687 | public function current() |
688 | 688 | { |
689 | - return isset($_SESSION[$this->_key])?$_SESSION[$this->_key]:null; |
|
689 | + return isset($_SESSION[$this->_key]) ? $_SESSION[$this->_key] : null; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | { |
698 | 698 | do |
699 | 699 | { |
700 | - $this->_key=next($this->_keys); |
|
700 | + $this->_key = next($this->_keys); |
|
701 | 701 | } |
702 | - while(!isset($_SESSION[$this->_key]) && $this->_key!==false); |
|
702 | + while (!isset($_SESSION[$this->_key]) && $this->_key !== false); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | /** |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | */ |
710 | 710 | public function valid() |
711 | 711 | { |
712 | - return $this->_key!==false; |
|
712 | + return $this->_key !== false; |
|
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | */ |
731 | 731 | class THttpSessionCookieMode extends TEnumerable |
732 | 732 | { |
733 | - const None='None'; |
|
734 | - const Allow='Allow'; |
|
735 | - const Only='Only'; |
|
733 | + const None = 'None'; |
|
734 | + const Allow = 'Allow'; |
|
735 | + const Only = 'Only'; |
|
736 | 736 | } |
737 | 737 |
@@ -118,8 +118,9 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function init($config) |
120 | 120 | { |
121 | - if($this->_autoStart) |
|
122 | - $this->open(); |
|
121 | + if($this->_autoStart) { |
|
122 | + $this->open(); |
|
123 | + } |
|
123 | 124 | $this->_initialized=true; |
124 | 125 | $this->getApplication()->setSession($this); |
125 | 126 | register_shutdown_function(array($this, "close")); |
@@ -132,12 +133,15 @@ discard block |
||
132 | 133 | { |
133 | 134 | if(!$this->_started) |
134 | 135 | { |
135 | - if($this->_customStorage) |
|
136 | - session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); |
|
137 | - if($this->_cookie!==null) |
|
138 | - session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); |
|
139 | - if(ini_get('session.auto_start')!=='1') |
|
140 | - session_start(); |
|
136 | + if($this->_customStorage) { |
|
137 | + session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); |
|
138 | + } |
|
139 | + if($this->_cookie!==null) { |
|
140 | + session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); |
|
141 | + } |
|
142 | + if(ini_get('session.auto_start')!=='1') { |
|
143 | + session_start(); |
|
144 | + } |
|
141 | 145 | $this->_started=true; |
142 | 146 | } |
143 | 147 | } |
@@ -202,10 +206,11 @@ discard block |
||
202 | 206 | */ |
203 | 207 | public function setSessionID($value) |
204 | 208 | { |
205 | - if($this->_started) |
|
206 | - throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
207 | - else |
|
208 | - session_id($value); |
|
209 | + if($this->_started) { |
|
210 | + throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
211 | + } else { |
|
212 | + session_id($value); |
|
213 | + } |
|
209 | 214 | } |
210 | 215 | |
211 | 216 | /** |
@@ -222,12 +227,13 @@ discard block |
||
222 | 227 | */ |
223 | 228 | public function setSessionName($value) |
224 | 229 | { |
225 | - if($this->_started) |
|
226 | - throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
227 | - else if(ctype_alnum($value)) |
|
228 | - session_name($value); |
|
229 | - else |
|
230 | - throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value); |
|
230 | + if($this->_started) { |
|
231 | + throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
232 | + } else if(ctype_alnum($value)) { |
|
233 | + session_name($value); |
|
234 | + } else { |
|
235 | + throw new TInvalidDataValueException('httpsession_sessionname_invalid',$value); |
|
236 | + } |
|
231 | 237 | } |
232 | 238 | |
233 | 239 | /** |
@@ -244,12 +250,13 @@ discard block |
||
244 | 250 | */ |
245 | 251 | public function setSavePath($value) |
246 | 252 | { |
247 | - if($this->_started) |
|
248 | - throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
249 | - else if(is_dir($value)) |
|
250 | - session_save_path($value); |
|
251 | - else |
|
252 | - throw new TInvalidDataValueException('httpsession_savepath_invalid',$value); |
|
253 | + if($this->_started) { |
|
254 | + throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
255 | + } else if(is_dir($value)) { |
|
256 | + session_save_path($value); |
|
257 | + } else { |
|
258 | + throw new TInvalidDataValueException('httpsession_savepath_invalid',$value); |
|
259 | + } |
|
253 | 260 | } |
254 | 261 | |
255 | 262 | /** |
@@ -276,8 +283,9 @@ discard block |
||
276 | 283 | */ |
277 | 284 | public function getCookie() |
278 | 285 | { |
279 | - if($this->_cookie===null) |
|
280 | - $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID()); |
|
286 | + if($this->_cookie===null) { |
|
287 | + $this->_cookie=new THttpCookie($this->getSessionName(),$this->getSessionID()); |
|
288 | + } |
|
281 | 289 | return $this->_cookie; |
282 | 290 | } |
283 | 291 | |
@@ -286,12 +294,13 @@ discard block |
||
286 | 294 | */ |
287 | 295 | public function getCookieMode() |
288 | 296 | { |
289 | - if(ini_get('session.use_cookies')==='0') |
|
290 | - return THttpSessionCookieMode::None; |
|
291 | - else if(ini_get('session.use_only_cookies')==='0') |
|
292 | - return THttpSessionCookieMode::Allow; |
|
293 | - else |
|
294 | - return THttpSessionCookieMode::Only; |
|
297 | + if(ini_get('session.use_cookies')==='0') { |
|
298 | + return THttpSessionCookieMode::None; |
|
299 | + } else if(ini_get('session.use_only_cookies')==='0') { |
|
300 | + return THttpSessionCookieMode::Allow; |
|
301 | + } else { |
|
302 | + return THttpSessionCookieMode::Only; |
|
303 | + } |
|
295 | 304 | } |
296 | 305 | |
297 | 306 | /** |
@@ -300,22 +309,20 @@ discard block |
||
300 | 309 | */ |
301 | 310 | public function setCookieMode($value) |
302 | 311 | { |
303 | - if($this->_started) |
|
304 | - throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
305 | - else |
|
312 | + if($this->_started) { |
|
313 | + throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
314 | + } else |
|
306 | 315 | { |
307 | 316 | $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode'); |
308 | 317 | if($value===THttpSessionCookieMode::None) |
309 | 318 | { |
310 | 319 | ini_set('session.use_cookies','0'); |
311 | 320 | ini_set('session.use_only_cookies','0'); |
312 | - } |
|
313 | - else if($value===THttpSessionCookieMode::Allow) |
|
321 | + } else if($value===THttpSessionCookieMode::Allow) |
|
314 | 322 | { |
315 | 323 | ini_set('session.use_cookies','1'); |
316 | 324 | ini_set('session.use_only_cookies','0'); |
317 | - } |
|
318 | - else |
|
325 | + } else |
|
319 | 326 | { |
320 | 327 | ini_set('session.use_cookies','1'); |
321 | 328 | ini_set('session.use_only_cookies','1'); |
@@ -338,10 +345,11 @@ discard block |
||
338 | 345 | */ |
339 | 346 | public function setAutoStart($value) |
340 | 347 | { |
341 | - if($this->_initialized) |
|
342 | - throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
343 | - else |
|
344 | - $this->_autoStart=TPropertyValue::ensureBoolean($value); |
|
348 | + if($this->_initialized) { |
|
349 | + throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
350 | + } else { |
|
351 | + $this->_autoStart=TPropertyValue::ensureBoolean($value); |
|
352 | + } |
|
345 | 353 | } |
346 | 354 | |
347 | 355 | /** |
@@ -359,18 +367,18 @@ discard block |
||
359 | 367 | */ |
360 | 368 | public function setGCProbability($value) |
361 | 369 | { |
362 | - if($this->_started) |
|
363 | - throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
364 | - else |
|
370 | + if($this->_started) { |
|
371 | + throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
372 | + } else |
|
365 | 373 | { |
366 | 374 | $value=TPropertyValue::ensureInteger($value); |
367 | 375 | if($value>=0 && $value<=100) |
368 | 376 | { |
369 | 377 | ini_set('session.gc_probability',$value); |
370 | 378 | ini_set('session.gc_divisor','100'); |
379 | + } else { |
|
380 | + throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value); |
|
371 | 381 | } |
372 | - else |
|
373 | - throw new TInvalidDataValueException('httpsession_gcprobability_invalid',$value); |
|
374 | 382 | } |
375 | 383 | } |
376 | 384 | |
@@ -387,13 +395,14 @@ discard block |
||
387 | 395 | */ |
388 | 396 | public function setUseTransparentSessionID($value) |
389 | 397 | { |
390 | - if($this->_started) |
|
391 | - throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
392 | - else |
|
398 | + if($this->_started) { |
|
399 | + throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
400 | + } else |
|
393 | 401 | { |
394 | 402 | $value=TPropertyValue::ensureBoolean($value); |
395 | - if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only) |
|
396 | - throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
403 | + if ($value && $this->getCookieMode()==THttpSessionCookieMode::Only) { |
|
404 | + throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
405 | + } |
|
397 | 406 | ini_set('session.use_trans_sid',$value?'1':'0'); |
398 | 407 | } |
399 | 408 | } |
@@ -412,10 +421,11 @@ discard block |
||
412 | 421 | */ |
413 | 422 | public function setTimeout($value) |
414 | 423 | { |
415 | - if($this->_started) |
|
416 | - throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
417 | - else |
|
418 | - ini_set('session.gc_maxlifetime',$value); |
|
424 | + if($this->_started) { |
|
425 | + throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
426 | + } else { |
|
427 | + ini_set('session.gc_maxlifetime',$value); |
|
428 | + } |
|
419 | 429 | } |
420 | 430 | |
421 | 431 | /** |
@@ -557,9 +567,9 @@ discard block |
||
557 | 567 | $value=$_SESSION[$key]; |
558 | 568 | unset($_SESSION[$key]); |
559 | 569 | return $value; |
570 | + } else { |
|
571 | + return null; |
|
560 | 572 | } |
561 | - else |
|
562 | - return null; |
|
563 | 573 | } |
564 | 574 | |
565 | 575 | /** |
@@ -567,8 +577,9 @@ discard block |
||
567 | 577 | */ |
568 | 578 | public function clear() |
569 | 579 | { |
570 | - foreach(array_keys($_SESSION) as $key) |
|
571 | - unset($_SESSION[$key]); |
|
580 | + foreach(array_keys($_SESSION) as $key) { |
|
581 | + unset($_SESSION[$key]); |
|
582 | + } |
|
572 | 583 | } |
573 | 584 | |
574 | 585 | /** |
@@ -39,6 +39,7 @@ |
||
39 | 39 | * HTML-decodes a string. |
40 | 40 | * It is the inverse of {@link htmlEncode}. |
41 | 41 | * @param string string to be decoded |
42 | + * @param string $s |
|
42 | 43 | * @return string decoded string |
43 | 44 | */ |
44 | 45 | public static function htmlDecode($s) |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class THttpUtility |
20 | 20 | { |
21 | - private static $_encodeTable=array('<'=>'<','>'=>'>','"'=>'"'); |
|
22 | - private static $_decodeTable=array('<'=>'<','>'=>'>','"'=>'"'); |
|
23 | - private static $_stripTable=array('<'=>'','>'=>'','"'=>''); |
|
21 | + private static $_encodeTable = array('<'=>'<', '>'=>'>', '"'=>'"'); |
|
22 | + private static $_decodeTable = array('<'=>'<', '>'=>'>', '"'=>'"'); |
|
23 | + private static $_stripTable = array('<'=>'', '>'=>'', '"'=>''); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * HTML-encodes a string. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function htmlEncode($s) |
34 | 34 | { |
35 | - return strtr($s,self::$_encodeTable); |
|
35 | + return strtr($s, self::$_encodeTable); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function htmlDecode($s) |
45 | 45 | { |
46 | - return strtr($s,self::$_decodeTable); |
|
46 | + return strtr($s, self::$_decodeTable); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function htmlStrip($s) |
56 | 56 | { |
57 | - return strtr($s,self::$_stripTable); |
|
57 | + return strtr($s, self::$_stripTable); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 |
@@ -96,6 +96,7 @@ discard block |
||
96 | 96 | * Initializes this module. |
97 | 97 | * This method is required by the IModule interface. |
98 | 98 | * @param mixed configuration for this module, can be null |
99 | + * @param TXmlDocument $config |
|
99 | 100 | * @throws TConfigurationException if module is configured in the global scope. |
100 | 101 | */ |
101 | 102 | public function init($config) |
@@ -606,6 +607,7 @@ discard block |
||
606 | 607 | |
607 | 608 | /** |
608 | 609 | * @param string full regular expression mapping pattern. |
610 | + * @param string $value |
|
609 | 611 | */ |
610 | 612 | public function setRegularExpression($value) |
611 | 613 | { |
@@ -715,6 +717,7 @@ discard block |
||
715 | 717 | * Uses URL pattern (or full regular expression if available) to |
716 | 718 | * match the given url path. |
717 | 719 | * @param THttpRequest the request module |
720 | + * @param THttpRequest $request |
|
718 | 721 | * @return array matched parameters, empty if no matches. |
719 | 722 | */ |
720 | 723 | public function getPatternMatches($request) |
@@ -785,7 +788,7 @@ discard block |
||
785 | 788 | } |
786 | 789 | |
787 | 790 | /** |
788 | - * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get. |
|
791 | + * @return string the format of URLs. Defaults to THttpRequestUrlFormat::Get. |
|
789 | 792 | */ |
790 | 793 | public function getUrlFormat() |
791 | 794 | { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @var TUrlMappingPattern[] list of patterns. |
72 | 72 | */ |
73 | - protected $_patterns=array(); |
|
73 | + protected $_patterns = array(); |
|
74 | 74 | /** |
75 | 75 | * @var TUrlMappingPattern matched pattern. |
76 | 76 | */ |
@@ -78,19 +78,19 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * @var string external configuration file |
80 | 80 | */ |
81 | - private $_configFile=null; |
|
81 | + private $_configFile = null; |
|
82 | 82 | /** |
83 | 83 | * @var boolean whether to enable custom contructUrl |
84 | 84 | */ |
85 | - private $_customUrl=false; |
|
85 | + private $_customUrl = false; |
|
86 | 86 | /** |
87 | 87 | * @var array rules for constructing URLs |
88 | 88 | */ |
89 | - protected $_constructRules=array(); |
|
89 | + protected $_constructRules = array(); |
|
90 | 90 | |
91 | - private $_urlPrefix=''; |
|
91 | + private $_urlPrefix = ''; |
|
92 | 92 | |
93 | - private $_defaultMappingClass='TUrlMappingPattern'; |
|
93 | + private $_defaultMappingClass = 'TUrlMappingPattern'; |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Initializes this module. |
@@ -101,22 +101,22 @@ discard block |
||
101 | 101 | public function init($config) |
102 | 102 | { |
103 | 103 | parent::init($config); |
104 | - if($this->getRequest()->getRequestResolved()) |
|
104 | + if ($this->getRequest()->getRequestResolved()) |
|
105 | 105 | throw new TConfigurationException('urlmapping_global_required'); |
106 | - if($this->_configFile!==null) |
|
106 | + if ($this->_configFile !== null) |
|
107 | 107 | $this->loadConfigFile(); |
108 | 108 | $this->loadUrlMappings($config); |
109 | - if($this->_urlPrefix==='') |
|
109 | + if ($this->_urlPrefix === '') |
|
110 | 110 | { |
111 | - $request=$this->getRequest(); |
|
112 | - if($request->getUrlFormat()===THttpRequestUrlFormat::HiddenPath) |
|
111 | + $request = $this->getRequest(); |
|
112 | + if ($request->getUrlFormat() === THttpRequestUrlFormat::HiddenPath) |
|
113 | 113 | { |
114 | - $this->_urlPrefix=dirname($request->getApplicationUrl()); |
|
114 | + $this->_urlPrefix = dirname($request->getApplicationUrl()); |
|
115 | 115 | } else { |
116 | - $this->_urlPrefix=$request->getApplicationUrl(); |
|
116 | + $this->_urlPrefix = $request->getApplicationUrl(); |
|
117 | 117 | } |
118 | 118 | } |
119 | - $this->_urlPrefix=rtrim($this->_urlPrefix,'/'); |
|
119 | + $this->_urlPrefix = rtrim($this->_urlPrefix, '/'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,22 +125,22 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function loadConfigFile() |
127 | 127 | { |
128 | - if(is_file($this->_configFile)) |
|
128 | + if (is_file($this->_configFile)) |
|
129 | 129 | { |
130 | - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
130 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
131 | 131 | { |
132 | 132 | $config = include $this->_configFile; |
133 | 133 | $this->loadUrlMappings($dom); |
134 | 134 | } |
135 | 135 | else |
136 | 136 | { |
137 | - $dom=new TXmlDocument; |
|
137 | + $dom = new TXmlDocument; |
|
138 | 138 | $dom->loadFromFile($this->_configFile); |
139 | 139 | $this->loadUrlMappings($dom); |
140 | 140 | } |
141 | 141 | } |
142 | 142 | else |
143 | - throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile); |
|
143 | + throw new TConfigurationException('urlmapping_configfile_inexistent', $this->_configFile); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function setEnableCustomUrl($value) |
166 | 166 | { |
167 | - $this->_customUrl=TPropertyValue::ensureBoolean($value); |
|
167 | + $this->_customUrl = TPropertyValue::ensureBoolean($value); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function setUrlPrefix($value) |
185 | 185 | { |
186 | - $this->_urlPrefix=$value; |
|
186 | + $this->_urlPrefix = $value; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function setConfigFile($value) |
203 | 203 | { |
204 | - if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null) |
|
205 | - throw new TConfigurationException('urlmapping_configfile_invalid',$value); |
|
204 | + if (($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) |
|
205 | + throw new TConfigurationException('urlmapping_configfile_invalid', $value); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function setDefaultMappingClass($value) |
225 | 225 | { |
226 | - $this->_defaultMappingClass=$value; |
|
226 | + $this->_defaultMappingClass = $value; |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -235,43 +235,43 @@ discard block |
||
235 | 235 | { |
236 | 236 | $defaultClass = $this->getDefaultMappingClass(); |
237 | 237 | |
238 | - if(is_array($config)) |
|
238 | + if (is_array($config)) |
|
239 | 239 | { |
240 | - if(isset($config['urls']) && is_array($config['urls'])) |
|
240 | + if (isset($config['urls']) && is_array($config['urls'])) |
|
241 | 241 | { |
242 | - foreach($config['urls'] as $url) |
|
242 | + foreach ($config['urls'] as $url) |
|
243 | 243 | { |
244 | - $class=isset($url['class'])?$url['class']:$defaultClass; |
|
245 | - $properties = isset($url['properties'])?$url['properties']:array(); |
|
246 | - $this->buildUrlMapping($class,$properties,$url); |
|
244 | + $class = isset($url['class']) ? $url['class'] : $defaultClass; |
|
245 | + $properties = isset($url['properties']) ? $url['properties'] : array(); |
|
246 | + $this->buildUrlMapping($class, $properties, $url); |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | } |
250 | 250 | else |
251 | 251 | { |
252 | - foreach($config->getElementsByTagName('url') as $url) |
|
252 | + foreach ($config->getElementsByTagName('url') as $url) |
|
253 | 253 | { |
254 | - $properties=$url->getAttributes(); |
|
255 | - if(($class=$properties->remove('class'))===null) |
|
256 | - $class=$defaultClass; |
|
257 | - $this->buildUrlMapping($class,$properties,$url); |
|
254 | + $properties = $url->getAttributes(); |
|
255 | + if (($class = $properties->remove('class')) === null) |
|
256 | + $class = $defaultClass; |
|
257 | + $this->buildUrlMapping($class, $properties, $url); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | 262 | private function buildUrlMapping($class, $properties, $url) |
263 | 263 | { |
264 | - $pattern=Prado::createComponent($class,$this); |
|
265 | - if(!($pattern instanceof TUrlMappingPattern)) |
|
264 | + $pattern = Prado::createComponent($class, $this); |
|
265 | + if (!($pattern instanceof TUrlMappingPattern)) |
|
266 | 266 | throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
267 | - foreach($properties as $name=>$value) |
|
268 | - $pattern->setSubproperty($name,$value); |
|
267 | + foreach ($properties as $name=>$value) |
|
268 | + $pattern->setSubproperty($name, $value); |
|
269 | 269 | |
270 | - if($url instanceof TXmlElement) { |
|
270 | + if ($url instanceof TXmlElement) { |
|
271 | 271 | $text = $url -> getValue(); |
272 | - if($text) { |
|
272 | + if ($text) { |
|
273 | 273 | $text = preg_replace('/(\s+)/S', '', $text); |
274 | - if(($regExp = $pattern->getRegularExpression()) !== '') |
|
274 | + if (($regExp = $pattern->getRegularExpression()) !== '') |
|
275 | 275 | trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
276 | 276 | get_class($pattern), |
277 | 277 | $regExp, |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - $this->_patterns[]=$pattern; |
|
286 | + $this->_patterns[] = $pattern; |
|
287 | 287 | $pattern->init($url); |
288 | 288 | |
289 | - $key=$pattern->getServiceID().':'.$pattern->getServiceParameter(); |
|
290 | - $this->_constructRules[$key][]=$pattern; |
|
289 | + $key = $pattern->getServiceID() . ':' . $pattern->getServiceParameter(); |
|
290 | + $this->_constructRules[$key][] = $pattern; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -300,21 +300,21 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function parseUrl() |
302 | 302 | { |
303 | - $request=$this->getRequest(); |
|
304 | - foreach($this->_patterns as $pattern) |
|
303 | + $request = $this->getRequest(); |
|
304 | + foreach ($this->_patterns as $pattern) |
|
305 | 305 | { |
306 | - $matches=$pattern->getPatternMatches($request); |
|
307 | - if(count($matches)>0) |
|
306 | + $matches = $pattern->getPatternMatches($request); |
|
307 | + if (count($matches) > 0) |
|
308 | 308 | { |
309 | - $this->_matched=$pattern; |
|
310 | - $params=array(); |
|
311 | - foreach($matches as $key=>$value) |
|
309 | + $this->_matched = $pattern; |
|
310 | + $params = array(); |
|
311 | + foreach ($matches as $key=>$value) |
|
312 | 312 | { |
313 | - if(is_string($key)) |
|
314 | - $params[$key]=$value; |
|
313 | + if (is_string($key)) |
|
314 | + $params[$key] = $value; |
|
315 | 315 | } |
316 | 316 | if (!$pattern->getIsWildCardPattern()) |
317 | - $params[$pattern->getServiceID()]=$pattern->getServiceParameter(); |
|
317 | + $params[$pattern->getServiceID()] = $pattern->getServiceParameter(); |
|
318 | 318 | return $params; |
319 | 319 | } |
320 | 320 | } |
@@ -345,36 +345,36 @@ discard block |
||
345 | 345 | * @see parseUrl |
346 | 346 | * @since 3.1.1 |
347 | 347 | */ |
348 | - public function constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems) |
|
348 | + public function constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems) |
|
349 | 349 | { |
350 | - if($this->_customUrl) |
|
350 | + if ($this->_customUrl) |
|
351 | 351 | { |
352 | - if(!(is_array($getItems) || ($getItems instanceof Traversable))) |
|
353 | - $getItems=array(); |
|
354 | - $key=$serviceID.':'.$serviceParam; |
|
355 | - $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ? |
|
356 | - $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*'; |
|
357 | - if(isset($this->_constructRules[$key])) |
|
352 | + if (!(is_array($getItems) || ($getItems instanceof Traversable))) |
|
353 | + $getItems = array(); |
|
354 | + $key = $serviceID . ':' . $serviceParam; |
|
355 | + $wildCardKey = ($pos = strrpos($serviceParam, '.')) !== false ? |
|
356 | + $serviceID . ':' . substr($serviceParam, 0, $pos) . '.*' : $serviceID . ':*'; |
|
357 | + if (isset($this->_constructRules[$key])) |
|
358 | 358 | { |
359 | - foreach($this->_constructRules[$key] as $rule) |
|
359 | + foreach ($this->_constructRules[$key] as $rule) |
|
360 | 360 | { |
361 | - if($rule->supportCustomUrl($getItems)) |
|
362 | - return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems); |
|
361 | + if ($rule->supportCustomUrl($getItems)) |
|
362 | + return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
|
363 | 363 | } |
364 | 364 | } |
365 | - elseif(isset($this->_constructRules[$wildCardKey])) |
|
365 | + elseif (isset($this->_constructRules[$wildCardKey])) |
|
366 | 366 | { |
367 | - foreach($this->_constructRules[$wildCardKey] as $rule) |
|
367 | + foreach ($this->_constructRules[$wildCardKey] as $rule) |
|
368 | 368 | { |
369 | - if($rule->supportCustomUrl($getItems)) |
|
369 | + if ($rule->supportCustomUrl($getItems)) |
|
370 | 370 | { |
371 | - $getItems['*']= $pos ? substr($serviceParam,$pos+1) : $serviceParam; |
|
372 | - return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems); |
|
371 | + $getItems['*'] = $pos ? substr($serviceParam, $pos + 1) : $serviceParam; |
|
372 | + return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
376 | 376 | } |
377 | - return parent::constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
|
377 | + return parent::constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | /** |
495 | 495 | * @var string service ID, default is 'page'. |
496 | 496 | */ |
497 | - private $_serviceID='page'; |
|
497 | + private $_serviceID = 'page'; |
|
498 | 498 | /** |
499 | 499 | * @var string url pattern to match. |
500 | 500 | */ |
@@ -510,19 +510,19 @@ discard block |
||
510 | 510 | /** |
511 | 511 | * @var string regular expression pattern. |
512 | 512 | */ |
513 | - private $_regexp=''; |
|
513 | + private $_regexp = ''; |
|
514 | 514 | |
515 | - private $_customUrl=true; |
|
515 | + private $_customUrl = true; |
|
516 | 516 | |
517 | 517 | private $_manager; |
518 | 518 | |
519 | - private $_caseSensitive=true; |
|
519 | + private $_caseSensitive = true; |
|
520 | 520 | |
521 | - private $_isWildCardPattern=false; |
|
521 | + private $_isWildCardPattern = false; |
|
522 | 522 | |
523 | - private $_urlFormat=THttpRequestUrlFormat::Get; |
|
523 | + private $_urlFormat = THttpRequestUrlFormat::Get; |
|
524 | 524 | |
525 | - private $_separator='/'; |
|
525 | + private $_separator = '/'; |
|
526 | 526 | |
527 | 527 | /** |
528 | 528 | * @var TUrlMappingPatternSecureConnection |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | */ |
537 | 537 | public function __construct(TUrlManager $manager) |
538 | 538 | { |
539 | - $this->_manager=$manager; |
|
539 | + $this->_manager = $manager; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -554,10 +554,10 @@ discard block |
||
554 | 554 | */ |
555 | 555 | public function init($config) |
556 | 556 | { |
557 | - if($this->_serviceParameter===null) |
|
557 | + if ($this->_serviceParameter === null) |
|
558 | 558 | throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
559 | - if(strpos($this->_serviceParameter,'*')!==false) |
|
560 | - $this->_isWildCardPattern=true; |
|
559 | + if (strpos($this->_serviceParameter, '*') !== false) |
|
560 | + $this->_isWildCardPattern = true; |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -567,32 +567,32 @@ discard block |
||
567 | 567 | */ |
568 | 568 | protected function getParameterizedPattern() |
569 | 569 | { |
570 | - $params=array(); |
|
571 | - $values=array(); |
|
570 | + $params = array(); |
|
571 | + $values = array(); |
|
572 | 572 | if ($this->_parameters) |
573 | 573 | { |
574 | - foreach($this->_parameters as $key=>$value) |
|
574 | + foreach ($this->_parameters as $key=>$value) |
|
575 | 575 | { |
576 | - $params[]='{'.$key.'}'; |
|
577 | - $values[]='(?P<'.$key.'>'.$value.')'; |
|
576 | + $params[] = '{' . $key . '}'; |
|
577 | + $values[] = '(?P<' . $key . '>' . $value . ')'; |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | if ($this->getIsWildCardPattern()) |
581 | 581 | { |
582 | - $params[]='{*}'; |
|
582 | + $params[] = '{*}'; |
|
583 | 583 | // service parameter must not contain '=' and '/' |
584 | - $values[]='(?P<'.$this->getServiceID().'>[^=/]+)'; |
|
584 | + $values[] = '(?P<' . $this->getServiceID() . '>[^=/]+)'; |
|
585 | 585 | } |
586 | - $params[]='/'; |
|
587 | - $values[]='\\/'; |
|
588 | - $regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/'); |
|
589 | - if ($this->_urlFormat===THttpRequestUrlFormat::Get) |
|
590 | - $regexp='/^'.$regexp.'$/u'; |
|
586 | + $params[] = '/'; |
|
587 | + $values[] = '\\/'; |
|
588 | + $regexp = str_replace($params, $values, trim($this->getPattern(), '/') . '/'); |
|
589 | + if ($this->_urlFormat === THttpRequestUrlFormat::Get) |
|
590 | + $regexp = '/^' . $regexp . '$/u'; |
|
591 | 591 | else |
592 | - $regexp='/^'.$regexp.'(?P<urlparams>.*)$/u'; |
|
592 | + $regexp = '/^' . $regexp . '(?P<urlparams>.*)$/u'; |
|
593 | 593 | |
594 | - if(!$this->getCaseSensitive()) |
|
595 | - $regexp.='i'; |
|
594 | + if (!$this->getCaseSensitive()) |
|
595 | + $regexp .= 'i'; |
|
596 | 596 | return $regexp; |
597 | 597 | } |
598 | 598 | |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | */ |
610 | 610 | public function setRegularExpression($value) |
611 | 611 | { |
612 | - $this->_regexp=$value; |
|
612 | + $this->_regexp = $value; |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | /** |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | */ |
626 | 626 | public function setCaseSensitive($value) |
627 | 627 | { |
628 | - $this->_caseSensitive=TPropertyValue::ensureBoolean($value); |
|
628 | + $this->_caseSensitive = TPropertyValue::ensureBoolean($value); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | */ |
634 | 634 | public function setServiceParameter($value) |
635 | 635 | { |
636 | - $this->_serviceParameter=$value; |
|
636 | + $this->_serviceParameter = $value; |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | */ |
650 | 650 | public function setServiceID($value) |
651 | 651 | { |
652 | - $this->_serviceID=$value; |
|
652 | + $this->_serviceID = $value; |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | { |
684 | 684 | if (!$this->_parameters) |
685 | 685 | { |
686 | - $this->_parameters=new TAttributeCollection; |
|
686 | + $this->_parameters = new TAttributeCollection; |
|
687 | 687 | $this->_parameters->setCaseSensitive(true); |
688 | 688 | } |
689 | 689 | return $this->_parameters; |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | */ |
695 | 695 | public function setParameters($value) |
696 | 696 | { |
697 | - $this->_parameters=$value; |
|
697 | + $this->_parameters = $value; |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -719,38 +719,38 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function getPatternMatches($request) |
721 | 721 | { |
722 | - $matches=array(); |
|
723 | - if(($pattern=$this->getRegularExpression())!=='') |
|
724 | - preg_match($pattern,$request->getPathInfo(),$matches); |
|
722 | + $matches = array(); |
|
723 | + if (($pattern = $this->getRegularExpression()) !== '') |
|
724 | + preg_match($pattern, $request->getPathInfo(), $matches); |
|
725 | 725 | else |
726 | - preg_match($this->getParameterizedPattern(),trim($request->getPathInfo(),'/').'/',$matches); |
|
726 | + preg_match($this->getParameterizedPattern(), trim($request->getPathInfo(), '/') . '/', $matches); |
|
727 | 727 | |
728 | - if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
729 | - $matches[$this->_serviceID]=str_replace('*',$matches[$this->_serviceID],$this->_serviceParameter); |
|
728 | + if ($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
729 | + $matches[$this->_serviceID] = str_replace('*', $matches[$this->_serviceID], $this->_serviceParameter); |
|
730 | 730 | |
731 | 731 | if (isset($matches['urlparams'])) |
732 | 732 | { |
733 | - $params=explode('/',$matches['urlparams']); |
|
734 | - if ($this->_separator==='/') |
|
733 | + $params = explode('/', $matches['urlparams']); |
|
734 | + if ($this->_separator === '/') |
|
735 | 735 | { |
736 | - while($key=array_shift($params)) |
|
737 | - $matches[$key]=($value=array_shift($params)) ? $value : ''; |
|
736 | + while ($key = array_shift($params)) |
|
737 | + $matches[$key] = ($value = array_shift($params)) ? $value : ''; |
|
738 | 738 | } |
739 | 739 | else |
740 | 740 | { |
741 | 741 | array_pop($params); |
742 | - foreach($params as $param) |
|
742 | + foreach ($params as $param) |
|
743 | 743 | { |
744 | - list($key,$value)=explode($this->_separator,$param,2); |
|
745 | - $matches[$key]=$value; |
|
744 | + list($key, $value) = explode($this->_separator, $param, 2); |
|
745 | + $matches[$key] = $value; |
|
746 | 746 | } |
747 | 747 | } |
748 | 748 | unset($matches['urlparams']); |
749 | 749 | } |
750 | 750 | |
751 | - if(count($matches) > 0 && $this->_constants) |
|
751 | + if (count($matches) > 0 && $this->_constants) |
|
752 | 752 | { |
753 | - foreach($this->_constants->toArray() as $key=>$value) |
|
753 | + foreach ($this->_constants->toArray() as $key=>$value) |
|
754 | 754 | $matches[$key] = $value; |
755 | 755 | } |
756 | 756 | |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | */ |
774 | 774 | public function setEnableCustomUrl($value) |
775 | 775 | { |
776 | - $this->_customUrl=TPropertyValue::ensureBoolean($value); |
|
776 | + $this->_customUrl = TPropertyValue::ensureBoolean($value); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | */ |
806 | 806 | public function setUrlFormat($value) |
807 | 807 | { |
808 | - $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat'); |
|
808 | + $this->_urlFormat = TPropertyValue::ensureEnum($value, 'THttpRequestUrlFormat'); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | /** |
@@ -822,8 +822,8 @@ discard block |
||
822 | 822 | */ |
823 | 823 | public function setUrlParamSeparator($value) |
824 | 824 | { |
825 | - if(strlen($value)===1) |
|
826 | - $this->_separator=$value; |
|
825 | + if (strlen($value) === 1) |
|
826 | + $this->_separator = $value; |
|
827 | 827 | else |
828 | 828 | throw new TInvalidDataValueException('httprequest_separator_invalid'); |
829 | 829 | } |
@@ -853,24 +853,24 @@ discard block |
||
853 | 853 | */ |
854 | 854 | public function supportCustomUrl($getItems) |
855 | 855 | { |
856 | - if(!$this->_customUrl || $this->getPattern()===null) |
|
856 | + if (!$this->_customUrl || $this->getPattern() === null) |
|
857 | 857 | return false; |
858 | 858 | if ($this->_parameters) |
859 | 859 | { |
860 | - foreach($this->_parameters as $key=>$value) |
|
860 | + foreach ($this->_parameters as $key=>$value) |
|
861 | 861 | { |
862 | - if(!isset($getItems[$key])) |
|
862 | + if (!isset($getItems[$key])) |
|
863 | 863 | return false; |
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | 867 | if ($this->_constants) |
868 | 868 | { |
869 | - foreach($this->_constants->toArray() as $key=>$value) |
|
869 | + foreach ($this->_constants->toArray() as $key=>$value) |
|
870 | 870 | { |
871 | 871 | if (!isset($getItems[$key])) |
872 | 872 | return false; |
873 | - if ($getItems[$key]!=$value) |
|
873 | + if ($getItems[$key] != $value) |
|
874 | 874 | return false; |
875 | 875 | } |
876 | 876 | } |
@@ -885,68 +885,68 @@ discard block |
||
885 | 885 | * @return string the constructed URL |
886 | 886 | * @since 3.1.1 |
887 | 887 | */ |
888 | - public function constructUrl($getItems,$encodeAmpersand,$encodeGetItems) |
|
888 | + public function constructUrl($getItems, $encodeAmpersand, $encodeGetItems) |
|
889 | 889 | { |
890 | 890 | if ($this->_constants) |
891 | 891 | { |
892 | - foreach($this->_constants->toArray() as $key=>$value) |
|
892 | + foreach ($this->_constants->toArray() as $key=>$value) |
|
893 | 893 | { |
894 | 894 | unset($getItems[$key]); |
895 | 895 | } |
896 | 896 | } |
897 | 897 | |
898 | - $extra=array(); |
|
899 | - $replace=array(); |
|
898 | + $extra = array(); |
|
899 | + $replace = array(); |
|
900 | 900 | // for the GET variables matching the pattern, put them in the URL path |
901 | - foreach($getItems as $key=>$value) |
|
901 | + foreach ($getItems as $key=>$value) |
|
902 | 902 | { |
903 | - if(($this->_parameters && $this->_parameters->contains($key)) || ($key==='*' && $this->getIsWildCardPattern())) |
|
904 | - $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value; |
|
903 | + if (($this->_parameters && $this->_parameters->contains($key)) || ($key === '*' && $this->getIsWildCardPattern())) |
|
904 | + $replace['{' . $key . '}'] = $encodeGetItems ? rawurlencode($value) : $value; |
|
905 | 905 | else |
906 | - $extra[$key]=$value; |
|
906 | + $extra[$key] = $value; |
|
907 | 907 | } |
908 | 908 | |
909 | - $url=$this->_manager->getUrlPrefix().'/'.ltrim(strtr($this->getPattern(),$replace),'/'); |
|
909 | + $url = $this->_manager->getUrlPrefix() . '/' . ltrim(strtr($this->getPattern(), $replace), '/'); |
|
910 | 910 | |
911 | 911 | // for the rest of the GET variables, put them in the query string |
912 | - if(count($extra)>0) |
|
912 | + if (count($extra) > 0) |
|
913 | 913 | { |
914 | - if ($this->_urlFormat===THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) { |
|
914 | + if ($this->_urlFormat === THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) { |
|
915 | 915 | foreach ($extra as $name=>$value) |
916 | - $url.='/'.$name.$this->_separator.($encodeGetItems?rawurlencode($value):$value); |
|
916 | + $url .= '/' . $name . $this->_separator . ($encodeGetItems ? rawurlencode($value) : $value); |
|
917 | 917 | return $url; |
918 | 918 | } |
919 | 919 | |
920 | - $url2=''; |
|
921 | - $amp=$encodeAmpersand?'&':'&'; |
|
922 | - if($encodeGetItems) |
|
920 | + $url2 = ''; |
|
921 | + $amp = $encodeAmpersand ? '&' : '&'; |
|
922 | + if ($encodeGetItems) |
|
923 | 923 | { |
924 | - foreach($extra as $name=>$value) |
|
924 | + foreach ($extra as $name=>$value) |
|
925 | 925 | { |
926 | - if(is_array($value)) |
|
926 | + if (is_array($value)) |
|
927 | 927 | { |
928 | - $name=rawurlencode($name.'[]'); |
|
929 | - foreach($value as $v) |
|
930 | - $url2.=$amp.$name.'='.rawurlencode($v); |
|
928 | + $name = rawurlencode($name . '[]'); |
|
929 | + foreach ($value as $v) |
|
930 | + $url2 .= $amp . $name . '=' . rawurlencode($v); |
|
931 | 931 | } |
932 | 932 | else |
933 | - $url2.=$amp.rawurlencode($name).'='.rawurlencode($value); |
|
933 | + $url2 .= $amp . rawurlencode($name) . '=' . rawurlencode($value); |
|
934 | 934 | } |
935 | 935 | } |
936 | 936 | else |
937 | 937 | { |
938 | - foreach($extra as $name=>$value) |
|
938 | + foreach ($extra as $name=>$value) |
|
939 | 939 | { |
940 | - if(is_array($value)) |
|
940 | + if (is_array($value)) |
|
941 | 941 | { |
942 | - foreach($value as $v) |
|
943 | - $url2.=$amp.$name.'[]='.$v; |
|
942 | + foreach ($value as $v) |
|
943 | + $url2 .= $amp . $name . '[]=' . $v; |
|
944 | 944 | } |
945 | 945 | else |
946 | - $url2.=$amp.$name.'='.$value; |
|
946 | + $url2 .= $amp . $name . '=' . $value; |
|
947 | 947 | } |
948 | 948 | } |
949 | - $url=$url.'?'.substr($url2,strlen($amp)); |
|
949 | + $url = $url . '?' . substr($url2, strlen($amp)); |
|
950 | 950 | } |
951 | 951 | return $this -> applySecureConnectionPrefix($url); |
952 | 952 | } |
@@ -962,19 +962,19 @@ discard block |
||
962 | 962 | protected function applySecureConnectionPrefix($url) |
963 | 963 | { |
964 | 964 | static $request; |
965 | - if($request === null) $request = Prado::getApplication() -> getRequest(); |
|
965 | + if ($request === null) $request = Prado::getApplication() -> getRequest(); |
|
966 | 966 | |
967 | 967 | static $isSecureConnection; |
968 | - if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
968 | + if ($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
969 | 969 | |
970 | - switch($this -> getSecureConnection()) |
|
970 | + switch ($this -> getSecureConnection()) |
|
971 | 971 | { |
972 | 972 | case TUrlMappingPatternSecureConnection::EnableIfNotSecure: |
973 | - if($isSecureConnection) return $url; |
|
973 | + if ($isSecureConnection) return $url; |
|
974 | 974 | return $request -> getBaseUrl(true) . $url; |
975 | 975 | break; |
976 | 976 | case TUrlMappingPatternSecureConnection::DisableIfSecure: |
977 | - if(!$isSecureConnection) return $url; |
|
977 | + if (!$isSecureConnection) return $url; |
|
978 | 978 | return $request -> getBaseUrl(false) . $url; |
979 | 979 | break; |
980 | 980 | case TUrlMappingPatternSecureConnection::Enable: |
@@ -101,10 +101,12 @@ discard block |
||
101 | 101 | public function init($config) |
102 | 102 | { |
103 | 103 | parent::init($config); |
104 | - if($this->getRequest()->getRequestResolved()) |
|
105 | - throw new TConfigurationException('urlmapping_global_required'); |
|
106 | - if($this->_configFile!==null) |
|
107 | - $this->loadConfigFile(); |
|
104 | + if($this->getRequest()->getRequestResolved()) { |
|
105 | + throw new TConfigurationException('urlmapping_global_required'); |
|
106 | + } |
|
107 | + if($this->_configFile!==null) { |
|
108 | + $this->loadConfigFile(); |
|
109 | + } |
|
108 | 110 | $this->loadUrlMappings($config); |
109 | 111 | if($this->_urlPrefix==='') |
110 | 112 | { |
@@ -131,16 +133,15 @@ discard block |
||
131 | 133 | { |
132 | 134 | $config = include $this->_configFile; |
133 | 135 | $this->loadUrlMappings($dom); |
134 | - } |
|
135 | - else |
|
136 | + } else |
|
136 | 137 | { |
137 | 138 | $dom=new TXmlDocument; |
138 | 139 | $dom->loadFromFile($this->_configFile); |
139 | 140 | $this->loadUrlMappings($dom); |
140 | 141 | } |
142 | + } else { |
|
143 | + throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile); |
|
141 | 144 | } |
142 | - else |
|
143 | - throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile); |
|
144 | 145 | } |
145 | 146 | |
146 | 147 | /** |
@@ -201,8 +202,9 @@ discard block |
||
201 | 202 | */ |
202 | 203 | public function setConfigFile($value) |
203 | 204 | { |
204 | - if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null) |
|
205 | - throw new TConfigurationException('urlmapping_configfile_invalid',$value); |
|
205 | + if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null) { |
|
206 | + throw new TConfigurationException('urlmapping_configfile_invalid',$value); |
|
207 | + } |
|
206 | 208 | } |
207 | 209 | |
208 | 210 | /** |
@@ -246,14 +248,14 @@ discard block |
||
246 | 248 | $this->buildUrlMapping($class,$properties,$url); |
247 | 249 | } |
248 | 250 | } |
249 | - } |
|
250 | - else |
|
251 | + } else |
|
251 | 252 | { |
252 | 253 | foreach($config->getElementsByTagName('url') as $url) |
253 | 254 | { |
254 | 255 | $properties=$url->getAttributes(); |
255 | - if(($class=$properties->remove('class'))===null) |
|
256 | - $class=$defaultClass; |
|
256 | + if(($class=$properties->remove('class'))===null) { |
|
257 | + $class=$defaultClass; |
|
258 | + } |
|
257 | 259 | $this->buildUrlMapping($class,$properties,$url); |
258 | 260 | } |
259 | 261 | } |
@@ -262,23 +264,26 @@ discard block |
||
262 | 264 | private function buildUrlMapping($class, $properties, $url) |
263 | 265 | { |
264 | 266 | $pattern=Prado::createComponent($class,$this); |
265 | - if(!($pattern instanceof TUrlMappingPattern)) |
|
266 | - throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
|
267 | - foreach($properties as $name=>$value) |
|
268 | - $pattern->setSubproperty($name,$value); |
|
267 | + if(!($pattern instanceof TUrlMappingPattern)) { |
|
268 | + throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
|
269 | + } |
|
270 | + foreach($properties as $name=>$value) { |
|
271 | + $pattern->setSubproperty($name,$value); |
|
272 | + } |
|
269 | 273 | |
270 | 274 | if($url instanceof TXmlElement) { |
271 | 275 | $text = $url -> getValue(); |
272 | 276 | if($text) { |
273 | 277 | $text = preg_replace('/(\s+)/S', '', $text); |
274 | - if(($regExp = $pattern->getRegularExpression()) !== '') |
|
275 | - trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
|
278 | + if(($regExp = $pattern->getRegularExpression()) !== '') { |
|
279 | + trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
|
276 | 280 | get_class($pattern), |
277 | 281 | $regExp, |
278 | 282 | $pattern->getServiceID(), |
279 | 283 | $pattern->getServiceParameter(), |
280 | 284 | $text), |
281 | 285 | E_USER_NOTICE); |
286 | + } |
|
282 | 287 | $pattern->setRegularExpression($text); |
283 | 288 | } |
284 | 289 | } |
@@ -310,11 +315,13 @@ discard block |
||
310 | 315 | $params=array(); |
311 | 316 | foreach($matches as $key=>$value) |
312 | 317 | { |
313 | - if(is_string($key)) |
|
314 | - $params[$key]=$value; |
|
318 | + if(is_string($key)) { |
|
319 | + $params[$key]=$value; |
|
320 | + } |
|
321 | + } |
|
322 | + if (!$pattern->getIsWildCardPattern()) { |
|
323 | + $params[$pattern->getServiceID()]=$pattern->getServiceParameter(); |
|
315 | 324 | } |
316 | - if (!$pattern->getIsWildCardPattern()) |
|
317 | - $params[$pattern->getServiceID()]=$pattern->getServiceParameter(); |
|
318 | 325 | return $params; |
319 | 326 | } |
320 | 327 | } |
@@ -349,8 +356,9 @@ discard block |
||
349 | 356 | { |
350 | 357 | if($this->_customUrl) |
351 | 358 | { |
352 | - if(!(is_array($getItems) || ($getItems instanceof Traversable))) |
|
353 | - $getItems=array(); |
|
359 | + if(!(is_array($getItems) || ($getItems instanceof Traversable))) { |
|
360 | + $getItems=array(); |
|
361 | + } |
|
354 | 362 | $key=$serviceID.':'.$serviceParam; |
355 | 363 | $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ? |
356 | 364 | $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*'; |
@@ -358,11 +366,11 @@ discard block |
||
358 | 366 | { |
359 | 367 | foreach($this->_constructRules[$key] as $rule) |
360 | 368 | { |
361 | - if($rule->supportCustomUrl($getItems)) |
|
362 | - return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems); |
|
369 | + if($rule->supportCustomUrl($getItems)) { |
|
370 | + return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems); |
|
371 | + } |
|
363 | 372 | } |
364 | - } |
|
365 | - elseif(isset($this->_constructRules[$wildCardKey])) |
|
373 | + } elseif(isset($this->_constructRules[$wildCardKey])) |
|
366 | 374 | { |
367 | 375 | foreach($this->_constructRules[$wildCardKey] as $rule) |
368 | 376 | { |
@@ -554,10 +562,12 @@ discard block |
||
554 | 562 | */ |
555 | 563 | public function init($config) |
556 | 564 | { |
557 | - if($this->_serviceParameter===null) |
|
558 | - throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
|
559 | - if(strpos($this->_serviceParameter,'*')!==false) |
|
560 | - $this->_isWildCardPattern=true; |
|
565 | + if($this->_serviceParameter===null) { |
|
566 | + throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
|
567 | + } |
|
568 | + if(strpos($this->_serviceParameter,'*')!==false) { |
|
569 | + $this->_isWildCardPattern=true; |
|
570 | + } |
|
561 | 571 | } |
562 | 572 | |
563 | 573 | /** |
@@ -586,13 +596,15 @@ discard block |
||
586 | 596 | $params[]='/'; |
587 | 597 | $values[]='\\/'; |
588 | 598 | $regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/'); |
589 | - if ($this->_urlFormat===THttpRequestUrlFormat::Get) |
|
590 | - $regexp='/^'.$regexp.'$/u'; |
|
591 | - else |
|
592 | - $regexp='/^'.$regexp.'(?P<urlparams>.*)$/u'; |
|
599 | + if ($this->_urlFormat===THttpRequestUrlFormat::Get) { |
|
600 | + $regexp='/^'.$regexp.'$/u'; |
|
601 | + } else { |
|
602 | + $regexp='/^'.$regexp.'(?P<urlparams>.*)$/u'; |
|
603 | + } |
|
593 | 604 | |
594 | - if(!$this->getCaseSensitive()) |
|
595 | - $regexp.='i'; |
|
605 | + if(!$this->getCaseSensitive()) { |
|
606 | + $regexp.='i'; |
|
607 | + } |
|
596 | 608 | return $regexp; |
597 | 609 | } |
598 | 610 | |
@@ -720,23 +732,25 @@ discard block |
||
720 | 732 | public function getPatternMatches($request) |
721 | 733 | { |
722 | 734 | $matches=array(); |
723 | - if(($pattern=$this->getRegularExpression())!=='') |
|
724 | - preg_match($pattern,$request->getPathInfo(),$matches); |
|
725 | - else |
|
726 | - preg_match($this->getParameterizedPattern(),trim($request->getPathInfo(),'/').'/',$matches); |
|
735 | + if(($pattern=$this->getRegularExpression())!=='') { |
|
736 | + preg_match($pattern,$request->getPathInfo(),$matches); |
|
737 | + } else { |
|
738 | + preg_match($this->getParameterizedPattern(),trim($request->getPathInfo(),'/').'/',$matches); |
|
739 | + } |
|
727 | 740 | |
728 | - if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
729 | - $matches[$this->_serviceID]=str_replace('*',$matches[$this->_serviceID],$this->_serviceParameter); |
|
741 | + if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) { |
|
742 | + $matches[$this->_serviceID]=str_replace('*',$matches[$this->_serviceID],$this->_serviceParameter); |
|
743 | + } |
|
730 | 744 | |
731 | 745 | if (isset($matches['urlparams'])) |
732 | 746 | { |
733 | 747 | $params=explode('/',$matches['urlparams']); |
734 | 748 | if ($this->_separator==='/') |
735 | 749 | { |
736 | - while($key=array_shift($params)) |
|
737 | - $matches[$key]=($value=array_shift($params)) ? $value : ''; |
|
738 | - } |
|
739 | - else |
|
750 | + while($key=array_shift($params)) { |
|
751 | + $matches[$key]=($value=array_shift($params)) ? $value : ''; |
|
752 | + } |
|
753 | + } else |
|
740 | 754 | { |
741 | 755 | array_pop($params); |
742 | 756 | foreach($params as $param) |
@@ -750,8 +764,9 @@ discard block |
||
750 | 764 | |
751 | 765 | if(count($matches) > 0 && $this->_constants) |
752 | 766 | { |
753 | - foreach($this->_constants->toArray() as $key=>$value) |
|
754 | - $matches[$key] = $value; |
|
767 | + foreach($this->_constants->toArray() as $key=>$value) { |
|
768 | + $matches[$key] = $value; |
|
769 | + } |
|
755 | 770 | } |
756 | 771 | |
757 | 772 | return $matches; |
@@ -822,10 +837,11 @@ discard block |
||
822 | 837 | */ |
823 | 838 | public function setUrlParamSeparator($value) |
824 | 839 | { |
825 | - if(strlen($value)===1) |
|
826 | - $this->_separator=$value; |
|
827 | - else |
|
828 | - throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
840 | + if(strlen($value)===1) { |
|
841 | + $this->_separator=$value; |
|
842 | + } else { |
|
843 | + throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
844 | + } |
|
829 | 845 | } |
830 | 846 | |
831 | 847 | /** |
@@ -853,14 +869,16 @@ discard block |
||
853 | 869 | */ |
854 | 870 | public function supportCustomUrl($getItems) |
855 | 871 | { |
856 | - if(!$this->_customUrl || $this->getPattern()===null) |
|
857 | - return false; |
|
872 | + if(!$this->_customUrl || $this->getPattern()===null) { |
|
873 | + return false; |
|
874 | + } |
|
858 | 875 | if ($this->_parameters) |
859 | 876 | { |
860 | 877 | foreach($this->_parameters as $key=>$value) |
861 | 878 | { |
862 | - if(!isset($getItems[$key])) |
|
863 | - return false; |
|
879 | + if(!isset($getItems[$key])) { |
|
880 | + return false; |
|
881 | + } |
|
864 | 882 | } |
865 | 883 | } |
866 | 884 | |
@@ -868,10 +886,12 @@ discard block |
||
868 | 886 | { |
869 | 887 | foreach($this->_constants->toArray() as $key=>$value) |
870 | 888 | { |
871 | - if (!isset($getItems[$key])) |
|
872 | - return false; |
|
873 | - if ($getItems[$key]!=$value) |
|
874 | - return false; |
|
889 | + if (!isset($getItems[$key])) { |
|
890 | + return false; |
|
891 | + } |
|
892 | + if ($getItems[$key]!=$value) { |
|
893 | + return false; |
|
894 | + } |
|
875 | 895 | } |
876 | 896 | } |
877 | 897 | return true; |
@@ -900,10 +920,11 @@ discard block |
||
900 | 920 | // for the GET variables matching the pattern, put them in the URL path |
901 | 921 | foreach($getItems as $key=>$value) |
902 | 922 | { |
903 | - if(($this->_parameters && $this->_parameters->contains($key)) || ($key==='*' && $this->getIsWildCardPattern())) |
|
904 | - $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value; |
|
905 | - else |
|
906 | - $extra[$key]=$value; |
|
923 | + if(($this->_parameters && $this->_parameters->contains($key)) || ($key==='*' && $this->getIsWildCardPattern())) { |
|
924 | + $replace['{'.$key.'}']=$encodeGetItems ? rawurlencode($value) : $value; |
|
925 | + } else { |
|
926 | + $extra[$key]=$value; |
|
927 | + } |
|
907 | 928 | } |
908 | 929 | |
909 | 930 | $url=$this->_manager->getUrlPrefix().'/'.ltrim(strtr($this->getPattern(),$replace),'/'); |
@@ -912,8 +933,9 @@ discard block |
||
912 | 933 | if(count($extra)>0) |
913 | 934 | { |
914 | 935 | if ($this->_urlFormat===THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) { |
915 | - foreach ($extra as $name=>$value) |
|
916 | - $url.='/'.$name.$this->_separator.($encodeGetItems?rawurlencode($value):$value); |
|
936 | + foreach ($extra as $name=>$value) { |
|
937 | + $url.='/'.$name.$this->_separator.($encodeGetItems?rawurlencode($value):$value); |
|
938 | + } |
|
917 | 939 | return $url; |
918 | 940 | } |
919 | 941 | |
@@ -926,24 +948,25 @@ discard block |
||
926 | 948 | if(is_array($value)) |
927 | 949 | { |
928 | 950 | $name=rawurlencode($name.'[]'); |
929 | - foreach($value as $v) |
|
930 | - $url2.=$amp.$name.'='.rawurlencode($v); |
|
951 | + foreach($value as $v) { |
|
952 | + $url2.=$amp.$name.'='.rawurlencode($v); |
|
953 | + } |
|
954 | + } else { |
|
955 | + $url2.=$amp.rawurlencode($name).'='.rawurlencode($value); |
|
931 | 956 | } |
932 | - else |
|
933 | - $url2.=$amp.rawurlencode($name).'='.rawurlencode($value); |
|
934 | 957 | } |
935 | - } |
|
936 | - else |
|
958 | + } else |
|
937 | 959 | { |
938 | 960 | foreach($extra as $name=>$value) |
939 | 961 | { |
940 | 962 | if(is_array($value)) |
941 | 963 | { |
942 | - foreach($value as $v) |
|
943 | - $url2.=$amp.$name.'[]='.$v; |
|
964 | + foreach($value as $v) { |
|
965 | + $url2.=$amp.$name.'[]='.$v; |
|
966 | + } |
|
967 | + } else { |
|
968 | + $url2.=$amp.$name.'='.$value; |
|
944 | 969 | } |
945 | - else |
|
946 | - $url2.=$amp.$name.'='.$value; |
|
947 | 970 | } |
948 | 971 | } |
949 | 972 | $url=$url.'?'.substr($url2,strlen($amp)); |
@@ -962,19 +985,27 @@ discard block |
||
962 | 985 | protected function applySecureConnectionPrefix($url) |
963 | 986 | { |
964 | 987 | static $request; |
965 | - if($request === null) $request = Prado::getApplication() -> getRequest(); |
|
988 | + if($request === null) { |
|
989 | + $request = Prado::getApplication() -> getRequest(); |
|
990 | + } |
|
966 | 991 | |
967 | 992 | static $isSecureConnection; |
968 | - if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
993 | + if($isSecureConnection === null) { |
|
994 | + $isSecureConnection = $request -> getIsSecureConnection(); |
|
995 | + } |
|
969 | 996 | |
970 | 997 | switch($this -> getSecureConnection()) |
971 | 998 | { |
972 | 999 | case TUrlMappingPatternSecureConnection::EnableIfNotSecure: |
973 | - if($isSecureConnection) return $url; |
|
1000 | + if($isSecureConnection) { |
|
1001 | + return $url; |
|
1002 | + } |
|
974 | 1003 | return $request -> getBaseUrl(true) . $url; |
975 | 1004 | break; |
976 | 1005 | case TUrlMappingPatternSecureConnection::DisableIfSecure: |
977 | - if(!$isSecureConnection) return $url; |
|
1006 | + if(!$isSecureConnection) { |
|
1007 | + return $url; |
|
1008 | + } |
|
978 | 1009 | return $request -> getBaseUrl(false) . $url; |
979 | 1010 | break; |
980 | 1011 | case TUrlMappingPatternSecureConnection::Enable: |
@@ -252,7 +252,7 @@ |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
255 | - * @return boolean true to observe changes. |
|
255 | + * @return boolean|string true to observe changes. |
|
256 | 256 | */ |
257 | 257 | public function getObserveChanges() |
258 | 258 | { |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public function setIsValid($value) |
106 | 106 | { |
107 | 107 | parent::setIsValid($value); |
108 | - if($this->getActiveControl()->canUpdateClientSide()) |
|
108 | + if ($this->getActiveControl()->canUpdateClientSide()) |
|
109 | 109 | { |
110 | 110 | $client = $this->getPage()->getCallbackClient(); |
111 | 111 | $func = 'Prado.Validation.updateActiveCustomValidator'; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function getClientScriptOptions() |
133 | 133 | { |
134 | - $options=TBaseValidator::getClientScriptOptions(); |
|
134 | + $options = TBaseValidator::getClientScriptOptions(); |
|
135 | 135 | $options['EventTarget'] = $this->getUniqueID(); |
136 | 136 | return $options; |
137 | 137 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function setErrorMessage($value) |
144 | 144 | { |
145 | 145 | parent::setErrorMessage($value); |
146 | - if($this->getActiveControl()->canUpdateClientSide()) |
|
146 | + if ($this->getActiveControl()->canUpdateClientSide()) |
|
147 | 147 | { |
148 | 148 | $client = $this->getPage()->getCallbackClient(); |
149 | 149 | $func = 'Prado.Validation.setErrorMessage'; |
@@ -257,6 +257,6 @@ discard block |
||
257 | 257 | public function getObserveChanges() |
258 | 258 | { |
259 | 259 | $changes = $this->getOption('ObserveChanges'); |
260 | - return ($changes===null) ? true : $changes; |
|
260 | + return ($changes === null) ? true : $changes; |
|
261 | 261 | } |
262 | 262 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | /** |
71 | 71 | * Javascript client class for this control. |
72 | 72 | * This method overrides the parent implementation. |
73 | - * @return null no javascript class name. |
|
73 | + * @return string no javascript class name. |
|
74 | 74 | */ |
75 | 75 | protected function getClientClassName() |
76 | 76 | { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | protected function createListItemCollection() |
64 | 64 | { |
65 | - $collection = new TActiveListItemCollection; |
|
65 | + $collection = new TActiveListItemCollection; |
|
66 | 66 | $collection->setControl($this); |
67 | 67 | return $collection; |
68 | 68 | } |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | { |
88 | 88 | parent::setSelectionMode($value); |
89 | 89 | $multiple = $this->getIsMultiSelect(); |
90 | - $id = $this->getUniqueID(); $multi_id = $id.'[]'; |
|
91 | - if($this->getActiveControl()->canUpdateClientSide()) |
|
90 | + $id = $this->getUniqueID(); $multi_id = $id . '[]'; |
|
91 | + if ($this->getActiveControl()->canUpdateClientSide()) |
|
92 | 92 | { |
93 | 93 | $client = $this->getPage()->getCallbackClient(); |
94 | 94 | $client->setAttribute($this, 'multiple', $multiple ? 'multiple' : false); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | protected function addAttributesToRender($writer) |
144 | 144 | { |
145 | 145 | parent::addAttributesToRender($writer); |
146 | - $writer->addAttribute('id',$this->getClientID()); |
|
146 | + $writer->addAttribute('id', $this->getClientID()); |
|
147 | 147 | if ($this->getAutoPostBack()) |
148 | 148 | $this->getActiveControl()->registerCallbackClientScript( |
149 | 149 | $this->getClientClassName(), $this->getPostBackOptions()); |
@@ -144,9 +144,10 @@ |
||
144 | 144 | { |
145 | 145 | parent::addAttributesToRender($writer); |
146 | 146 | $writer->addAttribute('id',$this->getClientID()); |
147 | - if ($this->getAutoPostBack()) |
|
148 | - $this->getActiveControl()->registerCallbackClientScript( |
|
147 | + if ($this->getAutoPostBack()) { |
|
148 | + $this->getActiveControl()->registerCallbackClientScript( |
|
149 | 149 | $this->getClientClassName(), $this->getPostBackOptions()); |
150 | + } |
|
150 | 151 | } |
151 | 152 | } |
152 | 153 |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TActiveListBox class file. |
|
4 | - * |
|
5 | - * @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Web.UI.ActiveControls |
|
10 | - */ |
|
3 | + * TActiveListBox class file. |
|
4 | + * |
|
5 | + * @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Web.UI.ActiveControls |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Load active list control adapter |
@@ -228,6 +228,8 @@ |
||
228 | 228 | |
229 | 229 | /** |
230 | 230 | * Appends data or javascript code to the body content surrounded with delimiters |
231 | + * @param THttpResponse $response |
|
232 | + * @param string $delimiter |
|
231 | 233 | */ |
232 | 234 | private function appendContentPart($response, $delimiter, $data) |
233 | 235 | { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private $_callbackClient; |
82 | 82 | |
83 | - private $_controlsToRender=array(); |
|
83 | + private $_controlsToRender = array(); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * Constructor, trap errors and exception to let the callback response |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function processCallbackEvent($writer) |
105 | 105 | { |
106 | - Prado::trace("ActivePage raiseCallbackEvent()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
106 | + Prado::trace("ActivePage raiseCallbackEvent()", 'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
107 | 107 | $this->raiseCallbackEvent(); |
108 | 108 | } |
109 | 109 | |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | * @param TControl control for defered rendering |
113 | 113 | * @param THtmlWriter the renderer |
114 | 114 | */ |
115 | - public function registerControlToRender($control,$writer) |
|
115 | + public function registerControlToRender($control, $writer) |
|
116 | 116 | { |
117 | 117 | $id = $control->getUniqueID(); |
118 | - if(!isset($this->_controlsToRender[$id])) |
|
119 | - $this->_controlsToRender[$id] = array($control,$writer); |
|
118 | + if (!isset($this->_controlsToRender[$id])) |
|
119 | + $this->_controlsToRender[$id] = array($control, $writer); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function renderCallbackResponse($writer) |
135 | 135 | { |
136 | - Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
137 | - if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null) |
|
136 | + Prado::trace("ActivePage renderCallbackResponse()", 'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
137 | + if (($url = $this->getResponse()->getAdapter()->getRedirectedUrl()) === null) |
|
138 | 138 | $this->renderResponse($writer); |
139 | 139 | else |
140 | 140 | $this->redirect($url); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | protected function redirect($url) |
148 | 148 | { |
149 | - Prado::trace("ActivePage redirect()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
149 | + Prado::trace("ActivePage redirect()", 'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
150 | 150 | $this->appendContentPart($this->getResponse(), self::CALLBACK_REDIRECT, $url); |
151 | 151 | } |
152 | 152 | |
@@ -157,18 +157,18 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function renderResponse($writer) |
159 | 159 | { |
160 | - Prado::trace("ActivePage renderResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
160 | + Prado::trace("ActivePage renderResponse()", 'System.Web.UI.ActiveControls.TActivePageAdapter'); |
|
161 | 161 | //renders all the defered render() calls. |
162 | - foreach($this->_controlsToRender as $rid => $forRender) |
|
162 | + foreach ($this->_controlsToRender as $rid => $forRender) |
|
163 | 163 | $forRender[0]->render($forRender[1]); |
164 | 164 | |
165 | 165 | $response = $this->getResponse(); |
166 | 166 | |
167 | 167 | //send response data in header |
168 | - if($response->getHasAdapter()) |
|
168 | + if ($response->getHasAdapter()) |
|
169 | 169 | { |
170 | 170 | $responseData = $response->getAdapter()->getResponseData(); |
171 | - if($responseData!==null) |
|
171 | + if ($responseData !== null) |
|
172 | 172 | { |
173 | 173 | $data = TJavaScript::jsonEncode($responseData); |
174 | 174 | |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | //sends page state in header |
180 | - if(($handler = $this->getCallbackEventTarget()) !== null) |
|
180 | + if (($handler = $this->getCallbackEventTarget()) !== null) |
|
181 | 181 | { |
182 | - if($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate()) |
|
182 | + if ($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate()) |
|
183 | 183 | { |
184 | 184 | $pagestate = $this->getPage()->getClientState(); |
185 | 185 | $this->appendContentPart($response, self::CALLBACK_PAGESTATE_HEADER, $pagestate); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $writer->write(" "); |
191 | 191 | |
192 | 192 | //output the end javascript |
193 | - if($this->getPage()->getClientScript()->hasEndScripts()) |
|
193 | + if ($this->getPage()->getClientScript()->hasEndScripts()) |
|
194 | 194 | { |
195 | 195 | $writer = $response->createHtmlWriter(); |
196 | 196 | $this->getPage()->getClientScript()->renderEndScriptsCallback($writer); |
@@ -207,22 +207,22 @@ discard block |
||
207 | 207 | |
208 | 208 | // collect all stylesheet file references |
209 | 209 | $stylesheets = $cs->getStyleSheetUrls(); |
210 | - if (count($stylesheets)>0) |
|
210 | + if (count($stylesheets) > 0) |
|
211 | 211 | $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets)); |
212 | 212 | |
213 | 213 | // collect all stylesheet snippets references |
214 | 214 | $stylesheets = $cs->getStyleSheetCodes(); |
215 | - if (count($stylesheets)>0) |
|
215 | + if (count($stylesheets) > 0) |
|
216 | 216 | $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets)); |
217 | 217 | |
218 | 218 | // collect all script file references |
219 | 219 | $scripts = $cs->getScriptUrls(); |
220 | - if (count($scripts)>0) |
|
220 | + if (count($scripts) > 0) |
|
221 | 221 | $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts)); |
222 | 222 | |
223 | 223 | // collect all hidden field references |
224 | 224 | $fields = $cs->getHiddenFields(); |
225 | - if (count($fields)>0) |
|
225 | + if (count($fields) > 0) |
|
226 | 226 | $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields)); |
227 | 227 | } |
228 | 228 | |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | */ |
245 | 245 | private function raiseCallbackEvent() |
246 | 246 | { |
247 | - if(($callbackHandler=$this->getCallbackEventTarget())!==null) |
|
247 | + if (($callbackHandler = $this->getCallbackEventTarget()) !== null) |
|
248 | 248 | { |
249 | - if($callbackHandler instanceof ICallbackEventHandler) |
|
249 | + if ($callbackHandler instanceof ICallbackEventHandler) |
|
250 | 250 | { |
251 | 251 | $param = $this->getCallbackEventParameter(); |
252 | 252 | $result = new TCallbackEventParameter($this->getResponse(), $param); |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function getCallbackEventTarget() |
273 | 273 | { |
274 | - if($this->_callbackEventTarget===null) |
|
274 | + if ($this->_callbackEventTarget === null) |
|
275 | 275 | { |
276 | - $eventTarget=$this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET); |
|
277 | - if(!empty($eventTarget)) |
|
278 | - $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget); |
|
276 | + $eventTarget = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET); |
|
277 | + if (!empty($eventTarget)) |
|
278 | + $this->_callbackEventTarget = $this->getPage()->findControl($eventTarget); |
|
279 | 279 | } |
280 | 280 | return $this->_callbackEventTarget; |
281 | 281 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function setCallbackEventTarget(TControl $control) |
288 | 288 | { |
289 | - $this->_callbackEventTarget=$control; |
|
289 | + $this->_callbackEventTarget = $control; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function getCallbackEventParameter() |
297 | 297 | { |
298 | - if($this->_callbackEventParameter===null) |
|
298 | + if ($this->_callbackEventParameter === null) |
|
299 | 299 | { |
300 | 300 | $param = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_PARAMETER); |
301 | - $this->_callbackEventParameter=$param; |
|
301 | + $this->_callbackEventParameter = $param; |
|
302 | 302 | } |
303 | 303 | return $this->_callbackEventParameter; |
304 | 304 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function setCallbackEventParameter($value) |
310 | 310 | { |
311 | - $this->_callbackEventParameter=$value; |
|
311 | + $this->_callbackEventParameter = $value; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function getCallbackClientHandler() |
320 | 320 | { |
321 | - if($this->_callbackClient===null) |
|
321 | + if ($this->_callbackClient === null) |
|
322 | 322 | $this->_callbackClient = new TCallbackClientScript; |
323 | 323 | return $this->_callbackClient; |
324 | 324 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | protected function displayException($exception) |
347 | 347 | { |
348 | - if($this->getApplication()->getMode()===TApplication::STATE_DEBUG) |
|
348 | + if ($this->getApplication()->getMode() === TApplication::STATE_DEBUG) |
|
349 | 349 | { |
350 | 350 | $response = $this->getApplication()->getResponse(); |
351 | 351 | $trace = $this->getExceptionStackTrace($exception); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $trace = TJavaScript::jsonEncode($trace); |
355 | 355 | } catch (Exception $e) { |
356 | 356 | // strip everythin not 7bit ascii |
357 | - $trace = preg_replace('/[^(\x20-\x7F)]*/','', serialize($trace)); |
|
357 | + $trace = preg_replace('/[^(\x20-\x7F)]*/', '', serialize($trace)); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | // avoid exception loop if headers have already been sent |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | } |
369 | 369 | else |
370 | 370 | { |
371 | - error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
|
371 | + error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
|
372 | 372 | header('HTTP/1.0 500 Internal Server Error', true, 500); |
373 | 373 | } |
374 | 374 | $this->getApplication()->getResponse()->flush(); |
@@ -380,24 +380,24 @@ discard block |
||
380 | 380 | */ |
381 | 381 | private function getExceptionStackTrace($exception) |
382 | 382 | { |
383 | - $data['code']=$exception->getCode() > 0 ? $exception->getCode() : 500; |
|
384 | - $data['file']=$exception->getFile(); |
|
385 | - $data['line']=$exception->getLine(); |
|
386 | - $data['trace']=$exception->getTrace(); |
|
387 | - if($exception instanceof TPhpErrorException) |
|
383 | + $data['code'] = $exception->getCode() > 0 ? $exception->getCode() : 500; |
|
384 | + $data['file'] = $exception->getFile(); |
|
385 | + $data['line'] = $exception->getLine(); |
|
386 | + $data['trace'] = $exception->getTrace(); |
|
387 | + if ($exception instanceof TPhpErrorException) |
|
388 | 388 | { |
389 | 389 | // if PHP exception, we want to show the 2nd stack level context |
390 | 390 | // because the 1st stack level is of little use (it's in error handler) |
391 | - if(isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) |
|
391 | + if (isset($trace[0]) && isset($trace[0]['file']) && isset($trace[0]['line'])) |
|
392 | 392 | { |
393 | - $data['file']=$trace[0]['file']; |
|
394 | - $data['line']=$trace[0]['line']; |
|
393 | + $data['file'] = $trace[0]['file']; |
|
394 | + $data['line'] = $trace[0]['line']; |
|
395 | 395 | } |
396 | 396 | } |
397 | - $data['type']=get_class($exception); |
|
398 | - $data['message']=$exception->getMessage(); |
|
399 | - $data['version']=$_SERVER['SERVER_SOFTWARE'].' '.Prado::getVersion(); |
|
400 | - $data['time']=@strftime('%Y-%m-%d %H:%M',time()); |
|
397 | + $data['type'] = get_class($exception); |
|
398 | + $data['message'] = $exception->getMessage(); |
|
399 | + $data['version'] = $_SERVER['SERVER_SOFTWARE'] . ' ' . Prado::getVersion(); |
|
400 | + $data['time'] = @strftime('%Y-%m-%d %H:%M', time()); |
|
401 | 401 | return $data; |
402 | 402 | } |
403 | 403 | } |
@@ -115,8 +115,9 @@ discard block |
||
115 | 115 | public function registerControlToRender($control,$writer) |
116 | 116 | { |
117 | 117 | $id = $control->getUniqueID(); |
118 | - if(!isset($this->_controlsToRender[$id])) |
|
119 | - $this->_controlsToRender[$id] = array($control,$writer); |
|
118 | + if(!isset($this->_controlsToRender[$id])) { |
|
119 | + $this->_controlsToRender[$id] = array($control,$writer); |
|
120 | + } |
|
120 | 121 | } |
121 | 122 | |
122 | 123 | /** |
@@ -134,10 +135,11 @@ discard block |
||
134 | 135 | public function renderCallbackResponse($writer) |
135 | 136 | { |
136 | 137 | Prado::trace("ActivePage renderCallbackResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
137 | - if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null) |
|
138 | - $this->renderResponse($writer); |
|
139 | - else |
|
140 | - $this->redirect($url); |
|
138 | + if(($url = $this->getResponse()->getAdapter()->getRedirectedUrl())===null) { |
|
139 | + $this->renderResponse($writer); |
|
140 | + } else { |
|
141 | + $this->redirect($url); |
|
142 | + } |
|
141 | 143 | } |
142 | 144 | |
143 | 145 | /** |
@@ -159,8 +161,9 @@ discard block |
||
159 | 161 | { |
160 | 162 | Prado::trace("ActivePage renderResponse()",'System.Web.UI.ActiveControls.TActivePageAdapter'); |
161 | 163 | //renders all the defered render() calls. |
162 | - foreach($this->_controlsToRender as $rid => $forRender) |
|
163 | - $forRender[0]->render($forRender[1]); |
|
164 | + foreach($this->_controlsToRender as $rid => $forRender) { |
|
165 | + $forRender[0]->render($forRender[1]); |
|
166 | + } |
|
164 | 167 | |
165 | 168 | $response = $this->getResponse(); |
166 | 169 | |
@@ -207,23 +210,27 @@ discard block |
||
207 | 210 | |
208 | 211 | // collect all stylesheet file references |
209 | 212 | $stylesheets = $cs->getStyleSheetUrls(); |
210 | - if (count($stylesheets)>0) |
|
211 | - $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets)); |
|
213 | + if (count($stylesheets)>0) { |
|
214 | + $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets)); |
|
215 | + } |
|
212 | 216 | |
213 | 217 | // collect all stylesheet snippets references |
214 | 218 | $stylesheets = $cs->getStyleSheetCodes(); |
215 | - if (count($stylesheets)>0) |
|
216 | - $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets)); |
|
219 | + if (count($stylesheets)>0) { |
|
220 | + $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets)); |
|
221 | + } |
|
217 | 222 | |
218 | 223 | // collect all script file references |
219 | 224 | $scripts = $cs->getScriptUrls(); |
220 | - if (count($scripts)>0) |
|
221 | - $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts)); |
|
225 | + if (count($scripts)>0) { |
|
226 | + $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts)); |
|
227 | + } |
|
222 | 228 | |
223 | 229 | // collect all hidden field references |
224 | 230 | $fields = $cs->getHiddenFields(); |
225 | - if (count($fields)>0) |
|
226 | - $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields)); |
|
231 | + if (count($fields)>0) { |
|
232 | + $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields)); |
|
233 | + } |
|
227 | 234 | } |
228 | 235 | |
229 | 236 | /** |
@@ -251,14 +258,12 @@ discard block |
||
251 | 258 | $param = $this->getCallbackEventParameter(); |
252 | 259 | $result = new TCallbackEventParameter($this->getResponse(), $param); |
253 | 260 | $callbackHandler->raiseCallbackEvent($result); |
254 | - } |
|
255 | - else |
|
261 | + } else |
|
256 | 262 | { |
257 | 263 | throw new TInvalidCallbackException( |
258 | 264 | 'callback_invalid_handler', $callbackHandler->getUniqueID()); |
259 | 265 | } |
260 | - } |
|
261 | - else |
|
266 | + } else |
|
262 | 267 | { |
263 | 268 | $target = $this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET); |
264 | 269 | throw new TInvalidCallbackException('callback_invalid_target', $target); |
@@ -274,8 +279,9 @@ discard block |
||
274 | 279 | if($this->_callbackEventTarget===null) |
275 | 280 | { |
276 | 281 | $eventTarget=$this->getRequest()->itemAt(TPage::FIELD_CALLBACK_TARGET); |
277 | - if(!empty($eventTarget)) |
|
278 | - $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget); |
|
282 | + if(!empty($eventTarget)) { |
|
283 | + $this->_callbackEventTarget=$this->getPage()->findControl($eventTarget); |
|
284 | + } |
|
279 | 285 | } |
280 | 286 | return $this->_callbackEventTarget; |
281 | 287 | } |
@@ -318,8 +324,9 @@ discard block |
||
318 | 324 | */ |
319 | 325 | public function getCallbackClientHandler() |
320 | 326 | { |
321 | - if($this->_callbackClient===null) |
|
322 | - $this->_callbackClient = new TCallbackClientScript; |
|
327 | + if($this->_callbackClient===null) { |
|
328 | + $this->_callbackClient = new TCallbackClientScript; |
|
329 | + } |
|
323 | 330 | return $this->_callbackClient; |
324 | 331 | } |
325 | 332 | } |
@@ -365,8 +372,7 @@ discard block |
||
365 | 372 | $content = $response->createHtmlWriter(); |
366 | 373 | $content->getWriter()->setBoundary(TActivePageAdapter::CALLBACK_ERROR_HEADER); |
367 | 374 | $content->write($trace); |
368 | - } |
|
369 | - else |
|
375 | + } else |
|
370 | 376 | { |
371 | 377 | error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
372 | 378 | header('HTTP/1.0 500 Internal Server Error', true, 500); |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TActivePageAdapter, TCallbackErrorHandler and TInvalidCallbackException class file. |
|
4 | - * |
|
5 | - * @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
6 | - * @author Gabor Berczi <[email protected]> (lazyload additions & progressive rendering) |
|
7 | - * @link https://github.com/pradosoft/prado |
|
8 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
9 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
10 | - * @package System.Web.UI.ActiveControls |
|
11 | - */ |
|
3 | + * TActivePageAdapter, TCallbackErrorHandler and TInvalidCallbackException class file. |
|
4 | + * |
|
5 | + * @author Wei Zhuo <weizhuo[at]gamil[dot]com> |
|
6 | + * @author Gabor Berczi <[email protected]> (lazyload additions & progressive rendering) |
|
7 | + * @link https://github.com/pradosoft/prado |
|
8 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
9 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
10 | + * @package System.Web.UI.ActiveControls |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Load callback response adapter class. |