Setting MVC

@param string $request_uri
161773
public static function setMvc($request_uri = null) {
		// storing previous mvc settings
		if (\Application::get('mvc.module')) {
			$mvc_prev = \Application::get('mvc_prev');
			if (is_array($mvc_prev)) $mvc_prev = [];
			$mvc_prev[] = \Application::get('mvc');
			\Application::set('mvc_prev', $mvc_prev);
		}
		// processing
		$request_uri = !empty($request_uri) ? $request_uri : $_SERVER['REQUEST_URI'];
		// routing based on rules
		$request_uri = self::route($request_uri);
		// parsing request
		$data = self::mvc($request_uri);
		// forming class name and file
		if (in_array('Controller', $data['controllers'])) {
			$controller_class = str_replace(' ', '\\', implode(' ', $data['controllers']));
			$file = './../libraries/private/' . str_replace('\\', DIRECTORY_SEPARATOR, $controller_class . '.php');
			if (!file_exists($file)) {
				$file = './../libraries/vendor/' . str_replace('\\', DIRECTORY_SEPARATOR, $controller_class . '.php');
			}
		} else {
			$controller_class = 'Controller\\' . str_replace(' ', '\\', implode(' ', $data['controllers']));
			$file = './' . str_replace('\\', DIRECTORY_SEPARATOR, $controller_class . '.php');
		}
		$controller_class = '\\' . $controller_class;
		// assembling everything into settings
		$data = $data;
		$data['controller_class'] = $controller_class;
		$data['controller_action'] = 'action' . str_replace('_', ' ', $data['action']);
		$data['controller_action_code'] = $data['action'];
		$data['controller_id'] = $data['id'];
		$data['controller_view'] = $data['action'];
		$data['controller_layout'] = \Application::get('application.layout.layout') ?? 'index';
		$data['controller_layout_extension'] = \Application::get('application.layout.extension') ?? 'html';
		$data['controller_layout_file'] = \Application::get(['application', 'path_full']) . 'Layout/' . $data['controller_layout'] . '.' . $data['controller_layout_extension'];
		$data['controller_file'] = $file;
		\Application::set('mvc', $data);
	}
972444
public void setImageURI(Uri uri, @Nullable Object callerContext) {
    DraweeController controller =
        mControllerBuilder
            .setCallerContext(callerContext)
            .setUri(uri)
            .setOldController(getController())
            .build();
    setController(controller);
  }
894906
public function setRequestUrl($requestUrl)
    {
        if (!$this->getUrlValidator()->isValid($requestUrl)) {
            throw new InvalidArgumentException('URL provided is invalid');
        }

        $this->requestUrl = $requestUrl;
    }
758124
private function _setRequest()
	{
		if ($this->_requestUri !== NULL) {
            $this->_request = preg_replace('#(^/)|(^' . ROOT . ')|(/$)#', '', $this->_requestUri);

            if (! $this->_request) {
            	$this->_request = self::DEFAULT_MODULE . '/' . self::DEFAULT_VIEW;
            }

            $this->_requestVars = explode('/', $this->_request);
            if (count($this->_requestVars) == 1) {
				$this->_request       .= '/' . self::DEFAULT_VIEW;
				$this->_requestVars[]  = self::DEFAULT_VIEW;
            }

            return $this;
        }

        throw new Exception('Request URI is not available');
	}
1319402
public static void setRequestURI(final HttpServletRequest request, final String requestURI) {
		request.getSession(true).setAttribute(STORE_URI_KEY, requestURI);
	}
414655
public function loadUri()
    {
        $this->contextScheme = $this->getEnv('REQUEST_SCHEME');
        $this->contextHost   = $this->getEnv('SERVER_NAME');

        $uri = explode('?', $this->getEnv('REQUEST_URI'));

        $this->contextBasePath = array_shift($uri);
    }
1081395
public function setRequest(Request $request)
    {
        $this->request = $request;

        $this->cachedRoot = null;
        $this->cachedScheme = null;
        $this->routeGenerator = null;
    }
789377
protected function setRequestProperties(Request $request)
    {
        $this["basePath"] = $request->getBasePath();
        $this["baseUrl"] = $request->getSchemeAndHttpHost() . $this["basePath"];
    }
1262276
public function loadRoute($uri)
    {
        $route = $this->getRoute($uri);

        if($route)
        {
            $controllerPath = $this->getControllerPath($route);

            if($controllerPath)
            {
                require $controllerPath;

                $controller = $this->initController($route->getControllerName(), $route->getControllerPath());
                $this->runController($controller, $route->getAction(), $route->getValues());
            }
        }
        else
        {
            throw new \Exception("No route was found that matched the requested URI.", 1);
        }
    }
1095796
public static function init(string $uri = null): void
    {
        if (!defined('KOLDY_CLI')) {
            // KOLDY_CLI is not defined, which probably means useConfig() wasn't called
            static::terminateWithError('Don\'t call \Koldy\Application::run() before calling useConfig(). Check the documentation');
        }

        spl_autoload_register('\Koldy\Application::autoload');

        // set the error reporting in development mode
        if (static::inDevelopment()) {
            error_reporting(-1);
        }

        $config = static::getConfig('application');

        date_default_timezone_set($config->get('timezone', 'UTC'));

        $includePaths = [];
        $basePath = static::getApplicationPath();

        // register include path of application itself
        $includePaths[] = $basePath . 'controllers';

        if (is_dir($basePath . 'library')) {
            $includePaths[] = $basePath . 'library';
        }

        // adding additional include paths if there are any
        $additionalIncludePath = $config->get('additional_include_path') ?? [];

        // set the include path
        static::addIncludePath($includePaths, $additionalIncludePath);

        // set the error handler
        set_error_handler(function ($errorNumber, $errorMessage, $errorFile, $errorLine) {
            if (!(error_reporting() & $errorNumber)) {
                // This error code is not included in error_reporting
                return;
            }

            switch ($errorNumber) {
                case E_USER_ERROR:
                    $logMessage = new \Koldy\Log\Message('error');
                    $logMessage->addPHPErrorMessage($errorMessage, $errorFile, $errorNumber, $errorLine);
                    Log::message($logMessage);
                    break;

                case E_USER_WARNING:
                case E_DEPRECATED:
                case E_STRICT:
                    $logMessage = new \Koldy\Log\Message('warning');
                    $logMessage->addPHPErrorMessage($errorMessage, $errorFile, $errorNumber, $errorLine);
                    Log::message($logMessage);
                    break;

                case E_USER_NOTICE:
                    $logMessage = new \Koldy\Log\Message('notice');
                    $logMessage->addPHPErrorMessage($errorMessage, $errorFile, $errorNumber, $errorLine);
                    Log::message($logMessage);
                    break;


                default:
                    $logMessage = new \Koldy\Log\Message('warning');
                    $logMessage->addPHPErrorMessage($errorMessage, $errorFile, $errorNumber, $errorLine);
                    Log::message($logMessage);
                    break;
            }

            /* Don't execute PHP internal error handler */
            return true;
        });

        // register PHP fatal errors
        register_shutdown_function(function () {
            if (!defined('KOLDY_FATAL_ERROR_HANDLER')) {
                // to prevent possible recursion if you run into problems with logger
                define('KOLDY_FATAL_ERROR_HANDLER', true);

                $fatalError = error_get_last();

                if ($fatalError !== null && $fatalError['type'] == E_ERROR) {
                    $errorNumber = E_ERROR;
                    $errorMessage = $fatalError['message'];
                    $errorFile = $fatalError['file'];
                    $errorLine = $fatalError['line'];

                    $logMessage = new \Koldy\Log\Message('error');
                    $logMessage->addPHPErrorMessage($errorMessage, $errorFile, $errorNumber, $errorLine);

                    Log::error($logMessage);
                }
            }
        });

        // check the log for any enabled adapter
        $logConfigs = static::getConfig('application')->get('log', []);
        $logConfigsCount = count($logConfigs);
        $logEnabled = false;

        for ($i = 0; $i < $logConfigsCount && !$logEnabled; $i++) {
            if (isset($logConfigs[$i]['enabled']) && $logConfigs[$i]['enabled'] === true) {
                $logEnabled = true;
            }
        }

        if ($logEnabled) {
            // TODO: Don't init if we don't have to and let's do the "post" work after request
            Log::init();
        }
    }
1166545
private function init($uri, $callback)
    {

        try {
            /**
             * check if there is a general type validation
             * can throw an exception
             */
            $this->validate($uri);

            switch (true) {
                /**
                 * check if the routing maps to an object via array or class
                 */
                case (is_array($callback) || (is_object($callback) && !is_callable($callback))) :
                    $this->setType(self::TYPE_O);
                    $this->strategy = StrategyFactory::make(self::TYPE_O, $callback, new RouteMethodAnnotaionParser());
                    break;

                /**
                 * maps a simple function
                 */
                case (is_string($callback)) :
                    $this->setType(self::TYPE_F);
                    $this->strategy = StrategyFactory::make(self::TYPE_F, $callback);

                    if (!function_exists($callback)) {
                        throw new RouteException(sprintf(_('There is no such Function like %s'), $callback));
                    }
                    break;

                /**
                 * Closure callback
                 */
                case (is_callable($callback)) :
                    $this->setType(self::TYPE_LF);
                    $this->strategy = StrategyFactory::make(self::TYPE_LF, $callback);
                    break;
            }
        } catch (RouteException $e) {
            throw $e;
        }

        return true;
    }
964424
public function setUri($uri)
    {
        if (is_string($uri)) {
            $uri = Zend_Uri::factory($uri);
        }

        if (!$uri instanceof Zend_Uri_Http) {
            /**
 * @see Zend_Http_Client_Exception 
*/
            include_once 'Zend/Http/Client/Exception.php';
            throw new Zend_Http_Client_Exception('Passed parameter is not a valid HTTP URI.');
        }

        // We have no ports, set the defaults
        if (! $uri->getPort()) {
            $uri->setPort(($uri->getScheme() == 'https' ? 443 : 80));
        }

        $this->uri = $uri;

        return $this;
    }
1075118
public function updateLegacyURI(Request $request)
    {
        $viewParametersString = rtrim(
            $request->attributes->get(
                'semanticPathinfo',
                $request->getPathinfo()
            ) . $request->attributes->get('viewParametersString'),
            '/'
        );

        $uri = eZURI::instance();
        $uri->setURIString($viewParametersString);
    }
813526
public function settingsAction(Request $request, View $view)
    {
        $pageSeo = $view->getSeo() ?: new PageSeo();
        $form = $this->createSettingsForm($pageSeo, $view);

        $form->handleRequest($request);

        $response = $this->getNotPersistedSettingsResponse(
            $form,
            $view,
            $request->query->get('novalidate', false)
        );

        return new JsonResponse($response);
    }
499193
public function render($uri, Request $request, array $options = [])
    {
        $reference = null;
        if ($uri instanceof ControllerReference) {
            $reference = $uri;

            // Remove attributes from the generated URI because if not, the Symfony
            // routing system will use them to populate the Request attributes. We don't
            // want that as we want to preserve objects (so we manually set Request attributes
            // below instead)
            $attributes = $reference->attributes;
            $reference->attributes = [];

            // The request format and locale might have been overridden by the user
            foreach (['_format', '_locale'] as $key) {
                if (isset($attributes[$key])) {
                    $reference->attributes[$key] = $attributes[$key];
                }
            }

            $uri = $this->generateFragmentUri($uri, $request, false, false);

            $reference->attributes = array_merge($attributes, $reference->attributes);
        }

        $subRequest = $this->createSubRequest($uri, $request);

        // override Request attributes as they can be objects (which are not supported by the generated URI)
        if (null !== $reference) {
            $subRequest->attributes->add($reference->attributes);
        }

        $level = ob_get_level();
        try {
            return SubRequestHandler::handle($this->kernel, $subRequest, HttpKernelInterface::SUB_REQUEST, false);
        } catch (\Exception $e) {
            // we dispatch the exception event to trigger the logging
            // the response that comes back is ignored
            if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
                $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);

                $this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
            }

            // let's clean up the output buffers that were created by the sub-request
            Response::closeOutputBuffers($level, false);

            if (isset($options['alt'])) {
                $alt = $options['alt'];
                unset($options['alt']);

                return $this->render($alt, $request, $options);
            }

            if (!isset($options['ignore_errors']) || !$options['ignore_errors']) {
                throw $e;
            }

            return new Response();
        }
    }
976136
public void setUri(String uri) {
                if (GitTaskUtils.isNullOrBlankString(uri)) {
                        throw new BuildException("Can't set null URI attribute.");
                }

                if (this.uri == null) {
                        try {
                                new URIish(uri);
                                this.uri = uri;
                        } catch (URISyntaxException e) {
                                throw new BuildException(String.format("Invalid URI '%s'.", uri), e);
                        }
                }
        }
285627
public function handle( $requestUri )
    {
        $url = $this->_di->getService( "url" );

        /**
         * Remove the uri prefix from the request uri
         * (the uri prefix is added when route is created)
         */
        $requestUri = str_replace( $url->getUriPrefix(), "", $requestUri );

        $request_route = $this->_createRoute( ["uri" => $requestUri] );

        /**
         * Passing the uri to the get function in the url service to make sure the uri:s have a consistent format
         */
        //$request_route->setUri( $url->get( $request_route->getUri() ) );

        $request_route_uri_fragments = explode( "/", $request_route->getUri() );

        foreach ($this->_routeDefinitions as $routeDefinition)
        {
            $route = call_user_func($routeDefinition);

            /**
             * Passing the uri to the get function in the url service to make sure the uri:s have a consistent format
             */
            //$route->setUri( $url->get( $route->getUri() ) );

            $route_uri_fragments = explode( "/", $route->getUri() );

            /**
             * Check if request uri and route uri has the same number of fragments.
             * If not, continue to next route.
             */
            if ( count($route_uri_fragments) != count($request_route_uri_fragments) )
            {
                continue;
            }

            $params = array();

            /**
             * Compare every fragment of the uris
             */
            for ( $i = 0; $i < count($route_uri_fragments); $i++ )
            {
                /**
                 * Parameters are not compared
                 */
                if ( $route_uri_fragments[$i] == "{param}" )
                {
                    $params[] = $request_route_uri_fragments[$i];

                    continue;
                }

                /**
                 * If a fragment is not equal -> continue to next route
                 */
                if ( $route_uri_fragments[$i] != $request_route_uri_fragments[$i] )
                {
                    continue 2;
                }
            }

            $route->setParams( $params );

            /**
             * We have a match!
             */
            $this->_matchRoute = $route;

            return;
        }

        /**
         * No match :(
         * If not found route has been set -> set as out match route
         */
        if ( isset($this->_notFoundRoute) )
        {
            $this->_matchRoute = $this->_notFoundRoute;

            return;
        }

        /**
         * With no other options, we set the match route to a default route
         */
        $this->_matchRoute = new Route();
    }