https://github.com/byjg/php-uri
An implementation of PSR UriInterface
https://github.com/byjg/php-uri
hacktoberfest
Last synced: 6 months ago
JSON representation
An implementation of PSR UriInterface
- Host: GitHub
- URL: https://github.com/byjg/php-uri
- Owner: byjg
- License: mit
- Created: 2017-02-05T16:45:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-23T14:40:50.000Z (7 months ago)
- Last Synced: 2025-04-17T04:19:11.009Z (6 months ago)
- Topics: hacktoberfest
- Language: PHP
- Homepage:
- Size: 87.9 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Uri class
[](https://scrutinizer-ci.com/g/byjg/uri/?branch=master)
[](https://github.com/byjg/uri/actions/workflows/phpunit.yml)
[](https://opensource.byjg.com)
[](https://github.com/byjg/uri/)
[](https://opensource.byjg.com/opensource/licensing.html)
[](https://github.com/byjg/uri/releases/)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:
```php
$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](https://github.com/php-fig/http-message/blob/master/src/UriInterface.php)## Install
```bash
composer require "byjg/uri"
```## Unit tests
```bash
vendor/bin/phpunit
```## Dependencies
```mermaid
flowchart TD
byjg/uri --> psr/http-message
```----
[Open source ByJG](https://opensource.byjg.com)