/** * Gets the function from the function map and runs it against the values. * * @param string $propertyName * @param string $funcName * @param array $arguments * @param array $errorValues * @param array $errors * * @throws \InvalidArgumentException * @return bool */ public function get($propertyName, $funcName, array $arguments = [], array &$errorValues = [], array &$errors) { if (false === \array_key_exists($funcName, $this->functionMap)) { throw new \InvalidArgumentException(\sprintf('Validator key \'%s\' not found', $funcName)); } $function = $this->functionMap[$funcName]; $class = \explode("::", $function); try { $result = \call_user_func_array([$class[0], $class[1]], $arguments); if (false === $result) { $funcName = $this->funcNameToUnderscore($funcName); if (false === \array_key_exists($funcName, $errors)) { throw new \InvalidArgumentException(\sprintf('Validator key \'%s\' not found in error file', $funcName)); } if (\strlen($errors[$funcName]) > 0) { $this->validator->setError($this->buildErrorMessage($errorValues, $errors, $funcName, $propertyName), $funcName); } } } catch (FileUploadException $e) { $lowerCaseFuncName = $this->funcNameToUnderscore($e->getMessage()); $this->validator->setError($this->buildErrorMessage($errorValues, $errors, $e->getMessage(), $propertyName), $lowerCaseFuncName); $result = false; } return $result; }
/** * @param $value * @param AbstractValidator $keyValidator * * @return bool */ public static function hasKeyFormat($value, AbstractValidator $keyValidator) { if ($value instanceof \ArrayObject) { $value = $value->getArrayCopy(); } if ($value instanceof \SplFixedArray) { $value = $value->toArray(); } $arrayKeys = \array_keys($value); $isValid = true; foreach ($arrayKeys as $key) { $isValid = $isValid && $keyValidator->validate($key); } return $isValid; }
/** * @param string $uploadName * @param AbstractValidator $validator * * @return bool */ public static function hasFileNameFormat($uploadName, AbstractValidator $validator) { if (isset($_FILES[$uploadName]['name']) && \is_array($_FILES[$uploadName]['name'])) { $isValid = true; foreach ($_FILES[$uploadName]['name'] as $name) { $isValid = $isValid && $validator->validate($name); } return $isValid; } return $validator->validate($_FILES[$uploadName]['name']); }
/** * @param string $propertyName * @param Validator $validator * @param array $errorMessages * @param array $functionMap */ public function __construct($propertyName, Validator $validator, array &$errorMessages, array &$functionMap) { parent::__construct($propertyName, $validator, $errorMessages, $functionMap); $this->addCondition(__METHOD__); }