Ai
5 Star 7 Fork 2

Gitee 极速下载/phpDocumentor2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/phpDocumentor/phpDocumentor2.git
克隆/下载
UriFactory.php 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
Jaapio 提交于 2025-02-15 19:11 +08:00 . Fix deprecations
<?php
declare(strict_types=1);
namespace phpDocumentor;
use InvalidArgumentException;
use League\Uri\Contracts\UriInterface;
use League\Uri\Uri as LeagueUri;
use Throwable;
use function preg_match;
use function sprintf;
use function str_replace;
use function str_starts_with;
use function strlen;
use function substr;
use const DIRECTORY_SEPARATOR;
final class UriFactory
{
public const WINDOWS_URI_FORMAT = '~^(file:\/\/\/)?(?<root>[a-zA-Z][:|\|])~';
public static function createUri(string $uriString): UriInterface
{
try {
$uriString = str_replace(DIRECTORY_SEPARATOR, '/', $uriString);
if (str_starts_with($uriString, 'phar://')) {
return self::createPharUri($uriString);
}
if (preg_match(self::WINDOWS_URI_FORMAT, $uriString)) {
if (str_starts_with($uriString, 'file:///')) {
$uriString = substr($uriString, strlen('file:///'));
}
return LeagueUri::fromWindowsPath($uriString);
}
return LeagueUri::new($uriString);
} catch (Throwable $exception) {
throw new InvalidArgumentException(
sprintf(
'The uri "%s" could not be parsed, the following error occured: %s',
$uriString,
$exception->getMessage(),
),
0,
$exception,
);
}
}
private static function createPharUri(string $uriString): UriInterface
{
$path = substr($uriString, strlen('phar://'));
if (! str_starts_with($path, '/')) {
$path = '/' . $path;
}
return LeagueUri::fromComponents(
[
'scheme' => 'phar',
'host' => '',
'path' => $path,
],
);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/mirrors/phpDocumentor2.git
git@gitee.com:mirrors/phpDocumentor2.git
mirrors
phpDocumentor2
phpDocumentor2
master

搜索帮助