Completed
Push — qa-cumulative-ezp-31278-31279-... ( f57b9c...05fe70 )
by
unknown
14:35
created

AbsolutePrefix::getPrefix()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\IO\UrlDecorator;
10
11
use eZ\Publish\Core\IO\UrlDecorator;
12
13
/**
14
 * Prefixes the URI with a string, and makes it absolute.
15
 */
16
class AbsolutePrefix extends Prefix implements UrlDecorator
17
{
18
    public function getPrefix(): string
19
    {
20
        $prefix = $this->ioConfigResolver->getLegacyUrlPrefix();
21
22
        if ($prefix !== '') {
23
            $urlParts = parse_url($prefix);
24
25
            // Since PHP 5.4.7 parse_url will return host when url scheme is ommited.
26
            // This allows urls like //static.example.com to be used
27
            if (isset($urlParts['scheme']) || isset($urlParts['host'])) {
28
                $prefix = rtrim($prefix, '/') . '/';
29
            } else {
30
                $prefix = '/' . trim($prefix, '/') . '/';
31
            }
32
        }
33
34
        return $prefix;
35
    }
36
}
37