zero-to-prod/url
Composer 安装命令:
composer require zero-to-prod/url
包简介
A DataModel for a Url
关键字:
README 文档
README
Contents
- Introduction
- Requirements
- Installation
- Documentation Publishing
- Usage
- Suggested Traits
- Local Development
- Contributing
Introduction
Parse and access url components with a class.
Requirements
- PHP 7.1 or higher.
Installation
Install Zerotoprod\Url via Composer:
composer require zero-to-prod/url
This will add the package to your project’s dependencies and create an autoloader entry for it.
Documentation Publishing
You can publish this README to your local documentation directory.
This can be useful for providing documentation for AI agents.
This can be done using the included script:
# Publish to default location (./docs/zero-to-prod/url) vendor/bin/zero-to-prod-url # Publish to custom directory vendor/bin/zero-to-prod-url /path/to/your/docs
Automatic Documentation Publishing
You can automatically publish documentation by adding the following to your composer.json:
{
"scripts": {
"post-install-cmd": [
"zero-to-prod-url"
],
"post-update-cmd": [
"zero-to-prod-url"
]
}
}
Usage
Use the from() static method to map array keys to class properties.
It is recommended to extend your own Url class with the \Zerotoprod\Url\Url class.
class Url extends \Zerotoprod\Url\Url { } $url = Url::from( parse_url('example.com') ); $url->host // 'example.com' // Passing an array $url = Url::new() ->set_host('example.com') ->set_scheme('https') ->set_path('/search') ->set_query('q=openai'); $url->host; // 'example.com'
Helper Methods
The Url class includes several helper methods for constructing URLs with specific schemes and ports.
<?php use Zerotoprod\Url\Url; // Create a new URL instance and set the host $url = Url::new()->set_host('example.com'); // Using the toProtocol method with custom schemes and ports echo $url->toProtocol('http'); // Outputs: "http://example.com:8080" echo $url->toProtocol('https', 8081); // Outputs: "https://example.com:8081" // Using different helper methods to generate URLs for various schemes echo $url->toSsl(); // Outputs: "ssl://example.com:443" echo $url->toFtp(); // Outputs: "ftp://example.com:21" echo $url->toFtps(); // Outputs: "ftps://example.com:990" echo $url->toSftp(); // Outputs: "sftp://example.com:22" echo $url->toTcp(); // Outputs: "tcp://example.com:80" echo $url->toUdp(); // Outputs: "udp://example.com:53" echo $url->toTls(); // Outputs: "tls://example.com:443" echo $url->toWs(); // Outputs: "ws://example.com:80" echo $url->toWss(); // Outputs: "wss://example.com:443" echo $url->toPop3(); // Outputs: "pop3://example.com:110" echo $url->toImap(); // Outputs: "imap://example.com:143" echo $url->toSmtp(); // Outputs: "smtp://example.com:25" // Optionally, you can pass a custom port to any of these methods echo $url->toSsl(8443); // Outputs: "ssl://example.com:8443" echo $url->toFtp(2121); // Outputs: "ftp://example.com:2121"
Suggested Traits
Parsable
The Parsable trait provides a method for parsing a URL string and ensuring that it starts with a supported protocol. This is useful when you want to handle various types of URLs and ensure they conform to a specific format before processing.
Installation
The Parsable trait is included within this package, so no additional installation is required.
Usage
To use the Zerotoprod\Url\Parsable trait in your class, simply include it:
class Url extends \Zerotoprod\Url\Url { use \Zerotoprod\Url\Parsable; } Url::parse('example.com'); // Defaults to 'https://example.com' Url::parse('example.com', 'custom://', ['http://', 'custom://']);
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Commit changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
zero-to-prod/url 适用场景与选型建议
zero-to-prod/url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.29k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「zero-to-prod」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zero-to-prod/url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zero-to-prod/url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zero-to-prod/url 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Array helpers.
A Generic Factory Pattern for Creating Arrays.
Build a Factory for Anything
A modern approach to extensible, typesafe DTOs with factory support.
Easy URL rewrites in your Laravel application
A Laravel helper to detect if the current route/path is active.
统计信息
- 总下载量: 1.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-26
