Convert given input data array to a ObjectInFolderContainer object

@param array|null $data
@return null|ObjectInFolderContainer
@throws CmisRuntimeException
514625
public function convertDescendant(array $data = null)
    {
        if (empty($data)) {
            return null;
        }

        $object = $this->convertObjectInFolder($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_OBJECT] ?? null);

        if ($object === null) {
            throw new CmisRuntimeException('Given data could not be converted to ObjectInFolder!');
        }

        $objectInFolderContainer = new ObjectInFolderContainer($object);

        $objectInFolderContainer->setChildren(
            array_filter(
                array_map(
                    [$this, 'convertDescendant'],
                    (array) ($data[JSONConstants::JSON_OBJECTINFOLDERCONTAINER_CHILDREN] ?? [])
                ),
                function ($item) { return !empty($item); }
            )
        );

        $objectInFolderContainer->setExtensions(
            $this->convertExtension($data, JSONConstants::getObjectInFolderContainerKeys())
        );

        return $objectInFolderContainer;
    }
569039
private function convertData(array $data = null)
    {
        if (!is_array($data)) {
            return $data;
        }

        foreach ($data as $key => $val) {
            /** convert dbrefs */
            if (is_array($val) && isset($val['$ref']) && isset($val['$id'])) {
                $data[$key] = $this->convertData(
                    $this->resolveObject($val['$ref'], $val['$id'])
                );
            } elseif (is_array($val)) {
                $data[$key] = $this->convertData($val);
            }
            /** convert mongodate to text dates **/
            if ($val instanceof \MongoDate) {
                $data[$key] = $this->dateConverter->formatDateTime($val->toDateTime());
            }
            /** convert mongoid */
            if ($val instanceof \MongoId) {
                $data[$key] = (string) $val;
            }
        }

        return $data;
    }
1151601
public static function fromArray(array $data)
    {
        return new PhpCsFixer(
            new Undefined(false),
            new Enabled($data['enabled']),
            PhpCsFixerLevelsFactory::fromArray($data['levels']),
            new PhpCsFixerOptions(isset($data['options']) ? $data['options'] : null)
        );
    }
457970
public function convertQueryResultList(array $data = null)
    {
        if (empty($data)) {
            return null;
        }

        $objectList = new ObjectList();
        $objects = [];

        foreach ((array) ($data[JSONConstants::JSON_QUERYRESULTLIST_RESULTS] ?? []) as $objectData) {
            $object = $this->convertObject($objectData);

            if ($object !== null) {
                $objects[] = $object;
            }
        }

        $objectList->setObjects($objects);
        $objectList->setHasMoreItems((boolean) ($data[JSONConstants::JSON_QUERYRESULTLIST_HAS_MORE_ITEMS] ?? false));

        if (isset($data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS])) {
            $objectList->setNumItems((integer) $data[JSONConstants::JSON_QUERYRESULTLIST_NUM_ITEMS]);
        }

        $objectList->setExtensions($this->convertExtension($data, JSONConstants::getQueryResultListKeys()));

        return $objectList;
    }
1258855
protected static function deserializeCommonAttributes(array $data)
    {
        $result = new static(isset($data['id']) ? $data['id'] : null);
        if ($result->getResourceType() != $data['meta']['resourceType']) {
            throw new \RuntimeException(sprintf('Error deserializing resource type "%s" into class "%s"', $data['meta']['resourceType'], get_class($result)));
        }
        $result->meta = Meta::deserializeObject($data['meta']);
        if (isset($arr['externalId'])) {
            $result->externalId = $data['externalId'];
        }
        if (isset($data['schemas'])) {
            foreach ($data['schemas'] as $schemaId) {
                if ($schemaId != $result->getSchemaId()) {
                    $result->extensions[$schemaId] = isset($data[$schemaId]) ? $data[$schemaId] : null;
                }
            }
        }

        return $result;
    }
63114
protected function normalize(array $data)
    {
        $body = json_encode($data);

        if ($this->length($body) > static::MAX_SIZE) {
            unset($data['events'][0]['metaData']);
        }

        $body = json_encode($data);

        if ($this->length($body) > static::MAX_SIZE) {
            throw new RuntimeException('Payload too large');
        }

        return $data;
    }
10648
protected function fromArray( array $data )
	{
		$conf = [];

		if( isset( $data['config']['key'] ) )
		{
			foreach( (array) $data['config']['key'] as $idx => $key )
			{
				if( trim( $key ) !== '' && isset( $data['config']['val'][$idx] ) )
				{
					if( ( $val = json_decode( $data['config']['val'][$idx] ) ) === null ) {
						$conf[$key] = $data['config']['val'][$idx];
					} else {
						$conf[$key] = $val;
					}
				}
			}
		}

		$manager = \Aimeos\MShop::create( $this->getContext(), 'service' );

		if( isset( $data['service.id'] ) && $data['service.id'] != '' ) {
			$item = $manager->getItem( $data['service.id'], $this->getDomains() );
		} else {
			$item = $manager->createItem();
		}

		$item->fromArray( $data, true );
		$item->setConfig( $conf );

		return $item;
	}
281568
public function toArray($data = null)
	{
		if ($data === null)
		{
			$data = $this->data;
		}

		$array = array();

		if (is_object($data) and ! $data instanceof \Iterator)
		{
			$data = get_object_vars($data);
		}

		if (empty($data))
		{
			return array();
		}

		foreach ($data as $key => $value)
		{
			if (is_object($value) or is_array($value))
			{
				$array[$key] = $this->toArray($value);
			}
			else
			{
				$array[$key] = $value;
			}
		}

		return $array;
	}
234781
public static function deserializeObject(array $data)
    {
        $result = new static($data['resourceType'], isset($data['created']) ? Helper::string2dateTime($data['created']) : null);
        if (isset($data['lastModified'])) {
            $result->lastModified = Helper::string2dateTime($data['lastModified']);
        }
        if (isset($data['location'])) {
            $result->location = $data['location'];
        }
        if (isset($data['version'])) {
            $result->version = $data['version'];
        }

        return $result;
    }
370419
public function create(array $data = [])
    {
        $engine = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE);

        $fullActionClass = $this->fullActionPool['default'];

        if (isset($this->fullActionPool[$engine])) {
            $fullActionClass = $this->fullActionPool[$engine];
        }

        return $this->objectManager->create($fullActionClass, ['data' => $data]);
    }
858203
private function convertSerializedToObjects($data)
    {
        $data = @unserialize($data);

        // If it is an object then
        // we can just return it...
        if (is_object($data))
        {
            return $data;
        }

        // It could be a associative array so use
        // JSON to encode it and then decode it properly...
        if (is_array($data) and $json = $this->convertToJson($data))
        {
            return $this->convertJsonToObjects($json);
        }

        return null;
    }
1125366
public static function fromData(array $data)
    {
        $reflection = new \ReflectionClass(static::class);
        $instance = $reflection->newInstanceWithoutConstructor();
        $instance->data = $data;
        $instance->jsonUnserialize($data);
        return $instance;
    }
563720
public function save($data = null)
    {
        if ($data !== null) {
            $this->content($data);
        }

        $filename = $this->filename;
        $dir = \dirname($filename);

        if (!$this->mkdir($dir)) {
            throw new \RuntimeException('Creating directory failed for ' . $filename);
        }

        try {
            if ($this->handle) {
                $tmp = true;
                // As we are using non-truncating locking, make sure that the file is empty before writing.
                if (@ftruncate($this->handle, 0) === false || @fwrite($this->handle, $this->raw()) === false) {
                    // Writing file failed, throw an error.
                    $tmp = false;
                }
            } else {
                // Create file with a temporary name and rename it to make the save action atomic.
                $tmp = $this->tempname($filename);
                if (file_put_contents($tmp, $this->raw()) === false) {
                    $tmp = false;
                } elseif (@rename($tmp, $filename) === false) {
                    @unlink($tmp);
                    $tmp = false;
                }
            }
        } catch (\Exception $e) {
            $tmp = false;
        }

        if ($tmp === false) {
            throw new \RuntimeException('Failed to save file ' . $filename);
        }

        // Touch the directory as well, thus marking it modified.
        @touch($dir);
    }
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);
    }
1103709
public function save(array $data)
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$userRepository = $main->getUserEntityRepository();
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$form = $this->getServiceLocator()->get('document.form.classifiedimageadd');
    	
		$classifiedId = !empty($data['classifiedid']) ? $data['classifiedid'] : null;
	    $classified = null !== $classifiedId ? 
	        $documentRepository->findByEncryptedId($classifiedId, 'documentId') : null;
	    
	    // remove parent cache
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		if (!empty($classifiedId) && $cache->hasItem($classifiedId)) {
			$cache->removeItem($classifiedId);
		}
	    
		$userId = !empty($data['userid']) ? $data['userid'] : null;
	    $user = null !== $userId ? 
	        $userRepository->findByEncryptedId($userId, 'userId') : null;
		
		$entity = new Document();
		$form->setData($data);
		
		if (!$form->isValid()) {
			throw new \Exception(serialize($form->getMessages('files')));
		}
		
		$data = $form->getData();
			
		// @todo Better recover this in a smarter way
		$files = isset($data['files']) ? $data['files'] : array();
		$firstFile = reset($files);
		
		if(empty($firstFile)) {
			throw new \Exception(serialize(array('Empty file')));
		}
		
		$title = is_array($firstFile) && isset($firstFile['name']) ? 
			$firstFile['name'] : '';
			
		$entity->setDocumentType(Document::DOCUMENT_TYPE_IMAGE);
		$entity->setTitle($title);
		$entity->setParent($classified);
		$entity->setUser($user);
		$entity->setState(Document::DOCUMENT_STATE_ACTIVE);
		
		$em->persist($entity);
		$em->flush();
		
    	// trigger saveClassified event with the saved entity
    	$this->getEventManager()->trigger('imageSaved', null, $entity);
    	
    	return $entity;
    }
471541
protected function createObjectFrom($data)
    {
        $class_name = $this->class_name;

        try {
            return new $class_name($data);
        } catch (\InvalidArgumentException $e) {
            throw new ConverterException(
                sprintf("Unable to create a '%s' instance.", $class_name),
                null,
                $e
            );
        }
    }
148639
public function initByData( array $data = null )
    {

        if( !$data ) {
            return null;
        }

        // table inheritance - ghetto?
        /*
        if( isset( $data['tableoid'] ) ) {
            if( $data['tableoid'] != static::OID ) {
                $repo = Repository::init( $data['tableoid'] );
                return $repo->initByData( $data );
            }
            unset( $data['tableoid'] );
        }
        */

        $key = call_user_func(
            array( $this->entityClass, 'keyGet' ),
            $data
        );

        // is this already in the cache? Are we initalising something we've already loaded?
        if( isset( $this->instancesPersisted[$key] ) ) {

            // Late loading? Don't need this anymore.
            $obj = $this->instancesPersisted[$key];
            $obj->__construct( $data );
            return $obj;

        }

        $obj = parent::initByData($data);
        $this->instancesPersisted[$key] = $obj;

        return $obj;

    }