Beispiel #1
0
 /**
  * Method to return data once it has been filtered through the validator
  *
  * @param array $data       Data to be validated, defaults to form's data
  * @param bool $addToFlash  Have flash messages already been added to the flash bag???
  *
  * @return array            Returns filtered data
  */
 public function getFilteredData($addToFlash = true)
 {
     $this->isValid($addToFlash);
     // here we want the filtered data from the validator but don't need to include the
     // data symfony removed because it doesn't match the type
     $data = $this->_validator->getData();
     // Sometimes date fields do not automatically get formatted to a
     // Datetime object due to browser differences. This ensures all dates
     // are instantiated correctly.
     foreach ($this->_fields as $name => $field) {
         if (in_array($field['type'], ['date', 'datetime']) and $value = $data[$name] and !$value instanceof \DateTime) {
             // If the value is an array it's date and time separately, so smush them together
             if (is_array($value)) {
                 $value = trim(implode(' ', $value));
             }
             $format = $this->_container['helper.date']->detectFormat($value);
             // The ! character is important as it tells DateTime to default
             // to epoch values where they are not defined in the value (i.e. if time is not set, default to 00:00:00)
             $data[$name] = \DateTime::createFromFormat('!' . $format, $value);
         }
     }
     return $data;
 }