00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 class RedirectView implements View
00017 {
00018 protected $url = null;
00019
00020 private $falseAsUnset = false;
00021
00022 public function __construct($url)
00023 {
00024 $this->url = $url;
00025 }
00026
00030 public static function create($url)
00031 {
00032 return new self($url);
00033 }
00034
00035 public function render($model = null)
00036 {
00037 $postfix = null;
00038
00039 if ($model && $model->getList()) {
00040 $qs = array();
00041
00042 foreach ($model->getList() as $key => $val) {
00043 if (
00044 (null === $val)
00045 || is_object($val)
00046 || is_array($val)
00047 ) {
00048 continue;
00049 } elseif (is_bool($val)) {
00050 if ($this->isFalseAsUnset() && (false === $val))
00051 continue;
00052
00053 $val = (int) $val;
00054 }
00055
00056 $qs[] = $key.'='.urlencode($val);
00057 }
00058
00059 if (strpos($this->getUrl(), '?') === false)
00060 $first = '?';
00061 else
00062 $first = '&';
00063
00064 if ($qs)
00065 $postfix = $first.implode('&', $qs);
00066 }
00067
00068 HeaderUtils::redirectRaw($this->getUrl().$postfix);
00069 }
00070
00071 public function getUrl()
00072 {
00073 return $this->url;
00074 }
00075
00076 public function isFalseAsUnset()
00077 {
00078 return $this->falseAsUnset;
00079 }
00080
00084 public function setFalseAsUnset($really)
00085 {
00086 Assert::isBoolean($really);
00087
00088 $this->falseAsUnset = $really;
00089
00090 return $this;
00091 }
00092 }
00093 ?>