CropExtension::getCropEndpoint()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Twig;
12
13
use Symfony\Component\Routing\Router;
14
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15
16
/**
17
 * CropExtension
18
 *
19
 * @author jobou
20
 */
21
class CropExtension extends \Twig_Extension
22
{
23
    /**
24
     * @var \Symfony\Component\Routing\Router
25
     */
26
    protected $router;
27
28
    /**
29
     * @var string
30
     */
31
    protected $routeName;
32
33
    /**
34
     * Constructor
35
     *
36
     * @param \Symfony\Component\Routing\Router $router
37
     * @param string $routeName
38
     */
39
    public function __construct(Router $router, $routeName)
40
    {
41
        $this->router = $router;
42
        $this->routeName = $routeName;
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function getFunctions()
49
    {
50
        return array(
51
            new \Twig_SimpleFunction(
52
                'jb_fileuploader_crop_endpoint',
53
                array($this, 'getCropEndpoint')
54
            )
55
        );
56
    }
57
58
    /**
59
     * Get crop endpoint url
60
     *
61
     * @param $endpoint
62
     * @param array $parameters
63
     * @param int $absolute
64
     *
65
     * @return string
66
     */
67
    public function getCropEndpoint(
68
        $endpoint,
69
        $parameters = array(),
70
        $absolute = UrlGeneratorInterface::ABSOLUTE_PATH
71
    ) {
72
        $parameters = array_merge($parameters, array('endpoint' => $endpoint));
73
74
        return $this->router->generate($this->routeName, $parameters, $absolute);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getName()
81
    {
82
        return 'jb_fileuploader_crop_extension';
83
    }
84
}
85