Passed
Push — master ( f14348...54cec8 )
by Romain
03:51
created

ignoreDoctrineAnnotation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C) 2018
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Service\Extension;
19
20
use CuyZ\Notiz\Backend\FormEngine\DataProvider\DefaultEventFromGet;
21
use CuyZ\Notiz\Backend\FormEngine\DataProvider\DefinitionError;
22
use CuyZ\Notiz\Backend\FormEngine\DataProvider\HideColumns;
23
use CuyZ\Notiz\Backend\ToolBarItems\NotificationsToolbarItem;
24
use CuyZ\Notiz\Core\Definition\Builder\DefinitionBuilder;
25
use CuyZ\Notiz\Core\Notification\TCA\Processor\GracefulProcessorRunner;
26
use CuyZ\Notiz\Core\Support\NotizConstants;
27
use CuyZ\Notiz\Domain\Definition\Builder\Component\DefaultDefinitionComponents;
28
use CuyZ\Notiz\Service\Container;
29
use CuyZ\Notiz\Service\ExtensionConfigurationService;
30
use CuyZ\Notiz\Service\Hook\EventDefinitionRegisterer;
31
use CuyZ\Notiz\Service\Traits\SelfInstantiateTrait;
32
use Doctrine\Common\Annotations\AnnotationReader;
33
use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Form\F...rovider\DatabaseEditRow was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRecordOverrideValues;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Form\F...aseRecordOverrideValues was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use TYPO3\CMS\Backend\Form\FormDataProvider\InitializeProcessedTca;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Form\F...\InitializeProcessedTca was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use TYPO3\CMS\Core\Cache\Backend\FileBackend;
37
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
38
use TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface;
39
use TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider;
40
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
41
use TYPO3\CMS\Core\Imaging\IconRegistry;
42
use TYPO3\CMS\Core\SingletonInterface;
43
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
44
use TYPO3\CMS\Core\Utility\GeneralUtility;
45
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\SignalSlot\Dispatcher was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
use TYPO3\CMS\Scheduler\Scheduler;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Scheduler\Scheduler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
48
/**
49
 * This class replaces the old-school procedural way of handling configuration
50
 * in `ext_localconf.php` file.
51
 *
52
 * @internal
53
 */
54
class LocalConfigurationService implements SingletonInterface, TableConfigurationPostProcessingHookInterface
55
{
56
    use SelfInstantiateTrait;
57
58
    /**
59
     * @var IconRegistry
60
     */
61
    protected $iconRegistry;
62
63
    /**
64
     * @var Dispatcher
65
     */
66
    protected $dispatcher;
67
68
    /**
69
     * @var ExtensionConfigurationService
70
     */
71
    protected $extensionConfigurationService;
72
73
    /**
74
     * Manual dependency injection.
75
     */
76
    public function __construct()
77
    {
78
        $this->dispatcher = GeneralUtility::makeInstance(Dispatcher::class);
79
        $this->iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
80
    }
81
82
    /**
83
     * Main processing methods that will call every method of this class.
84
     */
85
    public function process()
86
    {
87
        $this->registerLaterProcessHook();
88
        $this->registerDefinitionComponents();
89
        $this->registerEventDefinitionHook();
90
        $this->registerInternalCache();
91
        $this->registerIcons();
92
        $this->registerNotificationProcessorRunner();
93
        $this->registerFormEngineComponents();
94
        $this->resetTypeConvertersArray();
0 ignored issues
show
Deprecated Code introduced by
The function CuyZ\Notiz\Service\Exten...etTypeConvertersArray() has been deprecated: Must be removed when TYPO3 v8 is not supported anymore. ( Ignorable by Annotation )

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

94
        /** @scrutinizer ignore-deprecated */ $this->resetTypeConvertersArray();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

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

Loading history...
95
        $this->overrideScheduler();
96
        $this->ignoreDoctrineAnnotation();
97
    }
98
99
    /**
100
     * This is the second part of the process.
101
     *
102
     * Because the `ExtensionConfigurationService` needs the database to be
103
     * initialized (Extbase reflection service may need it), we need to hook
104
     * later in the TYPO3 bootstrap process to ensure everything has been
105
     * initialized.
106
     *
107
     * @see \CuyZ\Notiz\Service\Extension\LocalConfigurationService::registerLaterProcessHook
108
     */
109
    public function processData()
110
    {
111
        $this->extensionConfigurationService = Container::get(ExtensionConfigurationService::class);
112
113
        $this->registerToolBarItem();
114
    }
115
116
    /**
117
     * @see \CuyZ\Notiz\Service\Extension\LocalConfigurationService::processData
118
     */
119
    protected function registerLaterProcessHook()
120
    {
121
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'][] = static::class;
122
    }
123
124
    /**
125
     * Connects a slot on the definition components customization signal.
126
     */
127
    protected function registerDefinitionComponents()
128
    {
129
        $this->dispatcher->connect(
130
            DefinitionBuilder::class,
131
            DefinitionBuilder::COMPONENTS_SIGNAL,
132
            DefaultDefinitionComponents::class,
133
            'register'
134
        );
135
    }
136
137
    /**
138
     * Hooking in TYPO3 early process to register all hooks/signals added to the
139
     * event definition.
140
     */
141
    protected function registerEventDefinitionHook()
142
    {
143
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'][] = EventDefinitionRegisterer::class;
144
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'][] = EventDefinitionRegisterer::class . '->processData';
145
    }
146
147
    /**
148
     * Internal cache used by the extension.
149
     */
150
    protected function registerInternalCache()
151
    {
152
        if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][NotizConstants::CACHE_ID])) {
153
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][NotizConstants::CACHE_ID] = [
154
                'backend' => FileBackend::class,
155
                'frontend' => VariableFrontend::class,
156
                'groups' => ['all', 'system', 'pages'],
157
            ];
158
        }
159
    }
160
161
    /**
162
     * Registers icons that can then be used wherever in TYPO3 with the icon
163
     * API.
164
     */
165
    protected function registerIcons()
166
    {
167
        $iconsList = [
168
            SvgIconProvider::class => [
169
                'tx-notiz-icon' => ['source' => NotizConstants::EXTENSION_ICON_DEFAULT],
170
                'tx-notiz-icon-toolbar' => ['source' => NotizConstants::EXTENSION_ICON_PATH . 'notiz-icon-toolbar.svg'],
171
                'tx-notiz-icon-main-module' => ['source' => NotizConstants::EXTENSION_ICON_MAIN_MODULE_PATH],
172
            ],
173
            FontawesomeIconProvider::class => [
174
                'info-circle' => ['name' => 'info-circle'],
175
                'envelope' => ['name' => 'envelope'],
176
                'twitter' => ['name' => 'twitter'],
177
                'slack' => ['name' => 'slack'],
178
                'github' => ['name' => 'github'],
179
            ],
180
        ];
181
182
        foreach ($iconsList as $provider => $icons) {
183
            foreach ($icons as $name => $configuration) {
184
                $this->iconRegistry->registerIcon($name, $provider, $configuration);
185
            }
186
        }
187
    }
188
189
    /**
190
     * Registers the tool bar item shown on the header of the TYPO3 backend.
191
     */
192
    protected function registerToolBarItem()
193
    {
194
        $enableToolbar = $this->extensionConfigurationService->getConfigurationValue('toolbar.enable');
195
196
        if ($enableToolbar) {
197
            $GLOBALS['TYPO3_CONF_VARS']['BE']['toolbarItems'][1505997677] = NotificationsToolbarItem::class;
198
        }
199
    }
200
201
    /**
202
     * Because of some core issue concerning the type converters registration,
203
     * we need to make sure the array containing the entries is valid.
204
     *
205
     * See the ticket below for more information:
206
     *
207
     * @link https://forge.typo3.org/issues/82651
208
     *
209
     * @deprecated Must be removed when TYPO3 v8 is not supported anymore.
210
     */
211
    protected function resetTypeConvertersArray()
212
    {
213
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters'] = array_unique($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['typeConverters']);
214
    }
215
216
    /**
217
     * Registering a xClass that overrides core scheduler, to have access to
218
     * signals for when tasks are executed.
219
     *
220
     * @see \CuyZ\Notiz\Service\Scheduler\Scheduler
221
     */
222
    protected function overrideScheduler()
223
    {
224
        if (ExtensionManagementUtility::isLoaded('scheduler')) {
225
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][Scheduler::class] = ['className' => \CuyZ\Notiz\Service\Scheduler\Scheduler::class];
226
        }
227
    }
228
229
    /**
230
     * Registers the notification processor runner.
231
     *
232
     * @see \CuyZ\Notiz\Core\Notification\TCA\Processor\GracefulProcessorRunner
233
     */
234
    protected function registerNotificationProcessorRunner()
235
    {
236
        $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'][] = GracefulProcessorRunner::class;
237
    }
238
239
    /**
240
     * Registers components for TYPO3 form engine.
241
     */
242
    protected function registerFormEngineComponents()
243
    {
244
        /*
245
         * A new data provider is registered for the form engine.
246
         *
247
         * It will be used to select a default value for the field `event` of a
248
         * notification record, if an argument `selectedEvent` exists in the
249
         * request and matches a valid event identifier.
250
         */
251
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][DefaultEventFromGet::class] = ['depends' => [DatabaseEditRow::class]];
252
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][DatabaseRecordOverrideValues::class]['depends'][] = DefaultEventFromGet::class;
253
254
        /*
255
         * A data provider will be used to detect any definition error, in which
256
         * case an error message is shown to the user trying to create/edit an
257
         * entity notification.
258
         */
259
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][DefinitionError::class] = [];
260
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][InitializeProcessedTca::class]['depends'][] = DefinitionError::class;
261
262
        /*
263
         * A data provider is used to hide all columns when no event has been
264
         * selected for a notification entity.
265
         */
266
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][HideColumns::class] = [];
267
    }
268
269
    /**
270
     * Some annotations are used by this extension and can be confusing for
271
     * Doctrine.
272
     */
273
    protected function ignoreDoctrineAnnotation()
274
    {
275
        if (class_exists(AnnotationReader::class)) {
276
            AnnotationReader::addGlobalIgnoredName('label');
277
            AnnotationReader::addGlobalIgnoredName('marker');
278
            AnnotationReader::addGlobalIgnoredName('email');
279
        }
280
    }
281
}
282