Skip to content

Commit 916d2eb

Browse files
authored
Merge pull request #260 from raicabogdan/5.9.x
Update IP filter sanitize and Request documentation
2 parents 183c865 + d0242f4 commit 916d2eb

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

docs/api/phalcon_filter.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const FILTER_BOOL = bool;
6666
const FILTER_EMAIL = email;
6767
const FILTER_FLOAT = float;
6868
const FILTER_INT = int;
69+
const FILTER_IP = 'ip';
6970
const FILTER_LOWER = lower;
7071
const FILTER_LOWERFIRST = lowerfirst;
7172
const FILTER_REGEX = regex;
@@ -447,6 +448,38 @@ public function __invoke( mixed $input );
447448

448449

449450

451+
## Filter\Sanitize\Ip
452+
453+
[Source on GitHub](https://github.com/phalcon/cphalcon/blob/5.0.x/phalcon/Filter/Sanitize/Ip.zep)
454+
455+
456+
- __Namespace__
457+
458+
- `Phalcon\Filter\Sanitize`
459+
460+
- __Uses__
461+
462+
463+
- __Extends__
464+
465+
466+
- __Implements__
467+
468+
469+
Phalcon\Filter\Sanitize\Ip
470+
471+
Sanitizes a value to an IP address or CIDR IP range
472+
473+
474+
### Methods
475+
476+
```php
477+
public function __invoke(string input, int filter = 0);
478+
```
479+
480+
481+
482+
450483
## Filter\Sanitize\Lower
451484

452485
[Source on GitHub](https://github.com/phalcon/cphalcon/blob/5.0.x/phalcon/Filter/Sanitize/Lower.zep)

docs/api/phalcon_http.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ private $rawBody = ;
717717
*/
718718
private $strictHostCheck = false;
719719

720+
/**
721+
* @var array
722+
*/
723+
private $trustedProxies = [];
724+
720725
```
721726

722727
### Methods
@@ -1253,6 +1258,18 @@ final protected function getBestQuality( array $qualityParts, string $name ): st
12531258
Process a request header and return the one with best quality
12541259

12551260

1261+
```php
1262+
protected function setTrustedProxies(array $trustedProxies): RequestInterface;
1263+
```
1264+
Set trusted proxy list.
1265+
1266+
1267+
```php
1268+
protected function isIpAddressInCIDR(string $ip, string $cidr): bool;
1269+
```
1270+
Check if an IP address exists in CIDR range.
1271+
1272+
12561273
```php
12571274
final protected function getHelper( array $source, string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
12581275
```

docs/filter-filter.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ IntVal( mixed $input ): int
117117
```
118118
Remove all characters except digits, plus and minus sign, and casts the value as an integer. Internally it uses [filter_var][filter_var] and `(int)`.
119119

120+
#### `ip`
121+
```php
122+
Ip( string input, int filter = 0 ): int
123+
```
124+
Sanitize the IP address or CIDR IP range. Internally it uses [filter_var][filter_var]. You can pass specific filters to sanitize your input:
125+
126+
```
127+
FILTER_FLAG_IPV4
128+
FILTER_FLAG_IPV6
129+
FILTER_FLAG_NO_RES_RANGE
130+
FILTER_FLAG_NO_PRIV_RANGE
131+
```
132+
By default, it will detect the IPv4 or IPv6 protocol if you do not use a predefined filter and sanitize the input.
133+
It will return `false` for invalid IP address or CIDR IP range.
134+
120135
#### `lower`
121136
```php
122137
Lower( mixed $input ): string
@@ -220,6 +235,7 @@ const FILTER_BOOL = 'bool';
220235
const FILTER_EMAIL = 'email';
221236
const FILTER_FLOAT = 'float';
222237
const FILTER_INT = 'int';
238+
const FILTER_IP = 'ip';
223239
const FILTER_LOWER = 'lower';
224240
const FILTER_LOWERFIRST = 'lowerfirst';
225241
const FILTER_REGEX = 'regex';
@@ -262,6 +278,7 @@ $filter->bool(mixed $input): bool
262278
$filter->email(string $input): string
263279
$filter->float(mixed $input): float
264280
$filter->int(string $input): int
281+
$filter->ip(string $input, int $filter = FILTER_FLAG_NONE): string|false
265282
$filter->lower(string $input): string
266283
$filter->lowerfirst(string $input): string
267284
$filter->regex(mixed $input, mixed $pattern, mixed $replace): mixed
@@ -583,6 +600,7 @@ $filteredIp = $locator->sanitize('127.0.0.1', 'ipv4');
583600
[filter-sanitize-email]: api/phalcon_filter.md#filtersanitizeemail
584601
[filter-sanitize-floatval]: api/phalcon_filter.md#filtersanitizefloatval
585602
[filter-sanitize-intval]: api/phalcon_filter.md#filtersanitizeintval
603+
[filter-sanitize-ip]: api/phalcon_filter.md#filtersanitizeip
586604
[filter-sanitize-lower]: api/phalcon_filter.md#filtersanitizelower
587605
[filter-sanitize-lowerfirst]: api/phalcon_filter.md#filtersanitizelowerfirst
588606
[filter-sanitize-regex]: api/phalcon_filter.md#filtersanitizeregex

0 commit comments

Comments
 (0)