Set up into current route controller and action
in pascal case from request object.
@return void
437432
protected function rewriteRoutingSetUpCurrentRouteByRequest () {
		$request = & $this->request;
		$toolClass = self::$toolClass;
		$this->currentRoute
			->SetController(str_replace(['/', '\\\\'], ['\\', '//'],
				$toolClass::GetPascalCaseFromDashed($request->GetControllerName())
			))
			->SetAction(
				$toolClass::GetPascalCaseFromDashed($request->GetActionName())
			);
	}
355581
protected function run()
    {
        if (PHP_SAPI === 'cli') {
            return;
        }
        
        if ($this->ctrlRouterInfos->target === null) {
            return;
        }
        
        $this->module
            ->monolog
            ->getLogger()
            ->debug(
                'Execute current route.',
                ['target' => $this->ctrlRouterInfos->target]
            );
        
        $useClass = $this->config->getValue('useClass');
        
        if ($useClass === true) {
            $this->runObject();
        } else {
            $this->runProcedural();
        }
    }
450255
public function run()
    {
        if ($this->route === null && Cii::$app->controller !== null) {
            $this->route = Cii::$app->controller->getRoute();
        }
        if ($this->params === null) {
            $this->params = Cii::$app->request->getQueryParams();
        }
        $posDefaultAction = strpos($this->route, Cii::$app->controller->defaultAction);
        if ($posDefaultAction) {
            $this->noDefaultAction = rtrim(substr($this->route, 0, $posDefaultAction), '/');
        } else {
            $this->noDefaultAction = false;
        }
        $posDefaultRoute = strpos($this->route, Cii::$app->controller->module->defaultRoute);
        if ($posDefaultRoute) {
            $this->noDefaultRoute = rtrim(substr($this->route, 0, $posDefaultRoute), '/');
        } else {
            $this->noDefaultRoute = false;
        }
        $items = $this->normalizeItems($this->items, $hasActiveChild);
        if (!empty($items)) {
            $options = $this->options;
            $tag = ArrayHelper::remove($options, 'tag', 'ul');
            echo Html::tag($tag, $this->renderItems($items), $options);
        }
    }
295159
private function init()
    {
        // Set the layout from the Config file
        $this->layout = View::make(config('decoy.core.layout'));

        // Store the controller class for routing
        $this->controller = get_class($this);

        // Get the controller name
        $controller_name = $this->controllerName($this->controller);

        // Make a default title based on the controller name
        if (empty($this->title)) {
            $this->title = $this->title($controller_name);
        }

        // Figure out what the show view should be.  This is the path to the show
        // view file.  Such as 'admin.news.edit'
        if (empty($this->show_view)) {
            $this->show_view = $this->detailPath($this->controller);
        }

        // Try to suss out the model by singularizing the controller
        if (empty($this->model)) {
            $this->model = $this->model($this->controller);
            if (!class_exists($this->model)) {
                $this->model = null;
            }
        }

        // If the input contains info on the parent, immediately instantiate
        // the parent instance.  These are populated by some AJAX calls like
        // autocomplete on a many to many and the attach method.
        if (($parent_id = request('parent_id'))
            && ($parent_controller = request('parent_controller'))) {
            $parent_model_class = $this->model($parent_controller);
            $this->parent($parent_model_class::findOrFail($parent_id));
        }
    }
327278
public function run()
    {
        $this->tryAssignController();
        if (!$this->isControllerAssigned()) {
            throw new Exception("It's unable to assign controller to this route path.");
        }
        $oCtrl = $this->createCtrl();
        $oCtrl->{$this->actionName}($this->actionArgs);
    }
1186924
final public function startMvc() {
		
		$router	= Router::getInstance();
		$tran	= Translator::getInstance();
		
		// make sure to have a template set
		$template = $this->getTemplate();
		
		$controllerFile = 'modules/' . $router->module . '/controller.php';
		
		// check controller file existence
		if (!file_exists($controllerFile) or '404' == $router->url) {
			
			$this->enqueueError(Translator::do('RESOURCE_NOT_FOUND', $router->url));
			$this->style = '404';
			$this->pageTitle = 'HTTP 404 error';
			
		} else {
		
			require ($controllerFile);
			
			// build controller object
			$controllerName = ucfirst($router->module) . 'Controller';
			$controller = new $controllerName();
			
			// set the action
			$action = $router->action ? $router->action . 'Action' : 'defaultAction';

			// run the action
			$controller->$action();
			
			// log some events
			$logger	= Logger::getInstance();
			
			// set log of ajax call
			if ($router->ajax) {
				
				$params = array();
				foreach ($router->vars as $key=>$value) {
					$params[] = $key . '=' . Utilities::varToText($value);
				}
				$logger->addEvent(date('Y-m-d H:i:s') . ' AJAX call on ' . $this->module . '/' . $this->action . ' with params ' . implode(', ', $params));
				
			// log controller method call
			} else {
				
				$logger->addEvent('Called controller method ' . $controllerName . '->' . $action . '()');
				
			}
			
			// raw calls will jump controller->display, ob and log
			if ($router->isRaw()) {
				return;
			}
			
			// invoke the view
			$controller->display();
			
			// set the event log
			$this->log = $logger->getEventList();
			
		}
		
		// populate the placeholder for the content
		$this->pageContent = ob_get_clean();
		
		// initialize CSS and scripts
		$this->pageStyles = '';
		$this->pageScripts = '';

		// collect stylesheets
		foreach ($this->cssFiles as $href) {
				
			$this->pageStyles .= '<link rel="stylesheet" href="' . $href . '">' . "\n";
				
		}
		
		// collect script files
		foreach ($this->scriptFiles as $script) {
			
			// initialize attributes render
			$attribsRender = '';

			// render each attribute based on its variable type (string or boolean)
			foreach ($script as $tag => $value) {
				$attribsRender .= ' ' . (is_bool($value) ? $tag : $tag . '="' . htmlspecialchars($value) . '"');
			}
			
			// add each script
			$this->pageScripts .= '<script' . $attribsRender . '></script>' . "\n";
			
		}

		// collect plain text scripts
		if (count($this->scriptContent) or count($this->messages)) {

			$this->pageScripts .= "<div id=\"scriptContainer\"><script>\n";
			$this->pageScripts .= "$(document).ready(function(){\n";
			
			foreach ($this->scriptContent as $s) {
				$this->pageScripts .= $s ."\n";
			}
			
			$this->pageScripts .= $this->getMessageScript();
			$this->pageScripts .= "});\n";
			$this->pageScripts .= "</script></div>";
			
		}
		
		try {
			$template->loadStyle($this->style);
		} catch (\Exception $e) {
			print $e->getMessage();
		}
	
		// get output buffer and cleans it
		$page = ob_get_clean();
	
		print $page;

	}
1077175
protected function setUp()
	{
		$this->register(array(
			'finding' => Finding::class,
			'route' => Route::class,
			'group' => Group::class
			));

        $this->addDefaultGroupHandler(new ClosureHandler());
        $this->addDefaultGroupHandler(new ArrayHandler());
//        $this->addDefaultGroupHandler(new PathHandler());

		return $this;
	}
157144
public function launchAction()
    {
        self::$obLevel = ob_get_level();
        
        if (php_sapi_name() != 'cli') {
            ob_start();
        }
        
        $router = $this->_router;
        $activeRoute = $router->getActiveRoute();
        
        // optionally sets the content-type
        if (isset($activeRoute['contentType'])) {
            $this->_response->setContentType($activeRoute['contentType']);
        }
        
        // optionally sets the client cache duration
        if (isset($activeRoute['cacheMinutes'])) {
            $this->_response->setCacheable($activeRoute['cacheMinutes']);
        }
        
        // flag to allow the code of the controller to be executed
        // or not if a middleware returns false
        $allowedByPreMiddleware = true;

         // handle CORS using the cors built-in middleware
        $corsPreflight = new \Nf\Middleware\Cors();
        $allowedByPreMiddleware = $corsPreflight->execute();

        // call pre middlewares defined by the active route
        if (isset($activeRoute['middlewaresPre'])) {
            foreach ($activeRoute['middlewaresPre'] as $middleware) {
                if ($allowedByPreMiddleware) {
                    $object = new $middleware();
                    $ret = $object->execute();
                    if ($ret === false) {
                        $allowedByPreMiddleware = false;
                        break;
                    }
                }
            }
            unset($middleware);
        }
        // call pre middlewares defined programatically
        if (isset($this->registeredMiddlewares[self::MIDDLEWARE_PRE])) {
            foreach ($this->registeredMiddlewares[self::MIDDLEWARE_PRE] as $middleware) {
                if ($allowedByPreMiddleware) {
                    $object = new $middleware();
                    $ret = $object->execute();
                    if ($ret === false) {
                        $allowedByPreMiddleware = false;
                        break;
                    }
                }
            }
        }
        
        if ($allowedByPreMiddleware) {
            // call the action
            call_user_func(array(
                $this->_controllerInstance,
                $this->_actionName . 'Action'
            ));
            $content = ob_get_clean();
            $this->_response->addBodyPart($content);
            
            // call post middlewares
            if (isset($activeRoute['middlewaresPost'])) {
                foreach ($activeRoute['middlewaresPost'] as $middleware) {
                    $object = new $middleware();
                    $object->execute();
                }
                unset($middleware);
            }
            // call post middlewares defined programatically, by instance
            if (isset($this->registeredMiddlewares[self::MIDDLEWARE_POST])) {
                foreach ($this->registeredMiddlewares[self::MIDDLEWARE_POST] as $middleware) {
                    $middleware->execute();
                }
            }
        }
      
    }
818744
protected function setup() {
		$this->rs = new \HaveAPI\Client\Resource($this->client, 'token', $this->description->resources->token, array());
		$this->via = isSet($this->opts['via']) ? $this->opts['via'] : self::HTTP_HEADER;
		
		if(isSet($this->opts['token'])) {
			$this->configured = true;
			$this->token = $this->opts['token'];
			return;
		}
		
		$this->requestToken();
	}
560864
public static function dispatch()
    {
        $vars = [];

        $request = Request::createFromGlobals();

        $dispatcher = new Dispatcher(static::instance()->getData());
        $routeInfo = $dispatcher->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        $controller = "\\Barebone\\Controller";
        $action = "index";

        switch ($routeInfo[0]) {
        case Dispatcher::NOT_FOUND:
            $action = 'routerError';
            $vars['error'] = static::ERR_NOT_FOUND;
            $vars['subject'] = $request->getUri()->getPath();
            break;

        case Dispatcher::METHOD_NOT_ALLOWED:
            $action = 'routerError';
            $vars['error'] = static::ERR_BAD_METHOD;
            $vars['subject'] = $routeInfo[1];
            break;

        case Dispatcher::FOUND:
            $handler = $routeInfo[1];
            $vars = $routeInfo[2];

            if (!class_exists($handler[0])) {
                $action = 'routerError';
                $vars['error'] = static::ERR_MISSING_CONTROLLER;
                $vars['subject'] = $handler[0];
            } elseif (!method_exists($handler[0], $handler[1])) {
                $action = 'routerError';
                $vars['error'] = static::ERR_MISSING_ACTION;
                $vars['subject'] = $handler[0] . '::' . $handler[1];
            } else {
                $controller = $handler[0];
                $action = $handler[1];
            }
            break;
        }

        // Start with an empty response
        $response = new Response();
        $request->setAction($action);

        // @var Controller $instance
        $instance = new $controller($request, $response);
        $instance->initController();

        // Get Middleware stacks
        $before = $instance->getMiddlewareBefore();
        $after = $instance->getMiddlewareAfter();

        // Append the action call to the middleware stack
        $before[] = function (Request $request, Response $response,
            callable $next = null
        ) use ($instance, $action, $vars) {

            // assigned updated objects
            $instance->setRequest($request);
            $instance->setResponse($response);

            // get updated response from action
            $response = call_user_func_array([$instance, $action], $vars);

            // continue
            return $next($instance->getRequest(), $response);
        };

        // Run the middleware stack and return the Response
        $middlewares = array_reverse(array_merge($before, $after));
        $runner = \Sirius\Middleware\Runner::factory($middlewares);

        return $runner($request, $response);
    }
164200
private function setupRoutables()
    {
        $app = $this;
        // For now, need to rely on a catch-all...
        $this->get(
            '{catchall:.*}',
            function (
                RequestInterface $request,
                ResponseInterface $response,
                array $args
            ) use ($app) {
                $config = $app->config();
                $routables = $config['routables'];
                if ($routables === null || count($routables) === 0) {
                    return $this['notFoundHandler']($request, $response);
                }
                $routeFactory = $this['route/factory'];
                foreach ($routables as $routableType => $routableOptions) {
                    $route = $routeFactory->create($routableType, [
                        'path' => $args['catchall'],
                        'config' => $routableOptions
                    ]);
                    if ($route->pathResolvable($this)) {
                        $this['logger']->debug(
                            sprintf('Loaded routable "%s" for path %s', $routableType, $args['catchall'])
                        );
                        return $route($this, $request, $response);
                    }
                }

                // If this point is reached, no routable has provided a callback. 404.
                return $this['notFoundHandler']($request, $response);
            }
        );
    }
1159338
public function dispatch()
    {
		/**
         * Calling before dispatch listener
         */
		if ( is_object($this->_events_manager) )
        {
            $this->_events_manager->fire( "dispatch:beforeDispatch", $this );
		}

		$finished = false;

		$number_dispatches = 0;

		while ( !$finished )
		{
			$number_dispatches++;

			if ( $number_dispatches == 100 )
            {
                $this->_throwDispatchException( "Dispatch error. Cyclic routing.", self::EXCEPTION_CYCLIC_ROUTING );
				break;
			}

            $controller_name = $this->_route->getControllerName();
            $action_name     = $this->_route->getActionName();
            $params          = $this->_route->getParams();

            if ( !class_exists($controller_name) )
            {
                if ( $this->_throwDispatchException( $controller_name . " controller class cannot be loaded.", self::EXCEPTION_CONTROLLER_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            $controller_instance = new $controller_name();

            if ( !method_exists($controller_instance, $action_name) )
            {
                if ( $this->_throwDispatchException( $action_name . "Action action does not exist in " . $controller_name . ".", self::EXCEPTION_ACTION_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            /**
             * Calling before execute route listener
             */
            if ( is_object($this->_events_manager) )
            {
                $this->_events_manager->fire( "dispatch:beforeExecuteRoute", $this );

                /**
                 * If there was a forward in the listener
                 */
                if ( $this->_was_forwarded )
                {
                    $this->_was_forwarded = false;
                    continue;
                }
            }

            $controller_instance->setDI( $this->_di );

            $controller_instance->initialize();

			/**
             * Calling action in controller with params
             */
            call_user_func_array( array($controller_instance, $action_name), $params );

			/**
             * If there was a forward in the action
             */
			if ( $this->_was_forwarded )
            {
				$this->_was_forwarded = false;
				continue;
			}

			$finished = true;
		}
    }
74848
protected function doProcess(): void
    {
        $module = Request::getModule();
        $controller = Request::getController();
        $params = Request::getParams();

        try {
            // try to dispatch controller
            $result = $this->dispatch($module, $controller, $params);
        } catch (ForbiddenException $e) {
            // dispatch default error controller
            $result = $this->forbidden($e);
        } catch (RedirectException $e) {
            // should return `null` for disable output and setup redirect headers
            $result = $this->redirect($e);
        } catch (\Exception $e) {
            // dispatch default error controller
            $result = $this->error($e);
        }

        // setup layout, if needed
        if ($this->useLayout()) {
            // render view to layout
            // needed for headScript and headStyle helpers
            Layout::setContent($result->render());
            Response::setBody(Layout::getInstance());
        } else {
            Response::setBody($result);
        }
    }
684591
private function runRouteBinding(): void
    {
        // calculated depend of language
        $pathway = $this->getPathInfo();
        /** @var array $routing */
        $routing = App::$Properties->getAll('Routing');

        // try to work with static aliases
        if (Any::isArray($routing) && isset($routing['Alias'], $routing['Alias'][env_name])) {
            $pathway = $this->findStaticAliases($routing['Alias'][env_name], $pathway);
        }

        $this->setPathdata(explode('/', trim($pathway, '/')));

        // set default controller and action for undefined data
        if (!$this->action) {
            $this->action = 'Index';
        }

        // empty or contains backslashes? set to main
        if (!$this->controller || Str::contains('\\', $this->controller)) {
            $this->controller = 'Main';
        }

        // find callback injection in routing configs (calculated in App::run())
        if (Any::isArray($routing) && isset($routing['Callback'], $routing['Callback'][env_name])) {
            $this->findDynamicCallbacks($routing['Callback'][env_name], $this->controller);
        }
    }
775791
public function runApplication()
    {
        $routeCollection = $this->createRouteCollection();
        $dispatcher = $routeCollection->getDispatcher();

        $request = $this->createRequest();
        $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
        $response->send();
    }
726480
public function route()
    {
        if (!empty($this->mod)) {
            if ($this->mod == $this->modApiName) {
                $this->cmd = $this->ctrl . '.' . $this->action;
            }
        }
        if ($this->cmd != '') {
            $cmdParams = explode('.', $this->cmd);
            if (count($cmdParams) > 2) {
                $this->mod = $cmdParams[0];
                $this->cmd = $cmdParams[1] . '.' . $cmdParams[2];
            }
            $this->routeApi();
        } else {
            $this->routeCtrl();
        }
    }
556024
public function updateInstances($route, $request)
    {
        $this->request = $request;
        if ($request) {
            $this->uri = urldecode($request->path());
        }

        $this->route = $route;
        if ($route) {
            $this->action = $route->getActionName();

            $actionSegments   = Str::parseCallback($this->action, null);
            $this->controller = head($actionSegments);
            $this->method     = last($actionSegments);
        }
    }