[TASK] EXT:lang CodeCleanup
[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\Extbase\Object\ObjectManagerInterface;
19 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
20 use TYPO3\CMS\Lang\Domain\Model\Extension;
21
22 /**
23 * Extension repository
24 */
25 class ExtensionRepository
26 {
27 /**
28 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
29 */
30 protected $objectManager;
31
32 /**
33 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
34 */
35 protected $listUtility;
36
37 /**
38 * @var array
39 */
40 protected $extensions = array();
41
42 /**
43 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
44 */
45 public function injectObjectManager(ObjectManagerInterface $objectManager)
46 {
47 $this->objectManager = $objectManager;
48 }
49
50 /**
51 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
52 */
53 public function injectListUtility(ListUtility $listUtility)
54 {
55 $this->listUtility = $listUtility;
56 }
57
58 /**
59 * Returns all objects of this repository
60 *
61 * @return array The extensions
62 */
63 public function findAll()
64 {
65 if (empty($this->extensions)) {
66 $extensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
67 foreach ($extensions as $entry) {
68 /** @var $extension \TYPO3\CMS\Lang\Domain\Model\Extension */
69 $extension = $this->objectManager->get(
70 Extension::class,
71 $entry['key'],
72 $entry['title'],
73 $this->getExtensionIconWithPath($entry)
74 );
75 $extension->setVersionFromString($entry['version']);
76 if ($entry['ext_icon_width'] > 0) {
77 $extension->setIconWidth($entry['ext_icon_width']);
78 }
79 if ($entry['ext_icon_height'] > 0) {
80 $extension->setIconHeight($entry['ext_icon_height']);
81 }
82
83 $this->extensions[$entry['key']] = $extension;
84 }
85 ksort($this->extensions);
86 }
87 return $this->extensions;
88 }
89
90 /**
91 * Counts all objects of this repository
92 *
93 * @return int The extension count
94 */
95 public function countAll()
96 {
97 $extensions = $this->findAll();
98 return count($extensions);
99 }
100
101 /**
102 * Find one extension by offset
103 *
104 * @param int $offset The offset
105 * @return \TYPO3\CMS\Lang\Domain\Model\Extension The extension
106 */
107 public function findOneByOffset($offset)
108 {
109 $extensions = $this->findAll();
110 $extensions = array_values($extensions);
111 $offset = (int)$offset;
112 if (!empty($extensions[$offset])) {
113 return $extensions[$offset];
114 }
115 return null;
116 }
117
118 /**
119 * Returns the extension icon
120 *
121 * @param array $extensionEntry
122 * @return string
123 */
124 protected function getExtensionIconWithPath($extensionEntry)
125 {
126 $extensionIcon = $GLOBALS['TYPO3_LOADED_EXT'][$extensionEntry['key']]['ext_icon'];
127 if (empty($extensionIcon)) {
128 $extensionIcon = ExtensionManagementUtility::getExtensionIcon(PATH_site . $extensionEntry['siteRelPath'] . '/');
129 }
130 if (empty($extensionIcon)) {
131 $extensionIcon = '/typo3/sysext/core/ext_icon.png';
132 } else {
133 $extensionIcon = '../' . $extensionEntry['siteRelPath'] . '/' . $extensionIcon;
134 }
135 return $extensionIcon;
136 }
137 }