@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function init($config) |
187 | 187 | { |
188 | - if($this->_serviceParameter === null) |
|
188 | + if ($this->_serviceParameter === null) |
|
189 | 189 | throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
190 | - if(strpos($this->_serviceParameter, '*') !== false) |
|
190 | + if (strpos($this->_serviceParameter, '*') !== false) |
|
191 | 191 | $this->_isWildCardPattern = true; |
192 | 192 | } |
193 | 193 | |
@@ -202,27 +202,27 @@ discard block |
||
202 | 202 | $values = []; |
203 | 203 | if ($this->_parameters) |
204 | 204 | { |
205 | - foreach($this->_parameters as $key => $value) |
|
205 | + foreach ($this->_parameters as $key => $value) |
|
206 | 206 | { |
207 | - $params[] = '{' . $key . '}'; |
|
208 | - $values[] = '(?P<' . $key . '>' . $value . ')'; |
|
207 | + $params[] = '{'.$key.'}'; |
|
208 | + $values[] = '(?P<'.$key.'>'.$value.')'; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | if ($this->getIsWildCardPattern()) |
212 | 212 | { |
213 | 213 | $params[] = '{*}'; |
214 | 214 | // service parameter must not contain '=' and '/' |
215 | - $values[] = '(?P<' . $this->getServiceID() . '>[^=/]+)'; |
|
215 | + $values[] = '(?P<'.$this->getServiceID().'>[^=/]+)'; |
|
216 | 216 | } |
217 | 217 | $params[] = '/'; |
218 | 218 | $values[] = '\\/'; |
219 | - $regexp = str_replace($params, $values, trim($this->getPattern(), '/') . '/'); |
|
219 | + $regexp = str_replace($params, $values, trim($this->getPattern(), '/').'/'); |
|
220 | 220 | if ($this->_urlFormat === THttpRequestUrlFormat::Get) |
221 | - $regexp = '/^' . $regexp . '$/u'; |
|
221 | + $regexp = '/^'.$regexp.'$/u'; |
|
222 | 222 | else |
223 | - $regexp = '/^' . $regexp . '(?P<urlparams>.*)$/u'; |
|
223 | + $regexp = '/^'.$regexp.'(?P<urlparams>.*)$/u'; |
|
224 | 224 | |
225 | - if(!$this->getCaseSensitive()) |
|
225 | + if (!$this->getCaseSensitive()) |
|
226 | 226 | $regexp .= 'i'; |
227 | 227 | return $regexp; |
228 | 228 | } |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | public function getPatternMatches($request) |
352 | 352 | { |
353 | 353 | $matches = []; |
354 | - if(($pattern = $this->getRegularExpression()) !== '') |
|
354 | + if (($pattern = $this->getRegularExpression()) !== '') |
|
355 | 355 | preg_match($pattern, $request->getPathInfo(), $matches); |
356 | 356 | else |
357 | - preg_match($this->getParameterizedPattern(), trim($request->getPathInfo(), '/') . '/', $matches); |
|
357 | + preg_match($this->getParameterizedPattern(), trim($request->getPathInfo(), '/').'/', $matches); |
|
358 | 358 | |
359 | - if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
359 | + if ($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
360 | 360 | $matches[$this->_serviceID] = str_replace('*', $matches[$this->_serviceID], $this->_serviceParameter); |
361 | 361 | |
362 | 362 | if (isset($matches['urlparams'])) |
@@ -364,13 +364,13 @@ discard block |
||
364 | 364 | $params = explode('/', $matches['urlparams']); |
365 | 365 | if ($this->_separator === '/') |
366 | 366 | { |
367 | - while($key = array_shift($params)) |
|
367 | + while ($key = array_shift($params)) |
|
368 | 368 | $matches[$key] = ($value = array_shift($params)) ? $value : ''; |
369 | 369 | } |
370 | 370 | else |
371 | 371 | { |
372 | 372 | array_pop($params); |
373 | - foreach($params as $param) |
|
373 | + foreach ($params as $param) |
|
374 | 374 | { |
375 | 375 | list($key, $value) = explode($this->_separator, $param, 2); |
376 | 376 | $matches[$key] = $value; |
@@ -379,9 +379,9 @@ discard block |
||
379 | 379 | unset($matches['urlparams']); |
380 | 380 | } |
381 | 381 | |
382 | - if(count($matches) > 0 && $this->_constants) |
|
382 | + if (count($matches) > 0 && $this->_constants) |
|
383 | 383 | { |
384 | - foreach($this->_constants->toArray() as $key => $value) |
|
384 | + foreach ($this->_constants->toArray() as $key => $value) |
|
385 | 385 | $matches[$key] = $value; |
386 | 386 | } |
387 | 387 | |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | */ |
454 | 454 | public function setUrlParamSeparator($value) |
455 | 455 | { |
456 | - if(strlen($value) === 1) |
|
456 | + if (strlen($value) === 1) |
|
457 | 457 | $this->_separator = $value; |
458 | 458 | else |
459 | 459 | throw new TInvalidDataValueException('httprequest_separator_invalid'); |
@@ -484,20 +484,20 @@ discard block |
||
484 | 484 | */ |
485 | 485 | public function supportCustomUrl($getItems) |
486 | 486 | { |
487 | - if(!$this->_customUrl || $this->getPattern() === null) |
|
487 | + if (!$this->_customUrl || $this->getPattern() === null) |
|
488 | 488 | return false; |
489 | 489 | if ($this->_parameters) |
490 | 490 | { |
491 | - foreach($this->_parameters as $key => $value) |
|
491 | + foreach ($this->_parameters as $key => $value) |
|
492 | 492 | { |
493 | - if(!isset($getItems[$key])) |
|
493 | + if (!isset($getItems[$key])) |
|
494 | 494 | return false; |
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
498 | 498 | if ($this->_constants) |
499 | 499 | { |
500 | - foreach($this->_constants->toArray() as $key => $value) |
|
500 | + foreach ($this->_constants->toArray() as $key => $value) |
|
501 | 501 | { |
502 | 502 | if (!isset($getItems[$key])) |
503 | 503 | return false; |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | { |
521 | 521 | if ($this->_constants) |
522 | 522 | { |
523 | - foreach($this->_constants->toArray() as $key => $value) |
|
523 | + foreach ($this->_constants->toArray() as $key => $value) |
|
524 | 524 | { |
525 | 525 | unset($getItems[$key]); |
526 | 526 | } |
@@ -529,55 +529,55 @@ discard block |
||
529 | 529 | $extra = []; |
530 | 530 | $replace = []; |
531 | 531 | // for the GET variables matching the pattern, put them in the URL path |
532 | - foreach($getItems as $key => $value) |
|
532 | + foreach ($getItems as $key => $value) |
|
533 | 533 | { |
534 | - if(($this->_parameters && $this->_parameters->contains($key)) || ($key === '*' && $this->getIsWildCardPattern())) |
|
535 | - $replace['{' . $key . '}'] = $encodeGetItems ? rawurlencode($value) : $value; |
|
534 | + if (($this->_parameters && $this->_parameters->contains($key)) || ($key === '*' && $this->getIsWildCardPattern())) |
|
535 | + $replace['{'.$key.'}'] = $encodeGetItems ? rawurlencode($value) : $value; |
|
536 | 536 | else |
537 | 537 | $extra[$key] = $value; |
538 | 538 | } |
539 | 539 | |
540 | - $url = $this->_manager->getUrlPrefix() . '/' . ltrim(strtr($this->getPattern(), $replace), '/'); |
|
540 | + $url = $this->_manager->getUrlPrefix().'/'.ltrim(strtr($this->getPattern(), $replace), '/'); |
|
541 | 541 | |
542 | 542 | // for the rest of the GET variables, put them in the query string |
543 | - if(count($extra) > 0) |
|
543 | + if (count($extra) > 0) |
|
544 | 544 | { |
545 | 545 | if ($this->_urlFormat === THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) { |
546 | 546 | foreach ($extra as $name => $value) |
547 | - $url .= '/' . $name . $this->_separator . ($encodeGetItems?rawurlencode($value):$value); |
|
547 | + $url .= '/'.$name.$this->_separator.($encodeGetItems ?rawurlencode($value) : $value); |
|
548 | 548 | return $url; |
549 | 549 | } |
550 | 550 | |
551 | 551 | $url2 = ''; |
552 | - $amp = $encodeAmpersand?'&':'&'; |
|
553 | - if($encodeGetItems) |
|
552 | + $amp = $encodeAmpersand ? '&' : '&'; |
|
553 | + if ($encodeGetItems) |
|
554 | 554 | { |
555 | - foreach($extra as $name => $value) |
|
555 | + foreach ($extra as $name => $value) |
|
556 | 556 | { |
557 | - if(is_array($value)) |
|
557 | + if (is_array($value)) |
|
558 | 558 | { |
559 | - $name = rawurlencode($name . '[]'); |
|
560 | - foreach($value as $v) |
|
561 | - $url2 .= $amp . $name . '=' . rawurlencode($v); |
|
559 | + $name = rawurlencode($name.'[]'); |
|
560 | + foreach ($value as $v) |
|
561 | + $url2 .= $amp.$name.'='.rawurlencode($v); |
|
562 | 562 | } |
563 | 563 | else |
564 | - $url2 .= $amp . rawurlencode($name) . '=' . rawurlencode($value); |
|
564 | + $url2 .= $amp.rawurlencode($name).'='.rawurlencode($value); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | else |
568 | 568 | { |
569 | - foreach($extra as $name => $value) |
|
569 | + foreach ($extra as $name => $value) |
|
570 | 570 | { |
571 | - if(is_array($value)) |
|
571 | + if (is_array($value)) |
|
572 | 572 | { |
573 | - foreach($value as $v) |
|
574 | - $url2 .= $amp . $name . '[]=' . $v; |
|
573 | + foreach ($value as $v) |
|
574 | + $url2 .= $amp.$name.'[]='.$v; |
|
575 | 575 | } |
576 | 576 | else |
577 | - $url2 .= $amp . $name . '=' . $value; |
|
577 | + $url2 .= $amp.$name.'='.$value; |
|
578 | 578 | } |
579 | 579 | } |
580 | - $url = $url . '?' . substr($url2, strlen($amp)); |
|
580 | + $url = $url.'?'.substr($url2, strlen($amp)); |
|
581 | 581 | } |
582 | 582 | return $this -> applySecureConnectionPrefix($url); |
583 | 583 | } |
@@ -593,26 +593,26 @@ discard block |
||
593 | 593 | protected function applySecureConnectionPrefix($url) |
594 | 594 | { |
595 | 595 | static $request; |
596 | - if($request === null) $request = Prado::getApplication() -> getRequest(); |
|
596 | + if ($request === null) $request = Prado::getApplication() -> getRequest(); |
|
597 | 597 | |
598 | 598 | static $isSecureConnection; |
599 | - if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
599 | + if ($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
600 | 600 | |
601 | - switch($this -> getSecureConnection()) |
|
601 | + switch ($this -> getSecureConnection()) |
|
602 | 602 | { |
603 | 603 | case TUrlMappingPatternSecureConnection::EnableIfNotSecure: |
604 | - if($isSecureConnection) return $url; |
|
605 | - return $request -> getBaseUrl(true) . $url; |
|
604 | + if ($isSecureConnection) return $url; |
|
605 | + return $request -> getBaseUrl(true).$url; |
|
606 | 606 | break; |
607 | 607 | case TUrlMappingPatternSecureConnection::DisableIfSecure: |
608 | - if(!$isSecureConnection) return $url; |
|
609 | - return $request -> getBaseUrl(false) . $url; |
|
608 | + if (!$isSecureConnection) return $url; |
|
609 | + return $request -> getBaseUrl(false).$url; |
|
610 | 610 | break; |
611 | 611 | case TUrlMappingPatternSecureConnection::Enable: |
612 | - return $request -> getBaseUrl(true) . $url; |
|
612 | + return $request -> getBaseUrl(true).$url; |
|
613 | 613 | break; |
614 | 614 | case TUrlMappingPatternSecureConnection::Disable: |
615 | - return $request -> getBaseUrl(false) . $url; |
|
615 | + return $request -> getBaseUrl(false).$url; |
|
616 | 616 | break; |
617 | 617 | case TUrlMappingPatternSecureConnection::Automatic: |
618 | 618 | default: |
@@ -185,10 +185,12 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function init($config) |
187 | 187 | { |
188 | - if($this->_serviceParameter === null) |
|
189 | - throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
|
190 | - if(strpos($this->_serviceParameter, '*') !== false) |
|
191 | - $this->_isWildCardPattern = true; |
|
188 | + if($this->_serviceParameter === null) { |
|
189 | + throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern()); |
|
190 | + } |
|
191 | + if(strpos($this->_serviceParameter, '*') !== false) { |
|
192 | + $this->_isWildCardPattern = true; |
|
193 | + } |
|
192 | 194 | } |
193 | 195 | |
194 | 196 | /** |
@@ -217,13 +219,15 @@ discard block |
||
217 | 219 | $params[] = '/'; |
218 | 220 | $values[] = '\\/'; |
219 | 221 | $regexp = str_replace($params, $values, trim($this->getPattern(), '/') . '/'); |
220 | - if ($this->_urlFormat === THttpRequestUrlFormat::Get) |
|
221 | - $regexp = '/^' . $regexp . '$/u'; |
|
222 | - else |
|
223 | - $regexp = '/^' . $regexp . '(?P<urlparams>.*)$/u'; |
|
222 | + if ($this->_urlFormat === THttpRequestUrlFormat::Get) { |
|
223 | + $regexp = '/^' . $regexp . '$/u'; |
|
224 | + } else { |
|
225 | + $regexp = '/^' . $regexp . '(?P<urlparams>.*)$/u'; |
|
226 | + } |
|
224 | 227 | |
225 | - if(!$this->getCaseSensitive()) |
|
226 | - $regexp .= 'i'; |
|
228 | + if(!$this->getCaseSensitive()) { |
|
229 | + $regexp .= 'i'; |
|
230 | + } |
|
227 | 231 | return $regexp; |
228 | 232 | } |
229 | 233 | |
@@ -351,23 +355,25 @@ discard block |
||
351 | 355 | public function getPatternMatches($request) |
352 | 356 | { |
353 | 357 | $matches = []; |
354 | - if(($pattern = $this->getRegularExpression()) !== '') |
|
355 | - preg_match($pattern, $request->getPathInfo(), $matches); |
|
356 | - else |
|
357 | - preg_match($this->getParameterizedPattern(), trim($request->getPathInfo(), '/') . '/', $matches); |
|
358 | + if(($pattern = $this->getRegularExpression()) !== '') { |
|
359 | + preg_match($pattern, $request->getPathInfo(), $matches); |
|
360 | + } else { |
|
361 | + preg_match($this->getParameterizedPattern(), trim($request->getPathInfo(), '/') . '/', $matches); |
|
362 | + } |
|
358 | 363 | |
359 | - if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) |
|
360 | - $matches[$this->_serviceID] = str_replace('*', $matches[$this->_serviceID], $this->_serviceParameter); |
|
364 | + if($this->getIsWildCardPattern() && isset($matches[$this->_serviceID])) { |
|
365 | + $matches[$this->_serviceID] = str_replace('*', $matches[$this->_serviceID], $this->_serviceParameter); |
|
366 | + } |
|
361 | 367 | |
362 | 368 | if (isset($matches['urlparams'])) |
363 | 369 | { |
364 | 370 | $params = explode('/', $matches['urlparams']); |
365 | 371 | if ($this->_separator === '/') |
366 | 372 | { |
367 | - while($key = array_shift($params)) |
|
368 | - $matches[$key] = ($value = array_shift($params)) ? $value : ''; |
|
369 | - } |
|
370 | - else |
|
373 | + while($key = array_shift($params)) { |
|
374 | + $matches[$key] = ($value = array_shift($params)) ? $value : ''; |
|
375 | + } |
|
376 | + } else |
|
371 | 377 | { |
372 | 378 | array_pop($params); |
373 | 379 | foreach($params as $param) |
@@ -381,8 +387,9 @@ discard block |
||
381 | 387 | |
382 | 388 | if(count($matches) > 0 && $this->_constants) |
383 | 389 | { |
384 | - foreach($this->_constants->toArray() as $key => $value) |
|
385 | - $matches[$key] = $value; |
|
390 | + foreach($this->_constants->toArray() as $key => $value) { |
|
391 | + $matches[$key] = $value; |
|
392 | + } |
|
386 | 393 | } |
387 | 394 | |
388 | 395 | return $matches; |
@@ -453,10 +460,11 @@ discard block |
||
453 | 460 | */ |
454 | 461 | public function setUrlParamSeparator($value) |
455 | 462 | { |
456 | - if(strlen($value) === 1) |
|
457 | - $this->_separator = $value; |
|
458 | - else |
|
459 | - throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
463 | + if(strlen($value) === 1) { |
|
464 | + $this->_separator = $value; |
|
465 | + } else { |
|
466 | + throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
467 | + } |
|
460 | 468 | } |
461 | 469 | |
462 | 470 | /** |
@@ -484,14 +492,16 @@ discard block |
||
484 | 492 | */ |
485 | 493 | public function supportCustomUrl($getItems) |
486 | 494 | { |
487 | - if(!$this->_customUrl || $this->getPattern() === null) |
|
488 | - return false; |
|
495 | + if(!$this->_customUrl || $this->getPattern() === null) { |
|
496 | + return false; |
|
497 | + } |
|
489 | 498 | if ($this->_parameters) |
490 | 499 | { |
491 | 500 | foreach($this->_parameters as $key => $value) |
492 | 501 | { |
493 | - if(!isset($getItems[$key])) |
|
494 | - return false; |
|
502 | + if(!isset($getItems[$key])) { |
|
503 | + return false; |
|
504 | + } |
|
495 | 505 | } |
496 | 506 | } |
497 | 507 | |
@@ -499,10 +509,12 @@ discard block |
||
499 | 509 | { |
500 | 510 | foreach($this->_constants->toArray() as $key => $value) |
501 | 511 | { |
502 | - if (!isset($getItems[$key])) |
|
503 | - return false; |
|
504 | - if ($getItems[$key] != $value) |
|
505 | - return false; |
|
512 | + if (!isset($getItems[$key])) { |
|
513 | + return false; |
|
514 | + } |
|
515 | + if ($getItems[$key] != $value) { |
|
516 | + return false; |
|
517 | + } |
|
506 | 518 | } |
507 | 519 | } |
508 | 520 | return true; |
@@ -531,10 +543,11 @@ discard block |
||
531 | 543 | // for the GET variables matching the pattern, put them in the URL path |
532 | 544 | foreach($getItems as $key => $value) |
533 | 545 | { |
534 | - if(($this->_parameters && $this->_parameters->contains($key)) || ($key === '*' && $this->getIsWildCardPattern())) |
|
535 | - $replace['{' . $key . '}'] = $encodeGetItems ? rawurlencode($value) : $value; |
|
536 | - else |
|
537 | - $extra[$key] = $value; |
|
546 | + if(($this->_parameters && $this->_parameters->contains($key)) || ($key === '*' && $this->getIsWildCardPattern())) { |
|
547 | + $replace['{' . $key . '}'] = $encodeGetItems ? rawurlencode($value) : $value; |
|
548 | + } else { |
|
549 | + $extra[$key] = $value; |
|
550 | + } |
|
538 | 551 | } |
539 | 552 | |
540 | 553 | $url = $this->_manager->getUrlPrefix() . '/' . ltrim(strtr($this->getPattern(), $replace), '/'); |
@@ -543,8 +556,9 @@ discard block |
||
543 | 556 | if(count($extra) > 0) |
544 | 557 | { |
545 | 558 | if ($this->_urlFormat === THttpRequestUrlFormat::Path && $this->getIsWildCardPattern()) { |
546 | - foreach ($extra as $name => $value) |
|
547 | - $url .= '/' . $name . $this->_separator . ($encodeGetItems?rawurlencode($value):$value); |
|
559 | + foreach ($extra as $name => $value) { |
|
560 | + $url .= '/' . $name . $this->_separator . ($encodeGetItems?rawurlencode($value):$value); |
|
561 | + } |
|
548 | 562 | return $url; |
549 | 563 | } |
550 | 564 | |
@@ -557,24 +571,25 @@ discard block |
||
557 | 571 | if(is_array($value)) |
558 | 572 | { |
559 | 573 | $name = rawurlencode($name . '[]'); |
560 | - foreach($value as $v) |
|
561 | - $url2 .= $amp . $name . '=' . rawurlencode($v); |
|
574 | + foreach($value as $v) { |
|
575 | + $url2 .= $amp . $name . '=' . rawurlencode($v); |
|
576 | + } |
|
577 | + } else { |
|
578 | + $url2 .= $amp . rawurlencode($name) . '=' . rawurlencode($value); |
|
562 | 579 | } |
563 | - else |
|
564 | - $url2 .= $amp . rawurlencode($name) . '=' . rawurlencode($value); |
|
565 | 580 | } |
566 | - } |
|
567 | - else |
|
581 | + } else |
|
568 | 582 | { |
569 | 583 | foreach($extra as $name => $value) |
570 | 584 | { |
571 | 585 | if(is_array($value)) |
572 | 586 | { |
573 | - foreach($value as $v) |
|
574 | - $url2 .= $amp . $name . '[]=' . $v; |
|
587 | + foreach($value as $v) { |
|
588 | + $url2 .= $amp . $name . '[]=' . $v; |
|
589 | + } |
|
590 | + } else { |
|
591 | + $url2 .= $amp . $name . '=' . $value; |
|
575 | 592 | } |
576 | - else |
|
577 | - $url2 .= $amp . $name . '=' . $value; |
|
578 | 593 | } |
579 | 594 | } |
580 | 595 | $url = $url . '?' . substr($url2, strlen($amp)); |
@@ -593,19 +608,27 @@ discard block |
||
593 | 608 | protected function applySecureConnectionPrefix($url) |
594 | 609 | { |
595 | 610 | static $request; |
596 | - if($request === null) $request = Prado::getApplication() -> getRequest(); |
|
611 | + if($request === null) { |
|
612 | + $request = Prado::getApplication() -> getRequest(); |
|
613 | + } |
|
597 | 614 | |
598 | 615 | static $isSecureConnection; |
599 | - if($isSecureConnection === null) $isSecureConnection = $request -> getIsSecureConnection(); |
|
616 | + if($isSecureConnection === null) { |
|
617 | + $isSecureConnection = $request -> getIsSecureConnection(); |
|
618 | + } |
|
600 | 619 | |
601 | 620 | switch($this -> getSecureConnection()) |
602 | 621 | { |
603 | 622 | case TUrlMappingPatternSecureConnection::EnableIfNotSecure: |
604 | - if($isSecureConnection) return $url; |
|
623 | + if($isSecureConnection) { |
|
624 | + return $url; |
|
625 | + } |
|
605 | 626 | return $request -> getBaseUrl(true) . $url; |
606 | 627 | break; |
607 | 628 | case TUrlMappingPatternSecureConnection::DisableIfSecure: |
608 | - if(!$isSecureConnection) return $url; |
|
629 | + if(!$isSecureConnection) { |
|
630 | + return $url; |
|
631 | + } |
|
609 | 632 | return $request -> getBaseUrl(false) . $url; |
610 | 633 | break; |
611 | 634 | case TUrlMappingPatternSecureConnection::Enable: |
@@ -107,15 +107,15 @@ discard block |
||
107 | 107 | public function init($config) |
108 | 108 | { |
109 | 109 | parent::init($config); |
110 | - if($this->getRequest()->getRequestResolved()) |
|
110 | + if ($this->getRequest()->getRequestResolved()) |
|
111 | 111 | throw new TConfigurationException('urlmapping_global_required'); |
112 | - if($this->_configFile !== null) |
|
112 | + if ($this->_configFile !== null) |
|
113 | 113 | $this->loadConfigFile(); |
114 | 114 | $this->loadUrlMappings($config); |
115 | - if($this->_urlPrefix === '') |
|
115 | + if ($this->_urlPrefix === '') |
|
116 | 116 | { |
117 | 117 | $request = $this->getRequest(); |
118 | - if($request->getUrlFormat() === THttpRequestUrlFormat::HiddenPath) |
|
118 | + if ($request->getUrlFormat() === THttpRequestUrlFormat::HiddenPath) |
|
119 | 119 | { |
120 | 120 | $this->_urlPrefix = dirname($request->getApplicationUrl()); |
121 | 121 | } else { |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function loadConfigFile() |
133 | 133 | { |
134 | - if(is_file($this->_configFile)) |
|
134 | + if (is_file($this->_configFile)) |
|
135 | 135 | { |
136 | - if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
136 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
137 | 137 | { |
138 | 138 | $config = include $this->_configFile; |
139 | 139 | $this->loadUrlMappings($dom); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function setConfigFile($value) |
209 | 209 | { |
210 | - if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) |
|
210 | + if (($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) |
|
211 | 211 | throw new TConfigurationException('urlmapping_configfile_invalid', $value); |
212 | 212 | } |
213 | 213 | |
@@ -241,24 +241,24 @@ discard block |
||
241 | 241 | { |
242 | 242 | $defaultClass = $this->getDefaultMappingClass(); |
243 | 243 | |
244 | - if(is_array($config)) |
|
244 | + if (is_array($config)) |
|
245 | 245 | { |
246 | - if(isset($config['urls']) && is_array($config['urls'])) |
|
246 | + if (isset($config['urls']) && is_array($config['urls'])) |
|
247 | 247 | { |
248 | - foreach($config['urls'] as $url) |
|
248 | + foreach ($config['urls'] as $url) |
|
249 | 249 | { |
250 | - $class = isset($url['class'])?$url['class']:$defaultClass; |
|
251 | - $properties = isset($url['properties'])?$url['properties']:[]; |
|
250 | + $class = isset($url['class']) ? $url['class'] : $defaultClass; |
|
251 | + $properties = isset($url['properties']) ? $url['properties'] : []; |
|
252 | 252 | $this->buildUrlMapping($class, $properties, $url); |
253 | 253 | } |
254 | 254 | } |
255 | 255 | } |
256 | 256 | else |
257 | 257 | { |
258 | - foreach($config->getElementsByTagName('url') as $url) |
|
258 | + foreach ($config->getElementsByTagName('url') as $url) |
|
259 | 259 | { |
260 | 260 | $properties = $url->getAttributes(); |
261 | - if(($class = $properties->remove('class')) === null) |
|
261 | + if (($class = $properties->remove('class')) === null) |
|
262 | 262 | $class = $defaultClass; |
263 | 263 | $this->buildUrlMapping($class, $properties, $url); |
264 | 264 | } |
@@ -268,16 +268,16 @@ discard block |
||
268 | 268 | private function buildUrlMapping($class, $properties, $url) |
269 | 269 | { |
270 | 270 | $pattern = Prado::createComponent($class, $this); |
271 | - if(!($pattern instanceof TUrlMappingPattern)) |
|
271 | + if (!($pattern instanceof TUrlMappingPattern)) |
|
272 | 272 | throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
273 | - foreach($properties as $name => $value) |
|
273 | + foreach ($properties as $name => $value) |
|
274 | 274 | $pattern->setSubproperty($name, $value); |
275 | 275 | |
276 | - if($url instanceof TXmlElement) { |
|
276 | + if ($url instanceof TXmlElement) { |
|
277 | 277 | $text = $url -> getValue(); |
278 | - if($text) { |
|
278 | + if ($text) { |
|
279 | 279 | $text = preg_replace('/(\s+)/S', '', $text); |
280 | - if(($regExp = $pattern->getRegularExpression()) !== '') |
|
280 | + if (($regExp = $pattern->getRegularExpression()) !== '') |
|
281 | 281 | trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
282 | 282 | get_class($pattern), |
283 | 283 | $regExp, |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $this->_patterns[] = $pattern; |
293 | 293 | $pattern->init($url); |
294 | 294 | |
295 | - $key = $pattern->getServiceID() . ':' . $pattern->getServiceParameter(); |
|
295 | + $key = $pattern->getServiceID().':'.$pattern->getServiceParameter(); |
|
296 | 296 | $this->_constructRules[$key][] = $pattern; |
297 | 297 | } |
298 | 298 | |
@@ -307,16 +307,16 @@ discard block |
||
307 | 307 | public function parseUrl() |
308 | 308 | { |
309 | 309 | $request = $this->getRequest(); |
310 | - foreach($this->_patterns as $pattern) |
|
310 | + foreach ($this->_patterns as $pattern) |
|
311 | 311 | { |
312 | 312 | $matches = $pattern->getPatternMatches($request); |
313 | - if(count($matches) > 0) |
|
313 | + if (count($matches) > 0) |
|
314 | 314 | { |
315 | 315 | $this->_matched = $pattern; |
316 | 316 | $params = []; |
317 | - foreach($matches as $key => $value) |
|
317 | + foreach ($matches as $key => $value) |
|
318 | 318 | { |
319 | - if(is_string($key)) |
|
319 | + if (is_string($key)) |
|
320 | 320 | $params[$key] = $value; |
321 | 321 | } |
322 | 322 | if (!$pattern->getIsWildCardPattern()) |
@@ -353,26 +353,26 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems) |
355 | 355 | { |
356 | - if($this->_customUrl) |
|
356 | + if ($this->_customUrl) |
|
357 | 357 | { |
358 | - if(!(is_array($getItems) || ($getItems instanceof \Traversable))) |
|
358 | + if (!(is_array($getItems) || ($getItems instanceof \Traversable))) |
|
359 | 359 | $getItems = []; |
360 | - $key = $serviceID . ':' . $serviceParam; |
|
360 | + $key = $serviceID.':'.$serviceParam; |
|
361 | 361 | $wildCardKey = ($pos = strrpos($serviceParam, '.')) !== false ? |
362 | - $serviceID . ':' . substr($serviceParam, 0, $pos) . '.*' : $serviceID . ':*'; |
|
363 | - if(isset($this->_constructRules[$key])) |
|
362 | + $serviceID.':'.substr($serviceParam, 0, $pos).'.*' : $serviceID.':*'; |
|
363 | + if (isset($this->_constructRules[$key])) |
|
364 | 364 | { |
365 | - foreach($this->_constructRules[$key] as $rule) |
|
365 | + foreach ($this->_constructRules[$key] as $rule) |
|
366 | 366 | { |
367 | - if($rule->supportCustomUrl($getItems)) |
|
367 | + if ($rule->supportCustomUrl($getItems)) |
|
368 | 368 | return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
369 | 369 | } |
370 | 370 | } |
371 | - elseif(isset($this->_constructRules[$wildCardKey])) |
|
371 | + elseif (isset($this->_constructRules[$wildCardKey])) |
|
372 | 372 | { |
373 | - foreach($this->_constructRules[$wildCardKey] as $rule) |
|
373 | + foreach ($this->_constructRules[$wildCardKey] as $rule) |
|
374 | 374 | { |
375 | - if($rule->supportCustomUrl($getItems)) |
|
375 | + if ($rule->supportCustomUrl($getItems)) |
|
376 | 376 | { |
377 | 377 | $getItems['*'] = $pos ? substr($serviceParam, $pos + 1) : $serviceParam; |
378 | 378 | return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
@@ -107,10 +107,12 @@ discard block |
||
107 | 107 | public function init($config) |
108 | 108 | { |
109 | 109 | parent::init($config); |
110 | - if($this->getRequest()->getRequestResolved()) |
|
111 | - throw new TConfigurationException('urlmapping_global_required'); |
|
112 | - if($this->_configFile !== null) |
|
113 | - $this->loadConfigFile(); |
|
110 | + if($this->getRequest()->getRequestResolved()) { |
|
111 | + throw new TConfigurationException('urlmapping_global_required'); |
|
112 | + } |
|
113 | + if($this->_configFile !== null) { |
|
114 | + $this->loadConfigFile(); |
|
115 | + } |
|
114 | 116 | $this->loadUrlMappings($config); |
115 | 117 | if($this->_urlPrefix === '') |
116 | 118 | { |
@@ -137,16 +139,15 @@ discard block |
||
137 | 139 | { |
138 | 140 | $config = include $this->_configFile; |
139 | 141 | $this->loadUrlMappings($dom); |
140 | - } |
|
141 | - else |
|
142 | + } else |
|
142 | 143 | { |
143 | 144 | $dom = new TXmlDocument; |
144 | 145 | $dom->loadFromFile($this->_configFile); |
145 | 146 | $this->loadUrlMappings($dom); |
146 | 147 | } |
148 | + } else { |
|
149 | + throw new TConfigurationException('urlmapping_configfile_inexistent', $this->_configFile); |
|
147 | 150 | } |
148 | - else |
|
149 | - throw new TConfigurationException('urlmapping_configfile_inexistent', $this->_configFile); |
|
150 | 151 | } |
151 | 152 | |
152 | 153 | /** |
@@ -207,8 +208,9 @@ discard block |
||
207 | 208 | */ |
208 | 209 | public function setConfigFile($value) |
209 | 210 | { |
210 | - if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) |
|
211 | - throw new TConfigurationException('urlmapping_configfile_invalid', $value); |
|
211 | + if(($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) { |
|
212 | + throw new TConfigurationException('urlmapping_configfile_invalid', $value); |
|
213 | + } |
|
212 | 214 | } |
213 | 215 | |
214 | 216 | /** |
@@ -252,14 +254,14 @@ discard block |
||
252 | 254 | $this->buildUrlMapping($class, $properties, $url); |
253 | 255 | } |
254 | 256 | } |
255 | - } |
|
256 | - else |
|
257 | + } else |
|
257 | 258 | { |
258 | 259 | foreach($config->getElementsByTagName('url') as $url) |
259 | 260 | { |
260 | 261 | $properties = $url->getAttributes(); |
261 | - if(($class = $properties->remove('class')) === null) |
|
262 | - $class = $defaultClass; |
|
262 | + if(($class = $properties->remove('class')) === null) { |
|
263 | + $class = $defaultClass; |
|
264 | + } |
|
263 | 265 | $this->buildUrlMapping($class, $properties, $url); |
264 | 266 | } |
265 | 267 | } |
@@ -268,23 +270,26 @@ discard block |
||
268 | 270 | private function buildUrlMapping($class, $properties, $url) |
269 | 271 | { |
270 | 272 | $pattern = Prado::createComponent($class, $this); |
271 | - if(!($pattern instanceof TUrlMappingPattern)) |
|
272 | - throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
|
273 | - foreach($properties as $name => $value) |
|
274 | - $pattern->setSubproperty($name, $value); |
|
273 | + if(!($pattern instanceof TUrlMappingPattern)) { |
|
274 | + throw new TConfigurationException('urlmapping_urlmappingpattern_required'); |
|
275 | + } |
|
276 | + foreach($properties as $name => $value) { |
|
277 | + $pattern->setSubproperty($name, $value); |
|
278 | + } |
|
275 | 279 | |
276 | 280 | if($url instanceof TXmlElement) { |
277 | 281 | $text = $url -> getValue(); |
278 | 282 | if($text) { |
279 | 283 | $text = preg_replace('/(\s+)/S', '', $text); |
280 | - if(($regExp = $pattern->getRegularExpression()) !== '') |
|
281 | - trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
|
284 | + if(($regExp = $pattern->getRegularExpression()) !== '') { |
|
285 | + trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', |
|
282 | 286 | get_class($pattern), |
283 | 287 | $regExp, |
284 | 288 | $pattern->getServiceID(), |
285 | 289 | $pattern->getServiceParameter(), |
286 | 290 | $text), |
287 | 291 | E_USER_NOTICE); |
292 | + } |
|
288 | 293 | $pattern->setRegularExpression($text); |
289 | 294 | } |
290 | 295 | } |
@@ -316,11 +321,13 @@ discard block |
||
316 | 321 | $params = []; |
317 | 322 | foreach($matches as $key => $value) |
318 | 323 | { |
319 | - if(is_string($key)) |
|
320 | - $params[$key] = $value; |
|
324 | + if(is_string($key)) { |
|
325 | + $params[$key] = $value; |
|
326 | + } |
|
327 | + } |
|
328 | + if (!$pattern->getIsWildCardPattern()) { |
|
329 | + $params[$pattern->getServiceID()] = $pattern->getServiceParameter(); |
|
321 | 330 | } |
322 | - if (!$pattern->getIsWildCardPattern()) |
|
323 | - $params[$pattern->getServiceID()] = $pattern->getServiceParameter(); |
|
324 | 331 | return $params; |
325 | 332 | } |
326 | 333 | } |
@@ -355,8 +362,9 @@ discard block |
||
355 | 362 | { |
356 | 363 | if($this->_customUrl) |
357 | 364 | { |
358 | - if(!(is_array($getItems) || ($getItems instanceof \Traversable))) |
|
359 | - $getItems = []; |
|
365 | + if(!(is_array($getItems) || ($getItems instanceof \Traversable))) { |
|
366 | + $getItems = []; |
|
367 | + } |
|
360 | 368 | $key = $serviceID . ':' . $serviceParam; |
361 | 369 | $wildCardKey = ($pos = strrpos($serviceParam, '.')) !== false ? |
362 | 370 | $serviceID . ':' . substr($serviceParam, 0, $pos) . '.*' : $serviceID . ':*'; |
@@ -364,11 +372,11 @@ discard block |
||
364 | 372 | { |
365 | 373 | foreach($this->_constructRules[$key] as $rule) |
366 | 374 | { |
367 | - if($rule->supportCustomUrl($getItems)) |
|
368 | - return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
|
375 | + if($rule->supportCustomUrl($getItems)) { |
|
376 | + return $rule->constructUrl($getItems, $encodeAmpersand, $encodeGetItems); |
|
377 | + } |
|
369 | 378 | } |
370 | - } |
|
371 | - elseif(isset($this->_constructRules[$wildCardKey])) |
|
379 | + } elseif(isset($this->_constructRules[$wildCardKey])) |
|
372 | 380 | { |
373 | 381 | foreach($this->_constructRules[$wildCardKey] as $rule) |
374 | 382 | { |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | public function init($config) |
163 | 163 | { |
164 | 164 | // Fill in default request info when the script is run in command line |
165 | - if(php_sapi_name() === 'cli') |
|
165 | + if (php_sapi_name() === 'cli') |
|
166 | 166 | { |
167 | 167 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
168 | 168 | $_SERVER['REQUEST_METHOD'] = 'GET'; |
@@ -177,29 +177,29 @@ discard block |
||
177 | 177 | // QUERY_STRING is the string following the '?' in the ur (eg the a=x part in http://foo/bar?a=x) |
178 | 178 | // REQUEST_URI contains the URI part entered in the browser address bar |
179 | 179 | // SCRIPT_FILENAME is the file path to the executing script |
180 | - if(isset($_SERVER['REQUEST_URI'])) |
|
180 | + if (isset($_SERVER['REQUEST_URI'])) |
|
181 | 181 | $this->_requestUri = $_SERVER['REQUEST_URI']; |
182 | 182 | else // TBD: in this case, SCRIPT_NAME need to be escaped |
183 | - $this->_requestUri = $_SERVER['SCRIPT_NAME'] . (empty($_SERVER['QUERY_STRING'])?'':'?' . $_SERVER['QUERY_STRING']); |
|
183 | + $this->_requestUri = $_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING']) ? '' : '?'.$_SERVER['QUERY_STRING']); |
|
184 | 184 | |
185 | - if($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
185 | + if ($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
186 | 186 | $this->_pathInfo = substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
187 | - elseif(isset($_SERVER['PATH_INFO'])) |
|
187 | + elseif (isset($_SERVER['PATH_INFO'])) |
|
188 | 188 | $this->_pathInfo = $_SERVER['PATH_INFO']; |
189 | - elseif(strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) === 0 && $_SERVER['PHP_SELF'] !== $_SERVER['SCRIPT_NAME']) |
|
189 | + elseif (strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) === 0 && $_SERVER['PHP_SELF'] !== $_SERVER['SCRIPT_NAME']) |
|
190 | 190 | $this->_pathInfo = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
191 | 191 | else |
192 | 192 | $this->_pathInfo = ''; |
193 | 193 | |
194 | - if(get_magic_quotes_gpc()) |
|
194 | + if (get_magic_quotes_gpc()) |
|
195 | 195 | { |
196 | - if(isset($_GET)) |
|
196 | + if (isset($_GET)) |
|
197 | 197 | $_GET = $this->stripSlashes($_GET); |
198 | - if(isset($_POST)) |
|
198 | + if (isset($_POST)) |
|
199 | 199 | $_POST = $this->stripSlashes($_POST); |
200 | - if(isset($_REQUEST)) |
|
200 | + if (isset($_REQUEST)) |
|
201 | 201 | $_REQUEST = $this->stripSlashes($_REQUEST); |
202 | - if(isset($_COOKIE)) |
|
202 | + if (isset($_COOKIE)) |
|
203 | 203 | $_COOKIE = $this->stripSlashes($_COOKIE); |
204 | 204 | } |
205 | 205 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function stripSlashes(&$data) |
216 | 216 | { |
217 | - return is_array($data)?array_map([$this,'stripSlashes'], $data):stripslashes($data); |
|
217 | + return is_array($data) ?array_map([$this, 'stripSlashes'], $data) : stripslashes($data); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function getUrl() |
224 | 224 | { |
225 | - if($this->_url === null) |
|
225 | + if ($this->_url === null) |
|
226 | 226 | { |
227 | 227 | $secure = $this->getIsSecureConnection(); |
228 | - $url = $secure?'https://':'http://'; |
|
229 | - if(empty($_SERVER['HTTP_HOST'])) |
|
228 | + $url = $secure ? 'https://' : 'http://'; |
|
229 | + if (empty($_SERVER['HTTP_HOST'])) |
|
230 | 230 | { |
231 | 231 | $url .= $_SERVER['SERVER_NAME']; |
232 | 232 | $port = $_SERVER['SERVER_PORT']; |
233 | - if(($port != 80 && !$secure) || ($port != 443 && $secure)) |
|
234 | - $url .= ':' . $port; |
|
233 | + if (($port != 80 && !$secure) || ($port != 443 && $secure)) |
|
234 | + $url .= ':'.$port; |
|
235 | 235 | } |
236 | 236 | else |
237 | 237 | $url .= $_SERVER['HTTP_HOST']; |
@@ -270,13 +270,13 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function cacheUrlManager($manager) |
272 | 272 | { |
273 | - if($this->getEnableCache()) |
|
273 | + if ($this->getEnableCache()) |
|
274 | 274 | { |
275 | 275 | $cache = $this->getApplication()->getCache(); |
276 | - if($cache !== null) |
|
276 | + if ($cache !== null) |
|
277 | 277 | { |
278 | 278 | $dependencies = null; |
279 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
279 | + if ($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
280 | 280 | if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
281 | 281 | { |
282 | 282 | $fn = Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | */ |
295 | 295 | protected function loadCachedUrlManager() |
296 | 296 | { |
297 | - if($this->getEnableCache()) |
|
297 | + if ($this->getEnableCache()) |
|
298 | 298 | { |
299 | 299 | $cache = $this->getApplication()->getCache(); |
300 | - if($cache !== null) |
|
300 | + if ($cache !== null) |
|
301 | 301 | { |
302 | 302 | $manager = $cache->get($this->getCacheKey()); |
303 | - if($manager instanceof TUrlManager) |
|
303 | + if ($manager instanceof TUrlManager) |
|
304 | 304 | return $manager; |
305 | 305 | } |
306 | 306 | } |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | */ |
334 | 334 | public function getUrlManagerModule() |
335 | 335 | { |
336 | - if($this->_urlManager === null) |
|
336 | + if ($this->_urlManager === null) |
|
337 | 337 | { |
338 | - if(($this->_urlManager = $this->loadCachedUrlManager()) === null) |
|
338 | + if (($this->_urlManager = $this->loadCachedUrlManager()) === null) |
|
339 | 339 | { |
340 | - if(empty($this->_urlManagerID)) |
|
340 | + if (empty($this->_urlManagerID)) |
|
341 | 341 | { |
342 | 342 | $this->_urlManager = new TUrlManager; |
343 | 343 | $this->_urlManager->init(null); |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | else |
346 | 346 | { |
347 | 347 | $this->_urlManager = $this->getApplication()->getModule($this->_urlManagerID); |
348 | - if($this->_urlManager === null) |
|
348 | + if ($this->_urlManager === null) |
|
349 | 349 | throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
350 | - if(!($this->_urlManager instanceof TUrlManager)) |
|
350 | + if (!($this->_urlManager instanceof TUrlManager)) |
|
351 | 351 | throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
352 | 352 | } |
353 | 353 | $this->cacheUrlManager($this->_urlManager); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function setUrlParamSeparator($value) |
393 | 393 | { |
394 | - if(strlen($value) === 1) |
|
394 | + if (strlen($value) === 1) |
|
395 | 395 | $this->_separator = $value; |
396 | 396 | else |
397 | 397 | throw new TInvalidDataValueException('httprequest_separator_invalid'); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function getRequestType() |
404 | 404 | { |
405 | - return isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:null; |
|
405 | + return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -411,10 +411,10 @@ discard block |
||
411 | 411 | */ |
412 | 412 | public function getContentType($mimetypeOnly = true) |
413 | 413 | { |
414 | - if(!isset($_SERVER['CONTENT_TYPE'])) |
|
414 | + if (!isset($_SERVER['CONTENT_TYPE'])) |
|
415 | 415 | return null; |
416 | 416 | |
417 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
417 | + if ($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
418 | 418 | return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
419 | 419 | |
420 | 420 | return $_SERVER['CONTENT_TYPE']; |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public function getQueryString() |
443 | 443 | { |
444 | - return isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:null; |
|
444 | + return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function getHttpProtocolVersion() |
451 | 451 | { |
452 | - return isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:null; |
|
452 | + return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -460,19 +460,19 @@ discard block |
||
460 | 460 | { |
461 | 461 | static $result; |
462 | 462 | |
463 | - if($result === null && function_exists('apache_request_headers')) { |
|
463 | + if ($result === null && function_exists('apache_request_headers')) { |
|
464 | 464 | $result = apache_request_headers(); |
465 | 465 | } |
466 | - elseif($result === null) { |
|
466 | + elseif ($result === null) { |
|
467 | 467 | $result = []; |
468 | - foreach($_SERVER as $key => $value) { |
|
469 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
468 | + foreach ($_SERVER as $key => $value) { |
|
469 | + if (strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
470 | 470 | $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); |
471 | 471 | $result[$key] = $value; |
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
475 | - if($case !== null) |
|
475 | + if ($case !== null) |
|
476 | 476 | return array_change_key_case($result, $case); |
477 | 477 | |
478 | 478 | return $result; |
@@ -496,10 +496,10 @@ discard block |
||
496 | 496 | public function getBaseUrl($forceSecureConnection = null) |
497 | 497 | { |
498 | 498 | $url = $this->getUrl(); |
499 | - $scheme = ($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
|
499 | + $scheme = ($forceSecureConnection) ? "https" : (($forceSecureConnection === null) ? $url->getScheme() : 'http'); |
|
500 | 500 | $host = $url->getHost(); |
501 | - if (($port = $url->getPort())) $host .= ':' . $port; |
|
502 | - return $scheme . '://' . $host; |
|
501 | + if (($port = $url->getPort())) $host .= ':'.$port; |
|
502 | + return $scheme.'://'.$host; |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | */ |
508 | 508 | public function getApplicationUrl() |
509 | 509 | { |
510 | - if($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
510 | + if ($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
511 | 511 | return $_SERVER['ORIG_SCRIPT_NAME']; |
512 | 512 | |
513 | - return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
|
513 | + return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | */ |
523 | 523 | public function getAbsoluteApplicationUrl($forceSecureConnection = null) |
524 | 524 | { |
525 | - return $this->getBaseUrl($forceSecureConnection) . $this->getApplicationUrl(); |
|
525 | + return $this->getBaseUrl($forceSecureConnection).$this->getApplicationUrl(); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | */ |
531 | 531 | public function getApplicationFilePath() |
532 | 532 | { |
533 | - return realpath(isset($_SERVER['SCRIPT_FILENAME'])?$_SERVER['SCRIPT_FILENAME']:null); |
|
533 | + return realpath(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | */ |
539 | 539 | public function getServerName() |
540 | 540 | { |
541 | - return isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:null; |
|
541 | + return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | */ |
547 | 547 | public function getServerPort() |
548 | 548 | { |
549 | - return isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:null; |
|
549 | + return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | */ |
555 | 555 | public function getUrlReferrer() |
556 | 556 | { |
557 | - return isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:null; |
|
557 | + return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | /** |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | */ |
564 | 564 | public function getServerSoftware() |
565 | 565 | { |
566 | - return isset($_SERVER['SERVER_SOFTWARE'])?$_SERVER['SERVER_SOFTWARE']:null; |
|
566 | + return isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null; |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | /** |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | { |
577 | 577 | return get_browser(); |
578 | 578 | } |
579 | - catch(TPhpErrorException $e) |
|
579 | + catch (TPhpErrorException $e) |
|
580 | 580 | { |
581 | 581 | throw new TConfigurationException('httprequest_browscap_required'); |
582 | 582 | } |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function getUserAgent() |
589 | 589 | { |
590 | - return isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null; |
|
590 | + return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | */ |
596 | 596 | public function getUserHostAddress() |
597 | 597 | { |
598 | - return isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:null; |
|
598 | + return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | */ |
604 | 604 | public function getUserHost() |
605 | 605 | { |
606 | - return isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:null; |
|
606 | + return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | public function getAcceptTypes() |
613 | 613 | { |
614 | 614 | // TBD: break it into array?? |
615 | - return isset($_SERVER['HTTP_ACCEPT'])?$_SERVER['HTTP_ACCEPT']:null; |
|
615 | + return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -668,21 +668,21 @@ discard block |
||
668 | 668 | */ |
669 | 669 | public function getCookies() |
670 | 670 | { |
671 | - if($this->_cookies === null) |
|
671 | + if ($this->_cookies === null) |
|
672 | 672 | { |
673 | 673 | $this->_cookies = new THttpCookieCollection; |
674 | - if($this->getEnableCookieValidation()) |
|
674 | + if ($this->getEnableCookieValidation()) |
|
675 | 675 | { |
676 | 676 | $sm = $this->getApplication()->getSecurityManager(); |
677 | - foreach($_COOKIE as $key => $value) |
|
677 | + foreach ($_COOKIE as $key => $value) |
|
678 | 678 | { |
679 | - if(($value = $sm->validateData($value)) !== false) |
|
679 | + if (($value = $sm->validateData($value)) !== false) |
|
680 | 680 | $this->_cookies->add(new THttpCookie($key, $value)); |
681 | 681 | } |
682 | 682 | } |
683 | 683 | else |
684 | 684 | { |
685 | - foreach($_COOKIE as $key => $value) |
|
685 | + foreach ($_COOKIE as $key => $value) |
|
686 | 686 | $this->_cookies->add(new THttpCookie($key, $value)); |
687 | 687 | } |
688 | 688 | } |
@@ -733,10 +733,10 @@ discard block |
||
733 | 733 | public function constructUrl($serviceID, $serviceParam, $getItems = null, $encodeAmpersand = true, $encodeGetItems = true) |
734 | 734 | { |
735 | 735 | if ($this->_cookieOnly === null) |
736 | - $this->_cookieOnly = (int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
736 | + $this->_cookieOnly = (int) ini_get('session.use_cookies') && (int) ini_get('session.use_only_cookies'); |
|
737 | 737 | $url = $this->getUrlManagerModule()->constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
738 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
739 | - return $url . (strpos($url, '?') === false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
738 | + if (defined('SID') && SID != '' && !$this->_cookieOnly) |
|
739 | + return $url.(strpos($url, '?') === false ? '?' : ($encodeAmpersand ? '&' : '&')).SID; |
|
740 | 740 | else |
741 | 741 | return $url; |
742 | 742 | } |
@@ -764,15 +764,15 @@ discard block |
||
764 | 764 | */ |
765 | 765 | public function resolveRequest($serviceIDs) |
766 | 766 | { |
767 | - Prado::trace("Resolving request from " . $_SERVER['REMOTE_ADDR'], 'Prado\Web\THttpRequest'); |
|
767 | + Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'], 'Prado\Web\THttpRequest'); |
|
768 | 768 | $getParams = $this->parseUrl(); |
769 | - foreach($getParams as $name => $value) |
|
769 | + foreach ($getParams as $name => $value) |
|
770 | 770 | $_GET[$name] = $value; |
771 | 771 | $this->_items = array_merge($_GET, $_POST); |
772 | 772 | $this->_requestResolved = true; |
773 | - foreach($serviceIDs as $serviceID) |
|
773 | + foreach ($serviceIDs as $serviceID) |
|
774 | 774 | { |
775 | - if($this->contains($serviceID)) |
|
775 | + if ($this->contains($serviceID)) |
|
776 | 776 | { |
777 | 777 | $this->setServiceID($serviceID); |
778 | 778 | $this->setServiceParameter($this->itemAt($serviceID)); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | */ |
893 | 893 | public function remove($key) |
894 | 894 | { |
895 | - if(isset($this->_items[$key]) || array_key_exists($key, $this->_items)) |
|
895 | + if (isset($this->_items[$key]) || array_key_exists($key, $this->_items)) |
|
896 | 896 | { |
897 | 897 | $value = $this->_items[$key]; |
898 | 898 | unset($this->_items[$key]); |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | */ |
908 | 908 | public function clear() |
909 | 909 | { |
910 | - foreach(array_keys($this->_items) as $key) |
|
910 | + foreach (array_keys($this->_items) as $key) |
|
911 | 911 | $this->remove($key); |
912 | 912 | } |
913 | 913 |
@@ -177,30 +177,37 @@ discard block |
||
177 | 177 | // QUERY_STRING is the string following the '?' in the ur (eg the a=x part in http://foo/bar?a=x) |
178 | 178 | // REQUEST_URI contains the URI part entered in the browser address bar |
179 | 179 | // SCRIPT_FILENAME is the file path to the executing script |
180 | - if(isset($_SERVER['REQUEST_URI'])) |
|
181 | - $this->_requestUri = $_SERVER['REQUEST_URI']; |
|
182 | - else // TBD: in this case, SCRIPT_NAME need to be escaped |
|
180 | + if(isset($_SERVER['REQUEST_URI'])) { |
|
181 | + $this->_requestUri = $_SERVER['REQUEST_URI']; |
|
182 | + } else { |
|
183 | + // TBD: in this case, SCRIPT_NAME need to be escaped |
|
183 | 184 | $this->_requestUri = $_SERVER['SCRIPT_NAME'] . (empty($_SERVER['QUERY_STRING'])?'':'?' . $_SERVER['QUERY_STRING']); |
185 | + } |
|
184 | 186 | |
185 | - if($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
186 | - $this->_pathInfo = substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
187 | - elseif(isset($_SERVER['PATH_INFO'])) |
|
188 | - $this->_pathInfo = $_SERVER['PATH_INFO']; |
|
189 | - elseif(strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) === 0 && $_SERVER['PHP_SELF'] !== $_SERVER['SCRIPT_NAME']) |
|
190 | - $this->_pathInfo = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
|
191 | - else |
|
192 | - $this->_pathInfo = ''; |
|
187 | + if($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) { |
|
188 | + $this->_pathInfo = substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
|
189 | + } elseif(isset($_SERVER['PATH_INFO'])) { |
|
190 | + $this->_pathInfo = $_SERVER['PATH_INFO']; |
|
191 | + } elseif(strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME']) === 0 && $_SERVER['PHP_SELF'] !== $_SERVER['SCRIPT_NAME']) { |
|
192 | + $this->_pathInfo = substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
|
193 | + } else { |
|
194 | + $this->_pathInfo = ''; |
|
195 | + } |
|
193 | 196 | |
194 | 197 | if(get_magic_quotes_gpc()) |
195 | 198 | { |
196 | - if(isset($_GET)) |
|
197 | - $_GET = $this->stripSlashes($_GET); |
|
198 | - if(isset($_POST)) |
|
199 | - $_POST = $this->stripSlashes($_POST); |
|
200 | - if(isset($_REQUEST)) |
|
201 | - $_REQUEST = $this->stripSlashes($_REQUEST); |
|
202 | - if(isset($_COOKIE)) |
|
203 | - $_COOKIE = $this->stripSlashes($_COOKIE); |
|
199 | + if(isset($_GET)) { |
|
200 | + $_GET = $this->stripSlashes($_GET); |
|
201 | + } |
|
202 | + if(isset($_POST)) { |
|
203 | + $_POST = $this->stripSlashes($_POST); |
|
204 | + } |
|
205 | + if(isset($_REQUEST)) { |
|
206 | + $_REQUEST = $this->stripSlashes($_REQUEST); |
|
207 | + } |
|
208 | + if(isset($_COOKIE)) { |
|
209 | + $_COOKIE = $this->stripSlashes($_COOKIE); |
|
210 | + } |
|
204 | 211 | } |
205 | 212 | |
206 | 213 | $this->getApplication()->setRequest($this); |
@@ -230,11 +237,12 @@ discard block |
||
230 | 237 | { |
231 | 238 | $url .= $_SERVER['SERVER_NAME']; |
232 | 239 | $port = $_SERVER['SERVER_PORT']; |
233 | - if(($port != 80 && !$secure) || ($port != 443 && $secure)) |
|
234 | - $url .= ':' . $port; |
|
240 | + if(($port != 80 && !$secure) || ($port != 443 && $secure)) { |
|
241 | + $url .= ':' . $port; |
|
242 | + } |
|
243 | + } else { |
|
244 | + $url .= $_SERVER['HTTP_HOST']; |
|
235 | 245 | } |
236 | - else |
|
237 | - $url .= $_SERVER['HTTP_HOST']; |
|
238 | 246 | $url .= $this->getRequestUri(); |
239 | 247 | $this->_url = new TUri($url); |
240 | 248 | } |
@@ -276,10 +284,11 @@ discard block |
||
276 | 284 | if($cache !== null) |
277 | 285 | { |
278 | 286 | $dependencies = null; |
279 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
280 | - if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
287 | + if($this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
288 | + if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
281 | 289 | { |
282 | 290 | $fn = Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); |
291 | + } |
|
283 | 292 | $dependencies = new TFileCacheDependency($fn); |
284 | 293 | } |
285 | 294 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
@@ -300,8 +309,9 @@ discard block |
||
300 | 309 | if($cache !== null) |
301 | 310 | { |
302 | 311 | $manager = $cache->get($this->getCacheKey()); |
303 | - if($manager instanceof TUrlManager) |
|
304 | - return $manager; |
|
312 | + if($manager instanceof TUrlManager) { |
|
313 | + return $manager; |
|
314 | + } |
|
305 | 315 | } |
306 | 316 | } |
307 | 317 | return null; |
@@ -341,14 +351,15 @@ discard block |
||
341 | 351 | { |
342 | 352 | $this->_urlManager = new TUrlManager; |
343 | 353 | $this->_urlManager->init(null); |
344 | - } |
|
345 | - else |
|
354 | + } else |
|
346 | 355 | { |
347 | 356 | $this->_urlManager = $this->getApplication()->getModule($this->_urlManagerID); |
348 | - if($this->_urlManager === null) |
|
349 | - throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
|
350 | - if(!($this->_urlManager instanceof TUrlManager)) |
|
351 | - throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
|
357 | + if($this->_urlManager === null) { |
|
358 | + throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
|
359 | + } |
|
360 | + if(!($this->_urlManager instanceof TUrlManager)) { |
|
361 | + throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
|
362 | + } |
|
352 | 363 | } |
353 | 364 | $this->cacheUrlManager($this->_urlManager); |
354 | 365 | } |
@@ -391,10 +402,11 @@ discard block |
||
391 | 402 | */ |
392 | 403 | public function setUrlParamSeparator($value) |
393 | 404 | { |
394 | - if(strlen($value) === 1) |
|
395 | - $this->_separator = $value; |
|
396 | - else |
|
397 | - throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
405 | + if(strlen($value) === 1) { |
|
406 | + $this->_separator = $value; |
|
407 | + } else { |
|
408 | + throw new TInvalidDataValueException('httprequest_separator_invalid'); |
|
409 | + } |
|
398 | 410 | } |
399 | 411 | |
400 | 412 | /** |
@@ -411,11 +423,13 @@ discard block |
||
411 | 423 | */ |
412 | 424 | public function getContentType($mimetypeOnly = true) |
413 | 425 | { |
414 | - if(!isset($_SERVER['CONTENT_TYPE'])) |
|
415 | - return null; |
|
426 | + if(!isset($_SERVER['CONTENT_TYPE'])) { |
|
427 | + return null; |
|
428 | + } |
|
416 | 429 | |
417 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
418 | - return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
430 | + if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) { |
|
431 | + return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
|
432 | + } |
|
419 | 433 | |
420 | 434 | return $_SERVER['CONTENT_TYPE']; |
421 | 435 | } |
@@ -462,18 +476,20 @@ discard block |
||
462 | 476 | |
463 | 477 | if($result === null && function_exists('apache_request_headers')) { |
464 | 478 | $result = apache_request_headers(); |
465 | - } |
|
466 | - elseif($result === null) { |
|
479 | + } elseif($result === null) { |
|
467 | 480 | $result = []; |
468 | 481 | foreach($_SERVER as $key => $value) { |
469 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
482 | + if(strncasecmp($key, 'HTTP_', 5) !== 0) { |
|
483 | + continue; |
|
484 | + } |
|
470 | 485 | $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); |
471 | 486 | $result[$key] = $value; |
472 | 487 | } |
473 | 488 | } |
474 | 489 | |
475 | - if($case !== null) |
|
476 | - return array_change_key_case($result, $case); |
|
490 | + if($case !== null) { |
|
491 | + return array_change_key_case($result, $case); |
|
492 | + } |
|
477 | 493 | |
478 | 494 | return $result; |
479 | 495 | } |
@@ -498,7 +514,9 @@ discard block |
||
498 | 514 | $url = $this->getUrl(); |
499 | 515 | $scheme = ($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
500 | 516 | $host = $url->getHost(); |
501 | - if (($port = $url->getPort())) $host .= ':' . $port; |
|
517 | + if (($port = $url->getPort())) { |
|
518 | + $host .= ':' . $port; |
|
519 | + } |
|
502 | 520 | return $scheme . '://' . $host; |
503 | 521 | } |
504 | 522 | |
@@ -507,8 +525,9 @@ discard block |
||
507 | 525 | */ |
508 | 526 | public function getApplicationUrl() |
509 | 527 | { |
510 | - if($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
511 | - return $_SERVER['ORIG_SCRIPT_NAME']; |
|
528 | + if($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) { |
|
529 | + return $_SERVER['ORIG_SCRIPT_NAME']; |
|
530 | + } |
|
512 | 531 | |
513 | 532 | return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
514 | 533 | } |
@@ -575,8 +594,7 @@ discard block |
||
575 | 594 | try |
576 | 595 | { |
577 | 596 | return get_browser(); |
578 | - } |
|
579 | - catch(TPhpErrorException $e) |
|
597 | + } catch(TPhpErrorException $e) |
|
580 | 598 | { |
581 | 599 | throw new TConfigurationException('httprequest_browscap_required'); |
582 | 600 | } |
@@ -676,14 +694,15 @@ discard block |
||
676 | 694 | $sm = $this->getApplication()->getSecurityManager(); |
677 | 695 | foreach($_COOKIE as $key => $value) |
678 | 696 | { |
679 | - if(($value = $sm->validateData($value)) !== false) |
|
680 | - $this->_cookies->add(new THttpCookie($key, $value)); |
|
697 | + if(($value = $sm->validateData($value)) !== false) { |
|
698 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
699 | + } |
|
681 | 700 | } |
682 | - } |
|
683 | - else |
|
701 | + } else |
|
684 | 702 | { |
685 | - foreach($_COOKIE as $key => $value) |
|
686 | - $this->_cookies->add(new THttpCookie($key, $value)); |
|
703 | + foreach($_COOKIE as $key => $value) { |
|
704 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
705 | + } |
|
687 | 706 | } |
688 | 707 | } |
689 | 708 | return $this->_cookies; |
@@ -732,13 +751,15 @@ discard block |
||
732 | 751 | */ |
733 | 752 | public function constructUrl($serviceID, $serviceParam, $getItems = null, $encodeAmpersand = true, $encodeGetItems = true) |
734 | 753 | { |
735 | - if ($this->_cookieOnly === null) |
|
736 | - $this->_cookieOnly = (int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
754 | + if ($this->_cookieOnly === null) { |
|
755 | + $this->_cookieOnly = (int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
756 | + } |
|
737 | 757 | $url = $this->getUrlManagerModule()->constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
738 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
739 | - return $url . (strpos($url, '?') === false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
740 | - else |
|
741 | - return $url; |
|
758 | + if(defined('SID') && SID != '' && !$this->_cookieOnly) { |
|
759 | + return $url . (strpos($url, '?') === false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
760 | + } else { |
|
761 | + return $url; |
|
762 | + } |
|
742 | 763 | } |
743 | 764 | |
744 | 765 | /** |
@@ -766,8 +787,9 @@ discard block |
||
766 | 787 | { |
767 | 788 | Prado::trace("Resolving request from " . $_SERVER['REMOTE_ADDR'], 'Prado\Web\THttpRequest'); |
768 | 789 | $getParams = $this->parseUrl(); |
769 | - foreach($getParams as $name => $value) |
|
770 | - $_GET[$name] = $value; |
|
790 | + foreach($getParams as $name => $value) { |
|
791 | + $_GET[$name] = $value; |
|
792 | + } |
|
771 | 793 | $this->_items = array_merge($_GET, $_POST); |
772 | 794 | $this->_requestResolved = true; |
773 | 795 | foreach($serviceIDs as $serviceID) |
@@ -897,9 +919,9 @@ discard block |
||
897 | 919 | $value = $this->_items[$key]; |
898 | 920 | unset($this->_items[$key]); |
899 | 921 | return $value; |
922 | + } else { |
|
923 | + return null; |
|
900 | 924 | } |
901 | - else |
|
902 | - return null; |
|
903 | 925 | } |
904 | 926 | |
905 | 927 | /** |
@@ -907,8 +929,9 @@ discard block |
||
907 | 929 | */ |
908 | 930 | public function clear() |
909 | 931 | { |
910 | - foreach(array_keys($this->_items) as $key) |
|
911 | - $this->remove($key); |
|
932 | + foreach(array_keys($this->_items) as $key) { |
|
933 | + $this->remove($key); |
|
934 | + } |
|
912 | 935 | } |
913 | 936 | |
914 | 937 | /** |
@@ -66,48 +66,48 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems) |
68 | 68 | { |
69 | - $url = $serviceID . '=' . urlencode($serviceParam); |
|
70 | - $amp = $encodeAmpersand?'&':'&'; |
|
69 | + $url = $serviceID.'='.urlencode($serviceParam); |
|
70 | + $amp = $encodeAmpersand ? '&' : '&'; |
|
71 | 71 | $request = $this->getRequest(); |
72 | - if(is_array($getItems) || $getItems instanceof \Traversable) |
|
72 | + if (is_array($getItems) || $getItems instanceof \Traversable) |
|
73 | 73 | { |
74 | - if($encodeGetItems) |
|
74 | + if ($encodeGetItems) |
|
75 | 75 | { |
76 | - foreach($getItems as $name => $value) |
|
76 | + foreach ($getItems as $name => $value) |
|
77 | 77 | { |
78 | - if(is_array($value)) |
|
78 | + if (is_array($value)) |
|
79 | 79 | { |
80 | - $name = urlencode($name . '[]'); |
|
81 | - foreach($value as $v) |
|
82 | - $url .= $amp . $name . '=' . urlencode($v); |
|
80 | + $name = urlencode($name.'[]'); |
|
81 | + foreach ($value as $v) |
|
82 | + $url .= $amp.$name.'='.urlencode($v); |
|
83 | 83 | } |
84 | 84 | else |
85 | - $url .= $amp . urlencode($name) . '=' . urlencode($value); |
|
85 | + $url .= $amp.urlencode($name).'='.urlencode($value); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | else |
89 | 89 | { |
90 | - foreach($getItems as $name => $value) |
|
90 | + foreach ($getItems as $name => $value) |
|
91 | 91 | { |
92 | - if(is_array($value)) |
|
92 | + if (is_array($value)) |
|
93 | 93 | { |
94 | - foreach($value as $v) |
|
95 | - $url .= $amp . $name . '[]=' . $v; |
|
94 | + foreach ($value as $v) |
|
95 | + $url .= $amp.$name.'[]='.$v; |
|
96 | 96 | } |
97 | 97 | else |
98 | - $url .= $amp . $name . '=' . $value; |
|
98 | + $url .= $amp.$name.'='.$value; |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - switch($request->getUrlFormat()) |
|
103 | + switch ($request->getUrlFormat()) |
|
104 | 104 | { |
105 | 105 | case THttpRequestUrlFormat::Path: |
106 | - return $request->getApplicationUrl() . '/' . strtr($url, [$amp => '/','?' => '/','=' => $request->getUrlParamSeparator()]); |
|
106 | + return $request->getApplicationUrl().'/'.strtr($url, [$amp => '/', '?' => '/', '=' => $request->getUrlParamSeparator()]); |
|
107 | 107 | case THttpRequestUrlFormat::HiddenPath: |
108 | - return rtrim(dirname($request->getApplicationUrl()), '/') . '/' . strtr($url, [$amp => '/','?' => '/','=' => $request->getUrlParamSeparator()]); |
|
108 | + return rtrim(dirname($request->getApplicationUrl()), '/').'/'.strtr($url, [$amp => '/', '?' => '/', '=' => $request->getUrlParamSeparator()]); |
|
109 | 109 | default: |
110 | - return $request->getApplicationUrl() . '?' . $url; |
|
110 | + return $request->getApplicationUrl().'?'.$url; |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -128,22 +128,22 @@ discard block |
||
128 | 128 | { |
129 | 129 | $request = $this->getRequest(); |
130 | 130 | $pathInfo = trim($request->getPathInfo(), '/'); |
131 | - if(($request->getUrlFormat() === THttpRequestUrlFormat::Path || |
|
131 | + if (($request->getUrlFormat() === THttpRequestUrlFormat::Path || |
|
132 | 132 | $request->getUrlFormat() === THttpRequestUrlFormat::HiddenPath) && |
133 | 133 | $pathInfo !== '') |
134 | 134 | { |
135 | 135 | $separator = $request->getUrlParamSeparator(); |
136 | 136 | $paths = explode('/', $pathInfo); |
137 | 137 | $getVariables = []; |
138 | - foreach($paths as $path) |
|
138 | + foreach ($paths as $path) |
|
139 | 139 | { |
140 | - if(($path = trim($path)) !== '') |
|
140 | + if (($path = trim($path)) !== '') |
|
141 | 141 | { |
142 | - if(($pos = strpos($path, $separator)) !== false) |
|
142 | + if (($pos = strpos($path, $separator)) !== false) |
|
143 | 143 | { |
144 | 144 | $name = substr($path, 0, $pos); |
145 | 145 | $value = substr($path, $pos + 1); |
146 | - if(($pos = strpos($name, '[]')) !== false) |
|
146 | + if (($pos = strpos($name, '[]')) !== false) |
|
147 | 147 | $getVariables[substr($name, 0, $pos)][] = $value; |
148 | 148 | else |
149 | 149 | $getVariables[$name] = $value; |
@@ -78,24 +78,25 @@ discard block |
||
78 | 78 | if(is_array($value)) |
79 | 79 | { |
80 | 80 | $name = urlencode($name . '[]'); |
81 | - foreach($value as $v) |
|
82 | - $url .= $amp . $name . '=' . urlencode($v); |
|
81 | + foreach($value as $v) { |
|
82 | + $url .= $amp . $name . '=' . urlencode($v); |
|
83 | + } |
|
84 | + } else { |
|
85 | + $url .= $amp . urlencode($name) . '=' . urlencode($value); |
|
83 | 86 | } |
84 | - else |
|
85 | - $url .= $amp . urlencode($name) . '=' . urlencode($value); |
|
86 | 87 | } |
87 | - } |
|
88 | - else |
|
88 | + } else |
|
89 | 89 | { |
90 | 90 | foreach($getItems as $name => $value) |
91 | 91 | { |
92 | 92 | if(is_array($value)) |
93 | 93 | { |
94 | - foreach($value as $v) |
|
95 | - $url .= $amp . $name . '[]=' . $v; |
|
94 | + foreach($value as $v) { |
|
95 | + $url .= $amp . $name . '[]=' . $v; |
|
96 | + } |
|
97 | + } else { |
|
98 | + $url .= $amp . $name . '=' . $value; |
|
96 | 99 | } |
97 | - else |
|
98 | - $url .= $amp . $name . '=' . $value; |
|
99 | 100 | } |
100 | 101 | } |
101 | 102 | } |
@@ -143,19 +144,20 @@ discard block |
||
143 | 144 | { |
144 | 145 | $name = substr($path, 0, $pos); |
145 | 146 | $value = substr($path, $pos + 1); |
146 | - if(($pos = strpos($name, '[]')) !== false) |
|
147 | - $getVariables[substr($name, 0, $pos)][] = $value; |
|
148 | - else |
|
149 | - $getVariables[$name] = $value; |
|
147 | + if(($pos = strpos($name, '[]')) !== false) { |
|
148 | + $getVariables[substr($name, 0, $pos)][] = $value; |
|
149 | + } else { |
|
150 | + $getVariables[$name] = $value; |
|
151 | + } |
|
152 | + } else { |
|
153 | + $getVariables[$path] = ''; |
|
150 | 154 | } |
151 | - else |
|
152 | - $getVariables[$path] = ''; |
|
153 | 155 | } |
154 | 156 | } |
155 | 157 | return $getVariables; |
158 | + } else { |
|
159 | + return []; |
|
156 | 160 | } |
157 | - else |
|
158 | - return []; |
|
159 | 161 | } |
160 | 162 | } |
161 | 163 |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function init($config) |
169 | 169 | { |
170 | - if($this->_bufferOutput) |
|
170 | + if ($this->_bufferOutput) |
|
171 | 171 | ob_start(); |
172 | 172 | $this->_initialized = true; |
173 | 173 | $this->getApplication()->setResponse($this); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function setCacheControl($value) |
205 | 205 | { |
206 | - session_cache_limiter(TPropertyValue::ensureEnum($value, ['none','nocache','private','private_no_expire','public'])); |
|
206 | + session_cache_limiter(TPropertyValue::ensureEnum($value, ['none', 'nocache', 'private', 'private_no_expire', 'public'])); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function setCharset($charset) |
239 | 239 | { |
240 | - $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset; |
|
240 | + $this->_charset = (strToLower($charset) === 'false') ? false : (string) $charset; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function setBufferOutput($value) |
256 | 256 | { |
257 | - if($this->_initialized) |
|
257 | + if ($this->_initialized) |
|
258 | 258 | throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
259 | 259 | else |
260 | 260 | $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | if ($this->_httpHeaderSent) |
282 | 282 | throw new \Exception('Unable to alter response as HTTP header already sent'); |
283 | 283 | $status = TPropertyValue::ensureInteger($status); |
284 | - if(isset(self::$HTTP_STATUS_CODES[$status])) { |
|
284 | + if (isset(self::$HTTP_STATUS_CODES[$status])) { |
|
285 | 285 | $this->_reason = self::$HTTP_STATUS_CODES[$status]; |
286 | - }else{ |
|
287 | - if($reason === null || $reason === '') { |
|
286 | + } else { |
|
287 | + if ($reason === null || $reason === '') { |
|
288 | 288 | throw new TInvalidDataValueException("response_status_reason_missing"); |
289 | 289 | } |
290 | 290 | $reason = TPropertyValue::ensureString($reason); |
291 | - if(strpos($reason, "\r") != false || strpos($reason, "\n") != false) { |
|
291 | + if (strpos($reason, "\r") != false || strpos($reason, "\n") != false) { |
|
292 | 292 | throw new TInvalidDataValueException("response_status_reason_barchars"); |
293 | 293 | } |
294 | 294 | $this->_reason = $reason; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function getCookies() |
310 | 310 | { |
311 | - if($this->_cookies === null) |
|
311 | + if ($this->_cookies === null) |
|
312 | 312 | $this->_cookies = new THttpCookieCollection($this); |
313 | 313 | return $this->_cookies; |
314 | 314 | } |
@@ -353,31 +353,31 @@ discard block |
||
353 | 353 | 'xls' => 'application/vnd.ms-excel', |
354 | 354 | ]; |
355 | 355 | |
356 | - if($mimeType === null) |
|
356 | + if ($mimeType === null) |
|
357 | 357 | { |
358 | 358 | $mimeType = 'text/plain'; |
359 | - if(function_exists('mime_content_type')) |
|
359 | + if (function_exists('mime_content_type')) |
|
360 | 360 | $mimeType = mime_content_type($fileName); |
361 | - elseif(($ext = strrchr($fileName, '.')) !== false) |
|
361 | + elseif (($ext = strrchr($fileName, '.')) !== false) |
|
362 | 362 | { |
363 | 363 | $ext = substr($ext, 1); |
364 | - if(isset($defaultMimeTypes[$ext])) |
|
364 | + if (isset($defaultMimeTypes[$ext])) |
|
365 | 365 | $mimeType = $defaultMimeTypes[$ext]; |
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - if($clientFileName === null) |
|
369 | + if ($clientFileName === null) |
|
370 | 370 | $clientFileName = basename($fileName); |
371 | 371 | else |
372 | 372 | $clientFileName = basename($clientFileName); |
373 | 373 | |
374 | - if($fileSize === null || $fileSize < 0) |
|
375 | - $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
374 | + if ($fileSize === null || $fileSize < 0) |
|
375 | + $fileSize = ($content === null ?filesize($fileName) : strlen($content)); |
|
376 | 376 | |
377 | 377 | $this->sendHttpHeader(); |
378 | - if(is_array($headers)) |
|
378 | + if (is_array($headers)) |
|
379 | 379 | { |
380 | - foreach($headers as $h) |
|
380 | + foreach ($headers as $h) |
|
381 | 381 | header($h); |
382 | 382 | } |
383 | 383 | else |
@@ -389,10 +389,10 @@ discard block |
||
389 | 389 | $this->_contentTypeHeaderSent = true; |
390 | 390 | } |
391 | 391 | |
392 | - header('Content-Length: ' . $fileSize); |
|
393 | - header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
|
392 | + header('Content-Length: '.$fileSize); |
|
393 | + header("Content-Disposition: ".($forceDownload ? 'attachment' : 'inline')."; filename=\"$clientFileName\""); |
|
394 | 394 | header('Content-Transfer-Encoding: binary'); |
395 | - if($content === null) |
|
395 | + if ($content === null) |
|
396 | 396 | readfile($fileName); |
397 | 397 | else |
398 | 398 | echo $content; |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | */ |
407 | 407 | public function redirect($url) |
408 | 408 | { |
409 | - if($this->getHasAdapter()) |
|
409 | + if ($this->getHasAdapter()) |
|
410 | 410 | $this->_adapter->httpRedirect($url); |
411 | 411 | else |
412 | 412 | $this->httpRedirect($url); |
@@ -431,27 +431,27 @@ discard block |
||
431 | 431 | // Under IIS, explicitly send an HTTP response including the status code |
432 | 432 | // this is handled automatically by PHP on Apache and others |
433 | 433 | $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
434 | - if($url[0] === '/') |
|
435 | - $url = $this->getRequest()->getBaseUrl() . $url; |
|
434 | + if ($url[0] === '/') |
|
435 | + $url = $this->getRequest()->getBaseUrl().$url; |
|
436 | 436 | if ($this->_status >= 300 && $this->_status < 400) |
437 | 437 | { |
438 | 438 | // The status code has been modified to a valid redirection status, send it |
439 | - if($isIIS) |
|
439 | + if ($isIIS) |
|
440 | 440 | { |
441 | - header('HTTP/1.1 ' . $this->_status . ' ' . self::$HTTP_STATUS_CODES[ |
|
441 | + header('HTTP/1.1 '.$this->_status.' '.self::$HTTP_STATUS_CODES[ |
|
442 | 442 | array_key_exists($this->_status, self::$HTTP_STATUS_CODES) |
443 | 443 | ? $this->_status |
444 | 444 | : 302 |
445 | 445 | ]); |
446 | 446 | } |
447 | - header('Location: ' . str_replace('&', '&', $url), true, $this->_status); |
|
447 | + header('Location: '.str_replace('&', '&', $url), true, $this->_status); |
|
448 | 448 | } else { |
449 | - if($isIIS) |
|
450 | - header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
451 | - header('Location: ' . str_replace('&', '&', $url)); |
|
449 | + if ($isIIS) |
|
450 | + header('HTTP/1.1 302 '.self::$HTTP_STATUS_CODES[302]); |
|
451 | + header('Location: '.str_replace('&', '&', $url)); |
|
452 | 452 | } |
453 | 453 | |
454 | - if(!$this->getApplication()->getRequestCompleted()) |
|
454 | + if (!$this->getApplication()->getRequestCompleted()) |
|
455 | 455 | $this->getApplication()->onEndRequest(); |
456 | 456 | |
457 | 457 | exit(); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | */ |
473 | 473 | public function flush($continueBuffering = true) |
474 | 474 | { |
475 | - if($this->getHasAdapter()) |
|
475 | + if ($this->getHasAdapter()) |
|
476 | 476 | $this->_adapter->flushContent($continueBuffering); |
477 | 477 | else |
478 | 478 | $this->flushContent($continueBuffering); |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | { |
497 | 497 | Prado::trace("Flushing output", 'Prado\Web\THttpResponse'); |
498 | 498 | $this->ensureHeadersSent(); |
499 | - if($this->_bufferOutput) |
|
499 | + if ($this->_bufferOutput) |
|
500 | 500 | { |
501 | 501 | // avoid forced send of http headers (ob_flush() does that) if there's no output yet |
502 | 502 | if (ob_get_length() > 0) |
@@ -530,10 +530,10 @@ discard block |
||
530 | 530 | protected function sendHttpHeader() |
531 | 531 | { |
532 | 532 | $protocol = $this->getRequest()->getHttpProtocolVersion(); |
533 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
533 | + if ($this->getRequest()->getHttpProtocolVersion() === null) |
|
534 | 534 | $protocol = 'HTTP/1.1'; |
535 | 535 | |
536 | - header($protocol . ' ' . $this->_status . ' ' . $this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
536 | + header($protocol.' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
537 | 537 | |
538 | 538 | $this->_httpHeaderSent = true; |
539 | 539 | } |
@@ -552,18 +552,18 @@ discard block |
||
552 | 552 | */ |
553 | 553 | protected function sendContentTypeHeader() |
554 | 554 | { |
555 | - $contentType = $this->_contentType === null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
555 | + $contentType = $this->_contentType === null ?self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
556 | 556 | $charset = $this->getCharset(); |
557 | - if($charset === false) { |
|
558 | - $this->appendHeader('Content-Type: ' . $contentType); |
|
557 | + if ($charset === false) { |
|
558 | + $this->appendHeader('Content-Type: '.$contentType); |
|
559 | 559 | return; |
560 | 560 | } |
561 | 561 | |
562 | - if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
562 | + if ($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
563 | 563 | $charset = $globalization->getCharset(); |
564 | 564 | |
565 | - if($charset === '') $charset = self::DEFAULT_CHARSET; |
|
566 | - $this->appendHeader('Content-Type: ' . $contentType . ';charset=' . $charset); |
|
565 | + if ($charset === '') $charset = self::DEFAULT_CHARSET; |
|
566 | + $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
|
567 | 567 | |
568 | 568 | $this->_contentTypeHeaderSent = true; |
569 | 569 | } |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | public function getContents() |
578 | 578 | { |
579 | 579 | Prado::trace("Retrieving output", 'Prado\Web\THttpResponse'); |
580 | - return $this->_bufferOutput?ob_get_contents():''; |
|
580 | + return $this->_bufferOutput ?ob_get_contents() : ''; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function clear() |
587 | 587 | { |
588 | - if($this->_bufferOutput) |
|
588 | + if ($this->_bufferOutput) |
|
589 | 589 | ob_clean(); |
590 | 590 | Prado::trace("Clearing output", 'Prado\Web\THttpResponse'); |
591 | 591 | } |
@@ -598,17 +598,17 @@ discard block |
||
598 | 598 | { |
599 | 599 | $result = []; |
600 | 600 | $headers = headers_list(); |
601 | - foreach($headers as $header) { |
|
601 | + foreach ($headers as $header) { |
|
602 | 602 | $tmp = explode(':', $header); |
603 | 603 | $key = trim(array_shift($tmp)); |
604 | 604 | $value = trim(implode(':', $tmp)); |
605 | - if(isset($result[$key])) |
|
606 | - $result[$key] .= ', ' . $value; |
|
605 | + if (isset($result[$key])) |
|
606 | + $result[$key] .= ', '.$value; |
|
607 | 607 | else |
608 | 608 | $result[$key] = $value; |
609 | 609 | } |
610 | 610 | |
611 | - if($case !== null) |
|
611 | + if ($case !== null) |
|
612 | 612 | return array_change_key_case($result, $case); |
613 | 613 | |
614 | 614 | return $result; |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | public function addCookie($cookie) |
648 | 648 | { |
649 | 649 | $request = $this->getRequest(); |
650 | - if($request->getEnableCookieValidation()) |
|
650 | + if ($request->getEnableCookieValidation()) |
|
651 | 651 | { |
652 | 652 | $value = $this->getApplication()->getSecurityManager()->hashData($cookie->getValue()); |
653 | 653 | setcookie( |
@@ -714,9 +714,9 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function createHtmlWriter($type = null) |
716 | 716 | { |
717 | - if($type === null) |
|
717 | + if ($type === null) |
|
718 | 718 | $type = $this->getHtmlWriterType(); |
719 | - if($this->getHasAdapter()) |
|
719 | + if ($this->getHasAdapter()) |
|
720 | 720 | return $this->_adapter->createNewHtmlWriter($type, $this); |
721 | 721 | else |
722 | 722 | return $this->createNewHtmlWriter($type, $this); |
@@ -167,8 +167,9 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function init($config) |
169 | 169 | { |
170 | - if($this->_bufferOutput) |
|
171 | - ob_start(); |
|
170 | + if($this->_bufferOutput) { |
|
171 | + ob_start(); |
|
172 | + } |
|
172 | 173 | $this->_initialized = true; |
173 | 174 | $this->getApplication()->setResponse($this); |
174 | 175 | } |
@@ -211,8 +212,9 @@ discard block |
||
211 | 212 | */ |
212 | 213 | public function setContentType($type) |
213 | 214 | { |
214 | - if ($this->_contentTypeHeaderSent) |
|
215 | - throw new \Exception('Unable to alter content-type as it has been already sent'); |
|
215 | + if ($this->_contentTypeHeaderSent) { |
|
216 | + throw new \Exception('Unable to alter content-type as it has been already sent'); |
|
217 | + } |
|
216 | 218 | $this->_contentType = $type; |
217 | 219 | } |
218 | 220 | |
@@ -254,10 +256,11 @@ discard block |
||
254 | 256 | */ |
255 | 257 | public function setBufferOutput($value) |
256 | 258 | { |
257 | - if($this->_initialized) |
|
258 | - throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
259 | - else |
|
260 | - $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
|
259 | + if($this->_initialized) { |
|
260 | + throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
261 | + } else { |
|
262 | + $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
|
263 | + } |
|
261 | 264 | } |
262 | 265 | |
263 | 266 | /** |
@@ -278,12 +281,13 @@ discard block |
||
278 | 281 | */ |
279 | 282 | public function setStatusCode($status, $reason = null) |
280 | 283 | { |
281 | - if ($this->_httpHeaderSent) |
|
282 | - throw new \Exception('Unable to alter response as HTTP header already sent'); |
|
284 | + if ($this->_httpHeaderSent) { |
|
285 | + throw new \Exception('Unable to alter response as HTTP header already sent'); |
|
286 | + } |
|
283 | 287 | $status = TPropertyValue::ensureInteger($status); |
284 | 288 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
285 | 289 | $this->_reason = self::$HTTP_STATUS_CODES[$status]; |
286 | - }else{ |
|
290 | + } else{ |
|
287 | 291 | if($reason === null || $reason === '') { |
288 | 292 | throw new TInvalidDataValueException("response_status_reason_missing"); |
289 | 293 | } |
@@ -308,8 +312,9 @@ discard block |
||
308 | 312 | */ |
309 | 313 | public function getCookies() |
310 | 314 | { |
311 | - if($this->_cookies === null) |
|
312 | - $this->_cookies = new THttpCookieCollection($this); |
|
315 | + if($this->_cookies === null) { |
|
316 | + $this->_cookies = new THttpCookieCollection($this); |
|
317 | + } |
|
313 | 318 | return $this->_cookies; |
314 | 319 | } |
315 | 320 | |
@@ -321,8 +326,9 @@ discard block |
||
321 | 326 | public function write($str) |
322 | 327 | { |
323 | 328 | // when starting output make sure we send the headers first |
324 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
325 | - $this->ensureHeadersSent(); |
|
329 | + if (!$this->_bufferOutput and !$this->_httpHeaderSent) { |
|
330 | + $this->ensureHeadersSent(); |
|
331 | + } |
|
326 | 332 | echo $str; |
327 | 333 | } |
328 | 334 | |
@@ -356,31 +362,34 @@ discard block |
||
356 | 362 | if($mimeType === null) |
357 | 363 | { |
358 | 364 | $mimeType = 'text/plain'; |
359 | - if(function_exists('mime_content_type')) |
|
360 | - $mimeType = mime_content_type($fileName); |
|
361 | - elseif(($ext = strrchr($fileName, '.')) !== false) |
|
365 | + if(function_exists('mime_content_type')) { |
|
366 | + $mimeType = mime_content_type($fileName); |
|
367 | + } elseif(($ext = strrchr($fileName, '.')) !== false) |
|
362 | 368 | { |
363 | 369 | $ext = substr($ext, 1); |
364 | - if(isset($defaultMimeTypes[$ext])) |
|
365 | - $mimeType = $defaultMimeTypes[$ext]; |
|
370 | + if(isset($defaultMimeTypes[$ext])) { |
|
371 | + $mimeType = $defaultMimeTypes[$ext]; |
|
372 | + } |
|
366 | 373 | } |
367 | 374 | } |
368 | 375 | |
369 | - if($clientFileName === null) |
|
370 | - $clientFileName = basename($fileName); |
|
371 | - else |
|
372 | - $clientFileName = basename($clientFileName); |
|
376 | + if($clientFileName === null) { |
|
377 | + $clientFileName = basename($fileName); |
|
378 | + } else { |
|
379 | + $clientFileName = basename($clientFileName); |
|
380 | + } |
|
373 | 381 | |
374 | - if($fileSize === null || $fileSize < 0) |
|
375 | - $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
382 | + if($fileSize === null || $fileSize < 0) { |
|
383 | + $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
384 | + } |
|
376 | 385 | |
377 | 386 | $this->sendHttpHeader(); |
378 | 387 | if(is_array($headers)) |
379 | 388 | { |
380 | - foreach($headers as $h) |
|
381 | - header($h); |
|
382 | - } |
|
383 | - else |
|
389 | + foreach($headers as $h) { |
|
390 | + header($h); |
|
391 | + } |
|
392 | + } else |
|
384 | 393 | { |
385 | 394 | header('Pragma: public'); |
386 | 395 | header('Expires: 0'); |
@@ -392,10 +401,11 @@ discard block |
||
392 | 401 | header('Content-Length: ' . $fileSize); |
393 | 402 | header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
394 | 403 | header('Content-Transfer-Encoding: binary'); |
395 | - if($content === null) |
|
396 | - readfile($fileName); |
|
397 | - else |
|
398 | - echo $content; |
|
404 | + if($content === null) { |
|
405 | + readfile($fileName); |
|
406 | + } else { |
|
407 | + echo $content; |
|
408 | + } |
|
399 | 409 | } |
400 | 410 | |
401 | 411 | /** |
@@ -406,10 +416,11 @@ discard block |
||
406 | 416 | */ |
407 | 417 | public function redirect($url) |
408 | 418 | { |
409 | - if($this->getHasAdapter()) |
|
410 | - $this->_adapter->httpRedirect($url); |
|
411 | - else |
|
412 | - $this->httpRedirect($url); |
|
419 | + if($this->getHasAdapter()) { |
|
420 | + $this->_adapter->httpRedirect($url); |
|
421 | + } else { |
|
422 | + $this->httpRedirect($url); |
|
423 | + } |
|
413 | 424 | } |
414 | 425 | |
415 | 426 | /** |
@@ -431,8 +442,9 @@ discard block |
||
431 | 442 | // Under IIS, explicitly send an HTTP response including the status code |
432 | 443 | // this is handled automatically by PHP on Apache and others |
433 | 444 | $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
434 | - if($url[0] === '/') |
|
435 | - $url = $this->getRequest()->getBaseUrl() . $url; |
|
445 | + if($url[0] === '/') { |
|
446 | + $url = $this->getRequest()->getBaseUrl() . $url; |
|
447 | + } |
|
436 | 448 | if ($this->_status >= 300 && $this->_status < 400) |
437 | 449 | { |
438 | 450 | // The status code has been modified to a valid redirection status, send it |
@@ -446,13 +458,15 @@ discard block |
||
446 | 458 | } |
447 | 459 | header('Location: ' . str_replace('&', '&', $url), true, $this->_status); |
448 | 460 | } else { |
449 | - if($isIIS) |
|
450 | - header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
461 | + if($isIIS) { |
|
462 | + header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
463 | + } |
|
451 | 464 | header('Location: ' . str_replace('&', '&', $url)); |
452 | 465 | } |
453 | 466 | |
454 | - if(!$this->getApplication()->getRequestCompleted()) |
|
455 | - $this->getApplication()->onEndRequest(); |
|
467 | + if(!$this->getApplication()->getRequestCompleted()) { |
|
468 | + $this->getApplication()->onEndRequest(); |
|
469 | + } |
|
456 | 470 | |
457 | 471 | exit(); |
458 | 472 | } |
@@ -472,10 +486,11 @@ discard block |
||
472 | 486 | */ |
473 | 487 | public function flush($continueBuffering = true) |
474 | 488 | { |
475 | - if($this->getHasAdapter()) |
|
476 | - $this->_adapter->flushContent($continueBuffering); |
|
477 | - else |
|
478 | - $this->flushContent($continueBuffering); |
|
489 | + if($this->getHasAdapter()) { |
|
490 | + $this->_adapter->flushContent($continueBuffering); |
|
491 | + } else { |
|
492 | + $this->flushContent($continueBuffering); |
|
493 | + } |
|
479 | 494 | } |
480 | 495 | |
481 | 496 | /** |
@@ -505,14 +520,14 @@ discard block |
||
505 | 520 | { |
506 | 521 | $this->_bufferOutput = false; |
507 | 522 | ob_end_flush(); |
523 | + } else { |
|
524 | + ob_flush(); |
|
508 | 525 | } |
509 | - else |
|
510 | - ob_flush(); |
|
511 | 526 | flush(); |
512 | 527 | } |
528 | + } else { |
|
529 | + flush(); |
|
513 | 530 | } |
514 | - else |
|
515 | - flush(); |
|
516 | 531 | } |
517 | 532 | |
518 | 533 | /** |
@@ -520,8 +535,9 @@ discard block |
||
520 | 535 | */ |
521 | 536 | protected function ensureHttpHeaderSent() |
522 | 537 | { |
523 | - if (!$this->_httpHeaderSent) |
|
524 | - $this->sendHttpHeader(); |
|
538 | + if (!$this->_httpHeaderSent) { |
|
539 | + $this->sendHttpHeader(); |
|
540 | + } |
|
525 | 541 | } |
526 | 542 | |
527 | 543 | /** |
@@ -530,8 +546,9 @@ discard block |
||
530 | 546 | protected function sendHttpHeader() |
531 | 547 | { |
532 | 548 | $protocol = $this->getRequest()->getHttpProtocolVersion(); |
533 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
534 | - $protocol = 'HTTP/1.1'; |
|
549 | + if($this->getRequest()->getHttpProtocolVersion() === null) { |
|
550 | + $protocol = 'HTTP/1.1'; |
|
551 | + } |
|
535 | 552 | |
536 | 553 | header($protocol . ' ' . $this->_status . ' ' . $this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
537 | 554 | |
@@ -543,8 +560,9 @@ discard block |
||
543 | 560 | */ |
544 | 561 | protected function ensureContentTypeHeaderSent() |
545 | 562 | { |
546 | - if (!$this->_contentTypeHeaderSent) |
|
547 | - $this->sendContentTypeHeader(); |
|
563 | + if (!$this->_contentTypeHeaderSent) { |
|
564 | + $this->sendContentTypeHeader(); |
|
565 | + } |
|
548 | 566 | } |
549 | 567 | |
550 | 568 | /** |
@@ -559,10 +577,13 @@ discard block |
||
559 | 577 | return; |
560 | 578 | } |
561 | 579 | |
562 | - if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
563 | - $charset = $globalization->getCharset(); |
|
580 | + if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) { |
|
581 | + $charset = $globalization->getCharset(); |
|
582 | + } |
|
564 | 583 | |
565 | - if($charset === '') $charset = self::DEFAULT_CHARSET; |
|
584 | + if($charset === '') { |
|
585 | + $charset = self::DEFAULT_CHARSET; |
|
586 | + } |
|
566 | 587 | $this->appendHeader('Content-Type: ' . $contentType . ';charset=' . $charset); |
567 | 588 | |
568 | 589 | $this->_contentTypeHeaderSent = true; |
@@ -585,8 +606,9 @@ discard block |
||
585 | 606 | */ |
586 | 607 | public function clear() |
587 | 608 | { |
588 | - if($this->_bufferOutput) |
|
589 | - ob_clean(); |
|
609 | + if($this->_bufferOutput) { |
|
610 | + ob_clean(); |
|
611 | + } |
|
590 | 612 | Prado::trace("Clearing output", 'Prado\Web\THttpResponse'); |
591 | 613 | } |
592 | 614 | |
@@ -602,14 +624,16 @@ discard block |
||
602 | 624 | $tmp = explode(':', $header); |
603 | 625 | $key = trim(array_shift($tmp)); |
604 | 626 | $value = trim(implode(':', $tmp)); |
605 | - if(isset($result[$key])) |
|
606 | - $result[$key] .= ', ' . $value; |
|
607 | - else |
|
608 | - $result[$key] = $value; |
|
627 | + if(isset($result[$key])) { |
|
628 | + $result[$key] .= ', ' . $value; |
|
629 | + } else { |
|
630 | + $result[$key] = $value; |
|
631 | + } |
|
609 | 632 | } |
610 | 633 | |
611 | - if($case !== null) |
|
612 | - return array_change_key_case($result, $case); |
|
634 | + if($case !== null) { |
|
635 | + return array_change_key_case($result, $case); |
|
636 | + } |
|
613 | 637 | |
614 | 638 | return $result; |
615 | 639 | } |
@@ -659,8 +683,7 @@ discard block |
||
659 | 683 | $cookie->getSecure(), |
660 | 684 | $cookie->getHttpOnly() |
661 | 685 | ); |
662 | - } |
|
663 | - else { |
|
686 | + } else { |
|
664 | 687 | setcookie( |
665 | 688 | $cookie->getName(), |
666 | 689 | $cookie->getValue(), |
@@ -714,12 +737,14 @@ discard block |
||
714 | 737 | */ |
715 | 738 | public function createHtmlWriter($type = null) |
716 | 739 | { |
717 | - if($type === null) |
|
718 | - $type = $this->getHtmlWriterType(); |
|
719 | - if($this->getHasAdapter()) |
|
720 | - return $this->_adapter->createNewHtmlWriter($type, $this); |
|
721 | - else |
|
722 | - return $this->createNewHtmlWriter($type, $this); |
|
740 | + if($type === null) { |
|
741 | + $type = $this->getHtmlWriterType(); |
|
742 | + } |
|
743 | + if($this->getHasAdapter()) { |
|
744 | + return $this->_adapter->createNewHtmlWriter($type, $this); |
|
745 | + } else { |
|
746 | + return $this->createNewHtmlWriter($type, $this); |
|
747 | + } |
|
723 | 748 | } |
724 | 749 | |
725 | 750 | /** |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_cacheModuleID === '') |
|
60 | + if ($this->_cacheModuleID === '') |
|
61 | 61 | throw new TConfigurationException('cachesession_cachemoduleid_required'); |
62 | - elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
62 | + elseif (($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
63 | 63 | throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
64 | - elseif($cache instanceof ICache) |
|
64 | + elseif ($cache instanceof ICache) |
|
65 | 65 | $this->_cache = $cache; |
66 | 66 | else |
67 | 67 | throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function _read($id) |
102 | 102 | { |
103 | - return (string)$this->_cache->get($this->calculateKey($id)); |
|
103 | + return (string) $this->_cache->get($this->calculateKey($id)); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function calculateKey($id) |
149 | 149 | { |
150 | - return $this->_prefix . ':' . $id; |
|
150 | + return $this->_prefix.':'.$id; |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 |
@@ -57,14 +57,15 @@ |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_cacheModuleID === '') |
|
61 | - throw new TConfigurationException('cachesession_cachemoduleid_required'); |
|
62 | - elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
63 | - throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
|
64 | - elseif($cache instanceof ICache) |
|
65 | - $this->_cache = $cache; |
|
66 | - else |
|
67 | - throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
|
60 | + if($this->_cacheModuleID === '') { |
|
61 | + throw new TConfigurationException('cachesession_cachemoduleid_required'); |
|
62 | + } elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) { |
|
63 | + throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
|
64 | + } elseif($cache instanceof ICache) { |
|
65 | + $this->_cache = $cache; |
|
66 | + } else { |
|
67 | + throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
|
68 | + } |
|
68 | 69 | $this->setUseCustomStorage(true); |
69 | 70 | parent::init($config); |
70 | 71 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function init($config) |
127 | 127 | { |
128 | - if($this->_autoStart) |
|
128 | + if ($this->_autoStart) |
|
129 | 129 | $this->open(); |
130 | 130 | $this->_initialized = true; |
131 | 131 | $this->getApplication()->setSession($this); |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function open() |
139 | 139 | { |
140 | - if(!$this->_started) |
|
140 | + if (!$this->_started) |
|
141 | 141 | { |
142 | - if($this->_customStorage) |
|
143 | - session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
144 | - if($this->_cookie !== null) |
|
142 | + if ($this->_customStorage) |
|
143 | + session_set_save_handler([$this, '_open'], [$this, '_close'], [$this, '_read'], [$this, '_write'], [$this, '_destroy'], [$this, '_gc']); |
|
144 | + if ($this->_cookie !== null) |
|
145 | 145 | session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
146 | - if(ini_get('session.auto_start') !== '1') |
|
146 | + if (ini_get('session.auto_start') !== '1') |
|
147 | 147 | session_start(); |
148 | 148 | $this->_started = true; |
149 | 149 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function close() |
156 | 156 | { |
157 | - if($this->_started) |
|
157 | + if ($this->_started) |
|
158 | 158 | { |
159 | 159 | session_write_close(); |
160 | 160 | $this->_started = false; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function destroy() |
168 | 168 | { |
169 | - if($this->_started) |
|
169 | + if ($this->_started) |
|
170 | 170 | { |
171 | 171 | session_destroy(); |
172 | 172 | $this->_started = false; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function setSessionID($value) |
211 | 211 | { |
212 | - if($this->_started) |
|
212 | + if ($this->_started) |
|
213 | 213 | throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
214 | 214 | else |
215 | 215 | session_id($value); |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function setSessionName($value) |
231 | 231 | { |
232 | - if($this->_started) |
|
232 | + if ($this->_started) |
|
233 | 233 | throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
234 | - elseif(ctype_alnum($value)) |
|
234 | + elseif (ctype_alnum($value)) |
|
235 | 235 | session_name($value); |
236 | 236 | else |
237 | 237 | throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function setSavePath($value) |
253 | 253 | { |
254 | - if($this->_started) |
|
254 | + if ($this->_started) |
|
255 | 255 | throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
256 | - elseif(is_dir($value)) |
|
256 | + elseif (is_dir($value)) |
|
257 | 257 | session_save_path(realpath($value)); |
258 | - elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
258 | + elseif (null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
259 | 259 | session_save_path(realpath($ns)); |
260 | 260 | else |
261 | 261 | throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function getCookie() |
287 | 287 | { |
288 | - if($this->_cookie === null) |
|
288 | + if ($this->_cookie === null) |
|
289 | 289 | $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
290 | 290 | return $this->_cookie; |
291 | 291 | } |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function getCookieMode() |
297 | 297 | { |
298 | - if(ini_get('session.use_cookies') === '0') |
|
298 | + if (ini_get('session.use_cookies') === '0') |
|
299 | 299 | return THttpSessionCookieMode::None; |
300 | - elseif(ini_get('session.use_only_cookies') === '0') |
|
300 | + elseif (ini_get('session.use_only_cookies') === '0') |
|
301 | 301 | return THttpSessionCookieMode::Allow; |
302 | 302 | else |
303 | 303 | return THttpSessionCookieMode::Only; |
@@ -309,17 +309,17 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public function setCookieMode($value) |
311 | 311 | { |
312 | - if($this->_started) |
|
312 | + if ($this->_started) |
|
313 | 313 | throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
314 | 314 | else |
315 | 315 | { |
316 | 316 | $value = TPropertyValue::ensureEnum($value, 'Prado\\Web\\THttpSessionCookieMode'); |
317 | - if($value === THttpSessionCookieMode::None) |
|
317 | + if ($value === THttpSessionCookieMode::None) |
|
318 | 318 | { |
319 | 319 | ini_set('session.use_cookies', '0'); |
320 | 320 | ini_set('session.use_only_cookies', '0'); |
321 | 321 | } |
322 | - elseif($value === THttpSessionCookieMode::Allow) |
|
322 | + elseif ($value === THttpSessionCookieMode::Allow) |
|
323 | 323 | { |
324 | 324 | ini_set('session.use_cookies', '1'); |
325 | 325 | ini_set('session.use_only_cookies', '0'); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public function setAutoStart($value) |
349 | 349 | { |
350 | - if($this->_initialized) |
|
350 | + if ($this->_initialized) |
|
351 | 351 | throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
352 | 352 | else |
353 | 353 | $this->_autoStart = TPropertyValue::ensureBoolean($value); |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function setGCProbability($value) |
370 | 370 | { |
371 | - if($this->_started) |
|
371 | + if ($this->_started) |
|
372 | 372 | throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
373 | 373 | else |
374 | 374 | { |
375 | 375 | $value = TPropertyValue::ensureInteger($value); |
376 | - if($value >= 0 && $value <= 100) |
|
376 | + if ($value >= 0 && $value <= 100) |
|
377 | 377 | { |
378 | 378 | ini_set('session.gc_probability', $value); |
379 | 379 | ini_set('session.gc_divisor', '100'); |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function setUseTransparentSessionID($value) |
402 | 402 | { |
403 | - if($this->_started) |
|
403 | + if ($this->_started) |
|
404 | 404 | throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
405 | 405 | else |
406 | 406 | { |
407 | 407 | $value = TPropertyValue::ensureBoolean($value); |
408 | 408 | if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) |
409 | 409 | throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
410 | - ini_set('session.use_trans_sid', $value?'1':'0'); |
|
410 | + ini_set('session.use_trans_sid', $value ? '1' : '0'); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | */ |
426 | 426 | public function setTimeout($value) |
427 | 427 | { |
428 | - if($this->_started) |
|
428 | + if ($this->_started) |
|
429 | 429 | throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
430 | 430 | else |
431 | 431 | ini_set('session.gc_maxlifetime', $value); |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | */ |
566 | 566 | public function remove($key) |
567 | 567 | { |
568 | - if(isset($_SESSION[$key])) |
|
568 | + if (isset($_SESSION[$key])) |
|
569 | 569 | { |
570 | 570 | $value = $_SESSION[$key]; |
571 | 571 | unset($_SESSION[$key]); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function clear() |
582 | 582 | { |
583 | - foreach(array_keys($_SESSION) as $key) |
|
583 | + foreach (array_keys($_SESSION) as $key) |
|
584 | 584 | unset($_SESSION[$key]); |
585 | 585 | } |
586 | 586 |
@@ -125,8 +125,9 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function init($config) |
127 | 127 | { |
128 | - if($this->_autoStart) |
|
129 | - $this->open(); |
|
128 | + if($this->_autoStart) { |
|
129 | + $this->open(); |
|
130 | + } |
|
130 | 131 | $this->_initialized = true; |
131 | 132 | $this->getApplication()->setSession($this); |
132 | 133 | register_shutdown_function([$this, "close"]); |
@@ -139,12 +140,15 @@ discard block |
||
139 | 140 | { |
140 | 141 | if(!$this->_started) |
141 | 142 | { |
142 | - if($this->_customStorage) |
|
143 | - session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
144 | - if($this->_cookie !== null) |
|
145 | - session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
|
146 | - if(ini_get('session.auto_start') !== '1') |
|
147 | - session_start(); |
|
143 | + if($this->_customStorage) { |
|
144 | + session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
145 | + } |
|
146 | + if($this->_cookie !== null) { |
|
147 | + session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
|
148 | + } |
|
149 | + if(ini_get('session.auto_start') !== '1') { |
|
150 | + session_start(); |
|
151 | + } |
|
148 | 152 | $this->_started = true; |
149 | 153 | } |
150 | 154 | } |
@@ -209,10 +213,11 @@ discard block |
||
209 | 213 | */ |
210 | 214 | public function setSessionID($value) |
211 | 215 | { |
212 | - if($this->_started) |
|
213 | - throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
214 | - else |
|
215 | - session_id($value); |
|
216 | + if($this->_started) { |
|
217 | + throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
218 | + } else { |
|
219 | + session_id($value); |
|
220 | + } |
|
216 | 221 | } |
217 | 222 | |
218 | 223 | /** |
@@ -229,12 +234,13 @@ discard block |
||
229 | 234 | */ |
230 | 235 | public function setSessionName($value) |
231 | 236 | { |
232 | - if($this->_started) |
|
233 | - throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
234 | - elseif(ctype_alnum($value)) |
|
235 | - session_name($value); |
|
236 | - else |
|
237 | - throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
|
237 | + if($this->_started) { |
|
238 | + throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
239 | + } elseif(ctype_alnum($value)) { |
|
240 | + session_name($value); |
|
241 | + } else { |
|
242 | + throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
|
243 | + } |
|
238 | 244 | } |
239 | 245 | |
240 | 246 | /** |
@@ -251,14 +257,15 @@ discard block |
||
251 | 257 | */ |
252 | 258 | public function setSavePath($value) |
253 | 259 | { |
254 | - if($this->_started) |
|
255 | - throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
256 | - elseif(is_dir($value)) |
|
257 | - session_save_path(realpath($value)); |
|
258 | - elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
259 | - session_save_path(realpath($ns)); |
|
260 | - else |
|
261 | - throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
|
260 | + if($this->_started) { |
|
261 | + throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
262 | + } elseif(is_dir($value)) { |
|
263 | + session_save_path(realpath($value)); |
|
264 | + } elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) { |
|
265 | + session_save_path(realpath($ns)); |
|
266 | + } else { |
|
267 | + throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
|
268 | + } |
|
262 | 269 | } |
263 | 270 | |
264 | 271 | /** |
@@ -285,8 +292,9 @@ discard block |
||
285 | 292 | */ |
286 | 293 | public function getCookie() |
287 | 294 | { |
288 | - if($this->_cookie === null) |
|
289 | - $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
|
295 | + if($this->_cookie === null) { |
|
296 | + $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
|
297 | + } |
|
290 | 298 | return $this->_cookie; |
291 | 299 | } |
292 | 300 | |
@@ -295,12 +303,13 @@ discard block |
||
295 | 303 | */ |
296 | 304 | public function getCookieMode() |
297 | 305 | { |
298 | - if(ini_get('session.use_cookies') === '0') |
|
299 | - return THttpSessionCookieMode::None; |
|
300 | - elseif(ini_get('session.use_only_cookies') === '0') |
|
301 | - return THttpSessionCookieMode::Allow; |
|
302 | - else |
|
303 | - return THttpSessionCookieMode::Only; |
|
306 | + if(ini_get('session.use_cookies') === '0') { |
|
307 | + return THttpSessionCookieMode::None; |
|
308 | + } elseif(ini_get('session.use_only_cookies') === '0') { |
|
309 | + return THttpSessionCookieMode::Allow; |
|
310 | + } else { |
|
311 | + return THttpSessionCookieMode::Only; |
|
312 | + } |
|
304 | 313 | } |
305 | 314 | |
306 | 315 | /** |
@@ -309,22 +318,20 @@ discard block |
||
309 | 318 | */ |
310 | 319 | public function setCookieMode($value) |
311 | 320 | { |
312 | - if($this->_started) |
|
313 | - throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
314 | - else |
|
321 | + if($this->_started) { |
|
322 | + throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
323 | + } else |
|
315 | 324 | { |
316 | 325 | $value = TPropertyValue::ensureEnum($value, 'Prado\\Web\\THttpSessionCookieMode'); |
317 | 326 | if($value === THttpSessionCookieMode::None) |
318 | 327 | { |
319 | 328 | ini_set('session.use_cookies', '0'); |
320 | 329 | ini_set('session.use_only_cookies', '0'); |
321 | - } |
|
322 | - elseif($value === THttpSessionCookieMode::Allow) |
|
330 | + } elseif($value === THttpSessionCookieMode::Allow) |
|
323 | 331 | { |
324 | 332 | ini_set('session.use_cookies', '1'); |
325 | 333 | ini_set('session.use_only_cookies', '0'); |
326 | - } |
|
327 | - else |
|
334 | + } else |
|
328 | 335 | { |
329 | 336 | ini_set('session.use_cookies', '1'); |
330 | 337 | ini_set('session.use_only_cookies', '1'); |
@@ -347,10 +354,11 @@ discard block |
||
347 | 354 | */ |
348 | 355 | public function setAutoStart($value) |
349 | 356 | { |
350 | - if($this->_initialized) |
|
351 | - throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
352 | - else |
|
353 | - $this->_autoStart = TPropertyValue::ensureBoolean($value); |
|
357 | + if($this->_initialized) { |
|
358 | + throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
359 | + } else { |
|
360 | + $this->_autoStart = TPropertyValue::ensureBoolean($value); |
|
361 | + } |
|
354 | 362 | } |
355 | 363 | |
356 | 364 | /** |
@@ -368,18 +376,18 @@ discard block |
||
368 | 376 | */ |
369 | 377 | public function setGCProbability($value) |
370 | 378 | { |
371 | - if($this->_started) |
|
372 | - throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
373 | - else |
|
379 | + if($this->_started) { |
|
380 | + throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
381 | + } else |
|
374 | 382 | { |
375 | 383 | $value = TPropertyValue::ensureInteger($value); |
376 | 384 | if($value >= 0 && $value <= 100) |
377 | 385 | { |
378 | 386 | ini_set('session.gc_probability', $value); |
379 | 387 | ini_set('session.gc_divisor', '100'); |
388 | + } else { |
|
389 | + throw new TInvalidDataValueException('httpsession_gcprobability_invalid', $value); |
|
380 | 390 | } |
381 | - else |
|
382 | - throw new TInvalidDataValueException('httpsession_gcprobability_invalid', $value); |
|
383 | 391 | } |
384 | 392 | } |
385 | 393 | |
@@ -400,13 +408,14 @@ discard block |
||
400 | 408 | */ |
401 | 409 | public function setUseTransparentSessionID($value) |
402 | 410 | { |
403 | - if($this->_started) |
|
404 | - throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
405 | - else |
|
411 | + if($this->_started) { |
|
412 | + throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
413 | + } else |
|
406 | 414 | { |
407 | 415 | $value = TPropertyValue::ensureBoolean($value); |
408 | - if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) |
|
409 | - throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
416 | + if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) { |
|
417 | + throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
418 | + } |
|
410 | 419 | ini_set('session.use_trans_sid', $value?'1':'0'); |
411 | 420 | } |
412 | 421 | } |
@@ -425,10 +434,11 @@ discard block |
||
425 | 434 | */ |
426 | 435 | public function setTimeout($value) |
427 | 436 | { |
428 | - if($this->_started) |
|
429 | - throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
430 | - else |
|
431 | - ini_set('session.gc_maxlifetime', $value); |
|
437 | + if($this->_started) { |
|
438 | + throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
439 | + } else { |
|
440 | + ini_set('session.gc_maxlifetime', $value); |
|
441 | + } |
|
432 | 442 | } |
433 | 443 | |
434 | 444 | /** |
@@ -570,9 +580,9 @@ discard block |
||
570 | 580 | $value = $_SESSION[$key]; |
571 | 581 | unset($_SESSION[$key]); |
572 | 582 | return $value; |
583 | + } else { |
|
584 | + return null; |
|
573 | 585 | } |
574 | - else |
|
575 | - return null; |
|
576 | 586 | } |
577 | 587 | |
578 | 588 | /** |
@@ -580,8 +590,9 @@ discard block |
||
580 | 590 | */ |
581 | 591 | public function clear() |
582 | 592 | { |
583 | - foreach(array_keys($_SESSION) as $key) |
|
584 | - unset($_SESSION[$key]); |
|
593 | + foreach(array_keys($_SESSION) as $key) { |
|
594 | + unset($_SESSION[$key]); |
|
595 | + } |
|
585 | 596 | } |
586 | 597 | |
587 | 598 | /** |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | public function init($config) |
90 | 90 | { |
91 | 91 | $application = $this->getApplication(); |
92 | - if($this->_basePath === null) |
|
93 | - $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
92 | + if ($this->_basePath === null) |
|
93 | + $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
94 | + if (!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
95 | 95 | throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
96 | - if($this->_baseUrl === null) |
|
97 | - $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
96 | + if ($this->_baseUrl === null) |
|
97 | + $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\').'/'.self::DEFAULT_BASEPATH; |
|
98 | 98 | $application->setAssetManager($this); |
99 | 99 | $this->_initialized = true; |
100 | 100 | } |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function setBasePath($value) |
117 | 117 | { |
118 | - if($this->_initialized) |
|
118 | + if ($this->_initialized) |
|
119 | 119 | throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
120 | 120 | else |
121 | 121 | { |
122 | 122 | $this->_basePath = Prado::getPathOfNamespace($value); |
123 | - if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
123 | + if ($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
124 | 124 | throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
125 | 125 | } |
126 | 126 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function setBaseUrl($value) |
141 | 141 | { |
142 | - if($this->_initialized) |
|
142 | + if ($this->_initialized) |
|
143 | 143 | throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
144 | 144 | else |
145 | 145 | $this->_baseUrl = rtrim($value, '/'); |
@@ -161,28 +161,28 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function publishFilePath($path, $checkTimestamp = false) |
163 | 163 | { |
164 | - if(isset($this->_published[$path])) |
|
164 | + if (isset($this->_published[$path])) |
|
165 | 165 | return $this->_published[$path]; |
166 | - elseif(empty($path) || ($fullpath = realpath($path)) === false) |
|
166 | + elseif (empty($path) || ($fullpath = realpath($path)) === false) |
|
167 | 167 | throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
168 | - elseif(is_file($fullpath)) |
|
168 | + elseif (is_file($fullpath)) |
|
169 | 169 | { |
170 | 170 | $dir = $this->hash(dirname($fullpath)); |
171 | 171 | $fileName = basename($fullpath); |
172 | - $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
173 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
172 | + $dst = $this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
173 | + if (!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
174 | 174 | $this->copyFile($fullpath, $dst); |
175 | - return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName; |
|
175 | + return $this->_published[$path] = $this->_baseUrl.'/'.$dir.'/'.$fileName; |
|
176 | 176 | } |
177 | 177 | else |
178 | 178 | { |
179 | 179 | $dir = $this->hash($fullpath); |
180 | - if(!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
180 | + if (!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
181 | 181 | { |
182 | 182 | Prado::trace("Publishing directory $fullpath", 'Prado\Web\TAssetManager'); |
183 | - $this->copyDirectory($fullpath, $this->_basePath . DIRECTORY_SEPARATOR . $dir); |
|
183 | + $this->copyDirectory($fullpath, $this->_basePath.DIRECTORY_SEPARATOR.$dir); |
|
184 | 184 | } |
185 | - return $this->_published[$path] = $this->_baseUrl . '/' . $dir; |
|
185 | + return $this->_published[$path] = $this->_baseUrl.'/'.$dir; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | public function getPublishedPath($path) |
215 | 215 | { |
216 | 216 | $path = realpath($path); |
217 | - if(is_file($path)) |
|
218 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
217 | + if (is_file($path)) |
|
218 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
219 | 219 | else |
220 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
220 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | public function getPublishedUrl($path) |
231 | 231 | { |
232 | 232 | $path = realpath($path); |
233 | - if(is_file($path)) |
|
234 | - return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
233 | + if (is_file($path)) |
|
234 | + return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
235 | 235 | else |
236 | - return $this->_baseUrl . '/' . $this->hash($path); |
|
236 | + return $this->_baseUrl.'/'.$this->hash($path); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | protected function hash($dir) |
246 | 246 | { |
247 | - return sprintf('%x', crc32($dir . Prado::getVersion())); |
|
247 | + return sprintf('%x', crc32($dir.Prado::getVersion())); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | */ |
257 | 257 | protected function copyFile($src, $dst) |
258 | 258 | { |
259 | - if(!is_dir($dst)) |
|
259 | + if (!is_dir($dst)) |
|
260 | 260 | { |
261 | 261 | @mkdir($dst); |
262 | 262 | @chmod($dst, PRADO_CHMOD); |
263 | 263 | } |
264 | - $dstFile = $dst . DIRECTORY_SEPARATOR . basename($src); |
|
265 | - if(@filemtime($dstFile) < @filemtime($src)) |
|
264 | + $dstFile = $dst.DIRECTORY_SEPARATOR.basename($src); |
|
265 | + if (@filemtime($dstFile) < @filemtime($src)) |
|
266 | 266 | { |
267 | 267 | Prado::trace("Publishing file $src to $dstFile", 'Prado\Web\TAssetManager'); |
268 | 268 | @copy($src, $dstFile); |
@@ -279,27 +279,27 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function copyDirectory($src, $dst) |
281 | 281 | { |
282 | - if(!is_dir($dst)) |
|
282 | + if (!is_dir($dst)) |
|
283 | 283 | { |
284 | 284 | @mkdir($dst); |
285 | 285 | @chmod($dst, PRADO_CHMOD); |
286 | 286 | } |
287 | - if($folder = @opendir($src)) |
|
287 | + if ($folder = @opendir($src)) |
|
288 | 288 | { |
289 | - while($file = @readdir($folder)) |
|
289 | + while ($file = @readdir($folder)) |
|
290 | 290 | { |
291 | - if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
291 | + if ($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
292 | 292 | continue; |
293 | - elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
293 | + elseif (is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
294 | 294 | { |
295 | - if(@filemtime($dst . DIRECTORY_SEPARATOR . $file) < @filemtime($src . DIRECTORY_SEPARATOR . $file)) |
|
295 | + if (@filemtime($dst.DIRECTORY_SEPARATOR.$file) < @filemtime($src.DIRECTORY_SEPARATOR.$file)) |
|
296 | 296 | { |
297 | - @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
298 | - @chmod($dst . DIRECTORY_SEPARATOR . $file, PRADO_CHMOD); |
|
297 | + @copy($src.DIRECTORY_SEPARATOR.$file, $dst.DIRECTORY_SEPARATOR.$file); |
|
298 | + @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | else |
302 | - $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
302 | + $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file, $dst.DIRECTORY_SEPARATOR.$file); |
|
303 | 303 | } |
304 | 304 | closedir($folder); |
305 | 305 | } else { |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false) |
322 | 322 | { |
323 | - if(isset($this->_published[$md5sum])) |
|
323 | + if (isset($this->_published[$md5sum])) |
|
324 | 324 | return $this->_published[$md5sum]; |
325 | - elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
325 | + elseif (($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
326 | 326 | throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
327 | 327 | else |
328 | 328 | { |
329 | 329 | $dir = $this->hash(dirname($fullpath)); |
330 | 330 | $fileName = basename($fullpath); |
331 | - $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
332 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
331 | + $dst = $this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
332 | + if (!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
333 | 333 | { |
334 | - if(@filemtime($dst . DIRECTORY_SEPARATOR . $fileName) < @filemtime($fullpath)) |
|
334 | + if (@filemtime($dst.DIRECTORY_SEPARATOR.$fileName) < @filemtime($fullpath)) |
|
335 | 335 | { |
336 | 336 | $this->copyFile($fullpath, $dst); |
337 | 337 | $this->deployTarFile($tarfile, $dst); |
338 | 338 | } |
339 | 339 | } |
340 | - return $this->_published[$md5sum] = $this->_baseUrl . '/' . $dir; |
|
340 | + return $this->_published[$md5sum] = $this->_baseUrl.'/'.$dir; |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | */ |
351 | 351 | protected function deployTarFile($path, $destination) |
352 | 352 | { |
353 | - if(($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
353 | + if (($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
354 | 354 | throw new TIOException('assetmanager_tarfile_invalid', $path); |
355 | 355 | else |
356 | 356 | { |
@@ -89,12 +89,15 @@ discard block |
||
89 | 89 | public function init($config) |
90 | 90 | { |
91 | 91 | $application = $this->getApplication(); |
92 | - if($this->_basePath === null) |
|
93 | - $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
95 | - throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
|
96 | - if($this->_baseUrl === null) |
|
97 | - $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
92 | + if($this->_basePath === null) { |
|
93 | + $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | + } |
|
95 | + if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) { |
|
96 | + throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
|
97 | + } |
|
98 | + if($this->_baseUrl === null) { |
|
99 | + $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
100 | + } |
|
98 | 101 | $application->setAssetManager($this); |
99 | 102 | $this->_initialized = true; |
100 | 103 | } |
@@ -115,13 +118,14 @@ discard block |
||
115 | 118 | */ |
116 | 119 | public function setBasePath($value) |
117 | 120 | { |
118 | - if($this->_initialized) |
|
119 | - throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
120 | - else |
|
121 | + if($this->_initialized) { |
|
122 | + throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
123 | + } else |
|
121 | 124 | { |
122 | 125 | $this->_basePath = Prado::getPathOfNamespace($value); |
123 | - if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
124 | - throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
|
126 | + if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) { |
|
127 | + throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
|
128 | + } |
|
125 | 129 | } |
126 | 130 | } |
127 | 131 | |
@@ -139,10 +143,11 @@ discard block |
||
139 | 143 | */ |
140 | 144 | public function setBaseUrl($value) |
141 | 145 | { |
142 | - if($this->_initialized) |
|
143 | - throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
144 | - else |
|
145 | - $this->_baseUrl = rtrim($value, '/'); |
|
146 | + if($this->_initialized) { |
|
147 | + throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
148 | + } else { |
|
149 | + $this->_baseUrl = rtrim($value, '/'); |
|
150 | + } |
|
146 | 151 | } |
147 | 152 | |
148 | 153 | /** |
@@ -161,20 +166,20 @@ discard block |
||
161 | 166 | */ |
162 | 167 | public function publishFilePath($path, $checkTimestamp = false) |
163 | 168 | { |
164 | - if(isset($this->_published[$path])) |
|
165 | - return $this->_published[$path]; |
|
166 | - elseif(empty($path) || ($fullpath = realpath($path)) === false) |
|
167 | - throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
|
168 | - elseif(is_file($fullpath)) |
|
169 | + if(isset($this->_published[$path])) { |
|
170 | + return $this->_published[$path]; |
|
171 | + } elseif(empty($path) || ($fullpath = realpath($path)) === false) { |
|
172 | + throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
|
173 | + } elseif(is_file($fullpath)) |
|
169 | 174 | { |
170 | 175 | $dir = $this->hash(dirname($fullpath)); |
171 | 176 | $fileName = basename($fullpath); |
172 | 177 | $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
173 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
174 | - $this->copyFile($fullpath, $dst); |
|
178 | + if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
179 | + $this->copyFile($fullpath, $dst); |
|
180 | + } |
|
175 | 181 | return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName; |
176 | - } |
|
177 | - else |
|
182 | + } else |
|
178 | 183 | { |
179 | 184 | $dir = $this->hash($fullpath); |
180 | 185 | if(!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
@@ -214,10 +219,11 @@ discard block |
||
214 | 219 | public function getPublishedPath($path) |
215 | 220 | { |
216 | 221 | $path = realpath($path); |
217 | - if(is_file($path)) |
|
218 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
219 | - else |
|
220 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
222 | + if(is_file($path)) { |
|
223 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
224 | + } else { |
|
225 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
226 | + } |
|
221 | 227 | } |
222 | 228 | |
223 | 229 | /** |
@@ -230,10 +236,11 @@ discard block |
||
230 | 236 | public function getPublishedUrl($path) |
231 | 237 | { |
232 | 238 | $path = realpath($path); |
233 | - if(is_file($path)) |
|
234 | - return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
235 | - else |
|
236 | - return $this->_baseUrl . '/' . $this->hash($path); |
|
239 | + if(is_file($path)) { |
|
240 | + return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
241 | + } else { |
|
242 | + return $this->_baseUrl . '/' . $this->hash($path); |
|
243 | + } |
|
237 | 244 | } |
238 | 245 | |
239 | 246 | /** |
@@ -288,18 +295,18 @@ discard block |
||
288 | 295 | { |
289 | 296 | while($file = @readdir($folder)) |
290 | 297 | { |
291 | - if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
292 | - continue; |
|
293 | - elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
298 | + if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') { |
|
299 | + continue; |
|
300 | + } elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
294 | 301 | { |
295 | 302 | if(@filemtime($dst . DIRECTORY_SEPARATOR . $file) < @filemtime($src . DIRECTORY_SEPARATOR . $file)) |
296 | 303 | { |
297 | 304 | @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
298 | 305 | @chmod($dst . DIRECTORY_SEPARATOR . $file, PRADO_CHMOD); |
299 | 306 | } |
307 | + } else { |
|
308 | + $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
300 | 309 | } |
301 | - else |
|
302 | - $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
303 | 310 | } |
304 | 311 | closedir($folder); |
305 | 312 | } else { |
@@ -320,11 +327,11 @@ discard block |
||
320 | 327 | */ |
321 | 328 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false) |
322 | 329 | { |
323 | - if(isset($this->_published[$md5sum])) |
|
324 | - return $this->_published[$md5sum]; |
|
325 | - elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
326 | - throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
|
327 | - else |
|
330 | + if(isset($this->_published[$md5sum])) { |
|
331 | + return $this->_published[$md5sum]; |
|
332 | + } elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) { |
|
333 | + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
|
334 | + } else |
|
328 | 335 | { |
329 | 336 | $dir = $this->hash(dirname($fullpath)); |
330 | 337 | $fileName = basename($fullpath); |
@@ -350,9 +357,9 @@ discard block |
||
350 | 357 | */ |
351 | 358 | protected function deployTarFile($path, $destination) |
352 | 359 | { |
353 | - if(($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
354 | - throw new TIOException('assetmanager_tarfile_invalid', $path); |
|
355 | - else |
|
360 | + if(($fullpath = realpath($path)) === false || !is_file($fullpath)) { |
|
361 | + throw new TIOException('assetmanager_tarfile_invalid', $path); |
|
362 | + } else |
|
356 | 363 | { |
357 | 364 | $tar = new TTarFileExtractor($fullpath); |
358 | 365 | return $tar->extract($destination); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function getValue($key) |
141 | 141 | { |
142 | - $result = $this->request('GET', $this->_dir . '/' . $key); |
|
142 | + $result = $this->request('GET', $this->_dir.'/'.$key); |
|
143 | 143 | return property_exists($result, 'errorCode') ? false : unserialize($result->node->value); |
144 | 144 | } |
145 | 145 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | $value = ['value' => serialize($value)]; |
158 | 158 | if ($expire > 0) $value['ttl'] = $expire; |
159 | - $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
|
159 | + $result = $this->request('PUT', $this->_dir.'/'.$key, $value); |
|
160 | 160 | return !property_exists($result, 'errorCode'); |
161 | 161 | } |
162 | 162 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | { |
174 | 174 | $value = ['value' => serialize($value), 'prevExist' => 'false']; |
175 | 175 | if ($expire > 0) $value['ttl'] = $expire; |
176 | - $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
|
176 | + $result = $this->request('PUT', $this->_dir.'/'.$key, $value); |
|
177 | 177 | return !property_exists($result, 'errorCode'); |
178 | 178 | } |
179 | 179 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function deleteValue($key) |
187 | 187 | { |
188 | - $this->request('DELETE', $this->_dir . '/' . $key); |
|
188 | + $this->request('DELETE', $this->_dir.'/'.$key); |
|
189 | 189 | return true; |
190 | 190 | } |
191 | 191 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function flush() |
197 | 197 | { |
198 | - $this->request('DELETE', $this->_dir . '?recursive=true'); |
|
198 | + $this->request('DELETE', $this->_dir.'?recursive=true'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -79,7 +79,9 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function init($config) |
81 | 81 | { |
82 | - if (!function_exists('curl_version')) throw new TConfigurationException('curl_extension_required'); |
|
82 | + if (!function_exists('curl_version')) { |
|
83 | + throw new TConfigurationException('curl_extension_required'); |
|
84 | + } |
|
83 | 85 | parent::init($config); |
84 | 86 | } |
85 | 87 | |
@@ -155,7 +157,9 @@ discard block |
||
155 | 157 | protected function setValue($key, $value, $expire) |
156 | 158 | { |
157 | 159 | $value = ['value' => serialize($value)]; |
158 | - if ($expire > 0) $value['ttl'] = $expire; |
|
160 | + if ($expire > 0) { |
|
161 | + $value['ttl'] = $expire; |
|
162 | + } |
|
159 | 163 | $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
160 | 164 | return !property_exists($result, 'errorCode'); |
161 | 165 | } |
@@ -172,7 +176,9 @@ discard block |
||
172 | 176 | protected function addValue($key, $value, $expire) |
173 | 177 | { |
174 | 178 | $value = ['value' => serialize($value), 'prevExist' => 'false']; |
175 | - if ($expire > 0) $value['ttl'] = $expire; |
|
179 | + if ($expire > 0) { |
|
180 | + $value['ttl'] = $expire; |
|
181 | + } |
|
176 | 182 | $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
177 | 183 | return !property_exists($result, 'errorCode'); |
178 | 184 | } |