/** * Sets calls. * * @param type $args * @param type $value * @return type */ public static function check($args, $value) { // Init validation object if (is_null(self::$_validation_object)) { self::$_validation_object = new Toolset_CakePHP_Validation(); } // Init messages if (is_null(self::$messages)) { self::_set_messages(); } // Check if there is 'required' method if (array_key_exists('required', $args)) { self::$_is_required = true; } // Loop over validation array foreach ($args as $method => $v) { // Use this class method if (is_callable(array('Toolset_Validate', $method))) { $check = call_user_func_array(array('Toolset_Validate', $method), array($v, $value)); // Use CakePHP method } else { if (isset(self::$_cake_aliases[$method]) && is_callable(array('Toolset_CakePHP_Validation', self::$_cake_aliases[$method])) || is_callable(array('Toolset_CakePHP_Validation', $method))) { // Check if validation pattern is set if (isset($v['pattern'])) { $pattern = array_flip(explode('.', $v['pattern'])); foreach ($pattern as $arg_key => $arg_value) { if (isset($v[$arg_key])) { $pattern[$arg_key] = $v[$arg_key]; } } $pattern['check'] = $value; $v = $pattern; // Apply simple pattern (check, value) } else { unset($v['active'], $v['message']); $v = array($value) + $v; } // Validate if (isset(self::$_cake_aliases[$method]) && is_callable(array('Toolset_CakePHP_Validation', self::$_cake_aliases[$method]))) { // $check = @call_user_func_array(array('Toolset_CakePHP_Validation', self::$_cake_aliases[$method]), // array_values($v)); $check = @call_user_func_array(array(self::$_validation_object, self::$_cake_aliases[$method]), array_values($v)); } else { // $check = @call_user_func_array(array('Toolset_CakePHP_Validation', $method), // array_values($v)); $check = @call_user_func_array(array(self::$_validation_object, $method), array_values($v)); } if (!$check) { $check = array(); $check['error'] = 1; } // No method available } else { return array('error' => 1, 'message' => 'No validation method'); } } // Set error if (isset($check['error'])) { // Don't return error if it's empty but not required if (!empty($value) && $method != 'required' && self::$_is_required || empty($value) && $method == 'required') { $check['message'] = !empty($v['message']) ? $v['message'] : self::$messages[$method]; return $check; } } } return true; }