Issues (3627)

Templating/Twig/Extension/SlotExtension.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\CoreBundle\Templating\Twig\Extension;
13
14
use Mautic\CoreBundle\Templating\Helper\SlotsHelper;
15
use Twig_Extension;
16
use Twig_SimpleFunction;
17
18
class SlotExtension extends Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

18
class SlotExtension extends /** @scrutinizer ignore-deprecated */ Twig_Extension
Loading history...
19
{
20
    /**
21
     * @var SlotsHelper
22
     */
23
    protected $helper;
24
25
    public function __construct(SlotsHelper $slotsHelper)
26
    {
27
        $this->helper = $slotsHelper;
28
    }
29
30
    /**
31
     * @see Twig_Extension::getFunctions()
32
     */
33
    public function getFunctions()
34
    {
35
        return [
36
            'slot'           => new Twig_SimpleFunction('slot', [$this, 'getSlot'], ['is_safe' => ['html']]),
37
            'slotHasContent' => new Twig_SimpleFunction('slotHasContent', [$this, 'slotHasContent'], ['is_safe' => ['html']]),
38
        ];
39
    }
40
41
    public function getName()
42
    {
43
        return 'slot';
44
    }
45
46
    public function getSlot($name, $default = null)
47
    {
48
        ob_start();
49
50
        $this->helper->output($name, $default);
51
52
        return ob_get_clean();
53
    }
54
55
    public function slotHasContent($name)
56
    {
57
        return $this->helper->hasContent($name);
58
    }
59
}
60