Skip to content

Commit 4dbd2ce

Browse files
committed
adding features from the changelog
1 parent 1edea94 commit 4dbd2ce

File tree

6 files changed

+127
-30
lines changed

6 files changed

+127
-30
lines changed

docs/di.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ public function get(
403403
```
404404
Resolves the service based on its configuration
405405

406+
```php
407+
public function getAlias(string $name): string
408+
```
409+
Returns the resolved service name for an alias, or an empty string if the alias does not exist.
410+
public function setAlias(string $name, string|array $aliases): Di
411+
406412
```php
407413
public static function getDefault(): DiInterface | null
408414
```
@@ -575,6 +581,11 @@ public function set(
575581
```
576582
Registers a service in the services container
577583

584+
```php
585+
public function setAlias(string $name, string|array $aliases): Di
586+
```
587+
Registers one or more aliases for an existing service.
588+
578589
```php
579590
public static function setDefault(<DiInterface> container)
580591
```
@@ -1244,6 +1255,38 @@ $requestService->setShared(true);
12441255
$request = $requestService->resolve();
12451256
```
12461257

1258+
### Service Aliases
1259+
1260+
!!! warning "WARNING"
1261+
1262+
Alias names must be strings, cannot collide with existing services/aliases, and the target service must already exist.
1263+
1264+
You can register one or more aliases for an existing service name. Once aliases are set, calls such as `get()`, `getShared()`, `getService()`, `set()`, and `remove()` can resolve through the alias chain.
1265+
1266+
```php
1267+
<?php
1268+
1269+
use Phalcon\Di\Di;
1270+
use Phalcon\Http\Request;
1271+
1272+
$container = new Di();
1273+
1274+
$container->setShared("request", Request::class);
1275+
1276+
// single alias
1277+
$container->setAlias("request", "httpRequest");
1278+
1279+
// multiple aliases
1280+
$container->setAlias("request", ["req", "incomingRequest"]);
1281+
1282+
$requestA = $container->get("request");
1283+
$requestB = $container->get("httpRequest");
1284+
$requestC = $container->get("req");
1285+
1286+
var_dump($requestA === $requestB); // true
1287+
var_dump($container->getAlias("incomingRequest")); // "request"
1288+
```
1289+
12471290
## Instantiating Classes
12481291
When you request a service from the container, if it cannot be found by using the same name, it will try to load a class with the same name. This behavior allows you to replace any service with another, by simply registering a service with the common name:
12491292

docs/encryption-security-jwt.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ public function addClaim(string $name, mixed $value): Builder
292292
Adds a custom claim in the claims collection
293293

294294
```php
295-
public function getAudience(): array|string
295+
public function getAudience(): array
296296
```
297-
Returns the `aud` contents
297+
---
298+
Returns the `aud` contents. If `aud` is not set, this method returns an empty array.
298299

299300
```php
300301
public function getClaims(): array
@@ -394,7 +395,14 @@ Sets the subject (`sub`).
394395
```php
395396
public function setPassphrase(string $passphrase): Builder
396397
```
397-
Sets the passphrase. If the `$passphrase` is weak, a [Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException][security-jwt-exceptions-validatorexception] will be thrown.
398+
Sets the passphrase. A weak passphrase raises a [Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException][security-jwt-exceptions-validatorexception].
399+
400+
The passphrase must:
401+
- be at least 16 characters long
402+
- contain at least one uppercase letter
403+
- contain at least one lowercase letter
404+
- contain at least one digit
405+
- contain at least one special character
398406

399407
```php
400408
private function setClaim(string $name, $value): Builder
@@ -492,6 +500,21 @@ public function validateAudience(array|string $audience): Validator
492500
```
493501
Validates the audience. If it is not included in the token's `aud`, a [Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException][security-jwt-exceptions-validatorexception] will be thrown.
494502

503+
```php
504+
public function validateClaim(string $name, mixed $value): Validator
505+
```
506+
Validates a custom claim by name against an expected value.
507+
508+
In a validator example chain, include one custom claim check, e.g.:
509+
```php
510+
$validator
511+
->validateAudience($audience)
512+
->validateIssuer($issuer)
513+
->validateClaim("tenantId", "acme")
514+
;
515+
```
516+
517+
495518
```php
496519
public function validateExpiration(int $timestamp): Validator
497520
```

docs/filter-filter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ Remove all characters except digits, plus and minus sign, and casts the value as
119119

120120
#### `ip`
121121
```php
122-
Ip( string input, int filter = 0 ): int
122+
Ip( string $input, int $filter = 0 ): string|false
123123
```
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:
124+
Sanitizes an IP address or CIDR IP range. Internally it uses [filter_var][filter_var] for IP validation. CIDR masks are validated according to IP family (`0-32` for IPv4, `0-128` for IPv6). Returns `false` for invalid values.
125125

126126
```
127127
FILTER_FLAG_IPV4

docs/forms.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ The second optional parameter is `entity` (object). If passed, internally the co
334334

335335
Once the `bind()` process finishes, the modified `entity` will be passed in the `beforeValidation` event (if events are enabled) and after that, all the validators will be called on the form using the modified `entity` object.
336336

337+
!!! info "NOTE"
338+
339+
During `isValid()`, field filters are applied through the form binding flow even when an element has no validators. This keeps entity/input normalization consistent across validated and non-validated fields.
340+
337341
!!! info "NOTE"
338342

339343
Passing an `entity` object will result in the object being modified by the user input as described above. If you do not wish this behavior, you can clone the entity before passing it, to keep a copy of the original object

docs/logger.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ $logger->warning("This is a warning message");
159159
The log generated is as follows:
160160

161161
```bash
162-
[Tue, 25 Dec 18 12:13:14 -0400][ALERT] This is an alert message
163-
[Tue, 25 Dec 18 12:13:14 -0400][CRITICAL] This is a critical message
164-
[Tue, 25 Dec 18 12:13:14 -0400][DEBUG] This is a debug message
165-
[Tue, 25 Dec 18 12:13:14 -0400][ERROR] This is an error message
166-
[Tue, 25 Dec 18 12:13:14 -0400][EMERGENCY] This is an emergency message
167-
[Tue, 25 Dec 18 12:13:14 -0400][INFO] This is an info message
168-
[Tue, 25 Dec 18 12:13:14 -0400][CRITICAL] This is a log message
169-
[Tue, 25 Dec 18 12:13:14 -0400][NOTICE] This is a notice message
170-
[Tue, 25 Dec 18 12:13:14 -0400][WARNING] This is warning message
162+
[Tue, 25 Dec 18 12:13:14 -0400][alert] This is an alert message
163+
[Tue, 25 Dec 18 12:13:14 -0400][critical] This is a critical message
164+
[Tue, 25 Dec 18 12:13:14 -0400][debug] This is a debug message
165+
[Tue, 25 Dec 18 12:13:14 -0400][error] This is an error message
166+
[Tue, 25 Dec 18 12:13:14 -0400][emergency] This is an emergency message
167+
[Tue, 25 Dec 18 12:13:14 -0400][info] This is an info message
168+
[Tue, 25 Dec 18 12:13:14 -0400][critical] This is a log message
169+
[Tue, 25 Dec 18 12:13:14 -0400][notice] This is a notice message
170+
[Tue, 25 Dec 18 12:13:14 -0400][warning] This is warning message
171171
```
172172

173173
## Multiple Adapters
@@ -295,10 +295,10 @@ $logger->warning("This is a warning message");
295295
The log generated is as follows:
296296

297297
```bash
298-
[Tue, 25 Dec 18 12:13:14 -0400][ALERT] This is an alert message
299-
[Tue, 25 Dec 18 12:13:14 -0400][CRITICAL] This is a critical message
300-
[Tue, 25 Dec 18 12:13:14 -0400][EMERGENCY] This is an emergency message
301-
[Tue, 25 Dec 18 12:13:14 -0400][CRITICAL] This is a log message
298+
[Tue, 25 Dec 18 12:13:14 -0400][alert] This is an alert message
299+
[Tue, 25 Dec 18 12:13:14 -0400][critical] This is a critical message
300+
[Tue, 25 Dec 18 12:13:14 -0400][emergency] This is an emergency message
301+
[Tue, 25 Dec 18 12:13:14 -0400][critical] This is a log message
302302
```
303303

304304
The above can be used in situations where you want to log messages above a certain severity based on conditions in your application such as development mode vs. production.
@@ -307,6 +307,10 @@ The above can be used in situations where you want to log messages above a certa
307307

308308
The log level set is included in the logging. Anything **below** that level (i.e. higher number) will not be logged
309309

310+
!!! info "NOTE"
311+
312+
Log level names are emitted in lowercase (for example: `error`, `warning`, `info`).
313+
310314
!!! danger "DANGER"
311315

312316
It is **never** a good idea to suppress logging levels in your application since even warning errors do require CPU cycles to be processed, and neglecting these errors could potentially lead to unintended circumstances
@@ -376,11 +380,11 @@ Formats the messages using a one-line string. The default logging format is:
376380
#### Message Format
377381
If the default format of the message does not fit the needs of your application you can change it using the `setFormat()` method. The log format variables allowed are:
378382

379-
| Variable | Description |
380-
|-------------|------------------------------------------|
383+
| Variable | Description |
384+
|-------------|---------------------------------------------|
381385
| `%message%` | The message itself is expected to be logged |
382-
| `%date%` | Date the message was added |
383-
| `%level%` | Uppercase string with message level |
386+
| `%date%` | Date the message was added |
387+
| `%level%` | Lowercase string with message level |
384388

385389
The following example demonstrates how to change the message format:
386390

@@ -409,7 +413,7 @@ $logger->error('Something went wrong');
409413
which produces:
410414

411415
```bash
412-
[ALERT] - [Tue, 25 Dec 18 12:13:14 -0400] - Something went wrong
416+
[alert] - [Tue, 25 Dec 18 12:13:14 -0400] - Something went wrong
413417
```
414418

415419
If you do not want to use the constructor to change the message, you can always use the `setFormat()` on the formatter:
@@ -473,7 +477,7 @@ $logger->error('Something went wrong');
473477
which produces:
474478

475479
```bash
476-
[ERROR] - [20181225-121314] - Something went wrong
480+
[error] - [20181225-121314] - Something went wrong
477481
```
478482

479483
### JSON Formatter

docs/request.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,35 @@ The [Phalcon\Http\Request][http-request] object offers methods that provide addi
371371

372372
### Client
373373

374-
| Name | Description |
375-
|-----------------------|------------------------------------------------------------------------|
376-
| `getClientAddress()` | Gets most possible client IPv4 Address |
377-
| `getClientCharsets()` | Gets a charsets array and their quality accepted by the browser/client |
378-
| `getUserAgent()` | Gets HTTP user agent used to make the request |
379-
| `getHTTPReferer()` | Gets web page that refers active request |
374+
| Name | Description |
375+
|-----------------------|--------------------------------------------------------------------------|
376+
| `getClientAddress()` | Gets the most likely client IP address (supports proxy-aware resolution) |
377+
| `getClientCharsets()` | Gets a charsets array and their quality accepted by the browser/client |
378+
| `getUserAgent()` | Gets HTTP user agent used to make the request |
379+
| `getHTTPReferer()` | Gets web page that refers active request |
380+
381+
### Trusted Proxy Resolution
382+
383+
When you call `getClientAddress(true)`, the request component can resolve client IPs behind proxies.
384+
385+
Resolution order:
386+
1. If `trustedProxyHeader` is configured and present, use it first.
387+
2. If `trustedProxies` is configured and `REMOTE_ADDR` is not trusted, return `REMOTE_ADDR`.
388+
3. Otherwise, parse `HTTP_X_FORWARDED_FOR` from right to left, skip trusted proxies, and return the first valid public IP.
389+
390+
```php
391+
<?php
392+
393+
use Phalcon\Http\Request;
394+
395+
$request = new Request();
396+
397+
$request
398+
->setTrustedProxies(["10.0.0.10", "10.0.0.11"])
399+
->setTrustedProxyHeader("HTTP_CLIENT_IP");
400+
401+
$ipAddress = $request->getClientAddress(true);
402+
```
380403

381404
### Content
382405

0 commit comments

Comments
 (0)