Ai
5 Star 7 Fork 2

Gitee 极速下载/phpDocumentor2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/phpDocumentor/phpDocumentor2.git
克隆/下载
Path.php 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
Jaapio 提交于 2025-02-15 21:07 +08:00 . When path is empty fall back to root
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link https://phpdoc.org
*/
namespace phpDocumentor;
use Stringable;
use Webmozart\Assert\Assert;
use function array_pop;
use function ctype_alpha;
use function explode;
use function implode;
use function parse_url;
use function sprintf;
use function strlen;
use function strspn;
use const PHP_URL_SCHEME;
/**
* Value Object for paths.
* This can be absolute or relative.
*/
final class Path implements Stringable
{
/**
* Initializes the path.
*/
public function __construct(private readonly string $path)
{
Assert::notEmpty(
$path,
sprintf('"%s" is not a valid path', $path),
);
}
/**
* Verifies if another Path object has the same identity as this one.
*/
public function equals(self $otherPath): bool
{
return $this->path === (string) $otherPath;
}
/**
* returns a string representation of the path.
*/
public function __toString(): string
{
return $this->path;
}
/**
* Returns whether the file path is an absolute path.
*
* @param string $file A file path
*/
public static function isAbsolutePath(string $file): bool
{
return strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& $file[1] === ':'
&& strspn($file, '/\\', 2, 1)
)
|| parse_url($file, PHP_URL_SCHEME) !== null;
}
public static function dirname(Path $input): self
{
$parts = explode('/', (string) $input);
array_pop($parts);
$path = implode('/', $parts);
if ($path === '') {
return new self('/');
}
return new self($path);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/mirrors/phpDocumentor2.git
git@gitee.com:mirrors/phpDocumentor2.git
mirrors
phpDocumentor2
phpDocumentor2
master

搜索帮助