spatie/url
Composer 安装命令:
composer require spatie/url
包简介
Parse, build and manipulate URL's
README 文档
README
A simple package to deal with URLs in your applications.
Installation
You can install the package via composer:
composer require spatie/url
Usage
Parse and transform a URL
Retrieve any part of the URL:
use Spatie\Url\Url; $url = Url::fromString('https://spatie.be/opensource'); echo $url->getScheme(); // 'https' echo $url->getHost(); // 'spatie.be' echo $url->getPath(); // '/opensource'
Transform any part of the URL:
Note the
Urlclass is immutable.
$url = Url::fromString('https://spatie.be/opensource'); echo $url->withHost('github.com')->withPath('spatie'); // 'https://github.com/spatie'
Scheme
Transform the URL scheme.
$url = Url::fromString('http://spatie.be/opensource'); echo $url->withScheme('https'); // 'https://spatie.be/opensource'
Use a list of allowed schemes.
Note each scheme in the list will be sanitized
$url = Url::fromString('https://spatie.be/opensource'); echo $url->withAllowedSchemes(['wss'])->withScheme('wss'); // 'wss://spatie.be/opensource'
or pass the list directly to fromString as the URL's scheme will be sanitized and validated immediately:
$url = Url::fromString('https://spatie.be/opensource', [...SchemeValidator::VALID_SCHEMES, 'wss']); echo $url->withScheme('wss'); // 'wss://spatie.be/opensource'
Query parameters
Retrieve and transform query parameters:
$url = Url::fromString('https://spatie.be/opensource?utm_source=github&utm_campaign=packages'); echo $url->getQuery(); // 'utm_source=github&utm_campaign=packages' echo $url->getQueryParameter('utm_source'); // 'github' echo $url->getQueryParameter('utm_medium'); // null echo $url->getQueryParameter('utm_medium', 'social'); // 'social' echo $url->getQueryParameter('utm_medium', function() { //some logic return 'email'; }); // 'email' echo $url->withoutQueryParameter('utm_campaign'); // 'https://spatie.be/opensource?utm_source=github' echo $url->withQueryParameters(['utm_campaign' => 'packages']); // 'https://spatie.be/opensource?utm_source=github&utm_campaign=packages'
Path segments
Retrieve path segments:
$url = Url::fromString('https://spatie.be/opensource/laravel'); echo $url->getSegment(1); // 'opensource' echo $url->getSegment(2); // 'laravel'
PSR-7 UriInterface
Implements PSR-7's UriInterface interface:
class Url implements UriInterface { /* ... */ }
The league/uri is a more powerful package than this one. The main reason this package exists, is because the alternatives requires non-standard php extensions. If you're dealing with special character encodings or need bulletproof validation, you're definitely better off using league/uri.
Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Testing
composer test
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
We publish all received postcards on our company website.
Credits
License
The MIT License (MIT). Please see License File for more information.
spatie/url 适用场景与选型建议
spatie/url 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.77M 次下载、GitHub Stars 达 740, 最近一次更新时间为 2016 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「spatie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spatie/url 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spatie/url 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spatie/url 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy URL rewrites in your Laravel application
Receive webhooks in Laravel apps
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
Easily optimize images using PHP
Store your application settings
统计信息
- 总下载量: 15.77M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 753
- 点击次数: 13
- 依赖项目数: 91
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-14