setByPath
@param array|\ArrayAccess &$data
@param string              $path
@param mixed               $value
@param string              $separator
966095
public static function setByPath(&$data, string $path, $value, string $separator = '.'): void
    {
        if (false === \strpos($path, $separator)) {
            $data[$path] = $value;
            return;
        }

        if (!$nodes = \array_filter(\explode($separator, $path))) {
            return;
        }

        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (\is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    $dataTmp[$node] = [];
                }

                $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 = [];
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        $dataTmp = $value;
    }
1292372
public function resolve(array $path, $separator = '/')
    {
        $fields = false;
        $parts = [];
        $current = $this['form/fields'];
        $result = [null, null, null];

        while (($field = current($path)) !== null) {
            if (!$fields && isset($current['fields'])) {
                if (!empty($current['array'])) {
                    $result = [$current, $parts, $path ? implode($separator, $path) : null];
                    // Skip item offset.
                    $parts[] = array_shift($path);
                }

                $current = $current['fields'];
                $fields = true;

            } elseif (isset($current[$field])) {
                $parts[] = array_shift($path);
                $current = $current[$field];
                $fields = false;

            } elseif (isset($current[$index = '.' . $field])) {
                $parts[] = array_shift($path);
                $current = $current[$index];
                $fields = false;

            } else {
                break;
            }
        }

        return $result;
    }
1178737
public function set($path, $value, $constraint = null)
    {
        if ($constraint === null) {
            $constraint = $this->constraint;
        }

        if ($constraint) {
            $value = json_decode(json_encode($value), true);
        }

        if (is_null($path)) {
            $this->item[] = $value;
            return;
        }

        $path = explode($this->separator, $path);
        $last = array_pop($path);
        $item = &$this->item;

        foreach ($path as $key) {
            if (!array_key_exists($key, $item) || !is_array($item[$key])) {
                $item[$key] = array();
            }

            $item = &$item[$key];
        }

        $item[$last] = $value;
    }
407907
static function pathSet(&$values, $pathParts, $value) {
        $r = &$values;
        $last = array_pop($pathParts);
        foreach ($pathParts as $part) {
            if (!isset($r[$part])) {
                $r[$part] = array();
            }
            $r = &$r[$part];
        }
        $r[$last] = $value;
    }
1214624
public static function set(array $set, $path, $value = null) {
        if (is_array($path)) {
            foreach ($path as $key => $value) {
                $set = static::insert($set, $key, $value);
            }
        } else {
            $set = static::insert($set, $path, $value);
        }

        return $set;
    }
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;
    }
113547
public static function pathSet(&$array, $path, $value = null)
    {
        if (!\is_array($path)) {
            $path = \array_filter(\preg_split('#[\./]#', $path), 'strlen');
        }
        $found = true;
        $cur = &$array;
        $path = \array_reverse($path);
        while ($path) {
            $key = \array_pop($path);
            if (!\is_array($cur)) {
                $cur = array();
            }
            if (isset($cur[$key])) {
                $cur = &$cur[$key];
            } elseif ($key == '__end__') {
                $keys = \array_keys($cur);
                $path[] = \array_pop($keys);
            } elseif ($key == '__push__') {
                $cur[] = array();
                $keys = \array_keys($cur);
                $path[] = \array_pop($keys);
            } elseif ($key == '__reset__') {
                $keys = \array_keys($cur);
                $path[] = \array_shift($keys);
            } else {
                $found = false;
                $cur[$key] = array();
                $cur = &$cur[$key];
            }
        }
        $return = $found
            ? $cur
            : null;
        $cur = $value;
        return $return;
    }
927037
public function setPath($path, $value = null, $method = null)
    {
        $this->paths[$path] = [];

        if (! is_null($value)) {
            $this->paths[$path]['path'] = $value;
        }

        if (! is_null($method)) {
            $this->paths[$path]['method'] = $method;
        }
    }
1287242
public function setFilename($value, $overwrite = true, $separator = '_')
    {
        // recast to string if $value is array
        if (is_array($value)) {
            $value = implode($separator, $value);
        }

        // trim unneeded values
        $value = trim($value, $separator);

        // remove all spaces
        $value = preg_replace('/\s+/', $separator, $value);

        // if value is empty, stop here
        if (empty($value)) {
            return;
        }

        // decode value + lowercase the string
        $value = strtolower($this->decode($value));

        // urlize this part
        $value = Transliterator::urlize($value);

        // overwrite filename or add to filename using a prefix in between
        $this->filename = ($overwrite) ?
            $value : $this->filename . $separator . $value;
    }
165494
public static function setByPath(&$data, $path, $value, $separator = '.')
    {
        if (false === strpos($path, $separator)) {
            $data[$path] = $value;

            return true;
        }

        if (!$nodes = Str::toArray($path, $separator)) {
            return false;
        }

        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (\is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    $dataTmp[$node] = [];
                }

                $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 = array();
            }
        }

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

        return true;
    }
396239
public function set(string $path, array &$row, string $value = null): void
    {
        if (null === $content = $this->decode($row)) {
            $content = [];
        }

        $pathChunks = explode('.', $path);
        if (0 !== strpos($pathChunks[0], 'row')) {
            throw new \InvalidArgumentException('Path ' . $path . ' first part must be row, found: ' . $pathChunks[0]);
        }
        if (0 !== strpos($pathChunks[1], 'col')) {
            throw new \InvalidArgumentException('Path ' . $path . ' second part must be col, found: ' . $pathChunks[1]);
        }

        $rowIndex = (int) substr($pathChunks[0], 3);
        if (!array_key_exists($rowIndex, $content)) {
            $content[$rowIndex] = [];
        }
        $colIndex = (int) substr($pathChunks[1], 3);

        $content[$rowIndex][$colIndex] = $value;

        $row[$this->name()] = serialize($content);
    }
985709
public static function setPath(& $array, $path, $value, $delimiter = null)
    {
        // 使用默认分隔符
        if ( ! $delimiter)
        {
            $delimiter = self::$delimiter;
        }

        // 处理path节
        $keys = $path;
        if ( ! is_array($path))
        {
            $keys = explode($delimiter, $path);
        }

        while (count($keys) > 1)
        {
            $key = array_shift($keys);

            if (ctype_digit($key))
            {
                $key = (int) $key;
            }

            if ( ! isset($array[$key]))
            {
                $array[$key] = [];
            }

            $array = &$array[$key];
        }

        $array[array_shift($keys)] = $value;
    }
207548
public function edit(array &$array, string $path, $value): void
    {
        // If $path is not writable
        if (false === $this->isRoot($path) && false === $this->pa->isReadable($array, $path)) {
            throw new AccessException(sprintf('The path "%s" you are trying to edit isn\'t readable and so cannot be edited.', $path));
        }

        if ($this->isRoot($path)) {
            $array = $value;
        } else {
            $this->pa->setValue($array, $path, $value);
        }
    }
852739
protected function parseAsMultiple($value, $separator = ',')
    {
        if (is_array($value) || $value instanceof Traversable) {
            $parsed = [];
            foreach ($value as $val) {
                if (empty($val) && !is_numeric($val)) {
                    continue;
                }

                $parsed[] = $val;
            }

            return $parsed;
        }

        if ($separator instanceof PropertyInterface) {
            $separator = $separator->multipleSeparator();
        }

        if (is_object($value) && method_exists($value, '__toString')) {
            $value = strval($value);
        }

        if (empty($value) && !is_numeric($value)) {
            return [];
        }

        /**
         * This property is marked as "multiple".
         * Manually handling the resolution to array
         * until the property itself manages this.
         */
        if (is_string($value)) {
            return explode($separator, $value);
        }

        /**
         * If the parameter isn't an array yet,
         * means we might be dealing with an integer,
         * an empty string, or an object.
         */
        if (!is_array($value)) {
            return (array)$value;
        }

        return $value;
    }
1261238
public function set($path, $value)
    {
        // if is readonly
        if ($this->readonly && $this->has($path)) {
            throw new \InvalidArgumentException("Config data have been setting readonly. don't allow change.");
        }

        return parent::set($path, $value);
    }
1211443
public static function set(&$arr, $str_path, $value) {
		$path = explode('.', $str_path);
		static::array_set($arr, $path, $value);
	}
98274
public function set($path, $value)
    {
        if (strpos($path, '/') === false) {
            $this->data[$path] = $value;

            return $this;
        }

        $pathKeys = explode('/', $path);
        $key = array_pop($pathKeys);
        $data = &$this->data;
        foreach ($pathKeys as $pathKey) {
            if (is_array($data) && array_key_exists($pathKey, $data)) {
                $data = &$data[$pathKey];
            } else {
                continue;
            }
        }
        $data[$key] = $value;

        return $this;
    }