TYPO3 CMS  TYPO3_8-7
DownloadUtility.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  protected $terUtility;
26 
30  protected $repositoryHelper;
31 
35  protected $downloadPath = 'Local';
36 
41 
45  public function injectTerUtility(\TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility $terUtility)
46  {
47  $this->terUtility = $terUtility;
48  }
49 
53  public function injectRepositoryHelper(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper)
54  {
55  $this->repositoryHelper = $repositoryHelper;
56  }
57 
61  public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
62  {
63  $this->fileHandlingUtility = $fileHandlingUtility;
64  }
65 
71  public function download(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
72  {
73  $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
74  $fetchedExtension = $this->terUtility->fetchExtension($extension->getExtensionKey(), $extension->getVersion(), $extension->getMd5hash(), $mirrorUrl);
75  if (isset($fetchedExtension['extKey']) && !empty($fetchedExtension['extKey']) && is_string($fetchedExtension['extKey'])) {
76  $this->fileHandlingUtility->unpackExtensionFromExtensionDataArray($fetchedExtension, $extension, $this->getDownloadPath());
77  }
78  }
79 
86  public function setDownloadPath($downloadPath)
87  {
88  if (!in_array($downloadPath, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes())) {
89  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($downloadPath . ' not in allowed download paths', 1344766387);
90  }
91  $this->downloadPath = $downloadPath;
92  }
93 
99  public function getDownloadPath()
100  {
101  return $this->downloadPath;
102  }
103 }
injectRepositoryHelper(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $repositoryHelper)
injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
download(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
injectTerUtility(\TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility $terUtility)