diff --git a/api/ProVM/Alias/Filesystem.php b/api/ProVM/Alias/Filesystem.php index 89916ac..8d32a89 100644 --- a/api/ProVM/Alias/Filesystem.php +++ b/api/ProVM/Alias/Filesystem.php @@ -3,6 +3,7 @@ namespace ProVM\Alias; use function Safe\{touch,mkdir,unlink}; use ProVM\Concept\Filesystem as FilesystemInterface; +use ProVM\Implement\Path; abstract class Filesystem implements FilesystemInterface { @@ -19,7 +20,7 @@ abstract class Filesystem implements FilesystemInterface public function buildPath(string $relative_path): string { - return implode(DIRECTORY_SEPARATOR, [ + return Path::fromArray([ $this->getBasePath(), $relative_path ]); diff --git a/api/ProVM/Concept/Path.php b/api/ProVM/Concept/Path.php new file mode 100644 index 0000000..c5807c9 --- /dev/null +++ b/api/ProVM/Concept/Path.php @@ -0,0 +1,15 @@ +getParameters(); foreach ($params as $p) { diff --git a/api/ProVM/Implement/File.php b/api/ProVM/Implement/File.php index 3c35b3a..3c1a16a 100644 --- a/api/ProVM/Implement/File.php +++ b/api/ProVM/Implement/File.php @@ -1,7 +1,7 @@ path = []; + return $this->add($base_path); + } + public function add(string $path_segment): PathInterface + { + $this->path []= $path_segment; + return $this; + } + public function build(): string + { + return implode(DIRECTORY_SEPARATOR, $this->path); + } + public static function fromArray(array $path): string + { + $output = new Path(); + $output->compose(array_shift($path)); + foreach ($path as $p) { + $output->add($p); + } + return $output->build(); + } + + public static function isAbsolute(string $path): bool + { + return !file_exists(Path::fromArray([$path, '..'])); + } + public static function isRelative(string $path): bool + { + return !Path::isAbsolute($path); + } + + public function offsetExists(mixed $offset): bool + { + return isset($this->path[$offset]); + } + public function offsetGet(mixed $offset): mixed + { + return $this->path[$offset]; + } + public function offsetSet(mixed $offset, mixed $value): void + { + $this->path[$offset] = $value; + } + public function offsetUnset(mixed $offset): void + { + unset($this->path[$offset]); + } +} diff --git a/api/setup/settings/02_common.php b/api/setup/settings/02_common.php index ee3d5da..38c7030 100644 --- a/api/setup/settings/02_common.php +++ b/api/setup/settings/02_common.php @@ -6,25 +6,25 @@ return [ return \ProVM\Implement\Collection::fromArray([ 'base' => dirname(__DIR__, 2), 'resources' => function(\Psr\Collection\CollectionInterface $collection) { - return implode(DIRECTORY_SEPARATOR, [ + return \ProVM\Implement\Path::fromArray([ $collection['base'], 'resources' ]); }, 'documentation' => function(\Psr\Collection\CollectionInterface $collection) { - return implode(DIRECTORY_SEPARATOR, [ + return \ProVM\Implement\Path::fromArray([ $collection['resources'], 'documentation' ]); }, 'routes' => function(\Psr\Collection\CollectionInterface $collection) { - return implode(DIRECTORY_SEPARATOR, [ + return \ProVM\Implement\Path::fromArray([ $collection['resources'], 'routes' ]); }, 'public' => function(\Psr\Collection\CollectionInterface $collection) { - return implode(DIRECTORY_SEPARATOR, [ + return \ProVM\Implement\Path::fromArray([ $collection['base'], 'public' ]);