Source for file Max.php

Documentation is available at Max.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Max.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: 14c12a1fa15fe1054ff8a4fc4f50017e2f8dfa43 $
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Validator_Max
  13. /**
  14.  *  最大値チェックプラグイン
  15.  *
  16.  *  @author     ICHII Takashi <ichii386@schweetheart.jp>
  17.  *  @access     public
  18.  *  @package    Ethna
  19.  */
  20. {
  21.     /** @var    bool    配列を受け取るかフラグ */
  22.     public $accept_array = false;
  23.  
  24.     /**
  25.      *  最大値のチェックを行う
  26.      *
  27.      *  @access public
  28.      *  @param  string  $name       フォームの名前
  29.      *  @param  mixed   $var        フォームの値
  30.      *  @param  array   $params     プラグインのパラメータ
  31.      */
  32.     public function validate($name$var$params)
  33.     {
  34.         $true true;
  35.         $type $this->getFormType($name);
  36.         if (isset($params['max']== false || $this->isEmpty($var$type)) {
  37.             return $true;
  38.         }
  39.  
  40.         switch ($type{
  41.             case VAR_TYPE_INT:
  42.                 if ($var $params['max']{
  43.                     if (isset($params['error'])) {
  44.                         $msg $params['error'];
  45.                     else {
  46.                         $msg _et('Please input less than %d(int) to {form}.');
  47.                     }
  48.                     return Ethna::raiseNotice($msgE_FORM_MAX_INTarray($params['max']));
  49.                 }
  50.                 break;
  51.  
  52.             case VAR_TYPE_FLOAT:
  53.                 if ($var $params['max']{
  54.                     if (isset($params['error'])) {
  55.                         $msg $params['error'];
  56.                     else {
  57.                         $msg _et('Please input less than %f(float) to {form}.');
  58.                     }
  59.                     return Ethna::raiseNotice($msgE_FORM_MAX_FLOATarray($params['max']));
  60.                 }
  61.                 break;
  62.  
  63.             case VAR_TYPE_DATETIME:
  64.                 $t_max strtotime($params['max']);
  65.                 $t_var strtotime($var);
  66.                 if ($t_var $t_max{
  67.                     if (isset($params['error'])) {
  68.                         $msg $params['error'];
  69.                     else {
  70.                         $msg _et('Please input datetime value before %s to {form}.');
  71.                     }
  72.                     return Ethna::raiseNotice($msgE_FORM_MAX_DATETIMEarray($params['max']));
  73.                 }
  74.                 break;
  75.  
  76.             case VAR_TYPE_FILE:
  77.                 $st stat($var['tmp_name']);
  78.                 if ($st[7$params['max'1024{
  79.                     if (isset($params['error'])) {
  80.                         $msg $params['error'];
  81.                     else {
  82.                         $msg _et('Please specify file whose size is less than %d KB to {form}.');
  83.                     }
  84.                     return Ethna::raiseNotice($msgE_FORM_MAX_FILEarray($params['max']));
  85.                 }
  86.                 break;
  87.  
  88.             case VAR_TYPE_STRING:
  89.  
  90.                 //
  91.                 //  マルチバイトエンコーディングと、そうでない場合で
  92.                 //  異なるプラグインを呼ぶ。
  93.                 //
  94.                 //  これは Ethna_Controller#client_encoding の値によ
  95.                 //  って動きが決まる
  96.                 //
  97.  
  98.                 $ctl Ethna_Controller::getInstance();
  99.                 $client_enc $ctl->getClientEncoding();
  100.                 $plugin $this->backend->getPlugin();
  101.  
  102.                 //  select Plugin.
  103.                 if (mb_enabled(&& strcasecmp('UTF-8'$client_enc== 0{
  104.                     $plugin_name 'Mbstrmax';
  105.                     $params['mbstrmax'$params['max'];
  106.                 elseif (strcasecmp('EUC-JP'$client_enc == 0)
  107.                        || strcasecmp('eucJP-win'$client_enc == 0)) {
  108.                     //  2.3.x compatibility
  109.                     $plugin_name 'Strmaxcompat';
  110.                     $params['strmaxcompat'$params['max'];
  111.                 else {
  112.                     $plugin_name 'Strmax';
  113.                     $params['strmax'$params['max'];
  114.                 }
  115.                 unset($params['max']);
  116.  
  117.                 $vld $plugin->getPlugin('Validator'$plugin_name);
  118.                 return $vld->validate($name$var$params);
  119.  
  120.                 break;
  121.         }
  122.  
  123.         return $true;
  124.     }
  125. }
  126. // }}}

Documentation generated on Fri, 11 Nov 2011 03:58:37 +0900 by phpDocumentor 1.4.3