Completed
Pull Request — master (#5)
by Tadas
12:30
created

RouteChoiceTransformer::transform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
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 TTadcka\Bundle\RoutingBundle\Form\DataTransformer;
13
14
use Symfony\Component\Form\DataTransformerInterface;
15
use Tadcka\Component\Routing\Model\Manager\RouteManagerInterface;
16
use Tadcka\Component\Routing\Model\RouteInterface;
17
18
/**
19
 * @author Tadas Gliaubicas <[email protected]>
20
 *
21
 * @since 11/4/14 10:54 PM
22
 */
23
class RouteChoiceTransformer implements DataTransformerInterface
24
{
25
    /**
26
     * @var RouteManagerInterface
27
     */
28
    private $routeManager;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param RouteManagerInterface $routeManager
34
     */
35
    public function __construct(RouteManagerInterface $routeManager)
36
    {
37
        $this->routeManager = $routeManager;
38
    }
39
40
    /**
41
     * Transform.
42
     *
43
     * @param null|RouteInterface $route
44
     *
45
     * @return null|string
46
     */
47
    public function transform($route)
48
    {
49
        if (null !== $route) {
50
            return $route->getName();
51
        }
52
53
        return null;
54
    }
55
56
    /**
57
     * Reverse transform.
58
     *
59
     * @param null|string $routeName
60
     *
61
     * @return null|RouteInterface
62
     */
63
    public function reverseTransform($routeName)
64
    {
65
        if (null !== $routeName) {
66
            return $this->routeManager->findByName($routeName);
67
        }
68
69
        return null;
70
    }
71
}
72