Completed
Push — flash-id-class ( 031dcc...694601 )
by Kamil
20:18
created

CheckoutStateUrlGenerator::generateForCart()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Checkout;
13
14
use Sylius\Component\Core\Model\OrderInterface;
15
use Symfony\Component\Routing\Exception\RouteNotFoundException;
16
use Symfony\Component\Routing\RequestContext;
17
use Symfony\Component\Routing\RouterInterface;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
final class CheckoutStateUrlGenerator implements CheckoutStateUrlGeneratorInterface
23
{
24
    /**
25
     * @var RouterInterface
26
     */
27
    private $router;
28
29
    /**
30
     * @var array
31
     */
32
    private $routeCollection = [];
33
34
    /**
35
     * @param RouterInterface $router
36
     * @param array $routeCollection
37
     */
38
    public function __construct(RouterInterface $router, array $routeCollection)
39
    {
40
        $this->router = $router;
41
        $this->routeCollection = $routeCollection;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
48
    {
49
        return $this->router->generate($name, $parameters, $referenceType);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function generateForOrderCheckoutState(OrderInterface $order, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
56
    {
57
        if (!isset($this->routeCollection[$order->getCheckoutState()]['route'])) {
58
            throw new RouteNotFoundException();
59
        }
60
61
        return $this->router->generate($this->routeCollection[$order->getCheckoutState()]['route'], $parameters, $referenceType);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function generateForCart($parameters = [], $referenceType = self::ABSOLUTE_PATH)
68
    {
69
        if (!isset($this->routeCollection['empty_order']['route'])) {
70
            throw new RouteNotFoundException();
71
        }
72
73
        return $this->router->generate($this->routeCollection['empty_order']['route'], $parameters, $referenceType);    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function setContext(RequestContext $context)
79
    {
80
        $this->router->setContext($context);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getContext()
87
    {
88
        return $this->router->getContext();
89
    }
90
}
91