Conversation
samdark
commented
Apr 23, 2026
| Q | A |
|---|---|
| Is bugfix? | ❌ |
| New feature? | ✔️ |
| Breaks BC? | ❌ |
…validator
There was a problem hiding this comment.
Pull request overview
Adds a new File validation rule/handler to the validator package and extends the existing Image rule handler to accept SplFileInfo inputs (and to be more robust with UploadedFileInterface stream metadata failures).
Changes:
- Introduce
Yiisoft\Validator\Rule\FileandYiisoft\Validator\Rule\FileHandlerwith validation for file existence plus optional extension, MIME type, and size constraints. - Extend
ImageHandlerto acceptSplFileInfovalues and gracefully handleRuntimeExceptionwhen resolving an uploaded file stream URI. - Add/extend PHPUnit coverage and fixtures for the new
Filerule andImageupdates; update docs index and changelog.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Rule/Image/ImageTest.php | Adds coverage for SplFileInfo support and missing-temp-path upload behavior in Image. |
| tests/Rule/FileTest.php | New comprehensive test suite for the File rule/handler. |
| tests/Rule/File/notes.txt | Text fixture used for MIME/size checks. |
| tests/Rule/File/README | Fixture for “file without extension” scenarios. |
| src/Rule/Image/ImageHandler.php | Adds SplFileInfo support and handles stream URI runtime exceptions. |
| src/Rule/FileHandler.php | New handler implementing file validation logic for paths, SplFileInfo, and PSR-7 uploads. |
| src/Rule/File.php | New rule defining options/messages and normalization for extensions & MIME types. |
| docs/guide/en/built-in-rules.md | Adds File to the built-in rules list. |
| CHANGELOG.md | Records enhancement #591. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
File validator, add SplFileInfo support to Image validatorFile validator
There was a problem hiding this comment.
Pull request overview
Adds a new built-in File validation rule (and handler) to the Yiisoft Validator, enabling validation of file inputs with optional constraints (extensions, MIME types, and size), along with full test coverage and documentation/changelog updates.
Changes:
- Introduce
Yiisoft\Validator\Rule\Filerule with configurable extension/MIME/size constraints and messages. - Add
Yiisoft\Validator\Rule\FileHandlerimplementing the validation logic for file paths,SplFileInfo, andUploadedFileInterface. - Add comprehensive PHPUnit tests plus new fixture files; update docs index and changelog.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Rule/File.php |
New File rule definition, options normalization, and messages. |
src/Rule/FileHandler.php |
New handler implementing validation for file existence, extension/MIME checks, and size constraints. |
tests/Rule/FileTest.php |
New unit tests covering configuration, normalization, pass/fail scenarios, messages, and integration cases. |
tests/Rule/File/notes.txt |
Test fixture used for size/MIME/extension cases. |
tests/Rule/File/README |
Extensionless test fixture. |
docs/guide/en/built-in-rules.md |
Adds File to the built-in rules list. |
CHANGELOG.md |
Records the new feature (#591). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR adds a new built-in File validation rule to the Yiisoft Validator package, enabling validation of file paths, SplFileInfo, and PSR-7 UploadedFileInterface instances with optional checks for extension, MIME type (including wildcards), and size constraints.
Changes:
- Introduced
Yiisoft\Validator\Rule\Filerule andYiisoft\Validator\Rule\FileHandlerimplementation. - Added comprehensive unit tests and new test fixtures for file validation scenarios.
- Updated documentation index and changelog to list the new built-in rule.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Rule/File.php |
New File rule definition (options, messages, normalization, handler binding). |
src/Rule/FileHandler.php |
New handler implementing file detection and constraint validation (extension/MIME/size). |
tests/Rule/FileTest.php |
New test suite covering configuration errors, passing/failing validation cases, and warnings behavior. |
tests/Rule/File/README |
Fixture: file without extension. |
tests/Rule/File/notes.txt |
Fixture: plain text file for MIME/size checks. |
docs/guide/en/built-in-rules.md |
Adds File to the built-in rules list. |
CHANGELOG.md |
Documents the new feature addition (#591). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * | ||
| * @see $mimeTypes | ||
| */ | ||
| public function getMimeTypes(): ?array |
There was a problem hiding this comment.
Use promoted public readonly properties in constructor whenever possible.
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| * | ||
| * You may use the following placeholders in the message: | ||
| * | ||
| * - `{property}`: the translated label of the property being validated. |
| use WhenTrait; | ||
|
|
||
| /** | ||
| * @var list<string>|null |
There was a problem hiding this comment.
| * @var list<string>|null | |
| * @var string[]|null | |
| * @psalm-var list<string>|null |
| private ?array $extensions; | ||
|
|
||
| /** | ||
| * @var list<string>|null |
There was a problem hiding this comment.
| * @var list<string>|null | |
| * @var string[]|null | |
| * @psalm-var list<string>|null |
| /** | ||
| * @psalm-param list<string>|string|null $value | ||
| * | ||
| * @return list<string>|null |
There was a problem hiding this comment.
| * @return list<string>|null | |
| * @return string[]|null | |
| * @psalm-return list<string>|null |