@param mixed                 $data
@param TypeMetadataInterface $type
@param ContextInterface      $context

@return \DateTimeInterface
3776
private function deserialize($data, TypeMetadataInterface $type, ContextInterface $context)
    {
        $class = $type->getName();

        if (!method_exists($class, 'createFromFormat')) {
            throw new \InvalidArgumentException(sprintf(
                'The method "%s" does not exist on "%s".',
                'createFromFormat',
                $class
            ));
        }

        if (!method_exists($class, 'getLastErrors')) {
            throw new \InvalidArgumentException(sprintf(
                'The method "%s" does not exist on "%s".',
                'getLastErrors',
                $class
            ));
        }

        $result = $class::createFromFormat(
            $format = $type->getOption('format', $this->format),
            (string) $data,
            $timezone = new \DateTimeZone($type->getOption('timezone', $this->timeZone))
        );

        $errors = $class::getLastErrors();

        if (!empty($errors['warnings']) || !empty($errors['errors'])) {
            throw new \InvalidArgumentException(sprintf(
                'The date "%s" with format "%s" and timezone "%s" is not valid.',
                $data,
                $format,
                $timezone->getName()
            ));
        }

        return $result;
    }
1127888
public function dataType(string $type)
    {
        if (!in_array($type, $this->possible_types)) {
            throw new RuntimeException('Wrong data type, available: ' . implode(', ', $this->possible_types));
        }

        $this->data_type = $type;


        // Pre-format
        switch ($this->data_type) {
            case 'ts2datetime':
            case 'ts2date':
                $this->setWidth('1%');
                $this->disableNewlines();
                break;

            case 'truefalse':
                $this->setWidth('1%');
                $this->disableNewlines();
                $this->enableCenterAlign();
                break;
        }

        return $this;
    }
1173851
public static function decode($data, array $context = [])
    {
        $context = array_merge(static::$defaultDecodeContext, $context);

        return static::decodeData($data, $context);
    }
486609
private function resolveSingleType($type, Context $context)
    {
        switch (true) {
            case $this->isKeyword($type):
                return $this->resolveKeyword($type);
            case $this->isTypedArray($type):
                return $this->resolveTypedArray($type, $context);
            case $this->isFqsen($type):
                return $this->resolveTypedObject($type);
            case $this->isPartialStructuralElementName($type):
                return $this->resolveTypedObject($type, $context);
            // @codeCoverageIgnoreStart
            default:
                // I haven't got the foggiest how the logic would come here but added this as a defense.
                throw new \RuntimeException(
                    'Unable to resolve type "' . $type . '", there is no known method to resolve it'
                );
        }

        // @codeCoverageIgnoreEnd
    }
639072
public function doDeserialize(
        VisitorInterface $visitor,
        array $data,
        array $type,
        Context $context
    ) {
        $document = $context->accept($data['document'], ['name' => $data['documentClass']]);
        $structure = $this->structureFactory->getStructureMetadata('page', $data['structure']);
        $bridge = new PageBridge($structure, $this->inspector, $this->propertyFactory, $document);

        // filthy hack to set the Visitor::$result to null and force the
        // serializer to return the Bridge and not the Document
        $visitor->setNavigator($context->getNavigator());

        return $bridge;
    }
77670
public function getTempVariable($type, CompilationContext $compilationContext)
    {
        $compilationContext = $compilationContext ?: $this->compilationContext;

        $tempVar = $this->getNextTempVar();
        $variable = $this->addVariable($type, '_'.$tempVar, $compilationContext);
        $variable->setTemporal(true);

        return $variable;
    }
975730
public function convertFromMongoFormatToDateTime(VisitorInterface $visitor, $date, array $type, Context $context)
    {
        /**
         * this $dateTime object is incorrect in case of using microseconds
         * because after conversion of \MongoDB\BSON\UTCDateTime to \DateTime
         * method $dateTime->format('U.u') returns invalid string xxxxxxxxx.zzzzzzzzz
         * part after "." contains 9 digits but it should contain up to 6 digits
         * so we have to reduce this part to 6 digits.
         *
         * @var \DateTime
         */
        if (!is_string($date) && !$date instanceof UTCDatetime) {
            throw new \InvalidArgumentException('The provided date must be a valid string or an instance of UTCDateTime');
        }

        if (is_string($date)) {
            $dateTime = date_create($date);
            if (false === $dateTime) {
                throw new \InvalidArgumentException(sprintf('The provided date "%s" is not a valid date/time string', $date));
            }

            return $dateTime;
        }

        return self::convertMongoFormatToDateTime($date);
    }
73726
public static function secureKnownType($data, string $type)
    {
        $filterType = 'text';

        if ($type === 'int' || $type === 'integer') {
            $filterType = FILTER_VALIDATE_INT;
        } elseif ($type === 'float' || $type === 'double') {
            $filterType = FILTER_VALIDATE_FLOAT;
        } elseif ($type === 'bool' || $type === 'boolean') {
            $filterType = FILTER_VALIDATE_BOOLEAN;
        } elseif ($type === 'email') {
            $filterType = FILTER_VALIDATE_EMAIL;
        }

        if ($filterType === 'text') {
            throw new Exception(
                'Cannot secure the type',
                self::ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED
            );
        }

        return filter_var($data, $filterType);
    }
574028
public function deserialize(VisitorInterface $visitor, $data, Type $type, Context $context): ?UuidInterface
    {
        if (empty($data)) {
            return $visitor->visitNull(null, Type::null(), $context);
        }

        return Uuid::fromString($data);
    }
492420
public function writeTypedObject($data)
    {
        $this->_stream->writeUTF($this->_className);
        $this->writeObject($data);
        return $this;
    }
706428
public function sanitize($data, $type) {
        if (strtolower($type) == "create") $rules = $this->repository->getSanitationRulesForCreate();

        if (strtolower($type) == "update") $rules = $this->repository->getSanitationRulesForUpdate();

        $sanitizedData = $this->repository->getSanitize($data, $rules);

        return $sanitizedData;
    }
563461
public function convertObject(ObjectDataInterface $objectData, OperationContextInterface $context)
    {
        $type = $this->getTypeFromObjectData($objectData);
        if ($type === null) {
            throw new CmisRuntimeException('Could not get type from object data.');
        }
        $baseTypeId = $objectData->getBaseTypeId();

        if ($baseTypeId->equals(BaseTypeId::CMIS_DOCUMENT)) {
            return new Document($this->session, $type, $context, $objectData);
        } elseif ($baseTypeId->equals(BaseTypeId::CMIS_FOLDER)) {
            return new Folder($this->session, $type, $context, $objectData);
        } elseif ($baseTypeId->equals(BaseTypeId::CMIS_POLICY)) {
            return new Policy($this->session, $type, $context, $objectData);
        } elseif ($baseTypeId->equals(BaseTypeId::CMIS_RELATIONSHIP)) {
            return new Relationship($this->session, $type, $context, $objectData);
        } elseif ($baseTypeId->equals(BaseTypeId::CMIS_ITEM)) {
            return new Item($this->session, $type, $context, $objectData);
        } elseif ($baseTypeId->equals(BaseTypeId::CMIS_SECONDARY)) {
            throw new CmisRuntimeException('Secondary type is used as object type: ' . $baseTypeId);
        } else {
            throw new CmisRuntimeException('Unsupported base type: ' . $baseTypeId);
        }
    }
343773
public function newObject($type, array $data = [])
    {
        $type = $this->getFullType($type);
        if (class_exists($type)) {
            $table = $type::getCollection();
            return new $type($data, $this->mongodb->$table, $this->cache);
        }
        return null;
    }
459164
public function serializeEBDateTime(VisitorInterface $visitor, \DateTime $date, array $type, Context $context)
    {
        return ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData)
            ? $visitor->visitSimpleString($date->format($this->getFormat($type)), $type, $context)
            : $visitor->visitString($date->format($this->getFormat($type)), $type, $context);
    }
870221
public static function data($data, $type = null)
    {
        $type === null && $type = MongoBinData::BYTE_ARRAY;

        return new MongoBinData($data, $type);
    }
954342
public function render(array $data, ContextInterface $context)
    {
        $data += [
            'name' => '',
            'val' => null,
            'type' => 'text',
            'escape' => true,
        ];
        $data['value'] = $data['val'];
        $data['readonly'] = 'readonly';
        unset($data['val']);
        $this->_loadAssets();

        $data['class'] = !empty($data['class']) ? "{$data['class']} fontselector" : 'fontselector';

        return $this->_templates->format('input', [
            'name' => $data['name'],
            'type' => 'text',
            'attrs' => $this->_templates->formatAttributes(
                $data,
                ['name', 'type']
            ),
        ]) . '<p id="' . $data['id'] . '-preview" style="font:' . $data['value'] . ';">Example text</p>';
    }
294322
private function convertFromPg($data, TypeInterface $type)
    {
        if ($data === null) {
            return null;
        }

        if ($type instanceof ArrayType) {
            return $this->convertArrayFromPg($data, $type);
        }

        if (isset($this->mappings[(string) $type])) {
            return $this->convertCompositeFromPg($data, $type);
        }

        return $this->convertScalarFromPg($data, $type);
    }