gstarczyk/uri
Composer 安装命令:
composer require gstarczyk/uri
包简介
Library for building and creating immutable URI.
README 文档
README
Library that allow easy build and create immutable Uri.
Build
To make creation process convenient as possible, simple Uri builder is provided with this library.
build URI from parts
With builder you can easily build you uri, defining each part of uri separately:
$uri = UriBuilder::buildUri()
->withScheme('http')
->withUserInfo('user', 'pass')
->withHost('example.org')
->withPort(8080)
->withPath('/path/to/file.png')
->withQuery(['key' => 'value'])
->withFragment('top')
->getUri();
build URI from string
Of course you can use builder to create Uri from string:
$stringUri = 'https://example.org/my/page?sidebar=left@section1';
$uri = UriBuilder::buildUri()
->withPartsFromStringUri($stringUri)
->getUri();
If you need to modify existing Uri you have to create new one with modification
$stringUri = 'https://example.org/my/page?sidebar=left@section1';
$uri = UriBuilder::buildUri()
->withPartsFromStringUri($stringUri)
->withoutQuery()
->withoutFragment()
->withUserInfo('someuser')
->getUri();
build URI from existing URI
You can build URI from another existing URI:
$uri = UriBuilder::buildUri()
->withPartsFromUriObject($exitingUri)
->withoutQuery()
->getUri();
define slug
Some times you want change only part of path. To help with such case UriBuilder has support for slug manipulation.
$stringUri = 'https://example.org/my/cover.png';
$uri = UriBuilder::buildUri()
->withPartsFromStringUri($stringUri)
->withSlug('poster.jpg')
->getUri();
// $uri => https://example.org/my/poster.jpg
or if you want only remove slug from path:
$stringUri = 'https://example.org/my/cover.png';
$uri = UriBuilder::buildUri()
->withPartsFromStringUri($stringUri)
->withoutSlug()
->getUri();
// $uri => https://example.org/my/
remember that slug is last segment of path:
$stringUri = 'https://example.org/my/images';
// "images" from path will be treated as slug
$uri = UriBuilder::buildUri()
->withPartsFromStringUri($stringUri)
->withoutSlug()
->getUri();
// $uri => https://example.org/my/
resolving paths
You can build you "path" using relative path segments
$uri = UriBuilder::buildUri()
->withResolvedPath('/home/user1/documents/../downloads/./file1')
->getUri();
// $uri->getPath => /home/user1/downloads/file1
or you can build path by combining absolute base path with many relative paths
$uri = UriBuilder::buildUri()
->withPath('/home/user1/')
->withExistingPathResolvedWith('../user2/documents')
->withExistingPathResolvedWith('../downloads/file1.ext')
->getUri();
// $uri->getPath => /home/user2/downloads/file1.ext
Remember that path you build must be resolvable. For example cannot start with "../" or
//invalid base path
$uri = UriBuilder::buildUri()
->withResolvedPath('../home/user1/documents/file1')
->getUri();
//invalid base path
$uri = UriBuilder::buildUri()
->withPath('../home/user1/')
->withExistingPathResolvedWith('./documents')
->getUri();
//invalid path to resolve with
$uri = UriBuilder::buildUri()
->withPath('/home/user1/')
->withExistingPathResolvedWith('../../../../user2/documents')
->getUri();
// each above builders throw exception
gstarczyk/uri 适用场景与选型建议
gstarczyk/uri 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 883 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「url」 「uri」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gstarczyk/uri 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gstarczyk/uri 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gstarczyk/uri 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Safely namespaced guzzle psr7 for WP2Static
Easy URL rewrites in your Laravel application
uri signer with expiration option
Zend Framework 1 Uri package
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
统计信息
- 总下载量: 883
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2019-06-14