1<?php
2
3
4namespace ComboStrap;
5
6/**
7 * Class InternetPath
8 * @package ComboStrap
9 * A class that takes over the notion of external path
10 * (ie https or ftp scheme)
11 * This class does not make the difference
12 */
13class InternetPath extends PathAbs
14{
15
16
17    public const scheme = "internet";
18    const PATH_SEP = "/";
19
20    private $path;
21
22    /**
23     * InterWikiPath constructor.
24     */
25    public function __construct($path)
26    {
27        if (!media_isexternal($path)) {
28            LogUtility::msg("The path ($path) is not an internet path");
29        }
30        $this->path = $path;
31    }
32
33
34    public static function create(string $path): InternetPath
35    {
36        return new InternetPath($path);
37    }
38
39    function getScheme(): string
40    {
41        return self::scheme;
42    }
43
44    function getLastName()
45    {
46
47        $names = $this->getNames();
48        $size = sizeof($names);
49        if ($size === 0) {
50            return null;
51        }
52        return $names[$size - 1];
53
54    }
55
56    function getNames()
57    {
58
59        $names = explode("/", $this->path);
60        // with the scheme and the hostname, the names start at the third position
61        $size = sizeof($names);
62        if ($size <= 3) {
63            return [];
64        }
65        return array_slice($names, 3);
66
67    }
68
69    function getParent(): ?Path
70    {
71        throw new ExceptionComboRuntime("Not yet implemented");
72    }
73
74
75    function toString(): string
76    {
77        return $this->path;
78    }
79
80    function toAbsolutePath(): Path
81    {
82        return new InternetPath($this->path);
83    }
84
85
86    function resolve(string $name): InternetPath
87    {
88        return self::create($this->path . self::PATH_SEP . $name);
89    }
90}
91