public static function setPath(&$data, $path, $value)
    {
        $queue = explode('/', $path);
        // Optimization for simple sets.
        if (count($queue) === 1) {
            $data[$path] = $value;
            return;
        }

        $current =& $data;
        while (null !== ($key = array_shift($queue))) {
            if (!is_array($current)) {
                throw new \RuntimeException("Trying to setPath {$path}, but "
                    . "{$key} is set and is not an array");
            } elseif (!$queue) {
                if ($key == '[]') {
                    $current[] = $value;
                } else {
                    $current[$key] = $value;
                }
            } elseif (isset($current[$key])) {
                $current =& $current[$key];
            } else {
                $current[$key] = [];
                $current =& $current[$key];
            }
        }
    }