Add the context of each exception in the stack.

@param Exception $exceptionRoot
@param array     $context

@return array
546427
private function addStackContext(Exception $exceptionRoot, array $context)
    {
        $exception = $exceptionRoot;

        do {
            $context = $this->processExceptionContext($exception, $context);
        }
        while ($exception = $exception->getPrevious());

        return $context;
    }
956136
public static function setContextData(array $contextData = [])
    {
        $coroutineId = self::getcoroutine();
        self::$coroutineLocal[$coroutineId][self::COROUTINE_DATA] = $contextData;
    }
372795
public Exception getRootCause() {
		if (exception instanceof ServiceLocatorException) {
			return ((ServiceLocatorException) exception).getRootCause();
		}
		return exception == null ? this : exception;
	}
688986
public static function validate_context($context) {
        global $CFG, $PAGE;

        if (empty($context)) {
            throw new invalid_parameter_exception('Context does not exist');
        }
        if (empty(self::$contextrestriction)) {
            self::$contextrestriction = context_system::instance();
        }
        $rcontext = self::$contextrestriction;

        if ($rcontext->contextlevel == $context->contextlevel) {
            if ($rcontext->id != $context->id) {
                throw new restricted_context_exception();
            }
        } else if ($rcontext->contextlevel > $context->contextlevel) {
            throw new restricted_context_exception();
        } else {
            $parents = $context->get_parent_context_ids();
            if (!in_array($rcontext->id, $parents)) {
                throw new restricted_context_exception();
            }
        }

        $PAGE->reset_theme_and_output();
        list($unused, $course, $cm) = get_context_info_array($context->id);
        require_login($course, false, $cm, false, true);
        $PAGE->set_context($context);
    }
45707
protected function error(\Exception $error, Context $context = null)
    {
        $exception = get_class($error);
        $this->logger->error($error);

        if($this->catch) {
            foreach($this->errors as $class => $callback) {
                if(is_string($class) and $error instanceof $class) {
                    $context->error = $error;
                    $this->logger->debug('kernel.error: ' . $exception . ' raised, has callback');
                    return $context->forward($callback, $error);
                }
            }
        }

        $this->logger->debug('kernel.error: ' . $exception . ' raised, no callback');
        throw $error;
    }
1122996
public function setExtension($ext)
	{
		$this->extension = $ext;

		if(!$this->extensionMap->has($ext))
		{
			throw new Exceptions\InvalidExtension($ext);
		}

		return $this;
	}
89892
protected function throwUnauthorizedException(array $exceptionStack)
    {
        $exception = array_shift($exceptionStack);

        if ($exception === null) {
            $exception = new UnauthorizedException('Failed to authenticate because of bad credentials or an invalid authorization header');
        }

        throw $exception;
    }
1287209
public function deleteByRoot( $rootId = null, array $except = array() )
    {
        if ( null === $rootId )
        {
            $where = array( new Predicate\IsNull(
                'rootParagraphId'
            ) );
        }
        else
        {
            $where = array(
                'rootParagraphId' => (int) $rootId,
            );
        }

        if ( ! empty( $except ) )
        {
            $where[] = new Predicate\NotIn( 'id', $except );
        }

        $delete = $this->sql()
                       ->delete()
                       ->where( $where );

        $result = $this->sql()
                       ->prepareStatementForSqlObject( $delete )
                       ->execute();

        return $result->getAffectedRows();
    }
1059142
protected function convertToArray(\Exception $exception, Context $context)
    {
        $data = [];

        if ($context->hasAttribute('template_data')) {
            $templateData = $context->getAttribute('template_data');
            if (array_key_exists('status_code', $templateData)) {
                $data['code'] = $statusCode = $templateData['status_code'];
            }
        }

        $data['message'] = $this->getExceptionMessage($exception, isset($statusCode) ? $statusCode : null);

        return $data;
    }
1078998
public function getRoot() {
		if ($this->root) {

			if (!is_dir($this->root)) {
				throw new \Exception('Root directory not exists ' . $this->root, Consts::ERROR_CODE_NOT_EXISTS);
			}

			return realpath($this->root) . Consts::DS;
		}

		throw new \Exception('Set root directory for source', Consts::ERROR_CODE_NOT_IMPLEMENTED);
	}
754509
public function buildClassNameContext($context)
    {
        $contextClass = $context;
        if (is_object($contextClass)) {
            $contextClass = get_class($contextClass);
        }

        if (!is_string($contextClass)) {
            $errMsg = sprintf(
                'Context of type %s is invalid; Context not string.',
                (is_object($context) ? get_class($context) : gettype($context))
            );
            throw new Exception\InvalidContextException($errMsg);
        }

        return $contextClass;
    }
1190720
public function createRoot(Lang $lang) : void
    {
        if (php_sapi_name() !== 'cli')
        {
            throw new \Exception("Method createRoot() is allowed only in CLI mode.");
        }

        $root = $this->pageRepository->findOneAbsoluteRoot();

        if ($root === NULL)
        {
            $root = new Page;
            $root->setName('root');
            $root->setView('root');
            $root->makeRoot();
            $root->save();
        }

        $langRoot = $this->pageRepository->findOneLangRoot($lang, TRUE);

        if ($langRoot === NULL)
        {
            $langRootName = 'root-' . $lang->getName();

            $langRoot = new Page;
            $langRoot->setName($langRootName);
            $langRoot->setView($langRootName);
            $langRoot->setParent($root);
            $langRoot->insertAsLastChildOf($root);
            $langRoot->save();

            $this->pageUrlManager->saveUrl($lang, $langRoot, '__a@&*^-9' . $langRootName);
        }
    }
201181
protected function parseRootNode($jsonLDRoot)
    {
        $item = null;

        try {
            $jsonDLDocument = JsonLDParser::getDocument($jsonLDRoot, ['documentLoader' => $this->contextLoader]);

            // Run through all nodes to parse the first one
            /** @var Node $node */
            foreach ($jsonDLDocument->getGraph()->getNodes() as $node) {
                $item = $this->parseNode($node);
                break;
            }
        } catch (JsonLdException $exception) {
            $this->logger->error($exception->getMessage(), ['exception' => $exception]);
        }

        return $item;
    }
663472
public function emergency($messageOrException, $contextOrException = null, array $context = array()) {
        $this->log(LogLevel::EMERGENCY, $messageOrException, $contextOrException, $context);
    }
1191639
public function add_to_context( $context ) {
		$context['foo'] = 'bar';
		$context['stuff'] = 'I am a value set in your functions.php file';
		$context['notes'] = 'These values are available everytime you call Timber::context();';
		$context['menu'] = new Timber\Menu();
		$context['site'] = $this;
		return $context;
	}
1078106
public void setRoot(int context, Object environment)
  {

    m_context = context;
    
    XPathContext xctxt = (XPathContext)environment;
    m_execContext = xctxt;
    m_cdtm = xctxt.getDTM(context);
    
    m_currentContextNode = context; // only if top level?
    
    // Yech, shouldn't have to do this.  -sb
    if(null == m_prefixResolver)
    	m_prefixResolver = xctxt.getNamespaceContext();
        
    m_lastFetched = DTM.NULL;
    m_foundLast = false;
    m_pos = 0;
    m_length = -1;

    if (m_isTopLevel)
      this.m_stackFrame = xctxt.getVarStack().getStackFrame();
      
    // reset();
  }
878208
public function addContext($context = [])
    {
        if (!$context || empty($context)) {
            return $this;
        }
        $this->nestContext($context);
        $this->sanitizeContext($context);
        $this->context = array_merge($this->context, $context);

        return $this;
    }