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.

56 lines
1.4 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. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class ViewHelperGet extends ViewHelper
  12. {
  13. protected $get;
  14. public function get($replace)
  15. {
  16. $get = $this->getSanitizedRequest();
  17. if (!is_array($replace)) {
  18. $replace = array($replace);
  19. }
  20. foreach ($replace as $key => $value) {
  21. if (is_int($key)) {
  22. unset($get[$value]);
  23. } else {
  24. $get[$key] = $this->impl($key, $value);
  25. }
  26. }
  27. return '?' . $this->view->escape(implode('&', $get));
  28. }
  29. protected function getSanitizedRequest()
  30. {
  31. if ($this->get === null) {
  32. $get = Env::Get();
  33. foreach ($get as $key => $value) {
  34. $this->get[$key] = $this->impl($key, $value);
  35. }
  36. }
  37. return $this->get;
  38. }
  39. protected function impl($name, $value)
  40. {
  41. if (is_array($value)){
  42. $result = array();
  43. foreach ($value as $key => $val) {
  44. $result[] = $name . '[' . $key . ']=' . $val;
  45. }
  46. $result = implode('&', $result);
  47. } else {
  48. $result = $name . '=' . $value;
  49. }
  50. return $result;
  51. }
  52. }