forward example



        // Check session         try {
            $auth = $this->auth->checkAuth();
        } catch (Exception $e) {
            $auth = null;
        }

        // No session         if ($auth === null) {
            $this->forward('auth', 'index', 'backend');

            return;
        }

        $identity = $auth->getIdentity();

        $this->View()->assign('user', $identity, true);
        $app = $this->Request()->getParam('app', 'Index');
        $this->View()->assign('app', $app, true);

        $params = $this->Request()->getParam('params', []);
        

    public function preDispatch()
    {
        parent::preDispatch();

        $calledAction = $this->Request()->getActionName();

        if (Shopware()->Plugins()->Backend()->Auth()->shouldAuth()
            && $this->isPasswordConfirmProtectedAction($calledAction)
            && !$this->container->get('backendsession')->offsetGet('passwordVerified')
        ) {
            $this->forward('passwordConfirmationRequired');
        }
    }

    /** * Displays a JSON string indicating failure for password confirmation */
    public function passwordConfirmationRequiredAction()
    {
        $this->Front()->Plugins()->Json()->setRenderer();

        $this->View()->assign([
            
if (empty($error)) {
            return;
        }

        $code = $error->exception->getCode();
        switch ($code) {
            case Enlight_Controller_Exception::Controller_Dispatcher_Controller_Not_Found:
            case Enlight_Controller_Exception::Controller_Dispatcher_Controller_No_Route:
            case Enlight_Controller_Exception::PROPERTY_NOT_FOUND:
            case Enlight_Controller_Exception::ActionNotFound:
            case 404:
                $this->forward('pageNotFoundError');
                break;
            case 400:
            case 401:
            case 413:
                $this->forward('genericError', null, null, ['code' => $code]);
                break;
            default:
                $this->forward('genericError', null, null, ['code' => 503]);
                break;
        }
    }

    
$kernel = $this->createMock(HttpKernelInterface::class);
        $kernel->expects($this->once())->method('handle')->willReturnCallback(fn (Request $request) => new Response($request->getRequestFormat().'--'.$request->getLocale()));

        $container = new Container();
        $container->set('request_stack', $requestStack);
        $container->set('http_kernel', $kernel);

        $controller = $this->createController();
        $controller->setContainer($container);

        $response = $controller->forward('a_controller');
        $this->assertEquals('xml--fr', $response->getContent());
    }

    public function testGetUser()
    {
        $user = new InMemoryUser('user', 'pass');
        $token = new UsernamePasswordToken($user, 'default', ['ROLE_USER']);

        $controller = $this->createController();
        $controller->setContainer($this->getContainerWithTokenStorage($token));

        
if ($request === null) {
            $request = new Request();
        }

        $attributes = array_merge(
            $this->container->get(RequestTransformerInterface::class)->extractInheritableAttributes($request),
            $route,
            $attributes,
            ['_route_params' => $routeParameters]
        );

        return $this->forward($route['_controller']$attributes$routeParameters);
    }

    /** * @return array<string, mixed> */
    protected function decodeParam(Request $request, string $param): array
    {
        $params = $request->get($param);

        if (\is_string($params)) {
            $params = json_decode($params, true);
        }
 while (\array_key_exists(serialize($request)$this->redirects));

        return $this->requestFromRequest($request, false);
    }

    /** * Goes forward in the browser history. */
    public function forward(): Crawler
    {
        do {
            $request = $this->history->forward();
        } while (\array_key_exists(serialize($request)$this->redirects));

        return $this->requestFromRequest($request, false);
    }

    /** * Reloads the current browser. */
    public function reload(): Crawler
    {
        return $this->requestFromRequest($this->history->current(), false);
    }
/** * This logging method has been moved to \Shopware\Controllers\Backend\Logger::createLogAction * * @deprecated in Shopware 5.6, to be removed in 5.8. Use \Shopware\Controllers\Backend\Logger::createLogAction instead * * @return void */
    public function createLogAction()
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed in 5.8. Use \Shopware\Controllers\Backend\Logger::createLogAction instead.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $this->forward('createLog', 'logger', 'backend');
    }

    /** * @return void */
    public function downloadLogFileAction()
    {
        $logDir = $this->get('kernel')->getLogDir();
        $files = $this->getLogFiles($logDir);

        $logFile = $this->Request()->getParam('logFile');
        

    public function indexAction()
    {
        $id = (int) $this->Request()->getParam('sArticle');
        $tpl = (string) $this->Request()->getParam('template');

        if ($id <= 0) {
            $this->forward('error');

            return;
        }

        $view = $this->View();
        $view->assign('sAction', $view->getAssign('sAction') ?: 'index', true);
        $view->assign('sErrorFlag', $view->getAssign('sErrorFlag') ?: [], true);
        $view->assign('sFormData', $view->getAssign('sFormData') ?: [], true);
        $view->assign('userLoggedIn', (bool) $this->container->get('session')->get('sUserId'));

        if (!empty($this->container->get('session')->get('sUserId')) && empty($this->Request()->get('sVoteName'))
            

    public function init()
    {
        $this->admin = Shopware()->Modules()->Admin();
        $this->customerService = Shopware()->Container()->get(CustomerServiceInterface::class);
    }

    public function preDispatch()
    {
        $this->View()->setScope(Smarty::SCOPE_PARENT);
        if ($this->shouldForwardToRegister()) {
            $this->forward('index', 'register', 'frontend', $this->getForwardParameters());

            return;
        }
        $customerData = $this->admin->sGetUserData();
        if (!\is_array($customerData)) {
            $this->forward('index', 'register', 'frontend', $this->getForwardParameters());

            return;
        }

        $this->response->headers->addCacheControlDirective('no-store');
        
$this->assertSame('http://www.example.com/', $history->current()->getUri(), '->back() returns the previous request in the history');
    }

    public function testForward()
    {
        $history = new History();
        $history->add(new Request('http://www.example.com/', 'get'));
        $history->add(new Request('http://www.example1.com/', 'get'));

        try {
            $history->forward();
            $this->fail('->forward() throws a \LogicException if the history is already on the last page');
        } catch (\Exception $e) {
            $this->assertInstanceOf(\LogicException::class$e, '->forward() throws a \LogicException if the history is already on the last page');
        }

        $history->back();
        $history->forward();

        $this->assertSame('http://www.example1.com/', $history->current()->getUri(), '->forward() returns the next request in the history');
    }
}
$session = $this->container->get('session');
        if ($session->get('sOneTimeAccount') && $this->Request()->has('sidebar')) {
            $this->admin->logout();
        }

        $this->addressRepository = $this->get(ModelManager::class)->getRepository(Address::class);
        $this->addressService = $this->get(AddressServiceInterface::class);

        $this->View()->assign('sUserLoggedIn', $this->admin->sCheckUser());

        if (!$this->View()->getAssign('sUserLoggedIn')) {
            $this->forward('index', 'register', 'frontend', $this->getForwardParameters());

            return;
        }

        $this->View()->assign('userInfo', $this->get('shopware_account.store_front_greeting_service')->fetch());
        $this->View()->assign('sUserData', $this->admin->sGetUserData());
        $this->View()->assign('sAction', $this->Request()->getActionName());
    }

    /** * Address listing */
$sTargetAction = $this->Request()->getParam('sTargetAction', 'index');

        $this->View()->assign([
            'sTarget' => $sTarget,
            'sTargetAction' => $sTargetAction,
            'sEsd' => Shopware()->Modules()->Basket()->sCheckForESD(),
            'showNoAccount' => $this->Request()->getParam('showNoAccount', false),
            'accountMode' => $this->Request()->getParam('skipLogin'),
        ]);

        if ($this->shouldRedirectToAccount()) {
            $this->forward('index', 'account');

            return;
        }

        if ($this->shouldRedirectToCheckout()) {
            $this->forward('confirm', 'checkout');

            return;
        }

        if ($this->shouldRedirectToTarget()) {
            
use Shopware\Components\Compatibility\LegacyStructConverter;
use Shopware\Components\QueryAliasMapper;
use Shopware\Components\Routing\RouterInterface;

class Shopware_Controllers_Frontend_Search extends Enlight_Controller_Action
{
    /** * Index action method */
    public function indexAction()
    {
        return $this->forward('defaultSearch');
    }

    /** * Default search */
    public function defaultSearchAction()
    {
        $this->setDefaultSorting();

        $term = $this->getSearchTerm();

        

    }

    /** * Forward to cart or confirm action depending on user state * * @return void */
    public function indexAction()
    {
        if ($this->basket->sCountBasket() < 1 || empty($this->View()->sUserLoggedIn)) {
            $this->forward('cart');
        } else {
            $this->forward('confirm');
        }
    }

    /** * Read all data from objects / models that are required in cart view * (User-Data / Payment-Data / Basket-Data etc.) * * @return void */
    
$this->options += ['stale_if_error' => 0];
        }

        parent::__construct($kernel$this->createStore()$this->createSurrogate()array_merge($this->options, $this->getOptions()));
    }

    protected function forward(Request $request, bool $catch = false, Response $entry = null): Response
    {
        $this->getKernel()->boot();
        $this->getKernel()->getContainer()->set('cache', $this);

        return parent::forward($request$catch$entry);
    }

    /** * Returns an array of options to customize the Cache configuration. */
    protected function getOptions(): array
    {
        return [];
    }

    protected function createSurrogate(): SurrogateInterface
    {
Home | Imprint | This part of the site doesn't use cookies.