Skip to content

Fix #591: Add File validator#797

Open
samdark wants to merge 7 commits intomasterfrom
feature/591-file-validator
Open

Fix #591: Add File validator#797
samdark wants to merge 7 commits intomasterfrom
feature/591-file-validator

Conversation

@samdark
Copy link
Copy Markdown
Member

@samdark samdark commented Apr 23, 2026

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\File and Yiisoft\Validator\Rule\FileHandler with validation for file existence plus optional extension, MIME type, and size constraints.
  • Extend ImageHandler to accept SplFileInfo values and gracefully handle RuntimeException when resolving an uploaded file stream URI.
  • Add/extend PHPUnit coverage and fixtures for the new File rule and Image updates; 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.

Comment thread src/Rule/FileHandler.php
@samdark samdark changed the title Fix #591: Add File validator, add SplFileInfo support to Image validator Fix #591: Add File validator Apr 23, 2026
@samdark samdark requested a review from Copilot April 23, 2026 19:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\File rule with configurable extension/MIME/size constraints and messages.
  • Add Yiisoft\Validator\Rule\FileHandler implementing the validation logic for file paths, SplFileInfo, and UploadedFileInterface.
  • 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.

Comment thread src/Rule/FileHandler.php
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\File rule and Yiisoft\Validator\Rule\FileHandler implementation.
  • 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.

Comment thread src/Rule/File.php
Comment thread src/Rule/File.php
*
* @see $mimeTypes
*/
public function getMimeTypes(): ?array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use promoted public readonly properties in constructor whenever possible.

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
*
* You may use the following placeholders in the message:
*
* - `{property}`: the translated label of the property being validated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add {Property}

Comment thread src/Rule/File.php
use WhenTrait;

/**
* @var list<string>|null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var list<string>|null
* @var string[]|null
* @psalm-var list<string>|null

Comment thread src/Rule/File.php
private ?array $extensions;

/**
* @var list<string>|null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @var list<string>|null
* @var string[]|null
* @psalm-var list<string>|null

Comment thread src/Rule/File.php
/**
* @psalm-param list<string>|string|null $value
*
* @return list<string>|null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return list<string>|null
* @return string[]|null
* @psalm-return list<string>|null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants