xref: /template/strap/ComboStrap/Path.php (revision 04fd306c7c155fa133ebb3669986875d65988276)
1c3437056SNickeau<?php
2c3437056SNickeau
3c3437056SNickeau
4c3437056SNickeaunamespace ComboStrap;
5c3437056SNickeau
6*04fd306cSNickeauuse ComboStrap\Web\Url;
7*04fd306cSNickeau
8c3437056SNickeau/**
9c3437056SNickeau * Interface Path
10c3437056SNickeau * @package ComboStrap
11c3437056SNickeau *
12*04fd306cSNickeau * An interface that represents a path.
13c3437056SNickeau *
14*04fd306cSNickeau * For the path operations, see {@link FileSystems}
15c3437056SNickeau *
16*04fd306cSNickeau * The {@link Path::toAbsoluteId()} function is just the path part (no other URI query parameters)
17*04fd306cSNickeau *
18*04fd306cSNickeau * A lot of overlap with {@link Url}
19c3437056SNickeau */
20c3437056SNickeauinterface Path
21c3437056SNickeau{
22c3437056SNickeau
23*04fd306cSNickeau    /**
24*04fd306cSNickeau     * @param string $uri
25*04fd306cSNickeau     * @return Path
26*04fd306cSNickeau     */
27*04fd306cSNickeau    public static function createFromUri(string $uri): Path;
28c3437056SNickeau
29*04fd306cSNickeau    /**
30*04fd306cSNickeau     * @return string
31*04fd306cSNickeau     * @throws ExceptionNotFound - if the path does not have any extension
32*04fd306cSNickeau     */
33*04fd306cSNickeau    function getExtension(): string;
34*04fd306cSNickeau
35*04fd306cSNickeau    /**
36*04fd306cSNickeau     * @return string
37*04fd306cSNickeau     * @throws ExceptionNotFound - if the path does not have any last name
38*04fd306cSNickeau     */
39*04fd306cSNickeau    function getLastNameWithoutExtension(): string;
40c3437056SNickeau
41c3437056SNickeau    function getScheme();
42c3437056SNickeau
43c3437056SNickeau    /**
44*04fd306cSNickeau     * The last name of the path with or without an extension
45c3437056SNickeau     *
46c3437056SNickeau     * The Path class does not have a notion of "extension"
47c3437056SNickeau     * because the file does not have one but we provide the
48c3437056SNickeau     * {@link PathAbs::getExtension()} as utility
49c3437056SNickeau     *
50*04fd306cSNickeau     * @return string
51*04fd306cSNickeau     * @throws ExceptionNotFound - if the path does not have any last name
52c3437056SNickeau     */
53*04fd306cSNickeau    function getLastName(): string;
54c3437056SNickeau
55*04fd306cSNickeau    /**
56*04fd306cSNickeau     * @return mixed - the names are the words between the separator
57*04fd306cSNickeau     */
58c3437056SNickeau    function getNames();
59c3437056SNickeau
604cadd4f8SNickeau    /**
61*04fd306cSNickeau     * @return mixed - the names but without the extension
624cadd4f8SNickeau     */
63*04fd306cSNickeau    function getNamesWithoutExtension();
644cadd4f8SNickeau
654cadd4f8SNickeau    /**
66*04fd306cSNickeau     * @return Path
67*04fd306cSNickeau     * @throws ExceptionNotFound - for the root
68*04fd306cSNickeau     */
69*04fd306cSNickeau    function getParent(): Path;
70*04fd306cSNickeau
71*04fd306cSNickeau    /**
72*04fd306cSNickeau     *
73*04fd306cSNickeau     * @return string only the string representation of the path
74*04fd306cSNickeau     *
75*04fd306cSNickeau     * Same concept than the {@link WikiPath::getWikiId()} but enhanced to other
76*04fd306cSNickeau     * type of path.
77*04fd306cSNickeau     *
78*04fd306cSNickeau     * This is:
79*04fd306cSNickeau     * * the {@link WikiPath::getWikiId()} with the root for a WikiPath and the extension if not a wiki file to be compliant
80*04fd306cSNickeau     * * the path element for all others
81*04fd306cSNickeau     *
82*04fd306cSNickeau     * It's used mostly as common identifier that can be used with any path
83*04fd306cSNickeau     * (such as {@link LocalPath} or {@link WikiPath} path
84*04fd306cSNickeau     *
85*04fd306cSNickeau     */
86*04fd306cSNickeau    function toAbsoluteId(): string;
87*04fd306cSNickeau
88*04fd306cSNickeau    /**
89*04fd306cSNickeau     * @return string the uri string representation of this path (with all information, scheme, drive, attributes)
904cadd4f8SNickeau     */
914cadd4f8SNickeau    function toUriString(): string;
92c3437056SNickeau
93*04fd306cSNickeau    /**
94*04fd306cSNickeau     *
95*04fd306cSNickeau     * @return Path the absolute representation of the path
96*04fd306cSNickeau     *
97*04fd306cSNickeau     *
98*04fd306cSNickeau     * This is:
99*04fd306cSNickeau     * * the {@link WikiPath::getWikiId()} with the root character for a WikiPath and the extension (txt, ...)
100*04fd306cSNickeau     * * the asbolute path element for all others
101*04fd306cSNickeau     *
102*04fd306cSNickeau     * It's used mostly as common identifier that can be used with any path
103*04fd306cSNickeau     * (such as {@link LocalPath} or {@link WikiPath} path
104*04fd306cSNickeau     *
105*04fd306cSNickeau     */
106c3437056SNickeau    function toAbsolutePath(): Path;
107c3437056SNickeau
108c3437056SNickeau    /**
109c3437056SNickeau     * @return Mime the mime from the extension
110*04fd306cSNickeau     * @deprecated Uses {@link FileSystems::getMime()} instead
111c3437056SNickeau     */
112c3437056SNickeau    function getMime(): ?Mime;
1134cadd4f8SNickeau
114*04fd306cSNickeau    function resolve(string $name): Path;
1154cadd4f8SNickeau
1164cadd4f8SNickeau    /**
117*04fd306cSNickeau     * @return Url - the local URL
118*04fd306cSNickeau     * For external path (ie {@link Url}, there is no {@link IFetcher} implementation
119*04fd306cSNickeau     * To create a {@link ThirdMediaLink}, we use therefore this url
1204cadd4f8SNickeau     */
121*04fd306cSNickeau    function getUrl(): Url;
122*04fd306cSNickeau
123*04fd306cSNickeau    /**
124*04fd306cSNickeau     * Needed for the file protocol URI {@link LocalPath}
125*04fd306cSNickeau     * @return string
126*04fd306cSNickeau     */
127*04fd306cSNickeau    function getHost(): string;
128*04fd306cSNickeau
129*04fd306cSNickeau    /**
130*04fd306cSNickeau     * @return WikiPath an utility function
131*04fd306cSNickeau     * @throws ExceptionCast
132*04fd306cSNickeau     */
133*04fd306cSNickeau    function toWikiPath(): WikiPath;
134*04fd306cSNickeau
135*04fd306cSNickeau    /**
136*04fd306cSNickeau     * @return LocalPath an utility function
137*04fd306cSNickeau     * @throws ExceptionCast
138*04fd306cSNickeau     */
139*04fd306cSNickeau    function toLocalPath(): LocalPath;
140*04fd306cSNickeau
141*04fd306cSNickeau
142c3437056SNickeau}
143