Source for file Validator.php

Documentation is available at Validator.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Validator.php
  5.  *
  6.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id: 76a1a75df5d9f9d628a48e3fa453e14414f349db $
  10.  */
  11.  
  12. // UPLOAD_ERR_* が未定義の場合 (PHP 4.3.0 以前)
  13. if (defined('UPLOAD_ERR_OK'== false{
  14.     define('UPLOAD_ERR_OK'0);
  15. }
  16.  
  17. // {{{ Ethna_Plugin_Validator
  18. /**
  19.  *  バリデータプラグインの基底クラス
  20.  *  
  21.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  22.  *  @access     public
  23.  *  @package    Ethna
  24.  */
  25. {
  26.     /**#@+
  27.      *  @access private
  28.      */
  29.  
  30.     /** @var    bool    配列を受け取るバリデータかどうかのフラグ */
  31.     public $accept_array = false;
  32.  
  33.     /**#@-*/
  34.  
  35.     /**
  36.      *  フォーム値検証のためにActionFormから呼び出されるメソッド
  37.      *
  38.      *  @access public
  39.      *  @param  string  $name       フォームの名前
  40.      *  @param  mixed   $var        フォームの値
  41.      *  @param  array   $params     プラグインのパラメータ
  42.      */
  43.     public function validate($name$var$params)
  44.     {
  45.         die('override!');
  46.     }
  47.  
  48.     /**
  49.      *  フォーム定義を取得する
  50.      *
  51.      *  @access public
  52.      *  @param  string  $name       フォームの名前
  53.      */
  54.     public function getFormDef($name)
  55.     {
  56.         return $this->af->getDef($name);
  57.     }
  58.  
  59.     /**
  60.      *  フォームのtypeを取得する(配列の場合は値のみ)
  61.      *
  62.      *  @access public
  63.      *  @param  string  $name       フォームの名前
  64.      */
  65.     public function getFormType($name)
  66.     {
  67.         $def $this->af->getDef($name);
  68.         if (isset($def['type'])) {
  69.             if (is_array($def['type'])) {
  70.                 return $def['type'][0];
  71.             else {
  72.                 return $def['type'];
  73.             }
  74.         else {
  75.             return null;
  76.         }
  77.     }
  78.  
  79.     /**
  80.      *  フォーム値が空かどうかを判定 (配列フォームの場合は各要素に対して呼び出す)
  81.      *
  82.      *  @access protected
  83.      *  @param  mixed   $var       フォームの値 (配列フォームの場合は各要素)
  84.      *  @param  int     $type      フォームのtype
  85.      */
  86.     protected function isEmpty($var$type)
  87.     {
  88.         if ($type == VAR_TYPE_FILE{
  89.             if (isset($var['error']== false || $var['error'!= UPLOAD_ERR_OK{
  90.                 return true;
  91.             }
  92.             if (isset($var['tmp_name']== false || is_uploaded_file($var['tmp_name']== false{
  93.                 return true;
  94.             }
  95.             if (isset($var['size']== false || $var['size'== 0{
  96.                 return true;
  97.             }
  98.         else {
  99.             if (is_scalar($var== false || strlen($var== 0{
  100.                 return true;
  101.             }
  102.         }
  103.         return false;
  104.     }
  105.  
  106.     /**
  107.      *  return true
  108.      *
  109.      *  @access protected
  110.      */
  111.     protected function ok()
  112.     {
  113.         $true true;
  114.         return $true;
  115.     }
  116.  
  117.     /**
  118.      *  return error
  119.      *
  120.      *  @access protected
  121.      *  @param  string  $msg        エラーメッセージ
  122.      *  @param  int     $code       エラーコード
  123.      *  @param  mixed   $info       エラーメッセージにsprintfで渡すパラメータ
  124.      */
  125.     protected function error($msg$code$info null)
  126.     {
  127.         if ($info != null{
  128.             if (is_array($info)) {
  129.                 return Ethna::raiseNotice($msg$code$info);
  130.             else {
  131.                 return Ethna::raiseNotice($msg$codearray($info));
  132.             }
  133.         else {
  134.             return Ethna::raiseNotice($msg$code);
  135.         }
  136.     }
  137. }
  138. // }}}

Documentation generated on Fri, 11 Nov 2011 03:59:21 +0900 by phpDocumentor 1.4.3