/** * This method is called when all object are loaded into container for initialization * * @param Container $container * @return null */ public function containerInitialization(Container $container) { // Split server 'REQUEST_URI' on "?" char. So on next steps we will work only with parameters from URL not from GET $cleanAndHttpParams = explode("?", $_SERVER['REQUEST_URI']); // split server 'SCRIPT_NAME' into field $scriptPathFragments = explode("/", str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME'])); // Last two field items contains main run file "index.php" and hidden dir "www" in which is request redirected by apache array_pop($scriptPathFragments); //remove "index.php" array_pop($scriptPathFragments); //remove redirect "www" directory // Build up base url with requested SCHEME (it may be HTTP or HTTPS) server name. // Rest of path is build from existing directory structure which is common for server and access from web. // NOTE: Some mess can be made, if in some upper directory is also redirection through .htaccess $this->baseUrl = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . implode("/", $scriptPathFragments); // Break params from url to array $this->params = explode("/", reset($cleanAndHttpParams)); // Clean params from existing directory structure for ($i = 0; $i < count($scriptPathFragments); $i++) { array_shift($this->params); } // Check strings, so they are safe to use in application $this->checkArray($this->params); // Now router tries to define which router is called and which action -> method will run // As first we need config for default controller and action /** @var Configurator $config */ $config = $container->get(EnumCoreElements::config); // get un-filtered name of controller from request. If is present as part of url, name is corrected from URL state to class correct name // e.g. url name of controller 'some-my-control' to class type SomeMyControl $this->control = isset($this->params[0]) && !empty($this->params[0]) ? $this->transformNameFromUrl($this->params[0]) . "Control" : $config->get("www.defaultControlClass"); // process action name from URL $this->action = $this->transformNameFromUrl(isset($this->params[1]) && !empty($this->params[1]) ? $this->params[1] : "Default"); }
/** * This method is called when all object are loaded into container for initialization * * @param Container $container * @return null */ public function containerInitialization(Container $container) { //load object for template finding $this->scriptFinder = $container->get(EnumCoreElements::scriptFinder); /** @var IRouter $router */ $router = $container->get(EnumCoreElements::router); //set base url to template $this->baseUrl = $router->getBaseUrl(); $controlNameParts = explode("\\", $router->getControllerName()); $this->controlName = end($controlNameParts); $this->action = $router->getControllerAction(); }