Request.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ class FF_Request
00024 
00035 // }}}
00036 class FF_Request {
00037     // {{{ setParam()
00038 
00051     function setParam($in_varName, $in_val, $in_type)
00052     {
00053         $a_vars = array('c' => '$_COOKIE', 
00054                         'p' => '$_POST', 
00055                         'g' => '$_GET', 
00056                         's' => '$_SESSION', 
00057                         'f' => '$_FILES');
00058         // Set the variable in each requested type
00059         for ($i = 0; $i < strlen($in_type); $i++) {
00060             // Switch's aren't great, but variable variables of superglobals don't work in functions
00061             switch ($in_type{$i}) {
00062                 case 'g':
00063                     $_GET[$in_varName] = $in_val;
00064                 break;
00065                 case 'p':
00066                     $_POST[$in_varName] = $in_val;
00067                 break;
00068                 case 's':
00069                     $_SESSION[$in_varName] = $in_val;
00070                 break;
00071                 case 'c':
00072                     $_COOKIE[$in_varName] = $in_val;
00073                 break;
00074             }
00075         }
00076     }
00077 
00078     // }}}
00079     // {{{ getParam()
00080 
00100     function getParam($in_varName, $in_type = 'gpc', $in_default = null)
00101     {
00102         static $b_init;
00103         if (!isset($b_init)) {
00104             $b_init = true;
00105             if (get_magic_quotes_gpc()) {
00106                 $_POST = FF_Request::stripslashesDeep($_POST);
00107                 $_GET = FF_Request::stripslashesDeep($_GET);
00108                 $_COOKIE = FF_Request::stripslashesDeep($_COOKIE);
00109             }
00110         }
00111 
00112         // Get the variable from the first variable type in which it is present
00113         for ($i = 0; $i < strlen($in_type); $i++) {
00114             switch($in_type{$i}) {
00115                 case 'g':
00116                     if (isset($_GET[$in_varName])) {
00117                         return $_GET[$in_varName];
00118                     }
00119                 break;
00120                 case 'p':
00121                     if (isset($_POST[$in_varName])) {
00122                         return $_POST[$in_varName];
00123                     }
00124                 break;
00125                 case 's':
00126                     if (isset($_SESSION[$in_varName])) {
00127                         return $_SESSION[$in_varName];
00128                     }
00129                 break;
00130                 case 'c':
00131                     if (isset($_COOKIE[$in_varName])) {
00132                         return $_COOKIE[$in_varName];
00133                     }
00134                 break;
00135                 case 'f':
00136                     if (isset($_FILES[$in_varName])) {
00137                         return $_FILES[$in_varName];
00138                     }
00139                 break;
00140             }
00141         }
00142 
00143         return $in_default;
00144     }
00145 
00146     // }}}
00147     // {{{ unsetCookies()
00148 
00160     function unsetCookies($in_names, $in_path = '/', $in_domain = '') 
00161     {
00162         foreach ((array) $in_names as $s_name) {
00163             setcookie($s_name, '', time() - 3600, $in_path, $in_domain); 
00164             FF_Request::setParam($s_name, null, 'c'); 
00165         }
00166     }
00167 
00168     // }}}
00169     // {{{ setCookies()
00170 
00186     function setCookies($in_nameValues, $in_expire = 0, $in_path = '/', $in_domain = '')
00187     {
00188         foreach((array) $in_nameValues as $s_name => $s_value) {
00189             setcookie($s_name, $s_value, $in_expire, $in_path, $in_domain); 
00190             FF_Request::setParam($s_name, $s_value, 'c'); 
00191         }
00192     }
00193 
00194     // }}}
00195     // {{{ stripslashesDeep()
00196 
00205     function stripslashesDeep($in_var)
00206     {
00207         if (is_array($in_var)) {
00208             $in_var = array_map(array('FF_Request', 'stripslashesDeep'), $in_var);
00209         }
00210         else {
00211             // Stripslashes makes false turn to empty
00212             if (!is_bool($in_var)) {
00213                 $in_var = stripslashes($in_var);
00214             }
00215         }
00216 
00217         return $in_var;
00218     }
00219 
00220     // }}}
00221 }
00222 ?>

Generated on Fri Jun 23 11:38:17 2006 for FastFrame by  doxygen 1.4.4