Example #1
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (is_null($params) || !is_int($params)) {
         throw new Exception('Please provide the maximum length as an integer parameter');
     }
     $oField->setValue(substr($oField->getValue(), 0, $params));
 }
Example #2
0
 public static function process(FormChecker_Field &$oField, $params)
 {
     if (!is_array($params)) {
         $oField->raiseError('Les paramètres pour le fichier n\'ont pas été spécifiés');
     }
     if (!isset($params['directory'])) {
         $oField->raiseError('Veuillez indiquer le répertoire de stockage');
     }
     if (!isset($params['filename']) && !isset($params['rename_callback'])) {
         $oField->raiseError('Veuillez indiquer le nom du fichier à stocker ou une callback de renommage');
     }
     if (isset($params['rename_callback']) && !is_callable($params['rename_callback'])) {
         $oField->raiseError('Callback introuvable');
     }
     if (DIRECTORY_SEPARATOR != substr($params['directory'], -1)) {
         $params['directory'] .= DIRECTORY_SEPARATOR;
     }
     $value = $oField->getValue();
     if (!is_array($value)) {
         $oField->raiseError('Wrong value format');
     } else {
         if (!@file_exists($params['directory'])) {
             @mkdir($params['directory']);
         }
         if (isset($params['rename_callback'])) {
             $params['filename'] = call_user_func_array($params['rename_callback'], array($value['name']));
         }
         if (!move_uploaded_file($value['tmp_name'], $params['directory'] . $params['filename'])) {
             return $oField->raiseError('Le fichier n\'a pu être copié');
         }
         $oField->setValue($params['filename']);
     }
 }
Example #3
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (!isset($params['pattern'])) {
         throw new Exception('Please provide the "pattern" parameter to the Replace modifier');
     }
     if (!isset($params['replacement'])) {
         throw new Exception('Please provide the "replacement" parameter to the Replace modifier');
     }
     $oField->setValue(preg_replace($params['pattern'], $params['replacement'], $oField->getValue()));
 }
Example #4
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     if (!isset($params['char'])) {
         throw new Exception('Please provide the "char" parameter to the Pad modifier');
     }
     if (!isset($params['len'])) {
         throw new Exception('Please provide the "len" parameter to the Pad modifier');
     }
     $padType = STR_PAD_BOTH;
     if (isset($params['type'])) {
         if ('left' == $params['type']) {
             $padType = STR_PAD_LEFT;
         } elseif ('right' == $params['type']) {
             $padType = STR_PAD_RIGHT;
         }
     }
     $oField->setValue(str_pad($oField->getValue(), $params['len'], $params['char'], $padType));
 }
Example #5
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     $oField->setValue(mb_strtolower($oField->getValue()));
 }
Example #6
0
 public function process(FormChecker_Field &$oField, $params = null)
 {
     $oField->setValue(strip_tags($oField->getValue()));
 }