Source for file Request.php

Documentation is available at Request.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * POST/GETで受け取った値を格納する
  20.  *
  21.  * @package     teeple
  22.  */
  23. {
  24.     /**
  25.      * POT/GETで受け取った値を保持する
  26.      * @var array 
  27.      */
  28.     private $_params;
  29.     
  30.     /**
  31.      * @var array 
  32.      */
  33.     private $errorList array();
  34.     
  35.     /**
  36.      * @var string 
  37.      */
  38.     private $filterError;
  39.     
  40.     /**
  41.      * @var string 
  42.      */
  43.     private $actionMethod;
  44.     
  45.     /**
  46.      * Actionの実行が完了したかどうか
  47.      * @var boolean 
  48.      */
  49.     private $completeActionFlg FALSE;
  50.     
  51.     /**
  52.      * Responseの返却が完了したかどうか
  53.      * @var boolean 
  54.      */
  55.     private $completeResponseFlg FALSE;
  56.     
  57.     /**
  58.      * 
  59.      * @var boolean 
  60.      */
  61.     public $isRedirect = FALSE;
  62.         
  63.     /**
  64.      * @var Logger 
  65.      */
  66.     private $log;
  67.  
  68.     /**
  69.      * コンストラクタ
  70.      *
  71.      */
  72.     public function __construct({
  73.  
  74.         $this->log LoggerManager::getLogger(get_class($this));
  75.         
  76.         $request array_merge($_POST$_GET);
  77.         if (get_magic_quotes_gpc()) {
  78.             $request $this->_stripSlashesDeep($request);
  79.         }
  80.         if (!ini_get("mbstring.encoding_translation"&&
  81.             (INPUT_CODE != INTERNAL_CODE)) {
  82.              mb_convert_variables(INTERNAL_CODEINPUT_CODE$request);
  83.         }
  84.         
  85.         // action:~ではじまるパラメータがあればactionMethodをセットする
  86.         $methodName "execute";
  87.         $key NULL;
  88.         foreach($request as $k => $val{
  89.             if (preg_match('/^action:(.+)$/'$k$m)) {
  90.                 $methodName $m[1];
  91.                 $this->log->debug("actionMethodが指定されました。 {$methodName}");
  92.                 $key $k;
  93.                 break;
  94.             }
  95.         }
  96.         $this->actionMethod $methodName;
  97.         if ($key != NULL{
  98.             unset($request[$key]);
  99.         }
  100.  
  101.         $this->_params $request;
  102.         
  103.         return;
  104.     }
  105.     
  106.     /**
  107.      * stripslashes() 関数を再帰的に実行する
  108.      *
  109.      * @param   mixed  $value  処理する変数
  110.      * @return  mixed  処理結果
  111.      * @see     http://www.php.net/manual/ja/function.stripslashes.php#AEN181588
  112.      */
  113.     private function _stripSlashesDeep($value{
  114.  
  115.         if (is_array($value)) {
  116.             $value array_map(array($this'_stripSlashesDeep')$value);
  117.         else {
  118.             $value stripslashes($value);
  119.         }
  120.         return $value;
  121.     }
  122.  
  123.     /**
  124.      * REQUEST_METHODの値を返却
  125.      *
  126.      * @return  string  REQUEST_METHODの値
  127.      */
  128.     public function getMethod({
  129.         return $_SERVER["REQUEST_METHOD"];
  130.     }
  131.  
  132.     /**
  133.      * POST/GETの値を返却
  134.      *
  135.      * @param   string  $key    パラメータ名
  136.      * @return  string  パラメータの値
  137.      */
  138.     public function getParameter($key{
  139.         return isset($this->_params[$key]?
  140.             $this->_params[$keyNULL;
  141.     }
  142.  
  143.     /**
  144.      * POST/GETの値をセット
  145.      *
  146.      * @param   string  $key    パラメータ名
  147.      * @param   string  $value  パラメータの値
  148.      */
  149.     function setParameter($key$value{
  150.         $this->_params[$key$value;
  151.     }
  152.  
  153.     /**
  154.      * リクエストパラメータを削除する
  155.      *
  156.      * @param string $key 
  157.      */
  158.     function removeParameter($key{
  159.         unset($this->_params[$key]);
  160.     }
  161.     
  162.     /**
  163.      * POST/GETの値を返却(配列で返却)
  164.      *
  165.      * @param   string  $key    パラメータ名
  166.      * @return  array  パラメータの値(配列)
  167.  
  168.      */
  169.     function getParameters({
  170.         return $this->_params;
  171.     }
  172.  
  173.     /**
  174.      * エラーメッセージを追加します。
  175.      *
  176.      * @param string $message 
  177.      * @param string $target 
  178.      */
  179.     public function addErrorMessage($message$target="__DEFAULT"{
  180.         
  181.         if (isset($this->errorList[$target])) {
  182.             $this->errorList[$targetarray();
  183.         }
  184.         $this->errorList[$target][$message;
  185.         return;
  186.     }
  187.     
  188.     /**
  189.      * エラーがあるかどうか
  190.      *
  191.      * @return boolean 
  192.      */
  193.     public function isError({
  194.         return count($this->errorList0;
  195.     }
  196.     
  197.     /**
  198.      * 指定されたtargetのエラーメッセージを取得します。
  199.      *
  200.      * @param string $target 
  201.      * @return array 
  202.      */
  203.     public function getErrorMessages($target=NULL{
  204.         
  205.         if ($target == NULL{
  206.             return $this->getAllErrorMessages();
  207.         }
  208.         return isset($this->errorList[$target]?
  209.             $this->errorList[$targetarray();
  210.     }
  211.     
  212.     /**
  213.      * 全てのエラーメッセージを取得します。
  214.      *
  215.      * @return array 
  216.      */
  217.     public function getAllErrorMessages({
  218.         
  219.         $allmessages array();
  220.         foreach($this->errorList as $target => $errors{
  221.             $allmessages array_merge($allmessages$errors);
  222.         }
  223.         return $allmessages;
  224.     }
  225.     
  226.     /**
  227.      * エラーメッセージをクリアします。
  228.      *
  229.      */
  230.     public function resetErrorMessages({
  231.         $this->errorList array();
  232.         return;
  233.     }
  234.     
  235.     public function setFilterError($errorType{
  236.         $this->filterError $errorType;
  237.         return;
  238.     }
  239.     
  240.     public function getFilterError({
  241.         return $this->filterError;
  242.     }
  243.     
  244.     public function isFilterError({
  245.         return isset($this->filterError&& strlen($this->filterError);
  246.     }
  247.     
  248.     public function getActionMethod({
  249.         return $this->actionMethod;
  250.     }
  251.     
  252.     public function setActionMethod($method{
  253.         $this->actionMethod $method;
  254.     }
  255.     
  256.     
  257.     /**
  258.      * Actionの完了をセットします。
  259.      *
  260.      */
  261.     public function completeAction({
  262.         $this->completeActionFlg TRUE;
  263.     }
  264.     
  265.     /**
  266.      * Responseの完了をセットします。
  267.      *
  268.      */
  269.     public function completeResponse({
  270.         $this->completeActionFlg TRUE;
  271.         $this->completeResponseFlg TRUE;
  272.     }
  273.     
  274.     /**
  275.      * Actionが完了したかどうか?
  276.      * @return boolean 
  277.      */
  278.     public function isCompleteAction({
  279.         return $this->completeActionFlg;
  280.     }
  281.     
  282.     /**
  283.      * Responseが完了したかどうか?
  284.      * @return boolean 
  285.      */
  286.     public function isCompleteResponse({
  287.         return $this->completeResponseFlg;
  288.     }
  289.     
  290.     public function resetCompleteFlag({
  291.         $this->completeActionFlg FALSE;
  292.         $this->completeResponseFlg FALSE;
  293.     }    
  294.  
  295. }
  296. ?>

Documentation generated on Mon, 26 Apr 2010 08:59:54 +0900 by phpDocumentor 1.4.3