dealnews/url
Composer 安装命令:
composer require dealnews/url
包简介
URL Parser and Builder
README 文档
README
Utilities for parsing, normalizing, merging, and building URLs with fine‑grained control over query strings.
Installation
composer require dealnews/url
Classes
DealNews\Url\Url
High level URL helper that stores individual URL parts (scheme, host, path, query, etc.) and keeps a QueryString helper in sync with the query property.
Key capabilities:
parse(string $url, bool $reset = true, ?string $separator = null)– split a URL into parts and validate each component.- Magic setters/getters (
$url->host,$url->path,$url->query, …) – allow direct manipulation of parts with validation. build(?string $separator = null)– rebuild the URL, omitting default ports and honoring custom separators.normalize()– lowercases scheme/host, sorts query parameters, and normalizes percent‑encoding.sanitizePathComponent(string $input)– generate safe slug/path fragments.merge(string $url1, string ...$url2)– merge one or more URLs into the current instance without mutating the original data.
Example:
use DealNews\Url\Url; $url = new Url('https://user:pass@example.com:443/products/tv?q=4k#details'); $url->normalize(); // lowercases scheme/host and sorts query parameters $url->query_string->setParameter('page', '2'); $url->fragment = 'reviews'; echo $url->build(); // https://user:pass@example.com/products/tv?q=4k&page=2#reviews // Merge additional data without losing the existing state $combined = $url->merge('http://cdn.example.com/media', '?size=large'); // $combined => http://cdn.example.com/media?size=large // $url remains unchanged
DealNews\Url\QueryString
Lightweight parser/builder for ordered query strings. Allows unnamed entries, custom separators, front insertion, and selective replacement.
Key methods:
parse(string $query_string, string $separator = '&')build(?string $separator = null): stringaddParameter(?string $key, ?string $value, bool $front = false)setParameter(?string $key, ?string $value, bool $front = false)removeParameters(array $keys): voidsortParameters(): voidgetParameters(): array
Example:
use DealNews\Url\QueryString; $qs = new QueryString('foo=1&bar=2'); $qs->setParameter('foo', '3'); $qs->addParameter(null, 'feature'); // unnamed flag $qs->sortParameters(); // only sorts when all params are named echo $qs->build(); // foo=3&bar=2&feature
Custom separator example:
$qs = new QueryString(null, ';'); $qs->parse('token;user=john;role=admin', ';'); $qs->addParameter('expires', '1700000000'); echo $qs->build(); // token;user=john;role=admin;expires=1700000000
DealNews\Url\Exception\Parse
Custom exception extending \Exception. Methods such as Url::__construct() and Url::__set() throw Parse when a URL cannot be parsed or an invalid property is referenced.
use DealNews\Url\Exception\Parse; use DealNews\Url\Url; try { $url = new Url(); $url->invalid_property = 'value'; } catch (Parse $e) { // Handle invalid assignment }
Testing
composer install ./vendor/bin/phpunit
dealnews/url 适用场景与选型建议
dealnews/url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dealnews/url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dealnews/url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-11-08