Converts a struct to an associtive array based on the key value pair in the struct
@param array $struct Input struct to be converted
@return array Associtive array matching the struct
174634
final protected function struct_to_assoc($struct) {
        $result=array();
        foreach($struct as $item) {
            if(array_key_exists('key', $item) && array_key_exists('value', $item)) {
                if(array_key_exists($item['key'], $result)) {
                    user_error('Duplicate key detected in struct entry, content overwritten by the last entry: [New: '.print_r($item, true).'] [Previous: '.print_r($result[$item['key']], true).']', E_USER_WARNING);
                }
                
                $result[$item['key']]=$item['value'];
            }else {
                user_error('Key/Value pair not detected in struct entry: '.print_r($item, true), E_USER_NOTICE);
            }
        }
        
        return $result;
    }
283915
public function save( & $structure )
    {
        if ( ! $structure instanceof Structure\ProxyAbstract ||
             empty( $structure->type ) )
        {
            return 0;
        }

        $data   = ArrayUtils::iteratorToArray( $structure->getBaseIterator() );
        $label  = empty( $data['label'] ) ? '' : $data['label'];
        unset( $data['label'] );

        $result = parent::save( $data );

        if ( $result > 0 )
        {
            if ( empty( $structure->id ) )
            {
                $structure->setOption( 'id', $id = $data['id'] );
            }
            else
            {
                $id = $structure->id;
            }

            $result += $this->saveLabel( $id, $label );

            foreach ( $structure->getPropertiesIterator() as $property => $value )
            {
                $result += $this->saveProperty( $id, $property, $value );
            }
        }

        return $result;
    }
1287321
public function toOutput($structure, $assoc = true)
    {
        switch ($structure) {
            case 'string':
                $output = $this->toString();
                break;
            case 'array':
            default:
                $output = $this->toArray($assoc);
                break;
        }
        return $output;
    }
612963
public function toArray($deep = true) {

        // Get each property
        $array = array();
        foreach ($this->__getSerialisablePropertyMap() as $key => $value) {
            if ($value instanceof AssociativeArray) {
                $array[$key] = $deep ? $value->toArray() : $value;
            } else {
                $array[$key] = $value;
            }
        }

        return $array;
    }
591293
public function extract( $structure )
    {
        if ( $structure instanceof StructureAbstract )
        {
            return $structure->toArray();
        }

        if ( $structure instanceof Traversable )
        {
            return ArrayUtils::iteratorToArray( $structure );
        }

        return (array) $structure;
    }
394666
protected function isStructureAnCommomArray(string $structure) : bool
    {
        return (strpos($structure, "[") === 0 && strrpos($structure, "]") === (strlen($structure) - 1));
    }
1372486
protected function findCharset($struct)
    {
        if (isset($struct->parameters)) {
            foreach ($struct->parameters as $param) {
                if (strtolower($param->attribute) === 'charset') {
                    return strtoupper($param->value);
                }
            }
        }
        if (isset($struct->dparameters)) {
            foreach ($struct->dparameters as $param) {
                if (strtolower($param->attribute) === 'charset') {
                    return strtoupper($param->value);
                }
            }
        }

        return '';
    }
966523
public static function keyToCamel($array)
    {
        $result = [];
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $result[Strings::case2camel($key)] = self::keyToCamel($value);
            } else {
                $result[Strings::case2camel($key)] = $value;
            }
        }
        return $result;
    }
1342388
protected function toJsonSerialize()
    {
        return [
            'attributes' => $this->attributes,
            'restriction' => $this->isRestriction,
            'struct' => $this->isStruct,
            'types' => $this->types,
            'values' => $this->values,
            'list' => $this->list,
        ];
    }
837317
public static function structToString($struct, array $options = [])
    {
        $header = StructureHelper::getValue($options, 'header');
        $asArray = StructureHelper::getValue($options, 'as_array');
        $strict = StructureHelper::getValue($options, 'strict');

        // Build the object variables string
        $vars = '';

        foreach ($struct as $k => $v) {
            if (is_scalar($v)) {
                $vars .= sprintf("    '%s' => '%s',\n", $k, addcslashes($v, '\\\''));
            } elseif (is_array($v) || is_object($v)) {
                $vars .= sprintf("    '%s' => %s,\n", $k, static::getArrayString((array) $v));
            }
        }

        if (!$asArray) {
            if ($strict) {
                $str = "<?php declare(strict_types=1);\n";
            } else {
                $str = "<?php\n";
            }

            if ($header) {
                $str .= $header . "\n";
            }

            $str .= "\nreturn [\n";
        } else {
            $str = "[\n";
        }

        $str .= $vars;
        $str .= ']';

        if (!$asArray) {
            $str .= ";\n";

            // Use the closing tag if set to true in parameters.
            if (StructureHelper::getValue($options, 'closingtag', false)) {
                $str .= "\n?>";
            }
        }

        return $str;
    }
925653
public function arrayStringKeys(Array_ $array)
    {
        $keys = [];
        foreach ($array->items as $item) {
            if ($item->key instanceof String_) {
                $keys[] = $item->key->value;
            }
        }

        return $keys;
    }
467613
public function hydrate( array $data, $structure )
    {
        if ( ! empty( $data['file'] ) )
        {
            if ( ! empty( $data['file']['tmp_name'] ) )
            {
                $data['name'] = $data['file']['name'];
                $data['code'] = @ file_get_contents( $data['file']['tmp_name'] );
                @ unlink( $data['file']['tmp_name'] );
            }

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

        if ( ! empty( $data['type'] ) )
        {
            $data['name'] .= '.' . $data['type'];
            unset( $data['type'] );
        }

        if ( $structure instanceof StructureAbstract )
        {
            $structure->setOptions( $data );
        }
        else
        {
            foreach ( $data as $key => $value )
            {
                $structure->$key = $value;
            }
        }

        if ( $structure instanceof MapperAwareInterface )
        {
            $structure->setMapper( $this );
        }

        return $structure;
    }
333156
private function buildNormalizedRows(ITableStructure $structure, array $array) : array
    {
        $columns           = $structure->getColumns();
        $columnNames       = $structure->getColumnNames();
        $componentNamesMap = [];

        foreach ($columns as $column) {
            $componentNames = $column->getComponentNames();
            sort($componentNames);
            $componentNamesMap[$column->getName()] = $componentNames;
        }

        sort($columnNames);
        $rows = [];

        foreach ($array as $rowData) {
            $rowColumns = array_keys($rowData);
            sort($rowColumns);

            if ($columnNames !== $rowColumns) {
                throw InvalidArgumentException::format(
                    'Invalid row array: expecting columns names to be (%s), (%s) given',
                    Debug::formatValues($columnNames), Debug::formatValues($rowColumns)
                );
            }

            foreach ($rowData as $columnName => $componentData) {
                $column = $columns[$columnName];

                if (!is_array($componentData)) {
                    if ($column->hasSingleComponent()) {
                        $component            = $column->getComponent();
                        $rowData[$columnName] = [$component->getName() => $componentData];
                    } else {
                        throw InvalidArgumentException::format(
                            'Invalid row array: expecting columns data for column %s to be array, %s given',
                            $columnName, Debug::getType($componentData)
                        );
                    }
                } else {
                    $componentNames = array_keys($componentData);
                    sort($componentNames);

                    if ($componentNames !== $componentNamesMap[$columnName]) {
                        throw InvalidArgumentException::format(
                            'Invalid row array: expecting columns data for column %s to have be array with keys (%s), (%s) given',
                            $columnName, Debug::formatValues($componentNamesMap[$columnName]), Debug::formatValues($componentNames)
                        );
                    }
                }
            }

            $rows[] = new TableRow($rowData);
        }

        return $rows;
    }
253766
private function serializeArrayOrTable(array $array)
    {
        $assoc = false;
        $index = 0;
        $values = [];

        foreach ($array as $key => $value) {
            // We already know the array is associative, serialize both the key
            // and the value ...
            if ($assoc) {
                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                // Otherwise, if the key matches the index counter it is sequential,
                // only serialize the value ...
            } elseif ($key === $index++) {
                $values[] = $this->serializeField($value);

                // Otherwise, we've just discovered the array is NOT sequential,
                // Go back through the existing values and add the keys ...
            } else {
                foreach ($values as $k => $v) {
                    $values[$k] = $this->serializeShortString($k) . $v;
                }

                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                $assoc = true;
            }
        }

        return ($assoc ? 'F' : 'A') . $this->serializeByteArray(
                implode('', $values)
            );
    }
1201171
public function selectRow($struct, $fetch = \PDO::FETCH_ASSOC, $fetchArgs = null): \Generator
    {
        $lifetime = $this->lifetime;
        $rowLifetime = $lifetime ? $lifetime + 5 : 0;

        $key = $this->key('selectRow', [$struct, $fetch, $fetchArgs]);

        $countCache = $this->name($key . '_count')->doGet();
        if (($count = $this->getResult($countCache)) === null) {
            $rows = $this->db->selectRow($struct, $fetch, $fetchArgs);
            if (!$rows->valid()) {
                $this->reset();

                return;
            }

            $index = 0;
            foreach ($rows as $row) {
                yield $row;

                $this->name($key . '_' . (string) $index++)
                    ->expiresAfter($rowLifetime)
                    ->doSave($row);
            }

            $this->name($key . '_count')
                ->expiresAfter($lifetime)
                ->doSave((string) $index);
        } else {
            for ($i = 0; $i < $count; ++$i) {
                yield $this->getResult(
                    $this->name($key . '_' . (string) $i)
                        ->doGet()
                );
            }
        }

        $this->reset();
    }
101242
protected function parse(array $structure, int $offset = null)
    {
        $result = [];
        $current = $offset ?? 0;

        $count_structure = 0;
        foreach ($structure as $registry_group) {
            if (is_array($registry_group)) {
                $buffer = [];
                do {
                    try {
                        $rec = $this->parse($registry_group, $current);
                        $nested = (count($registry_group) > 1)
                            ? [$rec['registries']]
                            : $rec['registries'];
                        $buffer = array_merge($buffer, $nested);
                        $current = $rec['offset'];
                    } catch (ParseException $e) {
                        if (count($buffer) === 0) {
                            throw $e;
                        } else {
                            $first = $registry_group[0];
                            if (is_string($first)) {
                                $first = explode(' ', $first);
                            }
                            $in_first = array_intersect(
                                $first,
                                $e->getRegistries()
                            );
                            if (count($in_first) === 0) {
                                throw $e;
                            }
                            break;
                        }
                    }
                } while ($current < count($this->registries));
                $nested = (count($registry_group) > 1)
                    ? $buffer
                    : [$buffer];
                $result = array_merge($result, $nested);
            } else {
                $types = explode(' ', $registry_group);
                $registry = $this->pregRegistry($current, $types);

                if ($registry !== null) {
                    $result[] = $registry;
                    $current++;
                } elseif (count($result) === 0 || $count_structure > 0) {
                    throw new ParseException(
                        $this->config,
                        $types,
                        $current + 1
                    );
                }
            }
            $count_structure++;
        }

        return [
            'offset' => $current,
            'registries' => $result,
        ];
    }
630074
public function toArray(): array 
    {

        $to_array = function (EncapsulatedEdge $encapsulated): array {
            return $encapsulated->toArray();
        };

        $array = [];

        $array["to"] = [];
        foreach($this->to as $to => $encapsulated) {
            $array["to"][$to] = array_map($to_array, $encapsulated);
        }

        $array["from"] = [];
        foreach($this->from as $from => $encapsulated) {
            $array["from"][$from] = array_map($to_array, $encapsulated);
        }

        $array["in"] = array_map($to_array, $this->in);
        $array["out"] = array_map($to_array, $this->out);

        return $array;
    }