ngsoft/url

此包已被废弃且不再维护。未建议替代包。

esperecyan/url 分支,使用 polyfill 对 intl 进行处理,并与 psr-7 规范兼容。

维护者

详细信息

github.com/ngsoft/url

主页

源代码

6.0 2019-07-09 16:43 UTC

README

英文 / 日语

URL 标准

使 URL 标准 定义在 PHP 上可用的算法和 API。

描述

URL 标准是 Web 标准规范,替代了之前的标准 RFC 3986RFC 3987

该规范定义了 URL 接口URLSearchParams 接口 作为 API。此库允许您使用 esperecyan\url\URL 类 作为 URL 接口esperecyan\url\URLSearchParams 类 作为 URLSearchParams 接口。MDN 上的文档可能通过解释这些接口 https://mdn.org.cn/docs/Web/API/URL https://mdn.org.cn/docs/Web/API/URLSearchParams 更易于理解。

此库允许您使用 URL 标准定义的算法。详细信息,请参阅 算法对应表

示例

<?php
require_once 'vendor/autoload.php';

use esperecyan\url\URL;

$url = new URL('http://url.test/foobar?name=value');
var_dump($url->protocol, $url->pathname, $url->searchParams->get('name'));

上面的示例将输出

string(5) "http:"
string(7) "/foobar"
string(5) "value"

要求

  • PHP 5.4 或更高版本 (PHP 5.4 和 5.5 已弃用)
    • 不支持 SPL 类型 PECL 库
  • Intl 扩展模块

安装

composer require esperecyan/url

有关 Composer 安装的帮助,请参阅 Composer 文档

贡献

  1. 将其分叉( https://github.com/esperecyan/url
  2. 创建您的功能分支 git checkout -b my-new-feature
  3. 提交您的更改 git commit -am '添加一些功能'
  4. 推送到分支 git push origin my-new-feature
  5. 创建新的 Pull Request

创建新的 Issue

如果您在 README 或 Doc 注释中找到任何英语错误,或测试中的任何缺陷,请通过上述方式报告。我也欢迎对 README 的翻译。

致谢

我在实现从代码点生成 UTF-8 字符 - Qiita从 UTF-8 字符获取代码点 - Qiita时使用了代码。

创建这个库时,我参考了URL 标准日文版

HADAA帮助我将README翻译成英文。

语义化版本控制

该库使用语义化版本控制。库的文档中的类、方法、常量和属性是公共API。

许可证

该库受Mozilla公共许可证第2.0版(MPL-2.0)的许可。

算法对应表

1. 基础设施
百分比编码 esperecyan\url\lib\Infrastructure::percentEncode()
百分比解码 esperecyan\url\lib\Infrastructure::percentDecode()
C0 控制百分比编码集 esperecyan\url\lib\Infrastructure::C0_CONTROL_PERCENT_ENCODE_SET
路径百分比编码集 esperecyan\url\lib\Infrastructure::PATH_PERCENT_ENCODE_SET
用户信息百分比编码集 esperecyan\url\lib\Infrastructure::USERINFO_PERCENT_ENCODE_SET
UTF-8 百分比编码 esperecyan\url\lib\Infrastructure::utf8PercentEncode()
3. 主机(域名和IP地址)
域名
不透明主机
空主机
有效的UTF-8字符串
IPv4地址 范围在0到0xFFFFFFFF之间的整数或浮点数
IPv6地址 一个包含8个元素的整数数组,范围在0到0xFFFF之间
禁止的主机代码点 esperecyan\url\lib\HostProcessing::FORBIDDEN_HOST_CODE_POINTS
域名转ASCII esperecyan\url\lib\HostProcessing::domainToASCII()
域名转Unicode esperecyan\url\lib\HostProcessing::domainToUnicode()
有效域名 esperecyan\url\lib\HostProcessing::isValidDomain()
主机解析器 esperecyan\url\lib\HostProcessing::parseHost()
IPv4数字解析器 esperecyan\url\lib\HostProcessing::parseIPv4Number()
IPv4解析器 esperecyan\url\lib\HostProcessing::parseIPv4()
IPv6解析器 esperecyan\url\lib\HostProcessing::parseIPv6()
不透明主机解析器 esperecyan\url\lib\HostProcessing::parseOpaqueHost()
主机序列化器 esperecyan\url\lib\HostProcessing::serializeHost()
IPv4序列化器 esperecyan\url\lib\HostProcessing::serializeIPv4()
IPv6序列化器 esperecyan\url\lib\HostProcessing::serializeIPv6()
4. URL
URL esperecyan\url\lib\URL类的实例
方案 esperecyan\url\lib\URL->scheme
用户名 esperecyan\url\lib\URL->username
密码 esperecyan\url\lib\URL->password
主机 esperecyan\url\lib\URL->host
端口 esperecyan\url\lib\URL->port
路径 esperecyan\url\lib\URL->path
查询 esperecyan\url\lib\URL->query
片段 esperecyan\url\lib\URL->fragment
不能是基本URL的标志 esperecyan\url\lib\URL->cannotBeABaseURLFlag
对象 esperecyan\url\lib\URL->object
特殊方案 esperecyan\url\lib\URL::$specialSchemes
是否特殊 esperecyan\url\lib\URL->isSpecial()
包含凭据 esperecyan\url\lib\URL->isIncludingCredentials()
不能有用户名/密码/端口号 esperecyan\url\lib\URL->cannotHaveUsernamePasswordPort()
Windows驱动器字母 esperecyan\url\lib\URL::WINDOWS_DRIVE_LETTER
标准化Windows驱动器字母 esperecyan\url\lib\URL::NORMALIZED_WINDOWS_DRIVE_LETTER
以Windows驱动器字母开头 esperecyan\url\lib\URL::stringStartsWithWindowsDriveLetter()
缩短路径 esperecyan\url\lib\URL->shortenPath()
单点路径段 esperecyan\url\lib\URL::SINGLE_DOT_PATH_SEGMENT
双点路径段 esperecyan\url\lib\URL::DOUBLE_DOT_PATH_SEGMENT
URL码点 esperecyan\url\lib\URL::URL_CODE_POINTS
URL解析器 esperecyan\url\lib\URL::parseURL()
基本URL解析器 esperecyan\url\lib\URL::parseBasicURL()
设置用户名 esperecyan\url\lib\URL->setUsername()
设置密码 esperecyan\url\lib\URL->setPassword()
URL序列化器 esperecyan\url\lib\URL->serializeURL()
esperecyan\url\lib\URL->getOrigin()
5. application/x-www-form-urlencoded
application/x-www-form-urlencoded解析器 esperecyan\url\lib\URLencoding::parseURLencoded()
application/x-www-form-urlencoded字节序列化器 esperecyan\url\lib\URLencoding::serializeURLencodedByte()
application/x-www-form-urlencoded序列化器 esperecyan\url\lib\URLencoding::serializeURLencoded()
application/x-www-form-urlencoded字符串解析器 esperecyan\url\lib\URLencoding::parseURLencodedString()
名称-值或名称-值-类型元组 一个包含两个元素或三个元素的数组,第一个元素是名称,第二个是值,第三个是类型。值是一个数组,其中包含name键的值作为名称