Completed
Push — master ( e1aae9...7bc8ae )
by
unknown
96:15 queued 73:35
created

ProxyResolver::rewriteUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
rs 9.9
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
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver;
8
9
use Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver as ImagineProxyResolver;
10
11
class ProxyResolver extends ImagineProxyResolver
12
{
13
    /**
14
     * Replaces host with given proxy host.
15
     *
16
     * The original method from Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver:rewriteUrl()
17
     * doesn't behave correctly when working with domain and port or with host which contains trailing slash.
18
     *
19
     * @param string $url
20
     * @return string
21
     */
22
    protected function rewriteUrl($url)
23
    {
24
        if (empty($this->hosts)) {
25
            return $url;
26
        }
27
28
        $proxyHost = rtrim(reset($this->hosts), '/');
29
        $relativeUrl = parse_url($url, PHP_URL_PATH);
30
31
        return $proxyHost . $relativeUrl;
32
    }
33
}
34