Skip to content

Commit

Permalink
Query helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sirn-se committed Feb 3, 2024
1 parent ce77ea1 commit b2bcc83
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 41 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Will attempt to normalize paths, e.g. `./a/./path/../to//something` will transfo

Will IDNA-convert host using non-ASCII characters. Only available with [Intl extension](https://www.php.net/manual/en/intl.installation.php).

`RFC1738`

Will use RFC 1738 encoding (spaces encoded as `+`). Encoding by RFC 3986 (spaces encoded as `%20`) is default.


### Examples

Expand Down Expand Up @@ -67,7 +71,7 @@ There are two available classes, `Uri` and `UriFactory`.
### The Uri class

```php
class Phrity\Net\Uri implements Psr\Http\Message\UriInterface
class Phrity\Net\Uri implements JsonSerializable, Stringable, Psr\Http\Message\UriInterface
{
// Constructor

Expand All @@ -94,12 +98,24 @@ class Phrity\Net\Uri implements Psr\Http\Message\UriInterface
public function withQuery(string $query, int $flags = 0): UriInterface;
public function withFragment(string $fragment, int $flags = 0): UriInterface;

// PSR-7 string representation
// PSR-7 string representation & Stringable

public function __toString(): string;

// JsonSerializable

public function jsonSerialize(): string;

// Additional query methods

public function getQueryItems(int $flags = 0): array;
public function getQueryItem(string $name, int $flags = 0): array|string|null;
public function withQueryItems(array $items, int $flags = 0): UriInterface;
public function withQueryItem(string $name, array|string|null $value, int $flags = 0): UriInterface;

// Additional methods

public function getComponents(int $flags = 0): array;
public function with(array $components, int $flags = 0): UriInterface;
public function toString(int $flags = 0): string;
}
Expand All @@ -117,6 +133,10 @@ class Phrity\Net\UriFactory implements Psr\Http\Message\UriFactoryInterface
// PSR-17 factory

public function createUri(string $uri = ''): UriInterface;

// Additional methods

public function createUriFromInterface(UriInterface $uri): UriInterface;
}
```

Expand All @@ -125,7 +145,7 @@ class Phrity\Net\UriFactory implements Psr\Http\Message\UriFactoryInterface

| Version | PHP | |
| --- | --- | --- |
| `2.0` | `^7.4\|^8.0` | Strict types |
| `2.0` | `^8.0` | Query helpers, with([]) and getComponents() methods |
| `1.3` | `^7.4\|^8.0` | |
| `1.2` | `^7.4\|^8.0` | IDNA modifier |
| `1.1` | `^7.4\|^8.0` | Require port, Absolute path, Normalize path modifiers |
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
},
"require": {
"php": "^8.0",
"ext-mbstring": "*",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 | ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0 | ^10.0 | ^11.0",
"php-coveralls/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "^3.0"
},
"suggest": {
"ext-intl": "Enables IDNA suppoert for non-ascii domains"
}
}
Loading

0 comments on commit b2bcc83

Please sign in to comment.