Skip to content
This repository was archived by the owner on Nov 26, 2022. It is now read-only.

Commit 842d98f

Browse files
committed
remove functions
1 parent e39de00 commit 842d98f

File tree

6 files changed

+39
-113
lines changed

6 files changed

+39
-113
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ This package contains a userland PHP uri query parser and builder.
99
```php
1010
<?php
1111

12-
use function League\Uri\query_parse;
13-
use function League\Uri\query_build;
12+
use League\Uri\Parser\QueryString;
1413

15-
$pairs = query_parse('module=home&action=show&page=😓');
14+
$pairs = QueryString::parse('module=home&action=show&page=😓');
1615
// returns [
1716
// ['module', 'home'],
1817
// ['action', 'show'],
1918
// ['page', '😓']
2019
// ];
2120

22-
$str = query_build($pairs, '|');
21+
$str = QueryString::build($pairs, '|');
2322
// returns 'module=home|action=show|page=😓'
2423
```
2524

@@ -49,9 +48,9 @@ Parsing a query string is easy.
4948
```php
5049
<?php
5150

52-
use function League\Uri\query_parse;
51+
use League\Uri\Parser\QueryString;
5352

54-
$pairs = query_parse('module=home&action=show&page=😓');
53+
$pairs = QueryString::parse('module=home&action=show&page=😓');
5554
// returns [
5655
// ['module', 'home'],
5756
// ['action', 'show'],
@@ -64,12 +63,12 @@ $pairs = query_parse('module=home&action=show&page=😓');
6463
```php
6564
<?php
6665

67-
function League\Uri\query_parse($query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array;
66+
public static function QueryString::parse($query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array;
6867
```
6968

7069
The returned array is a collection of key/value pairs. Each pair is represented as an array where the first element is the pair key and the second element the pair value. While the pair key is always a string, the pair value can be a string or the `null` value.
7170

72-
The `League\Uri\query_parse` parameters are
71+
The `League\Uri\QueryString::parse` parameters are
7372

7473
- `$query` can be the `null` value, any scalar or object which is stringable;
7574
- `$separator` is a string; by default it is the `&` character;
@@ -82,9 +81,9 @@ Here's a simple example showing how to use all the given parameters:
8281
```php
8382
<?php
8483

85-
use function League\Uri\query_parse;
84+
use League\Uri\QueryString;
8685

87-
$pairs = query_parse(
86+
$pairs = QueryString::parse(
8887
'module=home:action=show:page=toto+bar&action=hide',
8988
':',
9089
PHP_QUERY_RFC1738
@@ -99,14 +98,14 @@ $pairs = query_parse(
9998

10099
### Building the URI query string
101100

102-
To convert back the collection of key/value pairs into a valid query string or the `null` value you can use the `League\Uri\query_build` function.
101+
To convert back the collection of key/value pairs into a valid query string or the `null` value you can use the `QueryString::build` function.
103102

104103
```php
105104
<?php
106105

107-
use function League\Uri\query_build;
106+
use League\Uri\Parser\QueryString;
108107

109-
$pairs = query_build([
108+
$pairs = QueryString::build([
110109
['module', 'home'],
111110
['action', 'show'],
112111
['page', 'toto bar'],
@@ -121,32 +120,32 @@ $pairs = query_build([
121120
```php
122121
<?php
123122

124-
function League\Uri\query_build(iterable $pairs, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): ?string;
123+
public static function QueryString::build(iterable $pairs, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): ?string;
125124
```
126125

127-
The `League\Uri\query_build` :
126+
The `QueryString::build` :
128127

129-
- accepts any iterable structure containing a collection of key/pair pairs as describe in the returned array of the `League\Uri\query_parse` function.
128+
- accepts any iterable structure containing a collection of key/pair pairs as describe in the returned array of the QueryString::parse` function.
130129

131-
Just like with `League\Uri\query_parse`, you can specify the separator and the encoding algorithm to use.
130+
Just like with `QueryString::parse`, you can specify the separator and the encoding algorithm to use.
132131

133132
- the function returns the `null` value if an empty array or collection is given as input.
134133

135134
### Extracting PHP variables
136135

137-
`League\Uri\query_parse` and `League\Uri\query_build` preserve the query string pairs content and order. If you want to extract PHP variables from the query string *à la* `parse_str` you can use `League\Uri\query_extract`. The function:
136+
`QueryString::parse` and `QueryString::build` preserve the query string pairs content and order. If you want to extract PHP variables from the query string *à la* `parse_str` you can use `QueryString::extract`. The public static method:
138137

139-
- takes the same parameters as `League\Uri\query_parse`
138+
- takes the same parameters as `League\Uri\QueryString::parse`
140139
- does not allow parameters key mangling in the returned array;
141140

142141
```php
143142
<?php
144143

145-
use function League\Uri\query_extract;
144+
use League\Uri\Parser\QueryString;
146145

147146
$query = 'module=show&arr.test[1]=sid&arr test[4][two]=fred&+module+=hide';
148147

149-
$params = query_extract($query, '&', PHP_QUERY_RFC1738);
148+
$params = QueryString::extract($query, '&', PHP_QUERY_RFC1738);
150149
// $params contains [
151150
// 'module' = 'show',
152151
// 'arr.test' => [
@@ -177,18 +176,18 @@ parse_str($query, $variables);
177176

178177
All exceptions extends the `League\Uri\Parser\InvalidUriComponent` marker class which extends PHP's `InvalidArgumentException` class.
179178

180-
- If the query string is invalid a `League\Uri\Parser\InvalidQueryString` exception is thrown.
179+
- If the query string is invalid a `League\Uri\Exception\MalformedUriComponent` exception is thrown.
181180
- If the query pair is invalid a `League\Uri\Parser\InvalidQueryPair` exception is thrown.
182181
- If the encoding algorithm is unknown or invalid a `League\Uri\Parser\UnknownEncoding` exception is thrown.
183182

184183
```php
185184
<?php
186185

187-
use League\Uri\Parser\InvalidUriComponent;
188-
use function League\Uri\query_extract;
186+
use League\Uri\Exception\InvalidUriComponent;
187+
use League\Uri\Parser\QueryString;
189188

190189
try {
191-
query_extract('foo=bar', '&', 42);
190+
QueryString::extract('foo=bar', '&', 42);
192191
} catch (InvalidUriComponent $e) {
193192
//$e is an instanceof League\Uri\Parser\UnknownEncoding
194193
}

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"autoload": {
3737
"psr-4": {
3838
"League\\Uri\\": "src"
39-
},
40-
"files": ["src/functions_include.php"]
39+
}
4140
},
4241
"autoload-dev": {
4342
"psr-4": {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
use const PHP_QUERY_RFC3986;
4646

4747
/**
48-
* A class to parse a URI query string.
48+
* A class to parse the URI query string.
4949
*
5050
* @package League\Uri
5151
* @author Ignace Nyamagana Butera <[email protected]>
5252
* @since 1.0.0
5353
* @see https://tools.ietf.org/html/rfc3986#section-3.4
5454
* @internal Use the function League\Uri\query_parse and League\Uri\query_extract instead
5555
*/
56-
final class QueryParser
56+
final class QueryString
5757
{
5858
private const REGEXP_INVALID_CHARS = '/[\x00-\x1f\x7f]/';
5959

@@ -124,7 +124,7 @@ public static function parse($query, string $separator = '&', int $enc_type = PH
124124
$query = str_replace('+', ' ', $query);
125125
}
126126

127-
return array_map([QueryParser::class, 'parsePair'], (array) explode($separator, $query));
127+
return array_map([self::class, 'parsePair'], (array) explode($separator, $query));
128128
}
129129

130130
/**

src/functions.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/functions_include.php

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
use League\Uri\Exception\InvalidQueryPair;
1919
use League\Uri\Exception\MalformedUriComponent;
2020
use League\Uri\Exception\UnknownEncoding;
21+
use League\Uri\Parser\QueryString;
2122
use PHPUnit\Framework\TestCase;
2223
use TypeError;
2324
use function date_create;
24-
use function League\Uri\query_build;
25-
use function League\Uri\query_extract;
26-
use function League\Uri\query_parse;
2725
use const PHP_QUERY_RFC1738;
2826
use const PHP_QUERY_RFC3986;
2927

@@ -32,31 +30,31 @@ class FunctionsTest extends TestCase
3230
public function testEncodingThrowsExceptionWithQueryParser(): void
3331
{
3432
self::expectException(UnknownEncoding::class);
35-
query_parse('foo=bar', '&', 42);
33+
QueryString::parse('foo=bar', '&', 42);
3634
}
3735

3836
public function testMalformedUriComponentThrowsExceptionWithQueryParser(): void
3937
{
4038
self::expectException(MalformedUriComponent::class);
41-
query_parse("foo=bar\0");
39+
QueryString::parse("foo=bar\0");
4240
}
4341

4442
public function testEncodingThrowsExceptionWithQueryBuilder(): void
4543
{
4644
self::expectException(UnknownEncoding::class);
47-
query_build([['foo', 'bar']], '&', 42);
45+
QueryString::build([['foo', 'bar']], '&', 42);
4846
}
4947

5048
public function testBuildThrowsExceptionWithQueryBuilder(): void
5149
{
5250
self::expectException(InvalidQueryPair::class);
53-
query_build([['foo', 'boo' => 'bar']]);
51+
QueryString::build([['foo', 'boo' => 'bar']]);
5452
}
5553

5654
public function testWrongTypeThrowExceptionParseQuery(): void
5755
{
5856
self::expectException(TypeError::class);
59-
query_parse(['foo=bar'], '&', PHP_QUERY_RFC1738);
57+
QueryString::parse(['foo=bar'], '&', PHP_QUERY_RFC1738);
6058
}
6159

6260
/**
@@ -66,7 +64,7 @@ public function testWrongTypeThrowExceptionParseQuery(): void
6664
*/
6765
public function testExtractQuery($query, array $expectedData): void
6866
{
69-
self::assertSame($expectedData, query_extract($query));
67+
self::assertSame($expectedData, QueryString::extract($query));
7068
}
7169

7270
public function extractQueryProvider(): array
@@ -145,7 +143,7 @@ public function extractQueryProvider(): array
145143
*/
146144
public function testParse($query, string $separator, array $expected, int $encoding): void
147145
{
148-
self::assertSame($expected, query_parse($query, $separator, $encoding));
146+
self::assertSame($expected, QueryString::parse($query, $separator, $encoding));
149147
}
150148

151149
public function parserProvider(): array
@@ -295,8 +293,8 @@ public function testBuild(
295293
?string $expected_rfc1738,
296294
?string $expected_rfc3986
297295
): void {
298-
self::assertSame($expected_rfc1738, query_build($pairs, '&', PHP_QUERY_RFC1738));
299-
self::assertSame($expected_rfc3986, query_build($pairs, '&', PHP_QUERY_RFC3986));
296+
self::assertSame($expected_rfc1738, QueryString::build($pairs, '&', PHP_QUERY_RFC1738));
297+
self::assertSame($expected_rfc3986, QueryString::build($pairs, '&', PHP_QUERY_RFC3986));
300298
}
301299

302300
public function buildProvider(): array
@@ -386,7 +384,7 @@ public function buildProvider(): array
386384
public function testBuildQueryThrowsException(iterable $pairs, int $enc_type): void
387385
{
388386
self::expectException(InvalidQueryPair::class);
389-
query_build($pairs, '&', $enc_type);
387+
QueryString::build($pairs, '&', $enc_type);
390388
}
391389

392390
public function failedBuilderProvider(): array

0 commit comments

Comments
 (0)