Skip to content

Commit 081bf6a

Browse files
authored
Merge pull request #262 from raicabogdan/6.0.x
Update Filter and API documentation for filter and Request
2 parents 7802b3e + 58e19d0 commit 081bf6a

File tree

3 files changed

+119
-14
lines changed

3 files changed

+119
-14
lines changed

docs/api/phalcon_filter.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ Exceptions thrown in Phalcon\Filter will use this class
5555

5656
Lazy loads, stores and exposes sanitizer objects
5757

58+
@method int absint(mixed $input)
59+
@method string alnum(mixed $input)
60+
@method string alpha(mixed $input)
61+
@method bool bool(mixed $input)
62+
@method string email(string $input)
63+
@method float float(mixed $input)
64+
@method int int(string $input)
65+
@method string|false ip(string $input, int $filter = FILTER_FLAG_NONE)
66+
@method string lower(string $input)
67+
@method string lowerfirst(string $input)
68+
@method mixed regex(mixed $input, mixed $pattern, mixed $replace)
69+
@method mixed remove(mixed $input, mixed $replace)
70+
@method mixed replace(mixed $input, mixed $source, mixed $target)
71+
@method string special(string $input)
72+
@method string specialfull(string $input)
73+
@method string string(string $input)
74+
@method string stringlegacy(mixed $input)
75+
@method string striptags(string $input)
76+
@method string trim(string $input)
77+
@method string upper(string $input)
78+
@method string upperFirst(string $input)
79+
@method null upperWords(string $input): strin
80+
@method null url(string $input): strin
81+
82+
@property array $mapper
83+
@property array $services
5884

5985

6086
### Constants
@@ -66,6 +92,7 @@ const FILTER_BOOL = bool;
6692
const FILTER_EMAIL = email;
6793
const FILTER_FLOAT = float;
6894
const FILTER_INT = int;
95+
const FILTER_IP = ip;
6996
const FILTER_LOWER = lower;
7097
const FILTER_LOWERFIRST = lowerfirst;
7198
const FILTER_REGEX = regex;
@@ -447,6 +474,39 @@ public function __invoke( mixed $input );
447474

448475

449476

477+
## Filter\Sanitize\Ip
478+
479+
[Source on GitHub](https://github.com/phalcon/cphalcon/blob/5.0.x/phalcon/Filter/Sanitize/Ip.zep)
480+
481+
482+
- __Namespace__
483+
484+
- `Phalcon\Filter\Sanitize`
485+
486+
- __Uses__
487+
488+
489+
- __Extends__
490+
491+
492+
- __Implements__
493+
494+
495+
Phalcon\Filter\Sanitize\IP
496+
497+
Sanitizes a value to an ip address or CIDR range
498+
499+
500+
### Methods
501+
502+
```php
503+
public function __invoke( string $input, int $filter = int ): string | false;
504+
```
505+
506+
507+
508+
509+
450510
## Filter\Sanitize\Lower
451511

452512
[Source on GitHub](https://github.com/phalcon/cphalcon/blob/5.0.x/phalcon/Filter/Sanitize/Lower.zep)
@@ -2223,6 +2283,16 @@ $validator->add(
22232283
]
22242284
)
22252285
);
2286+
2287+
$validator->add(
2288+
"täst@example.com",
2289+
new EmailValidator(
2290+
[
2291+
"message" => "The e-mail is not valid",
2292+
"allowUTF8" => true,
2293+
]
2294+
)
2295+
);
22262296
```
22272297

22282298

docs/api/phalcon_http.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected $value;
115115
### Methods
116116

117117
```php
118-
public function __construct( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] );
118+
public function __construct( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] );
119119
```
120120
Phalcon\Http\Cookie constructor.
121121

@@ -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
@@ -772,11 +777,11 @@ _SERVER["HTTP_ACCEPT_LANGUAGE"]
772777

773778

774779
```php
775-
public function getClientAddress( bool $trustForwardedHeader = bool ): string | bool;
780+
public function getClientAddress( bool $trustForwardedHeader = bool ): string | false;
776781
```
777-
Gets most possible client IPv4 Address. This method searches in
782+
Gets most possible client IP Address. This method searches in
778783
`$_SERVER["REMOTE_ADDR"]` and optionally in
779-
`$_SERVER["HTTP_X_FORWARDED_FOR"]`
784+
`$_SERVER["HTTP_X_FORWARDED_FOR"]` and returns the first non-private or non-reserved IP address
780785

781786

782787
```php
@@ -832,7 +837,7 @@ Retrieves a query/get value always sanitized with the preset filters
832837
```php
833838
public function getHTTPReferer(): string;
834839
```
835-
Gets web page that refers active request. ie: https://www.google.com
840+
Gets web page that refers active request. ie: http://www.google.com
836841

837842

838843
```php
@@ -980,13 +985,13 @@ Note: This method relies on the `$_SERVER["HTTP_ACCEPT_LANGUAGE"]` header.
980985
```php
981986
public function getPut( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
982987
```
983-
Gets a variable from put request
988+
Gets a variable from the PUT request
984989

985990
```php
986-
// Returns value from $_PUT["user_email"] without sanitizing
991+
// Returns value from PUT stream without sanitizing
987992
$userEmail = $request->getPut("user_email");
988993

989-
// Returns value from $_PUT["user_email"] with sanitizing
994+
// Returns value from PUT stream with sanitizing
990995
$userEmail = $request->getPut("user_email", "email");
991996
```
992997

@@ -1247,6 +1252,12 @@ Sets if the `Request::getHttpHost` method must be use strict validation
12471252
of host name or not
12481253

12491254

1255+
```php
1256+
public function setTrustedProxies( array $trustedProxies ): RequestInterface;
1257+
```
1258+
Set trusted proxy
1259+
1260+
12501261
```php
12511262
final protected function getBestQuality( array $qualityParts, string $name ): string;
12521263
```
@@ -1272,6 +1283,12 @@ final protected function hasFileHelper( mixed $data, bool $onlySuccessful ): lon
12721283
Recursively counts file in an array of files
12731284

12741285

1286+
```php
1287+
protected function isIpAddressInCIDR( string $ip, string $cidr ): bool;
1288+
```
1289+
Check if an IP address exists in CIDR range
1290+
1291+
12751292
```php
12761293
protected function resolveAuthorizationHeaders(): array;
12771294
```
@@ -1642,7 +1659,7 @@ $_SERVER["PHP_AUTH_DIGEST"]
16421659
```php
16431660
public function getHTTPReferer(): string;
16441661
```
1645-
Gets web page that refers active request. ie: https://www.google.com
1662+
Gets web page that refers active request. ie: http://www.google.com
16461663

16471664

16481665
```php
@@ -1756,13 +1773,13 @@ $userEmail = $request->getPost("user_email", "email");
17561773
```php
17571774
public function getPut( string $name = null, mixed $filters = null, mixed $defaultValue = null, bool $notAllowEmpty = bool, bool $noRecursive = bool ): mixed;
17581775
```
1759-
Gets a variable from put request
1776+
Gets a variable from the PUT request
17601777

17611778
```php
1762-
// Returns value from $_PUT["user_email"] without sanitizing
1779+
// Returns value from PUT stream without sanitizing
17631780
$userEmail = $request->getPut("user_email");
17641781

1765-
// Returns value from $_PUT["user_email"] with sanitizing
1782+
// Returns value from PUT stream with sanitizing
17661783
$userEmail = $request->getPut("user_email", "email");
17671784
```
17681785

@@ -2531,7 +2548,7 @@ Cookies aren't sent if headers are sent in the current request
25312548

25322549

25332550
```php
2534-
public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] ): CookiesInterface;
2551+
public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] ): CookiesInterface;
25352552
```
25362553
Sets a cookie to be sent at the end of the request.
25372554

@@ -2637,7 +2654,7 @@ Sends the cookies to the client
26372654

26382655

26392656
```php
2640-
public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = null, string $domain = null, bool $httpOnly = null, array $options = [] ): CookiesInterface;
2657+
public function set( string $name, mixed $value = null, int $expire = int, string $path = string, bool $secure = bool, string $domain = string, bool $httpOnly = bool, array $options = [] ): CookiesInterface;
26412658
```
26422659
Sets a cookie to be sent at the end of the request
26432660

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)