/
Controller.php
71 lines (62 loc) · 1.82 KB
/
Controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\CartBundle\Controller;
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Cart\Context\CartContextInterface;
use Sylius\Component\Cart\Model\CartInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* @author Paweł Jędrzejewski <pawel@sylius.org>
*/
abstract class Controller extends ResourceController
{
/**
* @param RequestConfiguration $configuration
*
* @return RedirectResponse
*/
protected function redirectToCartSummary(RequestConfiguration $configuration)
{
if (null === $configuration->getParameters()->get('redirect')) {
return $this->redirectHandler->redirectToRoute($configuration, $this->getCartSummaryRoute());
}
return $this->redirectHandler->redirectToRoute($configuration, $configuration->getParameters()->get('redirect'));
}
/**
* @return string
*/
protected function getCartSummaryRoute()
{
return 'sylius_cart_summary';
}
/**
* @return CartInterface
*/
protected function getCurrentCart()
{
return $this->getContext()->getCart();
}
/**
* @return CartContextInterface
*/
protected function getContext()
{
return $this->container->get('sylius.context.cart');
}
/**
* @return EventDispatcherInterface
*/
protected function getEventDispatcher()
{
return $this->container->get('event_dispatcher');
}
}