getModuleName example



    /** * getActionRoute takes a request and returns the concatenated module- and controller-name, * e.g. frontend/listing. * * @return string */
    public function getControllerRoute(Request $request)
    {
        return implode('/', [
            strtolower($request->getModuleName()),
            strtolower($request->getControllerName()),
        ]);
    }
}
/** * 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);
        $controllerName = $this->formatControllerName($request->getControllerName());

        $class = ['Shopware', 'Controllers', $moduleName$controllerName];
        /** @var class-string $className */
        

    public function onPreDispatch(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        $response = $args->getResponse();

        if ($response->isException()
            || $request->isPost()
            || $request->isXmlHttpRequest()             // is a ajax call             || $request->has('callback')                // is a jsonp call             || $request->getModuleName() != 'frontend'  // is not frontend             || !$request->getParam('rewriteAlias')      // is not a rewrite url alias         ) {
            return;
        }
        $router = $args->getSubject()->ensureRouter();

        $query = $request->getQuery();
        $location = $router->assemble($query);

        // Fix shop redirect / if it's not a seo url         if (preg_match('#\/[0-9]+$#', $location$match) > 0) {
            
case 'frontend/forms':
                return $this->getFormsCacheIds($request);

            default:
                return [];
        }
    }

    private function getControllerRoute(Request $request)
    {
        return implode('/', [
            strtolower($request->getModuleName()),
            strtolower($request->getControllerName()),
        ]);
    }

    /** * @return array */
    private function getBlogCacheIds(Request $request, View $view)
    {
        $cacheIds = [];

        
'onPreDispatch',
            10
        );

        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])) {
                        
// Remove comments                     '#/\*.*?\*/#ms' => '',
                    '#^\s*//.*$#m' => '',
                    // '#\n\s+#ms' => '',                     '#^\s+#ms' => '',
                    // '#\s+$#ms' => '',                 ];

                return preg_replace(array_keys($expressions)array_values($expressions)$source);
            }
        }
        if (!\in_array($request->getModuleName()['frontend', 'widgets'], true)) {
            return $args->getReturn();
        }
        $source = $this->filterUrls($source);

        return $this->filterSource($source);
    }

    /** * Initializes plugin config * * @throws Exception */
/** * This replaces the old event from the routerRewrite plugin * * The refreshSeoIndex method will only be called, if "live" mode is enabled. Else the process will be * triggered via plugin or manually */
    public function onAfterSendResponse(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();

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

        if (!Shopware()->Container()->initialized('shop')) {
            return;
        }

        /** * If 'live' mode is configured, pass the request to the SeoIndex component and handle it as in SW < 4.1.0. */
        $refreshStrategy = $this->Application()->Config()->get('seoRefreshStrategy');

        

    public function onPostDispatch(Enlight_Event_EventArgs $args)
    {
        $request = $args->getSubject()->Request();
        $response = $args->getSubject()->Response();

        /** @var Enlight_View_Default $view */
        $view = $args->getSubject()->View();

        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);
        


    /** * Load correct template */
    public function preDispatch()
    {
        if ($this->Request()->getActionName() === 'service') {
            return;
        }
        $templateModule = 'frontend';
        if ($this->Request()->getModuleName() === 'backend') {
            $templateModule = 'backend';
            $this->enableBackendTheme();
        }

        if ($this->Request()->isXmlHttpRequest() || !$this->container->initialized('db')) {
            $this->View()->loadTemplate($templateModule . '/error/exception.tpl');
        } elseif (isset($_ENV['SHELL']) || PHP_SAPI === 'cli') {
            $this->View()->loadTemplate($templateModule . '/error/cli.tpl');
        } elseif (empty($_SERVER['SERVER_NAME'])) {
            $this->View()->loadTemplate($templateModule . '/error/ajax.tpl');
        } else {
            
'Enlight_Controller_Front_DispatchLoopShutdown' => 'onDispatchLoopShutdown',
        ];
    }

    public function onDispatchLoopShutdown(Enlight_Event_EventArgs $args): void
    {
        /** @var Enlight_Controller_Request_Request $request */
        $request = $args->get('request');

        // Only use Server Push if it is enabled in the settings and the current module is "frontend"         if (!$this->pushEnabled
            || $request->getModuleName() !== 'frontend') {
            return;
        }

        /** @var Enlight_Controller_Response_Response $response */
        $response = $args->get('response');

        $linkProvider = $this->webLinkManager->getLinkProvider();
        if (!$linkProvider instanceof LinkProviderInterface) {
            return;
        }

        
/** * 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';

        

    public function dispatch($action)
    {
        $args = new Enlight_Controller_ActionEventArgs([
            'subject' => $this,
            'request' => $this->Request(),
            'response' => $this->Response(),
        ]);

        $moduleName = ucfirst($this->Request()->getModuleName());

        Shopware()->Events()->notify(
            __CLASS__ . '_PreDispatch',
            $args
        );

        Shopware()->Events()->notify(
            __CLASS__ . '_PreDispatch_' . $moduleName,
            $args
        );

        

    }

    /** * @see \Enlight_Controller_Router::setGlobalParam * * @return array{module?: string, controller?: string, action?: string} */
    public static function getGlobalParamsFromRequest(EnlightRequest $request)
    {
        $globalParams = [];
        if ($request->getModuleName()) {
            $globalParams['module'] = $request->getModuleName();
            if ($request->getControllerName() !== null) {
                $globalParams['controller'] = $request->getControllerName();
                if ($request->getActionName() !== null) {
                    $globalParams['action'] = $request->getActionName();
                }
            }
        }

        return $globalParams;
    }

    
/** * Listener method for the Enlight_Controller_Front_DispatchLoopStartup event. * * @return void */
    public function onDispatchLoopStartup(Enlight_Controller_EventArgs $args)
    {
        $this->request = $args->getSubject()->Request();
        $this->response = $args->getSubject()->Response();

        if ($this->request->getModuleName() != 'api') {
            return;
        }

        $this->isApiCall = true;

        $router = new Router();
        $router->assembleRoute($this->request, $this->response);
    }

    /** * This pre-dispatch event-hook checks permissions * * @return void */
return null;
        }

        if (!$this->get('shop')->get('esi')) {
            return null;
        }

        if (!$this->hasSurrogateEsiCapability($this->request)) {
            return null;
        }

        if (!\in_array($this->request->getModuleName()['frontend', 'widgets'], true)) {
            return null;
        }

        $targetName = strtolower($params['module'] . '/' . $params['controller']);

        /** @var CacheControl $cacheControl */
        $cacheControl = $this->get('http_cache.cache_control');

        if ($cacheControl->useNoCacheParameterForEsi($request$targetName)) {
            $params['nocache'] = 1;
        }

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