Completed
Push — master ( fecb59...e32f72 )
by Paweł
29:36
created

GimmeExtension::getGlobals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Templates System.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\TemplatesSystem\Twig\Extension;
16
17
use SWP\Component\TemplatesSystem\Gimme\Context\Context;
18
use SWP\Component\TemplatesSystem\Gimme\Loader\LoaderInterface;
19
use SWP\Component\TemplatesSystem\Twig\TokenParser\GimmeListTokenParser;
20
use SWP\Component\TemplatesSystem\Twig\TokenParser\GimmeTokenParser;
21
22
class GimmeExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
23
{
24
    protected $loader;
25
26
    protected $context;
27
28
    /**
29
     * GimmeExtension constructor.
30
     *
31
     * @param Context         $context
32
     * @param LoaderInterface $loader
33
     */
34 88
    public function __construct(Context $context, LoaderInterface $loader)
35
    {
36 88
        $this->context = $context;
37 88
        $this->loader = $loader;
38 88
    }
39
40 12
    public function getLoader()
41
    {
42 12
        return $this->loader;
43
    }
44
45 1
    public function getContext()
46
    {
47 1
        return $this->context;
48
    }
49
50 17
    public function getTokenParsers()
51
    {
52
        return [
53 17
            new GimmeTokenParser(),
54 17
            new GimmeListTokenParser(),
55
        ];
56
    }
57
58 17
    public function getFilters()
59
    {
60
        return [
61
            new \Twig_SimpleFilter('start', function ($context, $node, $value) {
62
                $node['_collection_type_filters']['start'] = $value;
63
64
                return $node;
65 17
            }, ['needs_context' => true]),
66
            new \Twig_SimpleFilter('limit', function ($context, $node, $value) {
67
                $node['_collection_type_filters']['limit'] = $value;
68
69
                return $node;
70 17
            }, ['needs_context' => true]),
71 17
            new \Twig_SimpleFilter('order', function ($context, $node, $value1, $value2) {
72
                $node['_collection_type_filters']['order'] = [$value1, $value2];
73
74
                return $node;
75 17
            }, ['needs_context' => true]),
76
        ];
77
    }
78
79 26
    public function getGlobals()
80
    {
81 26
        return ['gimme' => $this->context];
82
    }
83
84 87
    public function getName()
85
    {
86 87
        return 'swp_gimme';
87
    }
88
}
89