[BUGFIX] Prevent repopulating TYPO3_CONF_VARS
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Domain / Repository / ExtensionRepository.php
1 <?php
2 namespace TYPO3\CMS\Lang\Domain\Repository;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Utility\PathUtility;
20 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
21 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
22 use TYPO3\CMS\Lang\Domain\Model\Extension;
23
24 /**
25 * Extension repository
26 */
27 class ExtensionRepository
28 {
29 /**
30 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
31 */
32 protected $objectManager;
33
34 /**
35 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
36 */
37 protected $listUtility;
38
39 /**
40 * @var array
41 */
42 protected $extensions = [];
43
44 /**
45 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
46 */
47 public function injectObjectManager(ObjectManagerInterface $objectManager)
48 {
49 $this->objectManager = $objectManager;
50 }
51
52 /**
53 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
54 */
55 public function injectListUtility(ListUtility $listUtility)
56 {
57 $this->listUtility = $listUtility;
58 }
59
60 /**
61 * Returns all objects of this repository
62 *
63 * @return array The extensions
64 */
65 public function findAll()
66 {
67 if (empty($this->extensions)) {
68 $extensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
69 foreach ($extensions as $entry) {
70 /** @var $extension \TYPO3\CMS\Lang\Domain\Model\Extension */
71 $extension = $this->objectManager->get(
72 Extension::class,
73 $entry['key'],
74 $entry['title'],
75 $this->getExtensionIconWithPath($entry)
76 );
77 $extension->setVersionFromString($entry['version']);
78 if ($entry['ext_icon_width'] > 0) {
79 $extension->setIconWidth($entry['ext_icon_width']);
80 }
81 if ($entry['ext_icon_height'] > 0) {
82 $extension->setIconHeight($entry['ext_icon_height']);
83 }
84
85 $this->extensions[$entry['key']] = $extension;
86 }
87 ksort($this->extensions);
88 }
89 return $this->extensions;
90 }
91
92 /**
93 * Counts all objects of this repository
94 *
95 * @return int The extension count
96 */
97 public function countAll()
98 {
99 $extensions = $this->findAll();
100 return count($extensions);
101 }
102
103 /**
104 * Find one extension by offset
105 *
106 * @param int $offset The offset
107 * @return \TYPO3\CMS\Lang\Domain\Model\Extension The extension
108 */
109 public function findOneByOffset($offset)
110 {
111 $extensions = $this->findAll();
112 $extensions = array_values($extensions);
113 $offset = (int)$offset;
114 if (!empty($extensions[$offset])) {
115 return $extensions[$offset];
116 }
117 return null;
118 }
119
120 /**
121 * Returns the extension icon
122 *
123 * @param array $extensionEntry
124 * @return string
125 */
126 protected function getExtensionIconWithPath($extensionEntry)
127 {
128 $extensionIcon = $GLOBALS['TYPO3_LOADED_EXT'][$extensionEntry['key']]['ext_icon'];
129 if (empty($extensionIcon)) {
130 $extensionIcon = ExtensionManagementUtility::getExtensionIcon(PATH_site . $extensionEntry['siteRelPath'] . '/');
131 }
132 if (empty($extensionIcon)) {
133 $extensionIcon = GeneralUtility::getFileAbsFileName('EXT:core/Resources/Public/Icons/Extension.png');
134 $extensionIcon = PathUtility::stripPathSitePrefix($extensionIcon);
135 } else {
136 $extensionIcon = '../' . $extensionEntry['siteRelPath'] . '/' . $extensionIcon;
137 }
138 return $extensionIcon;
139 }
140 }