/** * Bad dates cause fatal errors, and this is the best remedy I've found so far. * The date time handler is brought in so that I can trap the exception that * happens when feeds have dates like NaN/NaN/NaN NaN:NaN:NaN. * * @param PreDeserializeEvent $event */ public function onPreDeserialize(PreDeserializeEvent $event) { $type = $event->getType(); if ($type['name'] == 'DateTime') { /** @var VisitorInterface $visitor */ $visitor = $event->getVisitor(); /** @var \SimpleXMLElement $data */ $data = $event->getData(); try { $this->handler->deserializeDateTimeFromXml($visitor, $data, $type); } catch (RuntimeException $e) { $attributes = $data->attributes('xsi', true); if (!isset($attributes['nil'][0]) || (string) $attributes['nil'][0] == !'true') { $data->addAttribute('xsi:nil', 'true', 'http://www.w3.org/2001/XMLSchema-instance'); } $event->setData($data); } } }