logbook/class/core/Path.class.php
linarphy a8aa60ae83
Fix following first run
The code 'works' as is
2025-04-15 21:03:44 +02:00

29 lines
635 B
PHP

<?php
namespace core;
/**
* Generic class to specify string type
*
* Use the library Path-PHP: https://path-php.net
*/
class Path extends \Path\Path
{
/**
* Append a child path to this parent path, checking if the result path is inside the parent path as it should
*
* @param \core\Path | \string $path Child path
*/
public function safe_append(\core\Path | string $path) : self
{
$old_realpath = \realpath($this->__tostring());
$new_realpath = \realpath($this->append($path)->__tostring());
if (\strpos($new_realpath, $old_realpath) !== 0)
{
$this = \core\Path($old_realpath);
}
return $this;
}
}
?>