Doctrine\ODM\MongoDB\Mapping\Types\DateType::convertToPHPValue PHP Method

convertToPHPValue() public method

public convertToPHPValue ( $value )
    public function convertToPHPValue($value)
    {
        if ($value === null) {
            return null;
        }
        if ($value instanceof \MongoDate) {
            $date = new \DateTime();
            $date->setTimestamp($value->sec);
        } else {
            $date = new \DateTime($value);
        }
        return $date;
    }

Usage Example

 public function convertToPHPValue($value)
 {
     if ($value === null) {
         return null;
     }
     if (!is_array($value)) {
         throw new CustomTypeException('Array expected.');
     }
     $converter = new DateType();
     $value = array_map(function ($date) use($converter) {
         return $converter->convertToPHPValue($date);
     }, array_values($value));
     return $value;
 }