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