This commit is contained in:
2022-08-08 23:03:28 -04:00
parent cdb4b382b7
commit 85fef16b27
7 changed files with 84 additions and 9 deletions

View File

@ -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
]);

View File

@ -0,0 +1,15 @@
<?php
namespace ProVM\Concept;
use ArrayAccess;
interface Path extends ArrayAccess
{
public function compose(string $base_path): Path;
public function add(string $path_segment): Path;
public function build(): string;
public static function fromArray(array $path): string;
public static function isAbsolute(string $path): bool;
public static function isRelative(string $path): bool;
}

View File

@ -2,6 +2,7 @@
namespace ProVM\Implement;
use Psr\Collection\CollectionInterface;
use ReflectionFunction;
class Collection implements CollectionInterface
{
@ -41,7 +42,7 @@ class Collection implements CollectionInterface
}
protected function processCallable(Callable $value)
{
$ref = new \ReflectionFunction($value);
$ref = new ReflectionFunction($value);
$param_array = [];
$params = $ref->getParameters();
foreach ($params as $p) {

View File

@ -1,7 +1,7 @@
<?php
namespace ProVM\Implement;
use Common\Alias\File as BaseFile;
use ProVM\Alias\File as BaseFile;
class File extends BaseFile
{

View File

@ -1,8 +1,8 @@
<?php
namespace ProVM\Implement;
use Common\Concept\File as FileInterface;
use Common\Alias\Filesystem as BaseFilesystem;
use ProVM\Concept\File as FileInterface;
use ProVM\Alias\Filesystem as BaseFilesystem;
class Filesystem extends BaseFilesystem
{

View File

@ -0,0 +1,58 @@
<?php
namespace ProVM\Implement;
use ProVM\Concept\Path as PathInterface;
class Path implements PathInterface
{
protected array $path;
public function compose(string $base_path): PathInterface
{
$this->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]);
}
}

View File

@ -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'
]);