Completed
Push — master ( f93802...a3beff )
by Paweł
34:14
created

MediaManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 23.08%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 34
ccs 3
cts 13
cp 0.2308
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setTenantContext() 0 4 1
A getMediaPublicUrl() 0 10 2
A getMediaBasePath() 0 7 1
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