Skip to content

byjg/php-uri

Repository files navigation

Uri class

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

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

Open source ByJG

About

An implementation of PSR UriInterface

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages