Parses the passed stream context and returns the context options
relevant for this stream wrapper

@param   boolean $all    Return all options instead of just the relevant options
@return  array           The context options
170519
protected function getContextOptions($all = false)
    {
        if ($this->contextOptions === null) {
            $this->contextOptions   = stream_context_get_options($this->context);
        }

        if (!$all && array_key_exists(self::$protocol, $this->contextOptions)) {
            return $this->contextOptions[self::$protocol];
        } else if ($all) {
            return $this->contextOptions;
        } else {
            return array();
        }
    }
511758
protected function getStreamContext($url)
    {
        $host = parse_url($url, PHP_URL_HOST);

        if (PHP_VERSION_ID < 50600) {
            $this->options['ssl']['CN_match'] = $host;
            $this->options['ssl']['SNI_server_name'] = $host;
        }

        return $this->getMergedStreamContext($url);
    }
680144
protected function parseRoutes(array $allRoutes)
    {
        return Collection::make($allRoutes)
            ->partition(function ($route) {
                return ! Str::startsWith($route, ['not:']);
            })
            ->transform(function (Collection $routes, $index) {
                return $index === 0
                    ? $routes
                    : $routes->transform(function ($route) { return substr($route, 4); });
            })
            ->toArray();
    }
562779
public function all($clear=false)
    {
        $parameters = $this->parameters;

        if($clear === true) {
            $this->parameters = array();
        }

        return $parameters;
    }
707523
public function getStream($context = null)
	{
		if (is_null($context)) {
			return fopen($this->path, 'rb', false);
		} else {
			return fopen($this->path, 'rb', false, $context);
		}
	}
734499
public function clearProxySettings($wrapper = null)
    {
        $wrappers = isset($wrapper) ? array($wrapper) : array_keys($this->_streamContextOptions);

        $clearedWrappers = array();
        $options = array('proxy', 'request_fulluri', 'header');
        foreach ($wrappers as $wrapper) {

            // remove wrapper options related to proxy settings
            if (isset($this->_streamContextOptions[$wrapper]['proxy'])) {
                foreach ($options as $option){
                    unset($this->_streamContextOptions[$wrapper][$option]);
                }

                // remove wrapper entry if there are no other options left
                if (empty($this->_streamContextOptions[$wrapper])) {
                    unset($this->_streamContextOptions[$wrapper]);
                }

                $clearedWrappers[] = $wrapper;
            }
        }

        return $clearedWrappers;
    }
1277480
public function getSegments($all = false)
    {
        if ($all) {
            return $this->segments;
        }
        $segments = [];
        foreach ($this->segments as $segment) {
            if ($segment->isEnabled()) {
                $segments[] = $segment;
            }
        }
        return $segments;
    }
12641
private function parsePoolOptions($options)
    {
        $defaults = [
            'pool_class' => $this->poolClass,
            'item_class' => $this->itemClass,
            'namespace'  => $this->namespace,
            'logger'     => $this->logger,
        ];

        if ($options === null) {
            return $defaults;
        }

        if (is_string($options)) {
            $options = [
                'namespace' => $options
            ];
        }

        if (!is_array($options)) {
            return $defaults;
        }

        return array_replace($defaults, $options);
    }
282346
public function getContainerFromContext($path)
    {
        $scheme = current(preg_split('#://#', $path));
        $options = stream_context_get_options(stream_context_get_default());

        return $options[$scheme]['Container'];
    }
1114530
public function getImportersForContext($all = false)
    {
        $importers = [];
        foreach ($this->configuration->getImporters($all) as $key => $importer) {
            if ($importer->supports($this->configuration)) {
                $importers[] = $importer;
            }
        }
        return $importers;
    }
104218
public function value_editor_options(\context $context = null) {
        global $CFG;
        require_once($CFG->libdir.'/formslib.php');
        if (!$context) {
            $context = $this->get_handler()->get_configuration_context();
        }
        return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context];
    }
38022
public function parse(Context $context) {
	    $this->context = $context;
		$this->viewElement = $context->tag;

		//Interpret an empty expression as boolean false.
		if(trim($this->expression) == '') {
		  $this->pushOperand(new TokenLiteral(false));
		  return true;
		}

		$char = '';

		try {
			$expressionSize = strlen($this->expression);
			for($this->parsingPosition = 0; $this->parsingPosition < $expressionSize; ++ $this->parsingPosition) {
				$char = $this->expression[$this->parsingPosition];
				$this->currentState->input($this, $char);
			}

			$this->currentState->endOfInput($this);

			while(count($this->stackOperators)) {
				$operator = array_pop($this->stackOperators);
				$nbOperands = $operator->getNumOperands();
				if($nbOperands) {
					// Check that we have enough operands on the stack.
					if (count($this->stackRP) < $nbOperands) {
						throw new LexerSyntaxErrorException('Missing operand', $this->getViewFile(), $this->getViewLine());
					}
					$operator->setOperands(array_splice($this->stackRP, count($this->stackRP) - $nbOperands, $nbOperands));
				}
				$this->stackRP[] = $operator;
				if($operator instanceof TokenFunction) {
									array_pop($this->stackFunctions);
				}
			}
		}

		// Enrich the Lexer parsing and tokenizing exceptions with template file and line
		catch (LexerUnbalancedParenthesesException $exception) {
		    throw new LexerUnbalancedParenthesesException($exception->getMessage(), $this->getViewFile(), $this->getViewLine());
        } catch (LexerSyntaxErrorException $exception) {
		    throw new LexerSyntaxErrorException($exception->getMessage(), $this->getViewFile(), $this->getViewLine());
        } catch (Exception $exception) {
			$errorMsg = "Unexpected character: $char at position: {$this->parsingPosition} in expression: {$this->expression}.";
			throw new LexerUnexpectedCharException($errorMsg, $this->getViewFile(), $this->getViewLine());
		}

		if( (count($this->stackOperators) > 0) ||
				(count($this->stackFunctions) > 0) ||
				(count($this->stackRP) != 1)
			)
		{
			$message = $this->getViewFile() . '(' . $this->getViewLine() . '): Syntax error in expression: ' . $this->expression;
			throw new LexerSyntaxErrorException($message,
					$this->getViewFile(),
					$this->getViewLine());
		}

		// Check for unbalanced parentheses:
		if( ($this->stackRP[0] instanceof TokenFunction) &&
		    (! $this->stackRP[0]->isClosed())
		)
		{
		  $message = $this->getViewFile() . '(' . $this->getViewLine() . '): Unbalanced parentheses in expression: ' . $this->expression;
		  throw new LexerUnbalancedParenthesesException($message,
		    $this->getViewFile(),
		    $this->getViewLine());
		}

		return true;
	}
1091147
function toContext()
    {
        $options  = new Std\Type\StdTravers($this);
        $options  = $options->toArray(function($val) {
            ### we don`t want null values on context params
            return ($val === null);
        });

        $params = (isset($options['params'])) ? $options['params'] : array();
        unset($options['params']);


        if (isset($options['options']))
            // We get bind context below; so unset here
            /** @see self::getItterator() */
            unset($options['options']);

        $options = array(
            $this->getWrapperName() => $options,
        );

        $bindOptions = $this->_getBindContextOptions();
        $options     = array_merge($bindOptions, $options);

        $context = stream_context_create($options, $params);
        return $context;
    }
681925
public function getContextOptions()
    {
        if ($this->_contextOptions === null) {
            $this->_contextOptions = stream_context_get_options($this->context);
        }
        return $this->_contextOptions;
    }
1038831
protected function _parseArgs()
    {
        $inString = false;
        $cpt = 0;
        $last = $char = $value = $name = '';
        $args = [];
        $body = '';
        while ($token = $this->_stream->current(true)) {
            $body .= $token[1];
            switch ($token[0]) {
                case '(':
                    if ($cpt) {
                        $value .= $token[1];
                    }
                    $cpt++;
                break;
                case '=':
                    $name = $value;
                    $value = '';
                break;
                case ')':
                    $cpt--;
                    if ($cpt) {
                        $value .= $token[1];
                        break;
                    }
                case ',':
                    $value = trim($value);
                    if ($value !== '') {
                        $name ? $args[trim($name)] = $value : $args[] = $value;
                    }
                    $name = $value = '';
                break;
                default:
                    $value .= $token[1];
                break;
            }
            if ($token[1] === ')' && $cpt === 0) {
                break;
            }
            $this->_stream->next();
        }
        return compact('args', 'body');
    }
290553
public function getOptions()
    {
        if($resource = $this->getResource())
        {
            $options = stream_context_get_options($resource);

            if(!empty($options))
            {
                $name = key($options);
                $result = $options[$name];
            }
            else $result = array();

            return $result;
        }

        return $this->_options;
    }
300555
public function parse($content)
    {
        if (!$content || strpos($content, '@view') === false) {
            return [];
        }
        $ret = [];

        if (preg_match(self::VIEW_RENDER, $content, $match)) {
            $ret[0] = array_pop($match);
        } else {
            $ret[0] = null;
        }

        if (preg_match(self::VIEW_TEMPLATE_FILE, $content, $match)) {
            $ret[1] = array_pop($match);
        } else {
            $ret[1] = null;
        }

        if (preg_match_all(self::VIEW_PARAMETERS, $content, $match, PREG_SET_ORDER)) {
            $set = [];
            // "all" is excluded
            foreach ($match as $position => $group) {
                $set[$group[1]] = $group[2];
            }

            if ($set){
                $ret[] = $set;
            }

        }

        return $ret;
    }