Passed
Branch master (c65ffc)
by Dāvis
03:08
created

MissingExtension::getFilters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Twig;
4
5
class MissingExtension extends \Twig_Extension
6
{
7
    use TwigTrait;
8
9
    protected $request;
10
    protected $entityManager;
11
    protected $shortFunctions;
12
13
    public function __construct($requestStack, $entityManager, $container)
14
    {
15
        $this->request = $requestStack->getCurrentRequest();
16
        $this->entityManager = $entityManager;
17
18
        $this->shortFunctions = $container->hasParameter('sludio_helper.script.short_functions') && $container->getParameter('sludio_helper.script.short_functions');
19
    }
20
21
    public function getName()
22
    {
23
        return 'sludio_helper.twig.missing_extension';
24
    }
25
26
    public function getFilters()
27
    {
28
        $input = [
29
            'objects' => 'getObjects',
30
            'svg' => 'getSvg',
31
        ];
32
33
        return $this->makeArray($input);
34
    }
35
36
    public function getObjects($class, $variable, $order = null, $one = false)
37
    {
38
        $variable = is_array($variable) ? $variable : [$variable];
39
        $order = is_array($order) ? $order : [$order];
40
41
        if ($one) {
42
            $objects = $this->entityManager->getRepository($class)->findOneBy($variable, $order);
43
        } else {
44
            $objects = $this->entityManager->getRepository($class)->findBy($variable, $order);
45
        }
46
47
        return $objects;
48
    }
49
50
    public function getSvg($svg)
51
    {
52
        return file_get_contents(getcwd().$svg);
53
    }
54
}
55