/** * Iterates through config.casting and if key exist in data then applied casting rules. * * @param array $data * @param array $casted - receives names of fields which where casted mapped to the casting types. * * @return array * @throws Exception */ protected function cast(array $data, array &$casted = array()) { foreach ($this->config()->get('casting') as $name => $type) { // casting may deal with null values so don't use isset() if (array_key_exists($name, $data)) { switch ($type) { case self::CastDate: $data[$name] = CheckfrontModule::from_checkfront_date($data[$name]); $casted[$name][] = $type; break; default: throw new CheckfrontException("Unknown cast type '{$type}'", CheckfrontException::TypeError); } } } return $data; }