@param array|\Traversable $data
@param string             $path
@param bool               $allowSerializeEmpty

@return AbstractParentNode

@throws \InvalidArgumentException
541996
public function convert($data, string $path = '', bool $allowSerializeEmpty = false): AbstractParentNode
    {
        if (!is_array($data) && !$data instanceof \Traversable) {
            throw new \InvalidArgumentException(sprintf('Params need to be array or %s', \Traversable::class));
        }

        $isArray = $this->isArray($data);
        $parentNode = $this->getParentNode($isArray, $allowSerializeEmpty);

        foreach ($data as $key => $value) {
            $this->addChildNode($parentNode, $key, $value, $path, $isArray, $allowSerializeEmpty);
        }

        return $parentNode;
    }
1108110
protected function chunkError(string $path, array $data): ?array
    {
        if (! isset($data['errors'])) {
            return null;
        }

        return (new Collection($data['errors']))
            ->filter(function (array $error) use ($path): bool {
                return Str::startsWith(implode('.', $error['path']), $path);
            })
            ->values()
            ->toArray();
    }
862731
public static function setByPath(&$data, $path, $value, $separator = '.', $storeType = 'array')
	{
		$nodes = array_values(array_filter(explode($separator, $path), 'strlen'));

		if (empty($nodes))
		{
			return false;
		}

		/**
		 * A closure as inner function to create data store.
		 *
		 * @param string $type
		 *
		 * @return  array
		 *
		 * @throws \InvalidArgumentException
		 */
		$createStore = function($type)
		{
			if (strtolower($type) == 'array')
			{
				return array();
			}

			if (class_exists($type))
			{
				return new $type;
			}

			throw new \InvalidArgumentException(sprintf('Type or class: %s not exists', $type));
		};

		$dataTmp = &$data;

		foreach ($nodes as $node)
		{
			if (is_object($dataTmp))
			{
				if (empty($dataTmp->$node))
				{
					$dataTmp->$node = $createStore($storeType);
				}

				$dataTmp = &$dataTmp->$node;
			}
			elseif (is_array($dataTmp))
			{
				if (empty($dataTmp[$node]))
				{
					$dataTmp[$node] = $createStore($storeType);
				}

				$dataTmp = &$dataTmp[$node];
			}
			else
			{
				// If a node is value but path is not go to the end, we replace this value as a new store.
				// Then next node can insert new value to this store.
				$dataTmp = &$createStore($storeType);
			}
		}

		// Now, path go to the end, means we get latest node, set value to this node.
		$dataTmp = $value;

		return true;
	}
656841
public function delete ($path) {
		list ($first, $rest) = self::getFirstAndRestPathElements($path);

		# If we are going still deeper...
		if (!is_null($rest)) {
			if (array_key_exists($first, $this -> data)) {
				if ($this -> data[$first] instanceof MutableTreeInterface) {
					/** @var MutableTreeInterface $tree */
					$tree = $this -> data[$first];
					$tree -> delete($rest);
				} else {
					throw new InvalidKeyException("Value at key `" . $first . "` is a scalar; cannot step further down the requested path `" . $rest . "`");
				}
			} else {
				throw new NonExistentKeyException("Key `" . $first . "` does not exist.");
			}
		} else {
			unset($this -> data[$first]);
		}

		return $this;
	}
1321960
private function deserializeStep(Path $path, $data, array &$stepIds, array $options = [])
    {
        if (in_array(Options::REFRESH_UUID, $options)) {
            $step = new Step();
        } else {
            $step = $this->stepRepo->findOneBy(['uuid' => $data['id']]) ?? new Step();
            $step->setUuid($data['id']);
        }

        $step->setPath($path);

        $stepIds[] = $step->getUuid();

        if (isset($data['title'])) {
            $step->setTitle($data['title']);
        }
        if (isset($data['description'])) {
            $step->setDescription($data['description']);
        }
        if (isset($data['poster'])) {
            $step->setPoster($data['poster']['url']);
        }

        if (isset($data['display'])) {
            if (isset($data['display']['numbering'])) {
                $step->setNumbering($data['display']['numbering']);
            }
            if (isset($data['display']['height'])) {
                $step->setActivityHeight($data['display']['height']);
            }
        }

        /* Set primary resource */
        $resource = isset($data['primaryResource']['id']) ?
            $this->resourceNodeRepo->findOneBy(['uuid' => $data['primaryResource']['id']]) :
            null;
        $step->setResource($resource);

        if (isset($data['showResourceHeader'])) {
            $step->setShowResourceHeader($data['showResourceHeader']);
        }

        // Set secondary resources
        if (isset($data['secondaryResources'])) {
            $step->emptySecondaryResources();

            foreach ($data['secondaryResources'] as $index => $resourceData) {
                $secondaryResource = new SecondaryResource();
                $secondaryResource->setOrder($index);

                /** @var ResourceNode $resource */
                $resource = $this->resourceNodeRepo->findOneBy(['uuid' => $resourceData['id']]);
                $secondaryResource->setResource($resource);

                $step->addSecondaryResource($secondaryResource);
            }
        }

        // Set children steps
        if (isset($data['children'])) {
            $step->emptyChildren();

            foreach ($data['children'] as $childIndex => $childData) {
                $child = $this->deserializeStep($path, $childData, $stepIds, $options);

                $child->setOrder($childIndex);
                $step->addChild($child);
            }
        }

        return $step;
    }
980373
public function create($path, array $data)
    {
        $data = array_merge($data, ['path' => $path]);

        return File::create($data);
    }
862300
public function get($path, array $data = [])
    {
        $contents = parent::get($path, $data);

        return $this->markdown->convertToHtml($contents);
    }
72475
public static function setByPath(&$data, $paths, $value, $separator = '/', $type = 'array')
    {
        if (empty($paths)) {
            return false;
        }

        $args = is_array($paths) ? $paths : explode($separator, $paths);

        /**
         * A closure as inner function to create data store.
         *
         * @param $type
         *
         * @return  array
         *
         * @throws \InvalidArgumentException
         */
        $createStore = function ($type) {
            if (strtolower($type) === 'array') {
                return [];
            }

            if (class_exists($type)) {
                return new $type();
            }

            throw new \InvalidArgumentException(sprintf('Type %s not supported of class not exists', $type));
        };

        $dataTmp = &$data;

        foreach ($args as $arg) {
            if (is_object($dataTmp)) {
                if (empty($dataTmp->$arg)) {
                    $dataTmp->$arg = $createStore($type);
                }

                $dataTmp = &$dataTmp->$arg;
            } elseif (is_array($dataTmp)) {
                if (empty($dataTmp[$arg])) {
                    $dataTmp[$arg] = $createStore($type);
                }

                $dataTmp = &$dataTmp[$arg];
            } else {
                $dataTmp = &$createStore($type);
            }
        }

        $dataTmp = $value;

        return true;
    }
727819
public function provide($data = null, array $options = [])
    {
        $result = '';
        $data = (string)$data;

        if ('' === trim($data)) {
            return $result;
        }

        if (empty($options['listItems']) && empty($options['fieldDefinitions'])) {
            throw new InvalidArgumentException("No listItems or fieldDefinitions options provided");
        }

        if (empty($options['listItems'])) {
            $selectListItems = $this->config->getProvider('selectOptions');
            $selectListItems = new $selectListItems($this->config);
            $listName = $options['fieldDefinitions']->getLimit();
            $listOptions = [];

            $options['listItems'] = $selectListItems->provide($listName, $listOptions);
        }

        $listItems = $options['listItems'];

        if (!is_array($options['listItems'])) {
            throw new InvalidArgumentException("List items is not an array");
        }

        if (!isset($listItems[$data])) {
            return sprintf(static::VALUE_NOT_FOUND_HTML, parent::provide($data, $options));
        }

        // Concatenate all parents together with value
        // Nested values are dot-separated.  At least the
        // value itself will be included, if no parents.
        $parents = explode('.', $data);
        $path = '';
        foreach ($parents as $parent) {
            $path = empty($path) ? $parent : $path . '.' . $parent;
            $result .= isset($listItems[$path]) ? $listItems[$path] : '';
        }

        return $result;
    }
608979
@Override
  public Stat createOrSetWithParents(String path, String data, List<ACL> acl, CreateMode createMode)
    throws InterruptedException, KeeperException

  {
    if(exists(path) != null)
      return setData(path, data);

    try
    {
      createWithParents(path, data, acl, createMode);
      return null;
    }
    catch(KeeperException.NodeExistsException e)
    {
      // this should not happen very often (race condition)
      return setData(path, data);
    }
  }
116703
public function removeValue($data, $keys)
    {
        if ($this->isKeysEmpty($keys)) {
            return;
        }
        if (!is_array($keys)) {
            $keys = [$keys];
        }

        $accessor = new Accessor($data);
        $keyCount = count($keys);
        $depth    = 0;
        foreach ($keys as $key) {
            if ($depth + 1 === $keyCount) {
                if ($accessor->remove($key) === false) {
                    throw new InvalidArgumentException(sprintf(
                        'Did not remove path %s in structure %s',
                        json_encode($keys),
                        json_encode($data)
                    ));
                }
            } elseif ($accessor->to($key) === false) {
                throw new InvalidArgumentException(sprintf(
                    'Did not find path %s in structure %s',
                    json_encode($keys),
                    json_encode($data)
                ));
            }

            ++$depth;
        }

        return $accessor->getData();
    }
1048014
public static function create(bool $allowSerializeEmpty = false): ObjectNode
    {
        $node = new self();
        $node->allowSerializeEmpty = $allowSerializeEmpty;

        return $node;
    }
1015635
public function post($path, $data)
    {
        if (false === $json = $this->runRequest($path, 'POST', $data)) {
            return false;
        }

        return $this->decode($json);

    }
599204
public function stringNode($value = null, bool $allowSerializeEmpty = false): StringNode
    {
        return StringNode::create($value, $allowSerializeEmpty);
    }
437395
public function lookup($context, $path, $require = false)
    {
        if (empty($path)) {
            throw new \InvalidArgumentException("Passed lookup path is empty.");
        }
        if (empty($context)) {
            throw new \InvalidArgumentException("Specified context is empty while resolving path " . json_encode($path));
        }
        return PropertyAccessor::getByPath($context, $this->path($path), $require);
    }
733333
public function sendRequest($path, $data = null)
    {
        if ($data === null) {
            $method = 'GET';
        } elseif (is_array($data)) {
            $method = 'POST';
            $data = json_encode($data);
        } else {
            throw new InvalidArgumentException('Unexpected type of $data, excepts array or null');
        }

        if (class_exists('Psr\Log\LogLevel')) {
            $log_level_debug = LogLevel::DEBUG;
            $log_level_warning = LogLevel::WARNING;
        }
        else {
            $log_level_debug = 'debug';
            $log_level_warning = 'warning';
        }

        $url = sprintf('%s/%s', $this->host, $path);
        $signature = hash_hmac('md5', $method . $url . ($data ? $data : ''), $this->secret);

        $headers = [
            'Accept: application/json',
            sprintf('Authorization: %s', $this->key),
            sprintf('X-HMAC-Signature: %s', $signature)
        ];
        if (!empty($this->partner)) {
            $headers[] = sprintf('X-Partner-ID: %s', $this->partner);
        }
        if ($method == 'POST') {
            $headers[] = 'Content-Type: application/json';
        }

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        $response = curl_exec($ch);

        $this->log($log_level_debug, 'request: url={url} headers={headers} data={data}', [
            'url' => $url,
            'headers' => $this->maskHeaders($headers),
            'data' => $data
        ]);

        $error = null;
        if ($response === false) {
            $error = curl_error($ch);
        } else {
            $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if ($status !== 200) {
                $error = sprintf('Unexpected status (%s)', $status);
            }
        }
        curl_close($ch);
        if ($error !== null) {
            $this->log($log_level_warning, 'error: {error} {response}', [
                'error' => $error,
                'response' => $response
            ]);
            throw new ClientException($error);
        }

        $this->log($log_level_debug, 'response: {response}', ['response' => $response]);

        return json_decode($response, true);
    }
154212
public function parseXPath(array $xPaths, SimpleXMLElement $elem, array $parentData = [])
    {

        $xPath      = array_shift($xPaths);
        $children   = $elem->xpath($xPath);

        if (false === $children) {
            throw new \Exception(sprintf('Invalid xPath: "%s"', $xPath));
        }

        if (!count($children) && !count($parentData)) {
            //this is the top level so we don't need to nest
            return [$parentData];
        } elseif (!count($children)) {
            return [$parentData];
        }

        $return = [];
        foreach ($children as $child) {
            $data = $this->getScalarRecords($child);
            $data = array_merge($parentData, $data);

            if (count($xPaths) > 0) {
                $return = array_merge($return, $this->parseXPath($xPaths, $child, $data));
            } else {
                $return[] = $data;
            }
        }

        return $return;
    }