getControllerName example

/** @var Enlight_Controller_Front $front */
    $front = Shopware()->Front();
    $request = $front->Request();

    if (empty($request) || !$request instanceof Enlight_Controller_Request_Request) {
        $e = new Exception(
            'Controller view helper requires a valid request object in the front controller instance'
        );
        throw $e;
    }

    return preg_replace('/[^a-zA-Z0-9]/', '', $request->getControllerName());
}

        return $this->defaultModule;
    }

    /** * Returns the controller class of the given request class. The class name is imploded by '_' * * @return class-string */
    public function getControllerClass(Enlight_Controller_Request_Request $request)
    {
        if (!$request->getControllerName()) {
            $request->setControllerName($this->defaultController);
        }

        if (!$request->getModuleName()) {
            $request->setModuleName($this->defaultModule);
        }

        $module = $request->getModuleName();
        $this->curModule = $module;

        $moduleName = $this->formatModuleName($module);
        
if (!$request->isDispatched() || $response->isException()
            || $request->getModuleName() !== 'frontend'
            || !$view->hasTemplate()
        ) {
            return;
        }

        $view->assign('baseUrl', $request->getBaseUrl() . $request->getPathInfo());

        $shop = Shopware()->Shop();
        $view->assign('Controller', $args->getSubject()->Request()->getControllerName());

        $view->assign('sBasketQuantity', $view->getAssign('sBasketQuantity') ?: 0);
        $view->assign('sBasketAmount', $view->getAssign('sBasketAmount') ?: 0);
        $view->assign('sNotesQuantity', $view->getAssign('sNotesQuantity') ?: 0);
        $view->assign('sUserLoggedIn', $view->getAssign('sUserLoggedIn') ?: false);

        $view->assign('Shop', $shop);
        if (!$shop->getLocale() instanceof ShopLocale) {
            throw new RuntimeException('Shop does not have a locale set');
        }
        $view->assign('Locale', $shop->getLocale()->getLocale());

        

        return 'Custom' . ucfirst($this->internalName);
    }

    public function getTableName(): string
    {
        return 's_custom_' . strtolower($this->internalName);
    }

    public function getSnippetNamespaceBackend(): string
    {
        return 'backend/' . strtolower($this->getControllerName()) . '/main';
    }

    public function getSnippetNamespaceFrontend(): string
    {
        return 'frontend/' . strtolower($this->getControllerName()) . '/main';
    }

    public function getInternalName(): string
    {
        return $this->internalName;
    }

    

    public function onPreDispatchBackend(Enlight_Event_EventArgs $args)
    {
        $this->action = $args->getSubject();
        $this->request = $this->action->Request();
        $this->aclResource = strtolower(str_replace('_', '', $this->request->getControllerName()));

        if ($this->aclResource === 'error' || $this->request->getModuleName() !== 'backend') {
            return;
        }

        if ($this->shouldAuth()) {
            if ($this->checkAuth() === null) {
                if ($this->request->isXmlHttpRequest()) {
                    throw new Enlight_Controller_Exception('Unauthorized', 401);
                }
                $this->action->redirect('backend/');
            }
$this->menuSynchronizer = $menuSynchronizer;
        $this->aclSynchronizer = $aclSynchronizer;
    }

    public function sync(bool $destructive = false): array
    {
        $types = $this->provider->getTypes();

        $this->menuSynchronizer->synchronize(self::getMenuEntries($types));
        $this->createTables($types$destructive);
        $this->aclSynchronizer->update(array_map(static function DType $type) {
            return strtolower($type->getControllerName());
        }$types));

        return $types;
    }

    public function setTypeProvider(TypeProvider $typeProvider): void
    {
        $this->provider = $typeProvider;
    }

    private static function getMenuEntries(array $types): array
    {
/** * Returns the template name of the current request instance. * The module, controller and action is gotten over the dispatcher instance of the Enlight_Controller_Front. * The template parts are imploded by "_" character. * * @return string */
    public function getTemplateName()
    {
        $request = $this->Action()->Request();
        $moduleName = $this->Front()->Dispatcher()->formatModuleName($request->getModuleName());
        $controllerName = $this->Front()->Dispatcher()->formatControllerName($request->getControllerName());
        $actionName = $this->Front()->Dispatcher()->formatActionName($request->getActionName());

        $parts = [$moduleName$controllerName$actionName];
        foreach ($parts as &$part) {
            $part = (string) preg_replace('#[A-Z]#', '_$0', $part);
            $part = trim($part, '_');
            $part = strtolower($part);
        }

        $templateName = implode(DIRECTORY_SEPARATOR, $parts) . '.tpl';

        

        $referer = $request->getHeader('referer');
        if (!\is_string($referer)) {
            $referer = 'notFound';
        }

        $message = sprintf(
            '%s. The request comes from: "%s". Module: "%s", Controller: "%s", Action: "%s",',
            $exceptionMessagePrefix,
            $referer,
            $request->getModuleName(),
            $request->getControllerName(),
            $request->getActionName()
        );

        parent::__construct($message, self::PROPERTY_NOT_FOUND);
    }
}

    protected function initServiceMode($request)
    {
        $config = $this->get(Shopware_Components_Config::class);
        if (!empty($config->get('setOffline'))
            && !str_contains($config->get('offlineIp')$request->getClientIp())
            && $request->getControllerName() !== 'error'
        ) {
            $request->setControllerName('error')->setActionName('service')->setDispatched(false);
        }
    }

    /** * @deprecated - Will be private with Shopware 5.8 * * @param Request $request * @param Enlight_Controller_Response_ResponseHttp $response * * @return void */
$this->refreshPartner($request$response);
        }
    }

    /** * @param Enlight_Controller_Request_Request $request * * @return void */
    public function refreshBasket(Enlight_Controller_Request_RequestHttp $request)
    {
        $currentController = $request->getParam('requestController', $request->getControllerName());
        $sessionId = (string) $request->getSession()->getId();

        if (!empty($currentController) && !empty($sessionId)) {
            $userId = (int) $request->getSession()->get('sUserId');
            $userAgent = (string) $request->getServer('HTTP_USER_AGENT');
            $sql = ' UPDATE s_order_basket SET lastviewport = ?, useragent = ?, userID = ? WHERE sessionID=? ';

    public function tagCloudAction()
    {
        $config = $this->container->get('plugins')->Frontend()->TagCloud()->Config();

        if (empty($config->get('show'))) {
            return;
        }

        $controller = $this->Request()->getParam('sController', $this->Request()->getControllerName());

        if (str_contains($config->get('controller')$controller)) {
            $this->View()->assign('sCloud', $this->container->get('modules')->Marketing()->sBuildTagCloud(
                $this->Request()->getParam('sCategory')
            ));
        }
    }

    /** * Loads the listing count for the provided listing parameters. * Sets a json response with: `facets`, `totalCount` and `products`. * * @return void */
$metaDescription = $view->getAssign('sCategoryContent')['metaDescription'];
            } elseif (!empty($view->getAssign('sCategoryContent')['cmstext'])) {
                $metaDescription = $view->getAssign('sCategoryContent')['cmstext'];
            }
            if (!empty($metaDescription)) {
                $metaDescription = html_entity_decode($metaDescription, ENT_COMPAT, 'UTF-8');
                $metaDescription = trim((string) preg_replace('/\s\s+/', ' ', strip_tags($metaDescription)));
                $metaDescription = htmlspecialchars($metaDescription, ENT_COMPAT);
            }
        }

        $controller = $request->getControllerName();

        if ($request->get('action') === 'manufacturer' && $request->get('controller') === 'listing') {
            $alias = $mapper->getQueryAliases();

            if (\array_key_exists('sSupplier', $alias) && ($index = array_search($alias['sSupplier']$queryBlacklist, true))) {
                unset($queryBlacklist[$index]);
            }

            if ($index = array_search('sSupplier', $queryBlacklist, true)) {
                unset($queryBlacklist[$index]);
            }

            


        $this->View()->assign('data', $result);
        $this->View()->assign('success', true);
    }

    public function postAction(): void
    {
        $params = $this->Request()->getPost();
        $result = [];
        $result['id'] = $this->repository->save($params);
        $result['location'] = $this->apiBaseUrl . $this->Request()->getControllerName() . '/' . $result['id'];

        $this->View()->assign($result);
        $this->Response()->setHeader('Location', $result['location']);
    }

    public function putAction(int $id): void
    {
        $params = $this->Request()->getPost();
        $result = [];
        $result['id'] = $this->repository->save($params$id);
        $result['location'] = $this->apiBaseUrl . $this->Request()->getControllerName() . '/' . $result['id'];

        
 elseif ($facet instanceof CombinedConditionFacet) {
                $this->handleCombinedConditionFacet($request$criteria$facet);
            }
        }
    }

    /** * @return bool */
    private function isCategoryListing(Request $request)
    {
        return strtolower($request->getControllerName()) === 'listing';
    }

    /** * @return bool */
    private function isSearchPage(Request $request)
    {
        $params = $request->getParams();

        return \array_key_exists('sSearch', $params);
    }

    
return true;
    }

    public static function onPreDispatch(Enlight_Event_EventArgs $args)
    {
        $request = $args->getSubject()->Request();

        if ($request->getModuleName() && $request->getModuleName() !== 'frontend') {
            return;
        }

        switch ($request->getControllerName()) {
            case 'sViewport,sale':
                $url = $args->getRequest()->getPathInfo();
                $url = trim($url, '/');

                foreach (explode('/', $url) as $part) {
                    $part = explode(',', $part);
                    if (!empty($part[0]) && !empty($part[1])) {
                        $request->setParam($part[0]$part[1]);
                    }
                }

                
Home | Imprint | This part of the site doesn't use cookies.