Add Multiple Built-in Validation Attributes#31
Conversation
Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
| $notEmpty = new NotEmpty(); | ||
| $this->assertFalse($notEmpty->validate('')); | ||
| $this->assertTrue($notEmpty->validate('value')); | ||
| $this->assertTrue($notEmpty->validate(0)); |
There was a problem hiding this comment.
php's empty() function considering zero as empty value so the NotEmpty atribute will return wrong validation. Can you fix it?
There was a problem hiding this comment.
Fixed in commit 5b953f7. Changed the NotEmpty validator implementation from using PHP's empty() function to explicit checks for null and empty string only. Now integer 0 is correctly treated as valid (not empty).
| } | ||
|
|
||
| return $value >= $this->min && $value <= $this->max; | ||
| } |
There was a problem hiding this comment.
You testing here length of string not the value itself... as few lines above you returning false when the length is numeric.
There was a problem hiding this comment.
Fixed in commit 6bb7661. Changed the numeric validators (Min, Max, Between) to use is_int($value) || is_float($value) instead of is_numeric($value) to only accept actual numeric types, not string representations. This ensures consistency with the test expectations where string values like '7' should be rejected.
Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…resentations Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
|
@copilot can you also add docblock to other validators you created? |
Co-authored-by: MayMeow <3164256+MayMeow@users.noreply.github.com>
Added comprehensive docblocks to all validation attributes in commit 5fd386b. Each validator now includes class-level documentation, constructor parameter details, and validate method documentation. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR adds a comprehensive set of built-in validation attributes to reduce the need for custom rule implementations for common validation scenarios.
Added Validation Attributes
Basic Constraints:
Required- Field must be present (but can be empty)NotEmpty(existing) - Field must be present and not emptyString Constraints:
MaxLength- Limits string length to a specified number of charactersMinLength- Ensures string has at least a specified number of charactersNumerical Constraints:
Min- Ensures numeric value is greater than or equal to specified minimumMax- Ensures numeric value is less than or equal to specified maximumBetween- Ensures numeric value is within a specified rangeFormat Constraints:
Email- Validates correct email formatUrl- Validates correct URL formatRegex- Allows custom regex pattern validationCollection Constraints:
Each- Applies a validator to each element in an arrayImplementation Details
All attributes:
BaseValidatorAttributeValidatorAttributeInterfacevalidate()methodExample Usage
Documentation
Fixes #19.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
api.github.com/usr/bin/php8.3 -n -c /tmp/z6uqU1 /usr/bin/composer install(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.