Backend\Core\Engine\Url::processQueryString PHP Method

processQueryString() private method

Process the querystring
private processQueryString ( )
    private function processQueryString()
    {
        // store the querystring local, so we don't alter it.
        $queryString = $this->getQueryString();
        // find the position of ? (which separates real URL and GET-parameters)
        $positionQuestionMark = mb_strpos($queryString, '?');
        // separate the GET-chunk from the parameters
        $getParameters = '';
        if ($positionQuestionMark === false) {
            $processedQueryString = $queryString;
        } else {
            $processedQueryString = mb_substr($queryString, 0, $positionQuestionMark);
            $getParameters = mb_substr($queryString, $positionQuestionMark);
        }
        // split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET)
        $chunks = (array) explode('/', trim($processedQueryString, '/'));
        // check if this is a request for a AJAX-file
        $isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax';
        // get the language, this will always be in front
        $language = '';
        if (isset($chunks[1]) && $chunks[1] != '') {
            $language = \SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '');
        }
        // no language provided?
        if ($language == '' && !$isAJAX) {
            // remove first element
            array_shift($chunks);
            // redirect to login
            $this->redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . (empty($chunks) ? '' : '/') . implode('/', $chunks) . $getParameters);
        }
        // get the module, null will be the default
        $module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'Dashboard';
        $module = \SpoonFilter::toCamelCase($module);
        // get the requested action, if it is passed
        if (isset($chunks[3]) && $chunks[3] != '') {
            $action = \SpoonFilter::toCamelCase($chunks[3]);
        } elseif (!$isAJAX) {
            // Check if we can load the config file
            $configClass = 'Backend\\Modules\\' . $module . '\\Config';
            if ($module == 'Core') {
                $configClass = 'Backend\\Core\\Config';
            }
            try {
                // when loading a backend url for a module that doesn't exist, without
                // providing an action, a FatalErrorException occurs, because the config
                // class we're trying to load doesn't exist. Let's just throw instead,
                // and catch it immediately.
                if (!class_exists($configClass)) {
                    throw new Exception('The config class does not exist');
                }
                /** @var BackendBaseConfig $config */
                $config = new $configClass($this->getKernel(), $module);
                // set action
                $action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'Index';
            } catch (Exception $ex) {
                if (BackendModel::getContainer()->getParameter('kernel.debug')) {
                    throw new Exception('The config file for the module (' . $module . ') can\'t be found.');
                } else {
                    // @todo    don't use redirects for error, we should have something like an invoke method.
                    // build the url
                    $errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed';
                    // add the querystring, it will be processed by the error-handler
                    $errorUrl .= '&querystring=' . rawurlencode('/' . $this->getQueryString());
                    // redirect to the error page
                    $this->redirect($errorUrl, 307);
                }
            }
        }
        // AJAX parameters are passed via GET or POST
        if ($isAJAX) {
            $module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
            $action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
            $language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
            $module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
            $action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
            $language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
            $this->setModule($module);
            $this->setAction($action);
            BackendLanguage::setWorkingLanguage($language);
        } else {
            $this->processRegularRequest($module, $action, $language);
        }
    }