[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / DownloadUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
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 * Utility for dealing with ext_emconf
18 *
19 * @author Susanne Moog <susanne.moog@typo3.org>
20 */
21 class DownloadUtility implements \TYPO3\CMS\Core\SingletonInterface {
22
23 /**
24 * @var \TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility
25 * @inject
26 */
27 protected $terUtility;
28
29 /**
30 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
31 * @inject
32 */
33 protected $repositoryHelper;
34
35 /**
36 * @var string
37 */
38 protected $downloadPath = 'Local';
39
40 /**
41 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
42 * @inject
43 */
44 protected $fileHandlingUtility;
45
46 /**
47 * Download an extension
48 *
49 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
50 * @return void
51 */
52 public function download(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
53 $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
54 $fetchedExtension = $this->terUtility->fetchExtension($extension->getExtensionKey(), $extension->getVersion(), $extension->getMd5hash(), $mirrorUrl);
55 if (isset($fetchedExtension['extKey']) && !empty($fetchedExtension['extKey']) && is_string($fetchedExtension['extKey'])) {
56 $this->fileHandlingUtility->unpackExtensionFromExtensionDataArray($fetchedExtension, $extension, $this->getDownloadPath());
57 }
58 }
59
60 /**
61 * Set the download path
62 *
63 * @param string $downloadPath
64 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
65 * @return void
66 */
67 public function setDownloadPath($downloadPath) {
68 if (!in_array($downloadPath, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes())) {
69 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(htmlspecialchars($downloadPath) . ' not in allowed download paths', 1344766387);
70 }
71 $this->downloadPath = $downloadPath;
72 }
73
74 /**
75 * Get the download path
76 *
77 * @return string
78 */
79 public function getDownloadPath() {
80 return $this->downloadPath;
81 }
82
83 }