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 /* $Id: RedirectView.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4