| 59 | | $this->classMap = array( |
| 60 | | 'and' => array('class' => 'AgaviAndoperatorValidator', 'parameters' => array('break' => '1')), |
| 61 | | 'datetime' => array('class' => 'AgaviDateTimeValidator', 'parameters' => array('check' => '1')), |
| 62 | | 'email' => array('class' => 'AgaviEmailValidator', 'parameters' => array()), |
| 63 | | 'equals' => array('class' => 'AgaviEqualsValidator', 'parameters' => array()), |
| 64 | | 'file' => array('class' => 'AgaviFileValidator', 'parameters' => array()), |
| 65 | | 'imagefile' => array('class' => 'AgaviImageFileValidator', 'parameters' => array()), |
| 66 | | 'inarray' => array('class' => 'AgaviInarrayValidator', 'parameters' => array('sep' => ',')), |
| 67 | | 'isset' => array('class' => 'AgaviIssetValidator', 'parameters' => array()), |
| 68 | | 'isnotempty' => array('class' => 'AgaviIsNotEmptyValidator', 'parameters' => array()), |
| 69 | | 'not' => array('class' => 'AgaviNotoperatorValidator', 'parameters' => array()), |
| 70 | | 'number' => array('class' => 'AgaviNumberValidator', 'parameters' => array('type' => 'int')), |
| 71 | | 'or' => array('class' => 'AgaviOroperatorValidator', 'parameters' => array('break' => '1')), |
| 72 | | 'regex' => array('class' => 'AgaviRegexValidator', 'parameters' => array('match' => '1')), |
| 73 | | 'set' => array('class' => 'AgaviSetValidator', 'parameters' => array()), |
| 74 | | 'string' => array('class' => 'AgaviStringValidator', 'parameters' => array('min' => '1')), |
| 75 | | 'xor' => array('class' => 'AgaviXoroperatorValidator', 'parameters' => array()), |
| 76 | | ); |
| 77 | | |
| 78 | | // parse the config file |
| 79 | | $configurations = $this->orderConfigurations(AgaviConfigCache::parseConfig($config, true, $this->getValidationFile(), $this->parser)->configurations, AgaviConfig::get('core.environment'), $context); |
| 80 | | |
| | 61 | $document->setDefaultNamespace(self::XML_NAMESPACE, 'validators'); |
| | 62 | |
| | 63 | $config = $document->documentURI; |
| | 64 | |
| | 65 | $classMap = array(); |
| 94 | | |
| 95 | | if(isset($cfg->validators)) { |
| 96 | | $hasValidators = false; |
| 97 | | foreach($cfg->getChildren() as $validators) { |
| 98 | | if($validators->getName() == 'validators') { |
| 99 | | $hasValidators = true; |
| 100 | | $stdSeverity = $validators->getAttribute('severity', 'error'); |
| 101 | | $stdMethod = $validators->getAttribute('method'); |
| 102 | | foreach($validators as $validator) { |
| 103 | | $code = $this->getValidatorArray($validator, $code, $stdSeverity, 'validationManager', $stdMethod); |
| 104 | | } |
| 105 | | } |
| 106 | | } |
| 107 | | if(!$hasValidators) { |
| 108 | | foreach($cfg->validators as $validator) { |
| 109 | | $code = $this->getValidatorArray($validator, $code, 'error', 'validationManager', null); |
| 110 | | } |
| 111 | | } |
| 112 | | } |
| | 79 | |
| | 80 | $code = $this->processValidatorElements($cfg, $code, 'validationManager'); |
| 135 | | * @param AgaviConfigValueHolder The value holder of this validator. |
| 136 | | * @param array The code of old validators (we simply overwrite "old" |
| 137 | | * validators here). |
| 138 | | * @param string The severity of the parent container. |
| 139 | | * @param string The name of the parent container. |
| 140 | | * @param string The method of the parent container. |
| 141 | | * @param bool Whether the parent container is required. |
| 142 | | * |
| 143 | | * @return array php code blocks that register the validators |
| | 103 | * @param AgaviXmlConfigDomElement The value holder of this validator. |
| | 104 | * @param array The code of old validators (we simply |
| | 105 | * overwrite "old" validators here). |
| | 106 | * @param string The name of the parent container. |
| | 107 | * @param string The severity of the parent container. |
| | 108 | * @param string The method of the parent container. |
| | 109 | * @param bool Whether parent container is required. |
| | 110 | * |
| | 111 | * @return array PHP code blocks that register the validators |
| 181 | | $parameters = $this->getItemParameters($validator, $parameters); |
| 182 | | if(isset($validator->arguments)) { |
| 183 | | if($validator->arguments->hasAttribute('base')) { |
| 184 | | $parameters['base'] = $validator->arguments->getAttribute('base'); |
| 185 | | } |
| 186 | | $args = array(); |
| 187 | | foreach($validator->arguments as $argument) { |
| 188 | | if($argument->hasAttribute('name')) { |
| 189 | | $args[$argument->getAttribute('name')] = $argument->getValue(); |
| 190 | | } else { |
| 191 | | $args[] = $argument->getValue(); |
| | 150 | $parameters = $validator->getAgaviParameters($parameters); |
| | 151 | |
| | 152 | foreach($validator->get('arguments') as $argument) { |
| | 153 | // let's see if this buddy has a <arguments> parent with valuable information |
| | 154 | if($argument->parentNode->localName == 'arguments') { |
| | 155 | if($argument->parentNode->hasAttribute('base')) { |
| | 156 | $parameters['base'] = $argument->parentNode->getAttribute('base'); |
| 194 | | $arguments = $args; |
| 195 | | } |
| 196 | | if(isset($validator->errors)) { |
| 197 | | foreach($validator->errors as $error) { |
| 198 | | if($error->hasAttribute('for')) { |
| 199 | | $errors[$error->getAttribute('for')] = $error->getValue(); |
| 200 | | } else { |
| 201 | | $errors[''] = $error->getValue(); |
| 202 | | } |
| 203 | | } |
| 204 | | } |
| | 159 | |
| | 160 | if($argument->hasAttribute('name')) { |
| | 161 | $arguments[$argument->getAttribute('name')] = $argument->getValue(); |
| | 162 | } else { |
| | 163 | $arguments[] = $argument->getValue(); |
| | 164 | } |
| | 165 | } |
| | 166 | |
| | 167 | foreach($validator->get('errors') as $error) { |
| | 168 | if($error->hasAttribute('for')) { |
| | 169 | $errors[$error->getAttribute('for')] = $error->getValue(); |
| | 170 | } else { |
| | 171 | $errors[''] = $error->getValue(); |
| | 172 | } |
| | 173 | } |
| | 174 | |
| 235 | | |
| 236 | | if(isset($validator->validators)) { |
| 237 | | $childSeverity = $validator->validators->getAttribute('severity', $stdSeverity); |
| 238 | | $childMethod = $validator->validators->getAttribute('method', $stdMethod); |
| 239 | | $childRequired = $stdRequired; |
| 240 | | if($validator->validators->hasAttribute('required')) { |
| 241 | | $childRequired = AgaviToolkit::literalize($validator->validators->getAttribute('required')); |
| 242 | | } |
| 243 | | foreach($validator->validators as $v) { |
| 244 | | $code = $this->getValidatorArray($v, $code, $childSeverity, $name, $childMethod, $childRequired); |
| 245 | | } |
| 246 | | // create child validators |
| 247 | | } |
| 248 | | |
| | 205 | |
| | 206 | // more <validator> or <validators> children |
| | 207 | $code = $this->processValidatorElements($validator, $code, $name, $stdSeverity, $stdMethod, $stdRequired); |
| | 208 | |
| | 209 | return $code; |
| | 210 | } |
| | 211 | |
| | 212 | /** |
| | 213 | * Grabs generated code from the given element. |
| | 214 | * |
| | 215 | * @see AgaviValidatorConfigHandler::getValidatorArray() |
| | 216 | * |
| | 217 | * @param AgaviXmlConfigDomElement The value holder of this validator. |
| | 218 | * @param array The code of old validators (we simply |
| | 219 | * overwrite "old" validators here). |
| | 220 | * @param string The severity of the parent container. |
| | 221 | * @param string The name of the parent container. |
| | 222 | * @param string The method of the parent container. |
| | 223 | * @param bool Whether parent container is required. |
| | 224 | * |
| | 225 | * @return array PHP code blocks that register the validators |
| | 226 | * |
| | 227 | * @author Uwe Mesecke <uwe@mesecke.net> |
| | 228 | * @author Dominik del Bondio <ddb@bitxtender.com> |
| | 229 | * @author David Zülke <david.zuelke@bitextender.com> |
| | 230 | * @since 0.11.0 |
| | 231 | */ |
| | 232 | protected function processValidatorElements($node, $code, $name, $defaultSeverity = 'error', $defaultMethod = null, $defaultRequired = true) |
| | 233 | { |
| | 234 | // the problem here is that the <validators> parent is not just optional, but can also occur more than once |
| | 235 | foreach($node->get('validators') as $validator) { |
| | 236 | // let's see if this buddy has a <validators> parent with valuable information |
| | 237 | if($validator->parentNode->localName == 'validators') { |
| | 238 | $severity = $validator->parentNode->getAttribute('severity', $defaultSeverity); |
| | 239 | $method = $validator->parentNode->getAttribute('method', $defaultMethod); |
| | 240 | $required = $defaultRequired; |
| | 241 | } |
| | 242 | |
| | 243 | // append the code to generate |
| | 244 | $code = $this->getValidatorArray($validator, $code, $name, $severity, $method, $required); |
| | 245 | } |
| | 246 | |