Processes the given array of arguments for an attribute.

@param string|array $stringOrArray
@param ViewableData $object
@param ViewableData $parent

@return array
187765
public function processAttributeArgs($stringOrArray, ViewableData $object, ViewableData $parent = null)
    {
        $args = (array) $stringOrArray;
        
        foreach ($args as $key => $arg) {
            $args[$key] = $this->processAttribute($arg, $object, $parent);
        }
        
        return $args;
    }
683563
protected function processResourceData(array $resourceData, array $parentModels, $type)
    {
        try {
            $this->seenTypes[$type] = $resourceData;
            return parent::processResourceData($resourceData, $parentModels, $type);
        } catch (MissingResolverException $exception) {
        } catch (\ReflectionException $exception) {
        }

        return null;
    }
593019
public static function toArray($stringOrArray, string $separator = '.'): array
    {
        if (is_string($stringOrArray)) {
            if (trim($stringOrArray) !== '') {
                $stringOrArray = explode($separator, $stringOrArray);
            }
        }
        if (!is_array($stringOrArray)) {
            return [];
        }
        return $stringOrArray;
    }
677180
public function normalize($object, $format = null, array $context = []): array
    {
        if (!$object instanceof RelationCollection && !$object instanceof ActionCollection) {
            throw new \InvalidArgumentException(sprintf(
                'The normalizer support only "%s" or "%s" but "%s" given.',
                RelationCollection::class,
                ActionCollection::class,
                is_object($object) ? get_class($object) : gettype($object)
            ));
        }

        $data = [];

        foreach ($object as $relation) {
            $data[$relation->getName()] = $this->normalizer->normalize($relation, $format);
        }

        return $data;
    }
105705
private function parse(array $data, NodePath $nodePath, $parentId = null)
    {
        $parentId = $this->validateParentId($parentId);
        $csvFile = $this->createCsvFile($this->structure->getTypeFromNodePath($nodePath), $nodePath, $parentId);
        $parentCols = array_fill_keys(array_keys($parentId), "string");

        foreach ($data as $row) {
            // in case of non-associative array of strings
            // prepare {"data": $value} objects for each row
            if (is_scalar($row) || is_null($row)) {
                $row = (object) [Structure::DATA_COLUMN => $row];
            } elseif ($this->analyzer->getNestedArrayAsJson() && is_array($row)) {
                $row = (object) [Structure::DATA_COLUMN => json_encode($row)];
            }

            // Add parentId to each row
            if (!empty($parentId)) {
                $row = (object) array_replace((array) $row, $parentId);
            }

            $csvRow = $this->parseRow($row, $nodePath, $parentCols);
            $csvFile->writeRow($csvRow->getRow());
        }
    }
1356204
public static function convertByParent($data, $parent_field, $options = []) {
		$pointers = [];
		foreach ($data as $k => $v) {
			if (empty($v[$parent_field])) {
				continue;
			}
			// if parent is down the road
			if (!empty($data[$v[$parent_field]])) {
				$data[$v[$parent_field]]['options'][$k] = $data[$k];
				// disable parents
				if (!empty($options['disable_parents'])) {
					$data[$v[$parent_field]]['disabled'] = 1;
				}
				$pointers[$k] = & $data[$v[$parent_field]]['options'][$k];
				unset($data[$k]);
			} else if (!empty($pointers[$v[$parent_field]])) {
				$pointer = & $pointers[$v[$parent_field]];
				$pointer['options'][$k] = $data[$k];
				$pointers[$k] = & $pointer['options'][$k];
				unset($data[$k]);
			}
		}
		return $data;
	}
1021530
public function normalize($object, $format = null, array $context = []): array
    {
        $nested = $object->getMessage() || $object->getReason();

        $errors = [];

        foreach ($object as $item) {
            $errors[] = $this->normalizer->normalize($item, $format, $context);
        }

        $links = [];

        if (count($object->getRelations())) {
            $links = array_merge($links, $this->normalizer->normalize($object->getRelations(), $format, $context));
        }

        if (count($object->getActions())) {
            $links = array_merge($links, $this->normalizer->normalize($object->getActions(), $format, $context));
        }

        if ($nested) {
            $innerError = new ErrorResource(
                $object->getMessage(),
                $object->getReason(),
                $object->getPath(),
                $object->getAttributes(),
                $object->getIdentifier()
            );

            $data = $this->normalizer->normalize($innerError, $format, $context);

            if (count($links)) {
                $data['_links'] = $links;
            }

            $data['_embedded'] = [
                'errors' => $errors,
            ];

            return $data;
        }

        $data = [
            'total' => count($errors),
            '_embedded' => [
                'errors' => $errors,
            ],
        ];

        if (count($links)) {
            $data['_links'] = $links;
        }

        return $data;
    }
988201
public static function queryString($params, $parent = null, $callback = 'rawurlencode', $ignoreNonValues = true)
    {
        $params = self::flattenRequestVars($params, $parent);
        $ret = [];
        foreach ($params as $pair) {
            list($name, $value) = $pair;
            if (!$value && $ignoreNonValues) {
                continue;
            }
            if ($callback) {
                $value = call_user_func($callback, $value);
            }
            $ret[] = sprintf('%s=%s', $name, $value);
        }
        return implode('&', $ret);
    }
1212719
protected function bindData(&$parent, $data)
  {
    if ( is_object($data) ){
      $data = get_object_vars($data);
    }
    else {
      $data = (array) $data;
    }
    
    foreach($data as $k => $v){
      if ( (is_array($v) && ArrayHelper::isAssociative($v)) || is_object($v) ){
        $parent->$k = new \stdClass;
        $this->bindData($parent->$k, $v);
      }
      else {
        $parent->$k = $v;
      }
    }
  }
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;
    }
983158
protected function getObjectParams(DOMElement $object)
	{
		$params      = [];
		$settingName = strtolower($this->settingName);
		foreach ($object->getElementsByTagName('param') as $param)
		{
			$paramName = strtolower($param->getAttribute('name'));
			if ($paramName === $settingName && $param->parentNode->isSameNode($object))
			{
				$params[] = $param;
			}
		}

		return $params;
	}
785070
private function sanitizeData(array $data, ?int $parentIndex = null)
    {
        $isMultiRows   = null === $parentIndex && $this->isMultiRows($data);
        $sanitizedData = [];

        foreach (array_values($data) as $index => $value) {
            if ($isMultiRows && !is_array($value)) {
                throw new WriteRequestFailedException(
                    sprintf('Input data started with an array  but found %s at index %s', gettype($value), $index)
                );
            }

            if ($isMultiRows) {
                $sanitizedData[] = $this->sanitizeData($value, $index);
                continue;
            }

            $sanitizedData[] = $this->sanitizeValue($value, $index, $parentIndex);
        }

        return $sanitizedData;
    }
72652
private function buildTree($account, &$data, $parent) {
    $data[] = array($account['name'], null, 1);
    if ($account['subAccounts']) {
      foreach($account['subAccounts'] as $subAccount) {
        $this->buildTree($subAccount, $data, $account['name']);
      }
    }
  }
358159
public function loadArguments($data, callable $callable, Context $context): array
    {
        if (is_object($data) && $data instanceof \stdClass) {
            $data = get_object_vars($data);
        }

        if (!is_array($data)) {
            throw new InvalidDataException('Argument data must array or stdClass');
        }

        $metadata = $this->callableMetadataProvider->getCallableMetadata($callable);

        $args = [];
        $paramPos = 0;
        $argPos = 0;
        while ($paramPos < count($metadata->parameters)) {
            $param = $metadata->parameters[$paramPos];
            $mangledName = $this->nameMangler->mangle($param->name);

            $key = null;
            if (array_key_exists($argPos, $data)) {
                $key = $argPos;
            } elseif (array_key_exists($mangledName, $data)) {
                $key = $mangledName;
            }

            if ($key !== null) {
                $context->pushPath('$' . $key);
                try {
                    $args[] = $this->loader->load($data[$key], $param->type, $context);
                } finally {
                    unset($data[$key]);
                    $context->popPath();
                }
            } elseif ($param->optional) {
                if ($param->variadic) {
                    break;
                }
                $args[] = $param->defaultValue;
            } else {
                throw new InvalidDataException("Required argument $param->name missing");
            }

            $argPos++;
            if (!$param->variadic) {
                $paramPos++;
            }
        }

        if (!empty($data) && $this->throwOnUnknownArgument) {
            throw new InvalidDataException(
                'Some arguments could not be matched: ' . implode(', ', array_keys($data))
            );
        }

        return $args;
    }
506675
protected function _arrayToXml($data, Xml $xml, $addCdata, $parent)
    {
        foreach ($data as $key => $value) {
            $key        = str_replace(' ', '_', $key);
            $attributes = [];
            $data       = '';

            if (is_object($value)) {
                try {
                    $data = Serializer::serialize($value);
                } catch (ExceptionInterface $exception) {
                    $this->_addException($exception);
                }

                $value = [
                    '@attributes' => ['serialized_object' => true],
                    $data
                ];
            }

            try {
                $isArray = is_array($value);

                if ($isArray && array_key_exists('@attributes', $value)) {
                    $attributes = $value['@attributes'];
                    unset ($value['@attributes']);
                }

                if ($isArray) {
                    $parent = $this->_convertArrayDataToXml(
                        $value,
                        $addCdata,
                        $xml,
                        $key,
                        $parent,
                        $attributes
                    );
                    continue;
                }

                $element = $this->_appendDataToNode($addCdata, $xml, $key, $value);
                $parent->appendChild($element);

            } catch (DOMException $exception) {
                $this->_addException($exception);
            }
        }

        return $xml;
    }
988299
public function normalize($object, $format = null, array $context = []): array
    {
        // Call to before normalization callback
        if (array_key_exists('before_normalization', $context)) {
            $beforeNormalization = $context['before_normalization'];

            if (!is_callable($beforeNormalization)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid callable for before normalization. "%s" given.',
                    is_object($beforeNormalization) ? get_class($beforeNormalization) : gettype($beforeNormalization)
                ));
            }

            $beforeNormalization($object, $format, $context);
        }

        // Normalize object
        $data = parent::normalize($object, $format, $context);

        if (!$this->serializeNull) {
            $data = $this->removeNullableAttributes($data);
        }

        // Call to after normalization callback
        if (array_key_exists('after_normalization', $context)) {
            $afterNormalization = $context['after_normalization'];

            if (!is_callable($afterNormalization)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid callable for after normalization. "%s" given.',
                    is_object($afterNormalization) ? get_class($afterNormalization) : gettype($afterNormalization)
                ));
            }

            $data = $afterNormalization($data, $object, $format, $context);

            if (!is_array($data)) {
                throw new \LogicException(sprintf(
                    'The after normalization callback should return array, but "%s" given.',
                    is_object($data) ? get_class($data) : gettype($data)
                ));
            }
        }

        return $data;
    }
766634
protected function writeObjectInheritance($object, $parentName)
    {
        try {
            $parent      = $this->reflector->getClass($parentName);
            $longName    = $parent->getName();

            $this->writeObjectElement($parent);

        } catch (\Exception $e) {
            // object is undeclared in data source
            $parts       = explode('\\', $parentName);
            $shortName   = array_pop($parts);
            $longName    = $parentName;
            $ns          = implode($this->namespaceSeparator, $parts);

            if (!isset($this->objects[$ns])) {
                $this->objects[$ns] = array();
            }

            if (!array_key_exists($shortName, $this->objects[$ns])) {
                $type = $object->isInterface() ? 'interface' : 'class';
                $this->pushObject($ns, $shortName, $longName, $type);
            }
        }

        $this->pushEdge(array($object->getName(), $longName));
    }