Convert an object to a simple type representation

@param mixed $data
@return mixed
@throws CmisRuntimeException Exception is thrown if no type converter could be found to convert the given data
to a simple type
196946
protected function convertObjectToSimpleType($data)
    {
        /** @var null|TypeConverterInterface $converterClassName */
        $converterClassName = null;
        if (class_exists($this->buildConverterClassName(get_class($data)))) {
            $converterClassName = $this->buildConverterClassName(get_class($data));
        } else {
            $classInterfaces = class_implements($data);
            foreach ((array) $classInterfaces as $classInterface) {
                if (class_exists($this->buildConverterClassName($classInterface))) {
                    $converterClassName = $this->buildConverterClassName($classInterface);
                    break;
                }
            }
            if ($converterClassName === null) {
                $classParents = class_parents($data);
                foreach ((array) $classParents as $classParent) {
                    if (class_exists($this->buildConverterClassName($classParent))) {
                        $converterClassName = $this->buildConverterClassName($classParent);
                        break;
                    }
                }
            }
        }

        if ($converterClassName === null) {
            throw new CmisRuntimeException(
                'Could not find a converter that converts "' . get_class($data) . '" to a simple type.'
            );
        }

        return $converterClassName::convertToSimpleType($data);
    }
526782
public function unserialize($data)
    {
        $this->throwIfTrue(!is_string($data), '$data must be a string');

        set_error_handler($this->getErrorHandler());
        try {
            $unserialized = unserialize($data);
            $this->throwIfTrue($unserialized === false, '$data could not be unserialized');
            return $unserialized;
        } finally {
            restore_error_handler();
        }
    }
710032
public function convertObjectParentData(array $data = null)
    {
        if (empty($data)) {
            return null;
        }
        $parent = new ObjectParentData();

        $object = $this->convertObject($data[JSONConstants::JSON_OBJECTPARENTS_OBJECT] ?? null);
        if ($object !== null) {
            $parent->setObject($object);
        }

        $parent->setRelativePathSegment((string) ($data[JSONConstants::JSON_OBJECTPARENTS_RELATIVE_PATH_SEGMENT] ?? ''));
        $parent->setExtensions($this->convertExtension($data, JSONConstants::getObjectParentsKeys()));

        return $parent;
    }
1132058
public function extract(array $data)
    {
        if (!array_key_exists('class', $data)) {
            throw new \RuntimeException('Unable to extract class name from data');
        }

        if (!array_key_exists('data', $data)) {
            throw new \RuntimeException('Unable to extract message body from data');
        }

        if (!is_array($data['data'])) {
            throw new \RuntimeException('Message body from data must be an array');
        }

        if (!class_exists($data['class'])) {
            throw new \RuntimeException(sprintf('Class %s does\'nt exist', $data['class']));
        }

        if (!in_array(MessageInterface::class, class_implements($data['class']))) {
            throw new \RuntimeException(sprintf('Class must implement %s', MessageInterface::class));
        }

        $message = new $data['class'];

        if (is_subclass_of($data['class'], MessageAwareInterface::class)) {
            $message->setMessage($this->extract($data['data']));

            unset($data['data']['class']);
            unset($data['data']['data']);
        }

        return $this->getHydrator()->hydrate($message, $data['data']);
    }
316022
public function appendSerialized($data)
    {
        try {
            $data = Serializer::unserialize($data);
        } catch (ExceptionInterface $exception) {
            $this->_addException($exception);
        }

        if (is_object($data)) {
            $name = $this->_convertKeyNames(get_class($data));
            $this->appendData($name, $data);
        } elseif (is_array($data)) {
            $this->appendArray($data);
        } else {
            $this->appendData($this->_defaultDataName, $data);
        }

        if ($this->_objectCreation) {
            return $this->_afterAppendDataToNewObject();
        }
        return $this;
    }
696302
static function smartUnserialize(string $data)
    {
        try {
            $value = @unserialize($data);
        } catch (\Throwable $e) {
            throw new DeserializationFailedException('An exception was thrown during unserialization', 0, $e);
        }

        // distinguish between "false on error" and a serialized FALSE value
        if ($value === false && $data !== self::getSerializedFalse()) {
            throw new DeserializationFailedException('Unserialization failed - data possibly malformed');
        }

        return $value;
    }
319093
protected function convertEncoding($data)
    {
        if (!$this->shouldConvert) {
            return $data;
        }
        return $this->stringConverter->convert("$data", 'utf-8', $this->getOption(self::ENCODING));
    }
458376
public function convert(array $data)
    {
        if (empty($data['code'])) {
            if (empty($data['ctcp'])) {
                $event = new UserEvent;
            } else {
                $event = new CtcpEvent;
                $event->setCtcpCommand($data['ctcp']['command']);
                if (!empty($data['ctcp']['params'])) {
                    $event->setCtcpParams($data['ctcp']['params']);
                }
            }
            if (!empty($data['prefix'])) {
                $event->setPrefix($data['prefix']);
            }
            if (!empty($data['nick'])) {
                $event->setNick($data['nick']);
            }
            if (!empty($data['user'])) {
                $event->setUsername($data['user']);
            }
            if (!empty($data['host'])) {
                $event->setHost($data['host']);
            }
            if (!empty($data['targets'])) {
               $event->setTargets($data['targets']);
            }
        } else {
            $event = new ServerEvent;
            $event->setServername($data['servername']);
            $event->setCode($data['code']);
        }
        $event->setMessage($data['message']);
        if (isset($data['params'])) {
            if (isset($data['params']['all'])) {
                unset($data['params']['all']);
            }
            $event->setParams($data['params']);
        }
        $event->setCommand($data['command']);
        return $event;
    }
777611
public function convertFrom(string $data): DataProviderInterface
    {
        $data = json_decode($data, true);

        if (!isset($data['data'], $data['class'])) {
            throw new ConverterException('Data have wrong format to convert (No class or data field)');
        }

        $provider = $data['class'];

        $provider = $this->createDataProvider($provider);
        $provider->fromArray($data['data']);

        return $provider;
    }
1288324
protected function toArrayRecursive($data)
    {
        $type = $data->getType();
        if (is_array($data->getValue())) {
            $result = [
                self::TYPE_LIST => [],
                'type'          => self::TYPE_LIST
            ];
            foreach ($data->getValue() as $key => $value) {
                if ($value instanceof $this) {
                    $result[self::TYPE_LIST][] = $data->toArrayRecursive($value);
                }
            }
            return $result;
        } else {
            return [
                $type  => $data->getValue(),
                'type' => $type,
            ];
        }
    }
52308
public function convertExtension(array $data = null, array $cmisKeys = [])
    {
        $extensions = [];

        foreach (array_diff_key((array) $data, array_flip($cmisKeys)) as $key => $value) {

            if (!is_array($value)) {
                $value = (empty($value)) ? null : (string) $value;
                $extensions[] = new CmisExtensionElement(null, $key, [], $value);
            } else {
                $extension = $this->convertExtension($value, $cmisKeys);

                if (!empty($extension)) {
                    $extensions[] = new CmisExtensionElement(
                        null,
                        $key,
                        [],
                        null,
                        $extension
                    );
                }
            }
        }

        return $extensions;
    }
329995
protected function encode($data)
    {
        if(null === $this->formatHandlerClass)
        {
            return $data;
        }
        else if(RequestContext::exsits() && null !== RequestContext::getServer())
        {
            return RequestContext::getServerBean($this->formatHandlerClass)->encode($data);
        }
        else
        {
            return App::getBean($this->formatHandlerClass)->encode($data);
        }
    }
834449
static public function toXml($data)
    {
        if (is_array($data)) {
            $data = static::encode($data);
        }
        return simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOCDATA);
    }
111489
private function convertArrayObjects($data)
    {
        if ($data instanceof \ArrayObject || $data instanceof \stdClass) {
            $data = (array) $data;
        }
        if (\is_array($data)) {
            foreach ($data as $k => $v) {
                $data[$k] = $this->convertArrayObjects($v);
            }
        }

        return $data;
    }
771543
public function newInstance($data=null)
    {
        $class = $this->getClassName();
        $conv = $this->newConverterInstance();

        if(is_null($data))
        {
            $data = array();
        }

        if($conv instanceof IListConverter)
        {
            $data = $conv;
        }

        $o = new $class($data);
        if($conv instanceof IBaseConverter)
        {
            $o->setConverter($conv);
        }

        return $o;
    }
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);
    }
503879
public static function unserialize ($data) {
		foreach (unserialize($data) ?? [] as $name => $datum) {
			static::$multitonInstances[$name] = unserialize($datum);
		}
	}