Completed
Pull Request — master (#211)
by Eric
05:30 queued 02:42
created

CKEditorHelper::renderWidget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\CKEditorBundle\Templating;
13
14
use Ivory\CKEditorBundle\Renderer\CKEditorRendererInterface;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Symfony\Component\Templating\Helper\Helper;
17
18
/**
19
 * CKEditor helper.
20
 *
21
 * @author GeLo <[email protected]>
22
 * @author Adam Misiorny <[email protected]>
23
 */
24
class CKEditorHelper extends Helper implements CKEditorRendererInterface
25
{
26
    /** @var \Ivory\CKEditorBundle\Renderer\CKEditorRendererInterface */
27
    private $renderer;
28
29
    /**
30
     * Creates a CKEditor template helper.
31
     *
32
     * @param \Ivory\CKEditorBundle\Renderer\CKEditorRendererInterface $renderer The CKEditor renderer.
33
     */
34
    public function __construct($renderer)
35
    {
36
        if ($renderer instanceof ContainerInterface) {
37
            @trigger_error(sprintf(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
38
                'Passing a "%s" to the "%s" constructor has been deprecated in IvoryCKEditorBundle 4.0 and will be removed in 5.0. Use the "%s" instead.',
39
                'Symfony\Component\DependencyInjection\ContainerInterface',
40
                'Ivory\CKEditorBundle\Templating\CKEditorHelper',
41
                'Ivory\CKEditorBundle\Renderer\CKEditorRenderer'
42
            ), E_USER_DEPRECATED);
43
44
            $renderer = $renderer->get('ivory_ck_editor.renderer');
45
        }
46
47
        if (!$renderer instanceof CKEditorRendererInterface) {
48
            throw new \InvalidArgumentException(sprintf(
49
                'The CKEditor renderer must be an instance of "%s".',
50
                'Ivory\CKEditorBundle\Renderer\CKEditorRendererInterface'
51
            ));
52
        }
53
54
        $this->renderer = $renderer;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function renderBasePath($basePath)
61
    {
62
        return $this->renderer->renderBasePath($basePath);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function renderJsPath($jsPath)
69
    {
70
        return $this->renderer->renderJsPath($jsPath);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function renderWidget($id, array $config, array $options = array())
77
    {
78
        return $this->renderer->renderWidget($id, $config, $options);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function renderDestroy($id)
85
    {
86
        return $this->renderer->renderDestroy($id);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function renderPlugin($name, array $plugin)
93
    {
94
        return $this->renderer->renderPlugin($name, $plugin);
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function renderStylesSet($name, array $stylesSet)
101
    {
102
        return $this->renderer->renderStylesSet($name, $stylesSet);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function renderTemplate($name, array $template)
109
    {
110
        return $this->renderer->renderTemplate($name, $template);
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function getName()
117
    {
118
        return 'ivory_ckeditor';
119
    }
120
}
121