Skip to content

Commit

Permalink
Merge pull request #3 from sirn-se/updates
Browse files Browse the repository at this point in the history
v2.0 features
  • Loading branch information
sirn-se committed Feb 4, 2024
2 parents 3f458e0 + b732a72 commit d96fb98
Show file tree
Hide file tree
Showing 9 changed files with 1,175 additions and 281 deletions.
141 changes: 61 additions & 80 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,91 @@ name: Acceptance
on: [push, pull_request]

jobs:
test-7-4:
runs-on: ubuntu-latest
name: Test PHP 7.4
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 7.4
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
- name: Composer
run: make deps-install
- name: Test
run: make test

test-8-0:
runs-on: ubuntu-latest
name: Test PHP 8.0
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.0
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: Composer
run: make deps-install
- name: Test
run: make test

test-8-1:
test:
strategy:
matrix:
php-versions: ["8.0", "8.1", "8.2", "8.3", "8.4"]
runs-on: ubuntu-latest
name: Test PHP 8.1
name: Unit test
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.1
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Composer
run: make deps-install
- name: Test
run: make test

test-8-2:
runs-on: ubuntu-latest
name: Test PHP 8.2
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Composer
run: make deps-install
- name: Test
run: make test

test-8-3:
runs-on: ubuntu-latest
name: Test PHP 8.3
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.3
uses: shivammathur/setup-php@v2
php-version: ${{ matrix.php-versions }}
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
php-version: '8.3'
- name: Composer
run: make deps-install
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Test
run: make test
run: vendor/bin/phpunit

cs-check:
runs-on: ubuntu-latest
name: Code standard
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.2
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Composer
run: make deps-install
php-version: "8.3"
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Code standard
run: make cs-check
run: vendor/bin/phpcs --standard=PSR1,PSR12 --encoding=UTF-8 --report=full --colors src tests

coverage:
runs-on: ubuntu-latest
name: Code coverage
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.2
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: xdebug
- name: Composer
run: make deps-install
- name: Code coverage
php-version: "8.3"
coverage: xdebug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist
- name: Code coverage build
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- name: Code coverage upload
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make coverage
run: vendor/bin/php-coveralls -v
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ Will cause paths to use absolute form, i.e. starting with `/`.

Will attempt to normalize paths, e.g. `./a/./path/../to//something` will transform to `a/to/something`.

`IDNA`
`IDN_ENCODE` + `IDN_ENCODE`

Will IDNA-convert host using non-ASCII characters. Only available with [Intl extension](https://www.php.net/manual/en/intl.installation.php).
Will IDN-encode 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 All @@ -56,7 +60,7 @@ $clone = $uri->withPath('path/./somewhere/else/..', Uri::ABSOLUTE_PATH | Uri::NO
$clone->getPath(); // => '/path/somewhere'

$uri = new Uri('https://ηßöø必Дあ.com');
$uri->getHost(Uri::IDNA); // => 'xn--zca0cg32z7rau82strvd.com'
$uri->getHost(Uri::IDN_ENCODE); // => 'xn--zca0cg32z7rau82strvd.com'
```


Expand All @@ -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 @@ -79,27 +83,40 @@ class Phrity\Net\Uri implements Psr\Http\Message\UriInterface
public function getAuthority(int $flags = 0): string;
public function getUserInfo(int $flags = 0): string;
public function getHost(int $flags = 0): string;
public function getPort(int $flags = 0): ?int;
public function getPort(int $flags = 0): int|null;
public function getPath(int $flags = 0): string;
public function getQuery(int $flags = 0): string;
public function getFragment(int $flags = 0): string;

// PSR-7 setters

public function withScheme($scheme, int $flags = 0): UriInterface;
public function withUserInfo($user, $password = null, int $flags = 0): UriInterface;
public function withHost($host, int $flags = 0): UriInterface;
public function withPort($port, int $flags = 0): UriInterface;
public function withPath($path, int $flags = 0): UriInterface;
public function withQuery($query, int $flags = 0): UriInterface;
public function withFragment($fragment, int $flags = 0): UriInterface;
public function withScheme(string $scheme, int $flags = 0): UriInterface;
public function withUserInfo(string $user, string|null $password = null, int $flags = 0): UriInterface;
public function withHost(string $host, int $flags = 0): UriInterface;
public function withPort(int|null $port, int $flags = 0): UriInterface;
public function withPath(string $path, int $flags = 0): 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 @@ -116,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 @@ -124,6 +145,7 @@ class Phrity\Net\UriFactory implements Psr\Http\Message\UriFactoryInterface

| Version | PHP | |
| --- | --- | --- |
| `2.0` | `^8.0` | Query helpers, with([]) and getComponents() methods, IDN encode/decode |
| `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
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
}
},
"require": {
"php": "^7.4 | ^8.0",
"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",
"phpunit/phpunit": "^9.0 | ^10.0 | ^11.0",
"php-coveralls/php-coveralls": "^2.0",
"squizlabs/php_codesniffer": "^3.0"
},
"suggest": {
"ext-intl": "Enables IDN conversion for non-ASCII domains"
}
}
Loading

0 comments on commit d96fb98

Please sign in to comment.