@@ 24-47 (lines=24) @@ | ||
21 | * @package BrightNucleus\View\Support |
|
22 | * @author Alain Schlesser <[email protected]> |
|
23 | */ |
|
24 | class ExtensionCollection extends ArrayCollection |
|
25 | { |
|
26 | ||
27 | /** |
|
28 | * Check whether a given URI has a specific extension. |
|
29 | * |
|
30 | * @since 0.1.0 |
|
31 | * |
|
32 | * @param string $uri URI to check the extension of. |
|
33 | * @param string $extension Extension to check for. |
|
34 | * |
|
35 | * @return bool |
|
36 | */ |
|
37 | public static function hasExtension($uri, $extension) |
|
38 | { |
|
39 | $uriLength = mb_strlen($uri); |
|
40 | $extensionLength = mb_strlen($extension); |
|
41 | if ($extensionLength > $uriLength) { |
|
42 | return false; |
|
43 | } |
|
44 | ||
45 | return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
46 | } |
|
47 | } |
|
48 |
@@ 22-59 (lines=38) @@ | ||
19 | * @package BrightNucleus\View\Support |
|
20 | * @author Alain Schlesser <[email protected]> |
|
21 | */ |
|
22 | class URIHelper |
|
23 | { |
|
24 | ||
25 | /** |
|
26 | * Check whether a given URI has a specific extension. |
|
27 | * |
|
28 | * @since 0.1.3 |
|
29 | * |
|
30 | * @param string $uri URI to check the extension of. |
|
31 | * @param string $extension Extension to check for. |
|
32 | * |
|
33 | * @return bool |
|
34 | */ |
|
35 | public static function hasExtension($uri, $extension) |
|
36 | { |
|
37 | $uriLength = mb_strlen($uri); |
|
38 | $extensionLength = mb_strlen($extension); |
|
39 | if ($extensionLength > $uriLength) { |
|
40 | return false; |
|
41 | } |
|
42 | ||
43 | return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Get the filename for an URI. |
|
48 | * |
|
49 | * @since 0.1.3 |
|
50 | * |
|
51 | * @param string $uri URI to get the filename from. |
|
52 | * |
|
53 | * @return string Filename without path. |
|
54 | */ |
|
55 | public static function getFilename($uri) |
|
56 | { |
|
57 | return basename($uri); |
|
58 | } |
|
59 | } |
|
60 |