Skip to content

The 'Validate' attribute works with a string passed - #48

Merged
moufmouf merged 4 commits into
thecodingmachine:masterfrom
Alejinho:feature/validate-attribute-fix
Oct 28, 2026
Merged

moufmouf merged 4 commits into
thecodingmachine:masterfrom
Alejinho:feature/validate-attribute-fix

Conversation

@Alejinho

@Alejinho Alejinho commented Dec 21, 2023 •

Copy link
Copy Markdown
Contributor

Fix the Validate Attribute. Currently the 'rule' argument passed to the Validate constructor is normalized but if the variable type is string, then it's not handled properly. Now the Validate attribute works properly if it's initialized with something like this:

<?php

class Foo {
  public function bar(
    #[Validate('some-rule')]
    string $name
  ): string {
    return 'ok';
  }
}

Fix the 'Validate' Attribute. Currently the 'rule' property passed to
the Validate constructor was normalized but wrong value was checked.
Now the Validate attribute should works properly if it's initialized
with something like this:

```php
<?php

class Foo {
  public function bar(
    #[Validate('some-rule')]
    string $name
  ): string {
    return 'ok';
  }
}
```
@Alejinho Alejinho closed this Dec 22, 2023
@Alejinho Alejinho reopened this Dec 22, 2023
- Accept Doctrine's positional "value" key (@Validate("email"))
- Reject non-string rules with a clear error instead of a later TypeError
- Accept "0" as a rule (strict check instead of empty())
- Fix #[Validate(...)] syntax in the error message
- Fix ValidateTest namespace, use plain PHPUnit TestCase, add edge-case tests
- Exercise the $bar parameter in testValidatorForParameterPHP8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moufmouf

Copy link
Copy Markdown
Member

Thanks a lot and very sorry for not noticing your PR waaaaay earlier :)

@moufmouf
moufmouf merged commit e66fd88 into thecodingmachine:master Oct 28, 2026
3 checks passed
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.

2 participants