CKEditorExtension   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 68
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A renderBasePath() 0 3 1
A renderDestroy() 0 3 1
A renderStylesSet() 0 3 1
A renderTemplate() 0 3 1
A renderPlugin() 0 3 1
A renderJsPath() 0 3 1
A renderWidget() 0 3 1
A getFunctions() 0 12 1
A getName() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the FOSCKEditor Bundle.
5
 *
6
 * (c) 2018 - present  Friends of Symfony
7
 * (c) 2009 - 2017     Eric GELOEN <[email protected]>
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace FOS\CKEditorBundle\Twig;
14
15
use FOS\CKEditorBundle\Renderer\CKEditorRendererInterface;
16
use Twig\Extension\AbstractExtension;
17
use Twig\TwigFunction;
18
19
/**
20
 * @author GeLo <[email protected]>
21
 */
22
final class CKEditorExtension extends AbstractExtension implements CKEditorRendererInterface
23
{
24
    /**
25
     * @var CKEditorRendererInterface
26
     */
27
    private $renderer;
28
29
    /**
30
     * @param CKEditorRendererInterface $renderer
31
     */
32
    public function __construct(CKEditorRendererInterface $renderer)
33
    {
34
        $this->renderer = $renderer;
35
    }
36
37
    public function getFunctions(): array
38
    {
39
        $options = ['is_safe' => ['html']];
40
41
        return [
42
            new TwigFunction('ckeditor_base_path', [$this, 'renderBasePath'], $options),
43
            new TwigFunction('ckeditor_js_path', [$this, 'renderJsPath'], $options),
44
            new TwigFunction('ckeditor_widget', [$this, 'renderWidget'], $options),
45
            new TwigFunction('ckeditor_destroy', [$this, 'renderDestroy'], $options),
46
            new TwigFunction('ckeditor_plugin', [$this, 'renderPlugin'], $options),
47
            new TwigFunction('ckeditor_styles_set', [$this, 'renderStylesSet'], $options),
48
            new TwigFunction('ckeditor_template', [$this, 'renderTemplate'], $options),
49
        ];
50
    }
51
52
    public function renderBasePath(string $basePath): string
53
    {
54
        return $this->renderer->renderBasePath($basePath);
55
    }
56
57
    public function renderJsPath(string $jsPath): string
58
    {
59
        return $this->renderer->renderJsPath($jsPath);
60
    }
61
62
    public function renderWidget(string $id, array $config, array $options = []): string
63
    {
64
        return $this->renderer->renderWidget($id, $config, $options);
65
    }
66
67
    public function renderDestroy(string $id): string
68
    {
69
        return $this->renderer->renderDestroy($id);
70
    }
71
72
    public function renderPlugin(string $name, array $plugin): string
73
    {
74
        return $this->renderer->renderPlugin($name, $plugin);
75
    }
76
77
    public function renderStylesSet(string $name, array $stylesSet): string
78
    {
79
        return $this->renderer->renderStylesSet($name, $stylesSet);
80
    }
81
82
    public function renderTemplate(string $name, array $template): string
83
    {
84
        return $this->renderer->renderTemplate($name, $template);
85
    }
86
87
    public function getName(): string
88
    {
89
        return 'fos_ckeditor';
90
    }
91
}
92