ExtensionInstalledEvent::injectListUtility()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
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\Domain\Event\TYPO3;
19
20
use CuyZ\Notiz\Core\Event\AbstractEvent;
21
use CuyZ\Notiz\Core\Event\Support\ProvidesExampleProperties;
22
use TYPO3\CMS\Core\Utility\PathUtility;
23
use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extensionmanager\Utility\ListUtility 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...
24
25
/**
26
 * Event triggered when an extension is installed via the extension manager.
27
 */
28
class ExtensionInstalledEvent extends AbstractEvent implements ProvidesExampleProperties
29
{
30
    /**
31
     * @label Event/TYPO3:extension_installed.marker.key
32
     * @marker
33
     *
34
     * @var string
35
     */
36
    protected $key;
37
38
    /**
39
     * @label Event/TYPO3:extension_installed.marker.title
40
     * @marker
41
     *
42
     * @var string
43
     */
44
    protected $title;
45
46
    /**
47
     * @label Event/TYPO3:extension_installed.marker.description
48
     * @marker
49
     *
50
     * @var string
51
     */
52
    protected $description;
53
54
    /**
55
     * @label Event/TYPO3:extension_installed.marker.version
56
     * @marker
57
     *
58
     * @var string
59
     */
60
    protected $version;
61
62
    /**
63
     * @var ListUtility
64
     */
65
    protected $listUtility;
66
67
    /**
68
     * @param string $extensionKey
69
     */
70
    public function run(string $extensionKey)
71
    {
72
        $extension = $this->getExtensionData($extensionKey);
73
74
        $this->key = $extensionKey;
75
        $this->title = $extension['title'];
76
        $this->version = $extension['version'];
77
        $this->description = $extension['description'];
78
    }
79
80
    /**
81
     * @param string $extensionKey
82
     * @return array
83
     */
84
    protected function getExtensionData(string $extensionKey): array
85
    {
86
        $extensionPackage = $this->listUtility->getExtension($extensionKey);
87
88
        $data = [
89
            'siteRelPath' => PathUtility::getRelativePath(PATH_site, $extensionPackage->getPackagePath()),
90
            'key' => $extensionKey,
91
        ];
92
93
        $extensionsInformation = $this->listUtility->enrichExtensionsWithEmConfInformation([$extensionKey => $data]);
94
95
        return $extensionsInformation[$extensionKey];
96
    }
97
98
    /**
99
     * @param ListUtility $listUtility
100
     */
101
    public function injectListUtility(ListUtility $listUtility)
102
    {
103
        $this->listUtility = $listUtility;
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function getExampleProperties(): array
110
    {
111
        return [
112
            'key' => 'my_extension',
113
            'title' => 'My Extension',
114
            'description' => 'Some random description that gives details about my extension.',
115
            'version' => '1.0.42',
116
        ];
117
    }
118
}
119