Changeset 2618
- Timestamp:
- 05/02/08 13:16:13 (2 months ago)
- Files:
-
- trunk/system/libraries/Validation.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/system/libraries/Validation.php
r2590 r2618 15 15 protected $any_field; 16 16 17 // Array fields 18 protected $array_fields = array(); 19 17 20 // Filters 18 21 protected $pre_filters = array(); … … 164 167 foreach ($fields as $field) 165 168 { 169 if (strpos($field, '.') > 0) 170 { 171 // Field keys 172 $keys = explode('.', $field); 173 174 // Add to array fields 175 $this->array_fields[$field] = $keys[0]; 176 } 177 166 178 // Add the filter to specified field 167 179 $this->pre_filters[$field][] = $filter; … … 200 212 foreach ($fields as $field) 201 213 { 214 if (strpos($field, '.') > 0) 215 { 216 // Field keys 217 $keys = explode('.', $field); 218 219 // Add to array fields 220 $this->array_fields[$field] = $keys[0]; 221 } 222 202 223 // Add the filter to specified field 203 224 $this->post_filters[$field][] = $filter; … … 259 280 $rule = (is_string($rule) AND strpos($rule, '::') !== FALSE) ? explode('::', $rule) : $rule; 260 281 282 if (strpos($field, '.') > 0) 283 { 284 // Field keys 285 $keys = explode('.', $field); 286 287 // Add to array fields 288 $this->array_fields[$field] = $keys[0]; 289 } 290 261 291 // Add the rule to specified field 262 292 $this->rules[$field][] = array($rule, $args); … … 297 327 298 328 $callback = (is_string($callback) AND strpos($callback, '::') !== FALSE) ? explode('::', $callback) : $callback; 329 330 if (strpos($field, '.') > 0) 331 { 332 // Field keys 333 $keys = explode('.', $field); 334 335 // Add to array fields 336 $this->array_fields[$field] = $keys[0]; 337 } 299 338 300 339 // Add the callback to specified field … … 333 372 } 334 373 335 // Make sure all fields are defined 336 isset($this[$field]) or $this[$field] = NULL; 374 if (isset($this->array_fields[$field])) 375 { 376 // Use the first key for the field 377 $field_key = $this->array_fields[$field]; 378 379 // Load the field as an array 380 $this[$field_key] = (array) Kohana::key_string($field, $this); 381 } 382 else 383 { 384 // Make sure all fields are defined 385 isset($this[$field]) or $this[$field] = NULL; 386 } 337 387 } 338 388 … … 374 424 foreach ($all_fields as $f) 375 425 { 376 // Prevent other rules from running when this field already has errors 377 if ( ! empty($this->errors[$f])) break; 378 379 // Don't process rules on empty fields 380 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$f] == NULL) 381 continue; 382 383 // Run each rule 384 if ( ! call_user_func($func, $this[$f], $args)) 426 if (isset($this->array_fields[$f])) 385 427 { 386 $this->errors[$f] = is_array($func) ? $func[1] : $func; 428 // Use the field key 429 $f_key = $this->array_fields[$f]; 430 431 // Prevent other rules from running when this field already has errors 432 if ( ! empty($this->errors[$f_key])) break; 433 434 // Don't process rules on empty fields 435 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$f_key] == NULL) 436 continue; 437 438 foreach ($this[$f_key] as $k => $v) 439 { 440 if ( ! call_user_func($func, $this[$f_key][$k], $args)) 441 { 442 // Run each rule 443 $this->errors[$f_key] = is_array($func) ? $func[1] : $func; 444 } 445 } 446 } 447 else 448 { 449 // Prevent other rules from running when this field already has errors 450 if ( ! empty($this->errors[$f])) break; 451 452 // Don't process rules on empty fields 453 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$f] == NULL) 454 continue; 455 456 if ( ! call_user_func($func, $this[$f], $args)) 457 { 458 // Run each rule 459 $this->errors[$f] = is_array($func) ? $func[1] : $func; 460 } 387 461 } 388 462 } … … 390 464 else 391 465 { 392 // Prevent other rules from running when this field already has errors 393 if ( ! empty($this->errors[$field])) break; 394 395 // Don't process rules on empty fields 396 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$field] == NULL) 397 continue; 398 399 // Run each rule 400 if ( ! call_user_func($func, $this[$field], $args)) 466 if (isset($this->array_fields[$field])) 401 467 { 402 $this->errors[$field] = is_array($func) ? $func[1] : $func; 403 // Stop after an error is found 404 break; 468 // Use the field key 469 $field_key = $this->array_fields[$field]; 470 471 // Prevent other rules from running when this field already has errors 472 if ( ! empty($this->errors[$field_key])) break; 473 474 // Don't process rules on empty fields 475 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$field_key] == NULL) 476 continue; 477 478 foreach ($this[$field_key] as $k => $val) 479 { 480 if ( ! call_user_func($func, $this[$field_key][$k], $args)) 481 { 482 // Run each rule 483 $this->errors[$field_key] = is_array($func) ? $func[1] : $func; 484 485 // Stop after an error is found 486 break 2; 487 } 488 } 489 } 490 else 491 { 492 // Prevent other rules from running when this field already has errors 493 if ( ! empty($this->errors[$field])) break; 494 495 // Don't process rules on empty fields 496 if ( ! in_array($func[1], $this->empty_rules, TRUE) AND $this[$field] == NULL) 497 continue; 498 499 if ( ! call_user_func($func, $this[$field], $args)) 500 { 501 // Run each rule 502 $this->errors[$field] = is_array($func) ? $func[1] : $func; 503 504 // Stop after an error is found 505 break; 506 } 405 507 } 406 508 } … … 442 544 foreach ($all_fields as $f) 443 545 { 546 if (isset($this->array_fields[$f])) 547 { 548 // Use the field key 549 $f = $this->array_fields[$f]; 550 } 551 444 552 // Process each filter 445 553 $this[$f] = is_array($this[$f]) ? array_map($func, $this[$f]) : call_user_func($func, $this[$f]); … … 448 556 else 449 557 { 558 if (isset($this->array_fields[$field])) 559 { 560 // Use the field key 561 $field = $this->array_fields[$field]; 562 } 563 450 564 // Process each filter 451 565 $this[$field] = is_array($this[$field]) ? array_map($func, $this[$field]) : call_user_func($func, $this[$field]);
