You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage View
  7. * @since 2010-03-09
  8. */
  9. class GetViewHelper extends ViewHelper
  10. {
  11. protected $get;
  12. public function get($replace)
  13. {
  14. $get = $this->getSanitizedRequest();
  15. if (!is_array($replace)) {
  16. $replace = array($replace);
  17. }
  18. foreach ($replace as $key => $value) {
  19. if (is_int($key)) {
  20. unset($get[$value]);
  21. } else {
  22. $get[$key] = $this->impl($key, $value);
  23. }
  24. }
  25. return '?' . $this->view->escape(implode('&', $get));
  26. }
  27. protected function getSanitizedRequest()
  28. {
  29. if ($this->get === null) {
  30. $get = Env::Get();
  31. foreach ($get as $key => $value) {
  32. $this->get[$key] = $this->impl($key, $value);
  33. }
  34. }
  35. return $this->get;
  36. }
  37. protected function impl($name, $value)
  38. {
  39. if (is_array($value)) {
  40. $result = array();
  41. foreach ($value as $key => $val) {
  42. $result[] = $name . '[' . $key . ']=' . urlencode($val);
  43. }
  44. $result = implode('&', $result);
  45. } else {
  46. $result = $name . '=' . urlencode($value);
  47. }
  48. return $result;
  49. }
  50. }