TYPO3 CMS  TYPO3_7-6
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 
72  public function download(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
73  {
74  $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
75  $fetchedExtension = $this->terUtility->fetchExtension($extension->getExtensionKey(), $extension->getVersion(), $extension->getMd5hash(), $mirrorUrl);
76  if (isset($fetchedExtension['extKey']) && !empty($fetchedExtension['extKey']) && is_string($fetchedExtension['extKey'])) {
77  $this->fileHandlingUtility->unpackExtensionFromExtensionDataArray($fetchedExtension, $extension, $this->getDownloadPath());
78  }
79  }
80 
88  public function setDownloadPath($downloadPath)
89  {
90  if (!in_array($downloadPath, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes())) {
91  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($downloadPath . ' not in allowed download paths', 1344766387);
92  }
93  $this->downloadPath = $downloadPath;
94  }
95 
101  public function getDownloadPath()
102  {
103  return $this->downloadPath;
104  }
105 }
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)