keppler/url
Composer 安装命令:
composer require keppler/url
包简介
Url manipulation
README 文档
README
Read the docs documentation
Installation
composer require keppler/url
Quickstart
Parser and Builder
This package is split into 2 independent pieces. These pieces are also split into several other pieces.
The Scheme.php will be referred to as Parser in the documentation.
Parser
The Parser is the entry point for parsing a url. It's immutable, meaning you cannot change it once it is created.
The scheme is split into schemes such as ftp, http, https, mailto, etc. Each scheme is used to parse a single url type, as you might have guessed.
require 'vendor/autoload.php'; $url = 'https://john.doe@www.example.com:123/forum/questions/answered/latest?tag=networking&order=newest#top'; $scheme = Scheme::https($url); print_r($scheme->all()); echo $scheme->getPathBag()->first(); // forum echo $scheme->getPathBag()->last(); // latest echo $scheme->getPathBag()->raw(); // /forum/questions/answered/latest echo $scheme->getPathBag()->get(1); // questions echo $scheme->getPathBag()->has(0); // true echo $scheme->getPathBag()->has(10); // false var_dump($scheme->getQueryBag()->first()); // ['tag' => 'networking'] etc
At the time of this writing the parser supports 4 schemes: FTP, HTTPS, HTTP, and MAILTO
Builder
The Builder.php class is the entry point for modifying a url or simply creating one from scratch. If you choose to build from an existing url you must pass it a Parser instance with the appropriate scheme.
At the time of this writing the Builder supports 4 schemes: FTP, HTTPS, HTTP, and MAILTO
require 'vendor/autoload.php'; $url = 'ftp://user:password@host:123/path'; $ftpScheme = Scheme::ftp($url); $builder = Builder::ftp($ftpScheme); $builder->setHost('example.com') ->setPassword('hunter2') ->setPort(5); print_r($builder->raw()); ... ftp://user:hunter2@example.com:5/path/ print_r($builder->encoded()); ... ftp://user:hunter2@example.com:5/path/to+encode/ // notice the extra +
Both the Parser and the Builder can be used independently.
Each supported scheme can also be used independently without the Builder or the Parser. Examples bellow.
Independent usage
Assuming you don't want to use the Parser/Builder classes directly you can choose not to.
Each scheme supported can be used independently of the Parser/Builder.
$ftpUrl = 'ftp://user:password@host:123/path'; $ftpImmutable = new FtpImmutable($ftpUrl); echo $ftpImmutable->raw(); $ftpBuilder = new FtpBuilder(); $ftpBuilder->setHost('host') ->setPassword('hunter2') ->setPort(987) ->setUser('hunter'); $ftpBuilder->getPathBag() ->set(0, 'path') ->set(1, 'new path'); echo $ftpBuilder->raw(); // ftp://hunter:hunter2@host:987/path/new path/ echo $ftpBuilder->encoded(); // ftp://hunter:hunter2@host:987/path/new+path/
keppler/url 适用场景与选型建议
keppler/url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 keppler/url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 keppler/url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-08