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\DependencyInjection; |
14
|
|
|
|
15
|
|
|
use FOS\CKEditorBundle\Exception\DependencyInjectionException; |
16
|
|
|
use Symfony\Component\Config\FileLocator; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
19
|
|
|
use Symfony\Component\Form\AbstractType; |
20
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author GeLo <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class FOSCKEditorExtension extends ConfigurableExtension |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
protected function loadInternal(array $config, ContainerBuilder $container) |
31
|
|
|
{ |
32
|
|
|
$this->loadResources($container); |
33
|
|
|
|
34
|
|
|
if (!isset($config['enable']) || $config['enable']) { |
35
|
|
|
$config = $this->resolveConfigs($config, $container); |
|
|
|
|
36
|
|
|
$config = $this->resolveStylesSet($config, $container); |
|
|
|
|
37
|
|
|
$this->registerFilebrowsers($config, $container); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$container->getDefinition('fos_ck_editor.form.type') |
41
|
|
|
->setArgument(0, $config); |
42
|
|
|
|
43
|
|
|
if (!method_exists(AbstractType::class, 'getBlockPrefix')) { |
44
|
|
|
$container->getDefinition('fos_ck_editor.form.type') |
45
|
|
|
->clearTag('form.type') |
46
|
|
|
->addTag('form.type', ['alias' => 'ckeditor']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
50
|
|
|
|
51
|
|
|
if (isset($bundles['IvoryCKEditorBundle'])) { |
52
|
|
|
@trigger_error( |
53
|
|
|
"IvoryCKEditorBundle isn't maintained anymore and should be replaced with FOSCKEditorBundle.", |
54
|
|
|
E_USER_DEPRECATED |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function loadResources(ContainerBuilder $container) |
60
|
|
|
{ |
61
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
62
|
|
|
|
63
|
|
|
$resources = [ |
64
|
|
|
'builder', |
65
|
|
|
'command', |
66
|
|
|
'form', |
67
|
|
|
'installer', |
68
|
|
|
'renderer', |
69
|
|
|
'twig', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
foreach ($resources as $resource) { |
73
|
|
|
$loader->load($resource.'.xml'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @throws DependencyInjectionException |
79
|
|
|
*/ |
80
|
|
|
private function resolveConfigs(array $config): array |
81
|
|
|
{ |
82
|
|
|
if (empty($config['configs'])) { |
83
|
|
|
return $config; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (!isset($config['default_config']) && !empty($config['configs'])) { |
87
|
|
|
reset($config['configs']); |
88
|
|
|
$config['default_config'] = key($config['configs']); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (isset($config['default_config']) && !isset($config['configs'][$config['default_config']])) { |
92
|
|
|
throw DependencyInjectionException::invalidDefaultConfig($config['default_config']); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $config; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function resolveStylesSet(array $config) |
99
|
|
|
{ |
100
|
|
|
if (empty($config['styles'])) { |
101
|
|
|
return $config; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$stylesSets = $config['styles']; |
105
|
|
|
|
106
|
|
|
foreach ($stylesSets as &$stylesSet) { |
107
|
|
|
foreach ($stylesSet as &$value) { |
108
|
|
|
$value = array_filter($value); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $config; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param array $config |
117
|
|
|
* @param ContainerBuilder $container |
118
|
|
|
*/ |
119
|
|
|
private function registerFilebrowsers(array $config, ContainerBuilder $container) |
120
|
|
|
{ |
121
|
|
|
if (!empty($config['filebrowsers'])) { |
122
|
|
|
$container |
123
|
|
|
->getDefinition('fos_ck_editor.form.type') |
124
|
|
|
->addMethodCall('setFilebrowsers', [$config['filebrowsers']]); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getAlias() |
129
|
|
|
{ |
130
|
|
|
return 'fos_ck_editor'; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.