承接 byjg/uri 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

byjg/uri

最新稳定版本:6.0.0

Composer 安装命令:

composer create-project byjg/uri

包简介

A PHP implementation of PSR-7 UriInterface with additional utility methods

README 文档

README

Sponsor Build Status Opensource ByJG GitHub source GitHub license GitHub release

A PHP implementation of PSR-7 UriInterface with additional utility methods.

Features

  • Fully compliant with PSR-7 UriInterface
  • Includes additional utility methods via CustomUriInterface
  • Supports RFC3986 URI specification
  • Type-safe implementation with PHP 8 attributes and strict typing
  • Immutable class design pattern

URI Encoding Behavior

PSR-7 requires URI compliant with RFC3986. This means the URI output will always be URL encoded. This applies to both creating a new instance and the string representation.

Examples:

// Creating a URI with special characters in the password
$uri = \ByJG\Util\Uri::getInstance("https://user:pa&@host");
print((string)$uri); // Will print "https://user:pa%26@host"

// Creating a URI with already encoded characters
$uri = \ByJG\Util\Uri::getInstance("https://user:pa%26@host");
print((string)$uri); // Will print "https://user:pa%26@host"

// Using withUserInfo with unencoded password
$uri = \ByJG\Util\Uri::getInstance("https://host")
    ->withUserInfo("user", "pa&");
print((string)$uri); // Will print "https://user:pa&@host"

// Using withUserInfo with already encoded password
$uri = \ByJG\Util\Uri::getInstance("https://host")
    ->withUserInfo("user", "pa%26");
print((string)$uri); // Will print "https://user:pa%2526@host"

Additional Methods

This implementation extends PSR-7 UriInterface with the following additional methods through \ByJG\Util\CustomUriInterface:

Method Description
getUsername(): ?string Get the username component of the URI
getPassword(): ?string Get the password component of the URI
getQueryPart(string $key): ?string Get a specific query parameter by key
withQueryKeyValue(string $key, string $value, bool $isEncoded = false): self Add or update a query parameter
hasQueryKey(string $key): bool Check if a query parameter exists

Static Factory Methods

The class provides convenient static factory methods:

// Create from string
$uri = Uri::getInstance("https://example.com/path?query=value#fragment");

// Create from another UriInterface
$uri2 = Uri::getInstance($uri);

Documentation

Install

composer require "byjg/uri"

Unit tests

vendor/bin/phpunit

Dependencies

flowchart TD
    byjg/uri --> psr/http-message
Loading

Open source ByJG

统计信息

  • 总下载量: 537.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-05