byjg/uri

An implementation of PSR-7 Uri Interface

Maintainers

Details

github.com/byjg/php-uri

Source

Issues

Fund package maintenance!
byjg

Installs: 439 803

Dependents: 3

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 3

Open Issues: 0

Type:project

5.0.2 2024-10-27 15:51 UTC

This package is auto-updated.

Last update: 2024-11-27 16:08:05 UTC


README

Scrutinizer Code Quality Build Status Opensource ByJG GitHub source GitHub license GitHub release

An implementation of PSR-7 UriInterface

PSR-7 requires URI compliant with RFC3986. It means the URI output will always be URL encoded. The same is valid for creating a new instance. The only way to store the plain password is using Uri::withUserInfo()

For example:

$uri = \ByJG\Util\Uri::getInstanceFromString("https://user:pa&@host");
print((string)$uri); // Will print "https://user:pa%26@host"

$uri = \ByJG\Util\Uri::getInstanceFromString("https://user:pa%26@host");
print((string)$uri); // Will print "https://user:pa%26@host"

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

Custom methods

This class fully complies with the PSR UriInterface (PSR-7) and also implements some additional useful methods in the \ByJG\Util\CustomUriInterface interface:

  • getUsername()
  • getPassword()
  • getQueryPart($key)
  • withQueryKeyValue($key, $value, $encode = true)
  • hasQueryKey(string $key): bool;

For more information about UriInterface, visit: https://github.com/php-fig/http-message/blob/master/src/UriInterface.php

Install

composer require "byjg/uri"

Unit tests

vendor/bin/phpunit

Dependencies

Open source ByJG