Preparing the array to convert to XML

@param array  $data       Source array
@param string $primaryKey Parent element name

@return array
498982
public function prepareArrayBeforeToXmlConvert(array $data, $primaryKey = '')
    {
        $result = [];
        $iterator = new RecursiveArrayIterator($data);
        $this->arrayWalk($iterator, $result, '');

        return '' !== (string) $primaryKey ? [$primaryKey => $result] : $result;
    }
906436
protected function _xmlToArray(DOMElement $data)
    {
        $temporaryData = [];

        /** @var $node DOMElement */
        foreach ($data->childNodes as $node) {
            $nodeName           = $this->_stringToIntegerKey($node->nodeName);
            $nodeData           = [];
            $unSerializedData   = [];

            if ($node->hasAttributes() && $node->getAttribute('serialized_object')) {
                try {
                    $unSerializedData = Serializer::unserialize($node->nodeValue);
                } catch (ExceptionInterface $exception) {
                    $this->_addException($exception);
                }

                $temporaryData[$nodeName] = $unSerializedData;
                continue;
            }

            if ($node->hasAttributes()) {
                foreach ($node->attributes as $key => $value) {
                    $nodeData['@attributes'][$key] = $value->nodeValue;
                }
            }

            if ($node->hasChildNodes()) {
                $childNodesData = [];

                /** @var $childNode DOMElement */
                foreach ($node->childNodes as $childNode) {
                    if ($childNode->nodeType === 1) {
                        $childNodesData = $this->_xmlToArray($node);
                    }
                }

                if (!empty($childNodesData)) {
                    $temporaryData[$nodeName] = $childNodesData;
                    continue;
                }
            }

            if (!empty($nodeData)) {
                $temporaryData[$nodeName] = array_merge(
                    [$node->nodeValue],
                    $nodeData
                );
            } else {
                $temporaryData[$nodeName] = $node->nodeValue;
            }
        }

        return $temporaryData;
    }
513472
public function toArray($data, $rootKey = null)
    {
        $data = json_decode($data, true);

        if ($rootKey === null) {
            return $data;
        }

        if (!isset($data[$rootKey])) {
            return [];
        }

        return $data[$rootKey];
    }
194629
public static function primaryKey()
    {
        $model = static::buildNoInitModel();
        if (is_string($model->guidAttribute) && !empty($model->guidAttribute)) {
            return [$model->guidAttribute];
        }
        return [$model->idAttribute];
    }
386484
protected function _parseParent($child, $data, $attributes) {
        $parent = $child->xpath("parent::*");

        if (is_object($parent[0]['name'])) {
            foreach ($attributes as $attribute) {
                $name = $attribute['name'];

                if (is_object($parent[0][$name])) {
                    /** @var SimpleXMLElement $element */
                    $element = $parent[0][$name];

                    if ($attribute['concatenate'] == true) {
                        if ($data[$name] != '') {
                            $data[$name] = $element->__toString() . $attribute['separator'] . $data[$name];
                        }
                        else {
                            $data[$name] = $element->__toString();
                        }
                    }
                    else {
                        if ($data[$name] == '') {
                            $data[$name] = $element->__toString();
                        }
                    }
                }
            }

            $data = $this->_parseParent($parent[0], $data, $attributes);
        }

        return $data;
    }
894845
public function save($data)
    {
        if (!isset($data[$this->primaryKey])) {
            $data[$this->primaryKey] = 0;
        }

        try {
            if (0 === $data[$this->primaryKey]) {
                unset($data[$this->primaryKey]);

                $id = $this->insert($data);
            } else {
                if ($this->find($data[$this->primaryKey], true)) {
                    $this->update($data);
                } else {
                    $this->insert($data);
                }

                $id = $data[$this->primaryKey];
            }
        } catch(\Exception $e) {
            return [
                'code' => $e->getCode(),
                'message' => $e->getMessage()
            ];
        }

        return $id;
    }
658969
protected function xml($key = null, $default = null)
    {
        if (empty($this->contentAsArray)) {
            $content = $this->getContent();
            $data = DataFormatter::xmlToArray($content);

            if (!empty($data)) {
                if ((1 === count($data)) && !array_key_exists(ResourcesWrapper::getWrapper(), $data)) {
                    // All XML comes wrapped in a single wrapper, if not resource wrapper, remove it
                    $data = reset($data);
                }

                $this->contentAsArray = $data;
            }
        }

        if (null === $key) {
            return $this->contentAsArray;
        } else {
            return array_get($this->contentAsArray, $key, $default);
        }
    }
1245839
protected function key($data = null)
    {
        if (is_null($data)) {
            $data = $this->getPK();
            //
            if (Table::count($data) > 1) {
                throw new ManyPrimaryKeysException();
            } elseif (Table::count($data) == 0) {
                throw new PrimaryKeyNotFoundException(static::$table);
            }
            //
            $this->_keyName = $data[0]['Column_name'];
            $this->_key['name'] = $data[0]['Column_name'];
        } else {
            $this->_keyName = $data['key'];
            $this->_key['name'] = $data['key'];
        }
    }
1143959
public function getSafeArray(string $key, array & $data, string $default = null)
    {
        $value = $this->getFromArray($key, $data, $default);

        return \htmlspecialchars($value);
    }
429379
private function generateCode($className, $primaryKey){
		$tags = $this->config->getTags();
		
		$class    = new ClassGenerator();
		$docblock = DocBlockGenerator::fromArray(array(
			'shortDescription' => ucfirst($className) .' model class',
			'longDescription'  => 'This is a model class generated with DavidePastore\ParisModelGenerator.',
			'tags'             => $tags
		));
		
		$idColumn = new PropertyGenerator('_id_column');
		
		$idColumn
			->setStatic(true)
			->setDefaultValue($primaryKey);
		
		$table = new PropertyGenerator('_table');
		
		$table
			->setStatic(true)
			->setDefaultValue($className);
			
		$tableUseShortName = new PropertyGenerator('_table_use_short_name');
		
		$tableUseShortName
			->setStatic(true)
			->setDefaultValue(true);
		
		$namespace = $this->config->getNamespace();
		$extendedClass = '\Model';
		if(isset($namespace) && !empty($namespace)){
			$class->setNamespaceName($this->config->getNamespace());
		}
		
		$class
			->setName(ucfirst($className))
			->setDocblock($docblock)
			->setExtendedClass($extendedClass)
			->addProperties(array(
				$idColumn,
				$table,
				$tableUseShortName
			));
		
		
			
		$file = FileGenerator::fromArray(array(
			'classes'  => array($class),
			'docblock' => DocBlockGenerator::fromArray(array(
				'shortDescription' => ucfirst($className) . ' class file',
				'longDescription'   => null,
				'tags'             => $tags
			))
		));
		
		$generatedCode = $file->generate();
		
		$directory = $this->config->getDestinationFolder() . $namespace;
		
		if(!file_exists($directory)){
			mkdir($directory, 0777, true);
		}
		
		$filePath = $directory . "/" . $class->getName() . ".php";
		
		if(file_exists($filePath) && !$this->force){
			$helper = $this->getHelper('question');
			$realPath = realpath($filePath);
			$this->output->writeln("\n");
			$question = new ConfirmationQuestion('Do you want to overwrite the file "' . $realPath . '"?', false);

			if ($helper->ask($this->input, $this->output, $question)) {
				$this->writeInFile($filePath, $generatedCode);
			}
		}
		else {
			$this->writeInFile($filePath, $generatedCode);
		}
	}
906807
private function composeFormInputs(array $data, $baseKey = '')
    {
        $result = [];
        foreach ($data as $key => $value) {
            if (!empty($baseKey)) {
                $key = $baseKey . '[' . $key . ']';
            }
            if (is_array($value)) {
                $result = array_merge($result, $this->composeFormInputs($value, $key));
            } else {
                $result[$key] = $value;
            }
        }
        return $result;
    }
834449
static public function toXml($data)
    {
        if (is_array($data)) {
            $data = static::encode($data);
        }
        return simplexml_load_string($str, 'SimpleXMLElement', LIBXML_NOCDATA);
    }
935926
public static function fromArray( $data, $rootName = null, $nodeName = null, $addHeader = true )
    {
        $_xml = true === $addHeader ? '<?xml version="1.0" encoding="UTF-8" ?>' : null;

        if ( null !== $rootName )
        {
            $_xml .= Markup::openTag( $rootName );
        }

        $_string = null;

        if ( $data instanceof \Traversable )
        {
            foreach ( $data as $_key => $_value )
            {
                if ( is_numeric( $_key ) )
                {
                    $_key = $nodeName ?: 'node';
                }

                $_string .= Markup::tag( $_key, array(), static::fromArray( $_value, $nodeName ) );
            }
        }
        else
        {
            $_string = htmlspecialchars( $data, ENT_QUOTES );
        }

        //	Add the converted XML
        $_xml .= $_string;

        if ( null !== $rootName )
        {
            $_xml .= Markup::closeTag( $rootName );
        }

        return $_xml;
    }
955210
protected function _setData(array $data)
    {
        $pmk = $this->getPrimaryKey();
        if (!empty($data)) {
            if (!isset($data[$pmk]) && !is_null($this->$pmk)) {
                $data[$pmk] = $this->$pmk;
            }
            return $data;
        }
        $columns = Manager::getInstance()->get($this)->getColumns();
        foreach (array_keys($columns) as $property) {
            $key = trim($property, '_');
            if ($key == $pmk && !$this->$pmk) {
                continue;
            }
            $data[$key] = $this->$property;
        }

        return $data;
    }
1224175
public function primaryKey()
    {
        $primaryKeys = [];
        foreach ($this->_columns as $name => $data) {
            if ((!array_key_exists('primaryKey', $data)) || ($data['primaryKey'] !== true)) {
                continue;
            }

            $primaryKeys[] = $name;
        }

        return $primaryKeys;
    }
393699
public function generateFromArray(array $data)
    {
        $xml = $this->processGenerate($this->rootName, $data);
        $this->createPiNode();
        $this->getDomDocument()->appendChild($xml);
        $xml = $this->getDomDocument()->saveXML();

        $this->flush();

        return $xml;
    }
996354
private function arrayToXml(array &$data, SimpleXMLElement $xmlData)
    {
        foreach ($data as $key => $value) {
            if (\is_array($value)) {
                if (\is_numeric($key)) {
                    $key = 'sequential-item';
                }
                $subnode = $xmlData->addChild($key);

                $this->arrayToXml($value, $subnode);
            } else {
                $subnode = $xmlData->addChild("$key", "$value");

                $type = \gettype($value);
                if ('array' !== $type) {
                    $subnode->addAttribute('type', $type);
                }
            }
        }
    }