1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\CoreBundle\Manager; |
16
|
|
|
|
17
|
|
|
use SWP\Bundle\ContentBundle\Manager\MediaManager as BaseMediaMnager; |
18
|
|
|
use SWP\Bundle\ContentBundle\Model\FileInterface; |
19
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
20
|
|
|
|
21
|
|
|
class MediaManager extends BaseMediaMnager |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TenantContextInterface |
25
|
|
|
*/ |
26
|
|
|
protected $tenantContext; |
27
|
|
|
|
28
|
8 |
|
public function setTenantContext(TenantContextInterface $tenantContext) |
29
|
|
|
{ |
30
|
8 |
|
$this->tenantContext = $tenantContext; |
31
|
8 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function getMediaPublicUrl(FileInterface $media) |
37
|
|
|
{ |
38
|
|
|
$tenant = $this->tenantContext->getTenant(); |
39
|
|
|
if ($subdomain = $tenant->getSubdomain()) { |
40
|
|
|
$context = $this->router->getContext(); |
41
|
|
|
$context->setHost($subdomain.'.'.$context->getHost()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return parent::getMediaPublicUrl($media); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function getMediaBasePath(): string |
48
|
|
|
{ |
49
|
|
|
$tenant = $this->tenantContext->getTenant(); |
50
|
|
|
$pathElements = ['swp', $tenant->getOrganization()->getCode(), $tenant->getCode(), 'media']; |
51
|
|
|
|
52
|
|
|
return implode('/', $pathElements); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|