Changeset 2626

Show
Ignore:
Timestamp:
05/05/08 11:56:32 (2 months ago)
Author:
Shadowhand
Message:

Updated Validation array handling using Kohana::key_string_set

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/system/libraries/Validation.php

    r2618 r2626  
    363363                )); 
    364364 
     365                // Copy the array from the object, to optimize multiple sets 
     366                $object_array = $this->getArrayCopy(); 
     367 
    365368                foreach ($all_fields as $i => $field) 
    366369                { 
     
    372375                        } 
    373376 
    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); 
     377                        if (substr($field, -2) === '.*') 
     378                        { 
     379                                // Set the key to be an array 
     380                                Kohana::key_string_set($object_array, substr($field, 0, -2), array()); 
    381381                        } 
    382382                        else 
    383383                        { 
    384                                 // Make sure all fields are defined 
    385                                 isset($this[$field]) or $this[$field] = NULL; 
    386                         } 
    387                 } 
     384                                // Set the key to be NULL 
     385                                Kohana::key_string_set($object_array, $field, NULL); 
     386                        } 
     387                } 
     388 
     389                // Swap the array back into the object 
     390                $this->exchangeArray($object_array); 
    388391 
    389392                // Reset all fields to ALL defined fields 
     
    399402                                        { 
    400403                                                // Process each filter 
    401                                                 $this[$f] = is_array($this[$f]) ? array_map($func, $this[$f]) : call_user_func($func, $this[$f]); 
     404                                                if (is_array($this[$f])) 
     405                                                { 
     406                                                        array_walk_recursive($this[$f], $func); 
     407                                                } 
     408                                                else 
     409                                                { 
     410                                                        $this[$f] = call_user_func($func, $this[$f]); 
     411                                                } 
    402412                                        } 
    403413                                } 
     
    405415                                { 
    406416                                        // Process each filter 
    407                                         $this[$field] = is_array($this[$field]) ? array_map($func, $this[$field]) : call_user_func($func, $this[$field]); 
     417                                        if (is_array($this[$field])) 
     418                                        { 
     419                                                array_walk_recursive($this[$field], $func); 
     420                                        } 
     421                                        else 
     422                                        { 
     423                                                $this[$field] = call_user_func($func, $this[$field]); 
     424                                        } 
    408425                                } 
    409426                        }