mtchabok/url
Composer 安装命令:
composer require mtchabok/url
包简介
PHP Url Class
关键字:
README 文档
README
PHP class for handling URLs.
- Parse Url string Customized and create objects
- check relative url
- add or modify any part of the url objects
- add or modify query parameters
- compare any part of url with another url or part of that
- support PSR-7 method`s
Installation
This package is listed on Packagist.
composer require mtchabok/url
How To Usage
Create Url Object
use \Mtchabok\Url\Url; $url = new Url('https://www.domain.com/dir1/dir2/file.ext?param1=val1¶m2=val2'); $url = Url::newUrl('https://www.domain.com/dir1/dir2/file.ext?param1=val1¶m2=val2'); $url = Url::newUrl() ->setScheme('https') ->setAuthority('www.domain.com') ->setPath('/dir1/dir2/file.ext') ->setQuery('param1=val1¶m2=val2') ;
Modify Url Object
use \Mtchabok\Url\Url; $url = Url::newUrl(); // change scheme $url->setScheme('http'); // return $url object $url->scheme = 'http'; // change authority = user: sam, pass: 123, host: domain.com $url->setAuthority('sam:123@domain.com'); // return $url object // change url path. $url->setPath('/dir2/dir1/'); // return $url object $url->path = '/dir2/dir1/'; // add path $url->addPath('./dir3/file.ext2'); // return $url object $url->path = $url::normalizePath($url->path, './dir3/file.ext2'); // change query $url->setQuery('p12=32&name=sara'); // return $url object $url->query = 'p12=32&name=sara'; // set query param $url->getQuery()->set('param1', 'test'); // return Url Query object $url->query->set('param1', 'test'); // return Url Query object $url->getQuery()->set('param4', ['p4_1'=>'val41', 'p4_2'=>'val42']); // return Url Query object $url->query['param4'] = ['p4_1'=>'val41', 'p4_2'=>'val42']; // return Url Query object // change fragment $url->setFragment('index12'); // return $url object $url->fragment = 'index12';
Check exist or set Url Properties
use \Mtchabok\Url\Url; $url = Url::newUrl(); // check scheme set $url->hasScheme(); // return bool // check userInfo set $url->hasUserInfo(); // return bool $url->hasUser(); // return bool $url->hasPass(); // return bool // check host set $url->hasHost(); // return bool // check port set $url->hasPort(); // return bool // check path set $url->hasPath(); // return bool // check query set $url->hasQuery(); // return bool // and ...
Get Url Properties
use \Mtchabok\Url\Url; $url = Url::newUrl(); // scheme $url->getScheme(); // return current scheme or empty string $url->scheme; // return current scheme or null $url->getScheme('file'); // reutrn current scheme or 'file' // user info $url->getUserInfo(); // return current userinfo or empty string $url->getUserInfo('test:123'); // return current userinfo or 'test:123' // host $url->getHost(); // return current host or empty string $url->getHost('host.org'); // return current host or 'host.org' // path $url->getPath(); // return current path or empty string $url->getPath('/dir1/dir2/file'); // return current path or '/dir1/dir2/file'
PSR-7 and Equals Method`s
use \Mtchabok\Url\Url; $url = Url::newUrl('https://www.domain.com/dir1/dir2/file.ext'); $url2 = $url->withHost('site.com'); // return new Url Object with host 'site.com' $url->equalsHost($url2->getHost()); // return false $url->equalsHost($url2); // return false
For More Usage Documentation, Use This Url Class By IDE
mtchabok/url 适用场景与选型建议
mtchabok/url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「php url」 「Url Class」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mtchabok/url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mtchabok/url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mtchabok/url 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Collection of methods that I or you usually use.
A very simple yet useful helper class to handle PHP file uploads.
Easy URL rewrites in your Laravel application
A Laravel helper to detect if the current route/path is active.
Provides a service and twig extension for getting short urls like http://your.host/~short
Yii2 js base class
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-13