mirror of
https://github.com/YGGverse/gemini-php.git
synced 2026-03-31 17:05:29 +00:00
add getDirectoryPathByUri, getDirectoryUriByPath methods
This commit is contained in:
parent
dff5ed97a1
commit
dbd5820c92
2 changed files with 63 additions and 2 deletions
|
|
@ -68,7 +68,7 @@ class Filesystem
|
|||
'%s/pages/',
|
||||
$this->_path
|
||||
),
|
||||
null,
|
||||
'',
|
||||
$path
|
||||
);
|
||||
|
||||
|
|
@ -93,9 +93,68 @@ class Filesystem
|
|||
$path
|
||||
);
|
||||
|
||||
return urlencode(
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function getDirectoryPathByUri(string $uri = ''): ?string
|
||||
{
|
||||
$path = rtrim(
|
||||
sprintf(
|
||||
'%s/pages/%s',
|
||||
$this->_path,
|
||||
str_replace(
|
||||
':',
|
||||
'/',
|
||||
mb_strtolower(
|
||||
urldecode(
|
||||
$uri
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'/'
|
||||
);
|
||||
|
||||
if (!isset($this->_tree[$path]) || !is_dir($path) || !is_readable($path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function getDirectoryUriByPath(string $path): ?string
|
||||
{
|
||||
if (!isset($this->_tree[$path]) || !is_dir($path) || !is_readable($path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = str_replace(
|
||||
sprintf(
|
||||
'%s/pages/',
|
||||
$this->_path
|
||||
),
|
||||
'',
|
||||
$path
|
||||
);
|
||||
|
||||
$path = trim(
|
||||
$path,
|
||||
'/'
|
||||
);
|
||||
|
||||
$path = str_replace(
|
||||
[
|
||||
'/'
|
||||
],
|
||||
[
|
||||
':'
|
||||
],
|
||||
$path
|
||||
);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function _index(string $path): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue