| 1 | <?php |
||||
| 2 | namespace EWW\Dpf\Helper; |
||||
| 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 EWW\Dpf\Configuration\ClientConfigurationManager; |
||||
| 18 | use TYPO3\CMS\Extbase\Object\ObjectManager; |
||||
| 19 | |||||
| 20 | class UploadFileUrl |
||||
| 21 | { |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * clientConfigurationManager |
||||
| 25 | * |
||||
| 26 | * @var \EWW\Dpf\Configuration\ClientConfigurationManager |
||||
| 27 | */ |
||||
| 28 | protected $clientConfigurationManager; |
||||
| 29 | |||||
| 30 | public function __construct() { |
||||
| 31 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class); |
||||
| 32 | $this->clientConfigurationManager = $objectManager->get(ClientConfigurationManager::class); |
||||
| 33 | } |
||||
| 34 | |||||
| 35 | |||||
| 36 | public function getBaseUrl() |
||||
| 37 | { |
||||
| 38 | $uploadDomain = $this->clientConfigurationManager->getUploadDomain(); |
||||
| 39 | |||||
| 40 | $baseUrl = trim($uploadDomain, "/ "); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 41 | |||||
| 42 | if (empty($baseUrl)) { |
||||
| 43 | $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === false ? 'http://' : 'https://'; |
||||
| 44 | $baseUrl = $protocol . $_SERVER['HTTP_HOST']; |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | return $baseUrl; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | public function getDirectory() |
||||
| 51 | { |
||||
| 52 | $uploadDirectory = $this->clientConfigurationManager->getUploadDirectory(); |
||||
| 53 | |||||
| 54 | $uploadDirectory = trim($uploadDirectory, "/ "); |
||||
|
0 ignored issues
–
show
It seems like
$uploadDirectory can also be of type null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 55 | |||||
| 56 | $uploadDir = empty($uploadDirectory) ? "uploads/tx_dpf" : $uploadDirectory; |
||||
| 57 | |||||
| 58 | return $uploadDir; |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | public function getUploadUrl() |
||||
| 62 | { |
||||
| 63 | return $this->getBaseUrl() . "/" . $this->getDirectory(); |
||||
| 64 | } |
||||
| 65 | |||||
| 66 | } |
||||
| 67 |