/** * @param Path $Path * @param int $mode * @throws \Exception */ public final function __construct(Path $Path, int $mode = self::AM_DEFAULT) { if ($Path->isFile()) { throw new \Exception('Path "' . $Path->toString() . '" is a file!'); } if ($Path->isLink()) { throw new \Exception('Path "' . $Path->toString() . '" is a link!'); } if (!$Path->isExists() && in_array($mode, [self::AM_PUBLIC, self::AM_INHERIT])) { if (!is_writable($root = Fs::ppath($Path->toString()))) { throw new \Exception('Parent path for "' . $Path->toString() . '" is not exists or not writable!'); } mkdir($Path->toString(), $mode == self::AM_INHERIT ? fileperms($root) : 0777, true); } parent::__construct($Path); }
/** * @param Path $Path * @param int $mode * @throws \Exception */ public final function __construct(Path $Path, int $mode = self::AM_READ) { if ($Path->isDir()) { throw new \Exception('Path "' . $Path->toString() . '" is a directory!'); } if ($Path->isLink()) { throw new \Exception('Path "' . $Path->toString() . '" is a link!'); } if (!$Path->isExists() && in_array($mode, [self::AM_WRITE, self::AM_APPEND])) { if (!$Path->getParent()->toDerectory()->getPath()->isWritable()) { throw new \Exception('Path "' . $Path->toString() . '" is not exists or not writable!'); } file_put_contents($Path->toString(), null); } if ($Path->isExists() && $mode == self::AM_WRITE) { file_put_contents($Path->toString(), null); } parent::__construct($Path); }