Ejemplo n.º 1
0
 /**
 @param	rules	string or array	
 	Rules can be an array of rules, or a string separated by "," for each rule.  
 	Each rule can be a string or an array.  
 	As a string, the rule should be in one of the following forms:
 			"f:name|param1;param2" indicates InputFilter method
 			"v:name|param1;param2" indicates InputValidate function
 			"g:name|param1;param2" indicates global scoped function
 			"class:name|param1,param2,param3" indicates static method "name: of class "class" 
 			"l:name|param1,param2,param3" Local tool method
 			"name" replaced by Field fieldType of the same name
 	As an array, the rule function part (type:method) is the first element, and the parameters to the function part are the following elements.  Useful if function arguments contain commas or semicolons.  Ex:
 		array('type:method','arg1','arg2','arg3')
 	
 	The "type:method" part can be prefixed with "!" to indicate there should be a break on error, and no more rules for that field should be applied
 	The "type:method" part can be prefixed with "!!" to indicate there should be a break on error and no more rules for any field should be applied
 	
 	If array, first part of rule is taken as string with the behavior above without parameters and the second part is taken as the parameters; useful for parameters that include commas or semicolons or which aren't strings
 	
 	Examples for rules:
 		1: 'v:email|bob.com,customClass:method|param1;param2',
 		2: array('v:email|bob.com','customClass:method|param1;param2'),
 		3: array(array('v:email','bob.com'),array('customClass:method','param1','param2')),
 */
 function applyFilterValidateRules($field, $rules, $errorOptions)
 {
     $originalRules = $rules;
     $rules = Arrays::stringArray($rules);
     for ($i = 0; $i < count($rules); $i++) {
         $rule = $rules[$i];
         $params = array(&$this->in[$field]);
         if (is_array($rule)) {
             $callback = array_shift($rule);
             $params2 =& $rule;
         } else {
             list($callback, $params2) = explode('|', $rule);
             if ($params2) {
                 $params2 = explode(';', $params2);
             }
         }
         ///merge field value param with the user provided params
         if ($params2) {
             Arrays::mergeInto($params, $params2);
         }
         //used in combination with !, like ?! for fields that, if not empty, should be validated, otherwise, ignored.
         $ignoreError = false;
         if (substr($callback, 0, 1) == '?') {
             $callback = substr($callback, 1);
             $ignoreError = true;
         }
         if (substr($callback, 0, 2) == '!!') {
             $callback = substr($callback, 2);
             $superBreak = true;
         }
         if (substr($callback, 0, 1) == '!') {
             $callback = substr($callback, 1);
             $break = true;
         }
         list($type, $method) = explode(':', $callback, 2);
         if (!$method) {
             $method = $type;
             $type = '';
         }
         if (!$method) {
             Debug::quit('Failed to provide method for input handler on field: ' . $field, 'Rules:', $rules);
         }
         try {
             switch ($type) {
                 case 'f':
                     call_user_func_array(array('InputFilter', $method), $params);
                     break;
                 case 'v':
                     call_user_func_array(array('InputValidate', $method), $params);
                     break;
                 case 'l':
                     call_user_func_array(array($this->lt, $method), $params);
                     break;
                 case 'g':
                     call_user_func_array($method, $params);
                     break;
                 case '':
                     if ($this->inputRuleAliases === null) {
                         $this->inputRuleAliases = \control\Field::$ruleAliases;
                     }
                     //get new named rules and parse
                     if (!$this->inputRuleAliases[$method]) {
                         Debug::toss('Unknown input rule alias on field ' . $field . ' Rule:' . $rule);
                     }
                     $newRules = Arrays::stringArray($this->inputRuleAliases[$method]);
                     if ($i + 1 < count($rules)) {
                         ///there are rules after this alias, so combine alias with those existing after
                         $newRules = array_merge($newRules, array_slice($rules, $i + 1));
                     }
                     $rules = $newRules;
                     $i = -1;
                     break;
                 default:
                     call_user_func_array(array($type, $method), $params);
                     break;
             }
         } catch (InputException $e) {
             //add error to messages
             if (!$ignoreError) {
                 $this->error($e->getMessage(), $field, $errorOptions);
             }
             //super break will break out of all fields
             if ($superBreak) {
                 return false;
             }
             //break will stop validators for this one field
             if ($break) {
                 break;
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 static function fileList($dir, $prefix = '', $filterFn = null)
 {
     $realPath = realpath($dir) . '/';
     $files = array();
     foreach (scandir($realPath) as $v) {
         if ($v != '.' && $v != '..') {
             if (is_dir($realPath . $v)) {
                 $newFiles = self::fileLIst($realPath . $v, $prefix . $v . '/');
                 Arrays::mergeInto($files, $newFiles);
             } else {
                 if (!$filterFn || $filterFn($prefix . $v)) {
                     $files[] = $prefix . $v;
                 }
             }
         }
     }
     return $files;
 }