Completed
Push — master ( b2a3d2...f8de40 )
by David
10:38
created

src/Twig/CacheTagExtension.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle\Twig;
13
14
use FOS\HttpCache\ResponseTagger;
15
16
/**
17
 * A Twig extension to allow adding cache tags from twig templates.
18
 */
19
class CacheTagExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    /**
22
     * @var ResponseTagger
23
     */
24
    private $responseTagger;
25
26 3
    public function __construct(ResponseTagger $responseTagger)
27
    {
28 3
        $this->responseTagger = $responseTagger;
29 3
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function getFunctions()
35
    {
36
        return [
37 2
            new \Twig_SimpleFunction('fos_httpcache_tag', [$this, 'addTag']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
38
        ];
39
    }
40
41
    /**
42
     * Add a single tag or an array of tags to the response.
43
     *
44
     * The tag string is *not* further processed, you can't use a comma
45
     * separated string to pass several tags but need to build a twig array.
46
     *
47
     * Calling this twig function adds nothing to the output.
48
     *
49
     * @param string|array $tag
50
     */
51 1
    public function addTag($tag)
52
    {
53 1
        $this->responseTagger->addTags((array) $tag);
54 1
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getName()
60
    {
61
        return 'fos_httpcache_tag_extension';
62
    }
63
}
64