Completed
Push — master ( e61258...4cb8f2 )
by Arthur
9s
created

UrlUtils::generateRelativeUrlFromPath()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebThumbnailer\Utils;
4
5
/**
6
 * Class UrlUtils
7
 *
8
 * Util class for operations on URL strings.
9
 *
10
 * @package WebThumbnailer\Utils
11
 */
12
class UrlUtils
13
{
14
    /**
15
     * Extract the domains from an URL.
16
     *
17
     * @param string $url Given URL.
18
     *
19
     * @return string Extracted domains, lowercase.
20
     */
21
    public static function getDomain($url)
22
    {
23
        if (! parse_url($url, PHP_URL_SCHEME)) {
24
            $url = 'http://' . $url;
25
        }
26
        return strtolower(parse_url($url, PHP_URL_HOST));
27
    }
28
29
    /**
30
     * Retrieve the file extension from a URL.
31
     *
32
     * @param string $url given URL.
33
     *
34
     * @return string|bool File extension or false if not found.
35
     */
36
    public static function getUrlFileExtension($url)
37
    {
38
        $path = parse_url($url, PHP_URL_PATH);
39
        if (preg_match('/\.(\w+)$/i', $path, $match) > 0) {
40
            return strtolower($match[1]);
41
        }
42
        return '';
43
    }
44
}
45