RedirectView.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     class RedirectView extends CleanRedirectView
00016     {
00017         private $falseAsUnset = null;
00018         private $buildArrays = null;
00019         
00023         public static function create($url)
00024         {
00025             return new self($url);
00026         }
00027         
00028         public function isFalseAsUnset()
00029         {
00030             return $this->falseAsUnset;
00031         }
00032         
00036         public function setFalseAsUnset($really)
00037         {
00038             Assert::isBoolean($really);
00039             
00040             $this->falseAsUnset = $really;
00041             
00042             return $this;
00043         }
00044         
00045         public function isBuildArrays()
00046         {
00047             return $this->buildArrays;
00048         }
00049         
00053         public function setBuildArrays($really)
00054         {
00055             Assert::isBoolean($really);
00056             
00057             $this->buildArrays = $really;
00058             
00059             return $this;
00060         }
00061         
00062         protected function getLocationUrl($model = null)
00063         {
00064             $postfix = null;
00065             
00066             if ($model && $model->getList()) {
00067                 $qs = array();
00068                 
00069                 foreach ($model->getList() as $key => $val) {
00070                     if (
00071                         (null === $val)
00072                         || is_object($val)
00073                     ) {
00074                         continue;
00075                     } elseif (is_array($val)) {
00076                         if ($this->buildArrays) {
00077                             $qs[] = http_build_query(
00078                                 array($key => $val), null, '&'
00079                             );
00080                         }
00081                         
00082                         continue;
00083                         
00084                     } elseif (is_bool($val)) {
00085                         if ($this->isFalseAsUnset() && (false === $val))
00086                             continue;
00087                         
00088                         $val = (int) $val;
00089                     }
00090                     
00091                     $qs[] = $key.'='.urlencode($val);
00092                 }
00093                 
00094                 if (strpos($this->getUrl(), '?') === false)
00095                     $first = '?';
00096                 else
00097                     $first = '&';
00098                     
00099                 if ($qs)
00100                     $postfix = $first.implode('&', $qs);
00101             }
00102             
00103             return $this->getUrl().$postfix;
00104         }
00105     }
00106 ?>