<?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;
	}
}

?>