596 Commits

Author SHA1 Message Date
Nicolas Grekas
0852aa41b7 Dont use ->getDeclaringClass() when ->class is enough 2025-12-17 21:42:10 +01:00
Nicolas Grekas
e764d277ef Merge branch '7.4' into 8.0
* 7.4:
  [FrameworkBundle] Dump all registered extensions’ configuration reference
  fix merge
  Mark FormFlow as finished if the last step is skipped
  [HttpKernel] Fix using MapRequestPayload on nullable arguments
  [ObjectMapper] bypass lazy ghost with class transform
  [WebProfilerBundle] fix displaying runner
  [DependencyInjection] Fix preloading LazyClosure
  [Emoji] Update list to version 17
  make doLoadClassMetadata() methods private
  fix routing config type information
  [HttpClient] Don't reset unused clients in data collector
2025-11-20 13:42:53 +01:00
Christian Flothmann
829d4acbec make doLoadClassMetadata() methods private 2025-11-18 14:23:20 +01:00
Christian Flothmann
620d6a6af3 clean up the XML schema definition 2025-09-26 11:28:38 +02:00
Christian Flothmann
382e0c75a3 remove support for implicit constraint option names in YAML/XML mapping files 2025-09-26 11:14:49 +02:00
Christian Flothmann
c52ab90ae3 Merge branch '7.4' into 8.0
* 7.4:
  deprecate passing an associative array to GroupSequence
  [Uid] Add `MockUuidFactory` for deterministic UUID generation in tests
  deprecate extending RememberMeDetails using legacy constructor signature
  [Notifier][LOX24] Add Lox24 webhook request parser support
  [WebProfilerBundle] Upgrade mermaid to v11.12.0
  [MonologBridge] Deprecate `NotFoundActivationStrategy`
  Simplify ConsoleFormatterTest
  deprecate implicit constraint option names in YAML/XML mapping files
  [Security] Fix preload warning in `AuthorizationChecker`
  [Notifier] Add support for building SmsEvent by dlr_code and RemoteEvent for other LOX24 webhook event types
  allow protocols to be passed as a string
  Fix merge
  fix high deps tests
2025-09-26 09:52:19 +02:00
Christian Flothmann
e9787b1690 deprecate implicit constraint option names in YAML/XML mapping files 2025-09-24 17:29:42 +02:00
Nicolas Grekas
c261b2e61d Merge branch '7.4' into 8.0
* 7.4:
  [SecurityBundle] Fix semantic configuration for singulars/plurals in XML
  [JsonPath] Make the component RFC compliant
  [Security] Add `$tokenSource` argument to `#[IsCsrfTokenValid]` to support reading tokens from the query string or headers
  [Config] Fix generics on TreeBuilder and ArrayNodeDefinition
  Fix `#[IsCsrfTokenValid]` to ensure `$tokenKey` is non-nullable
  [Security] Deprecate `PersistentToken::getClass()` and `RememberMeDetails::getUserFqcn()` in order to remove the user FQCN from the remember-me cookie in 8.0
  [Serializer] Add `#[ExtendsSerializationFor]` to declare new serialization attributes for a class
  [Validator] Add `#[ExtendsValidationFor]` to declare new constraints for a class
  [WebProfilerBundle] Show `EventStream`s in debug toolbar
2025-09-10 14:05:54 +02:00
Fabien Potencier
9cc995d743 feature #61545 [Validator] Add #[ExtendsValidationFor] to declare new constraints for a class (nicolas-grekas)
This PR was merged into the 7.4 branch.

Discussion
----------

[Validator] Add `#[ExtendsValidationFor]` to declare new constraints for a class

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

This PR builds on #61528

I propose to add a `#[ExtendsValidationFor]` attribute that allows adding validation constraints to another class.
This is typically needed for third party classes. For context, Sylius has a nice doc about this:
 https://docs.sylius.com/the-customization-guide/customizing-validation

At the moment, the only way to achieve this is by declaring the new constraints in the (hardcoded) `config/validation/` folder, using either xml or yaml. No attributes.

With this PR, one will be able to define those extra constraints using PHP attributes, set on classes that'd mirror the properties/getters of the targeted class. The compiler pass will ensure that all properties/getters declared in these source classes also exist in the target class. (source = the app's class that declares the new constraints; target = the existing class to add constraints to.)

```php
#[ExtendsValidationFor(TargetClass::class)]
abstract class SourceClass
{
    #[Assert\NotBlank(groups: ['my_app'])]
    #[Assert\Length(min: 3, groups: ['my_app'])]
    public string $name = '';

    #[Assert\Email(groups: ['my_app'])]
    public string $email = '';

    #[Assert\Range(min: 18, groups: ['my_app'])]
    public int $age = 0;
}
```

(I made the class abstract because it's not supposed to be instantiated - but it's not mandatory.)

Here are the basics of how this works:

1. During container compilation, classes marked with `#[ExtendsValidationFor(Target::class)]` are collected and validated: the container checks that members declared on the source exist on the target. If not, a `MappingException` is thrown.
2. The validator is configured to map the target to its source classes.
3. At runtime, when loading validation metadata for the target, attributes (constraints, callbacks, group providers) are read from both the target and its mapped source classes and applied accordingly.

Commits
-------

e884a769a70 [Validator] Add `#[ExtendsValidationFor]` to declare new constraints for a class
2025-09-10 08:06:37 +02:00
Nicolas Grekas
cbaea54316 Merge branch '7.3' into 7.4
* 7.3:
  fall back to legacy options handling if configured named arguments do not match
  [DependencyInjection] Fix optimizing ClassExistenceResource
2025-09-04 09:03:44 +02:00
Christian Flothmann
7dd22de924 fall back to legacy options handling if configured named arguments do not match 2025-09-04 08:57:35 +02:00
Nicolas Grekas
b19f08c77a Merge branch '7.4' into 8.0
* 7.4:
  [Serializer] Allow using attributes to declare compile-time serialization metadata
  [Validator] Allow using attributes to declare compile-time constraint metadata
  [DoctrineBridge] Use a single table in isSameDatabaseChecker
  [DependencyInjection] Minor optims
2025-09-03 19:54:46 +02:00
Nicolas Grekas
249bb3b345 [Validator] Add #[ExtendsValidationFor] to declare new constraints for a class 2025-09-03 18:44:49 +02:00
Nicolas Grekas
1b35885e51 [Validator] Allow using attributes to declare compile-time constraint metadata 2025-09-03 17:41:19 +02:00
Nicolas Grekas
ec0c988cc1 Merge branch '7.4' into 8.0
* 7.4: (31 commits)
  [Validator] Update Romanian translations
  fix tests
  [JsonStreamer] Fix decoding iterable lists
  [String][Inflector] Fix edge cases
  [Serializer][Validator] Add JSON schema for validating and autocompleting YAML config files
  [DependencyInjection] Allow adding resource tags using any config formats
  Fix merge
  Add missing Sweego Mailer Bridge webhook events
  [Security] Fix attribute-based chained user providers
  [Intl] Fix Intl::getIcuStubVersion()
  [Intl] Add methods to filter currencies more precisely
  [Notifier] Add tests for option classes
  Sync intl scripts
  [Intl] Add metadata about currencies' validtity dates
  Bump Symfony version to 7.3.4
  Update VERSION for 7.3.3
  Update CHANGELOG for 7.3.3
  Bump Symfony version to 6.4.26
  Update VERSION for 6.4.25
  Update CONTRIBUTORS for 6.4.25
  ...
2025-09-01 11:26:06 +02:00
Nicolas Grekas
74e760ca61 [Serializer][Validator] Add JSON schema for validating and autocompleting YAML config files 2025-08-30 13:14:35 +02:00
Nicolas Grekas
db6b7c8db2 Merge branch '7.4' into 8.0
* 7.4:
  [Validator][Serializer] Make internal properties private
  [VarExporter] Fix serializing classes with __serialize() returning unprefixed private properties
  Remove direct access to internal properties cross-components
  remove deprecated nullable option from primary key columns
  [Validator] Optimize serialized metadata and cleanup tests
  specific fix to avoid 'outag' when inflecting 'outages'
  Use <info> for options in command description
  [ObjectMapper] Remove obsolete TODO
  [HttpFoundation][HttpKernel][WebProfilerBundle] Add support for the `QUERY` HTTP method
  [DependencyInjection] Don’t autowire excluded services
  Add bool return type to CustomCredentials callable parameter
  [Process] Enhance hasSystemCallBeenInterrupted function for non-english locale
  [FrameworkBundle] Make `cache:warmup` warm up read-only caches
2025-08-18 15:24:29 +02:00
Nicolas Grekas
29a8a56879 [Validator][Serializer] Make internal properties private 2025-08-18 15:17:18 +02:00
Nicolas Grekas
a9eb369e14 [Validator] Optimize serialized metadata and cleanup tests 2025-08-18 10:46:12 +02:00
Nicolas Grekas
125ecb7811 [HttpKernel][Mime][Serializer][String][Validator] Replace __sleep/wakeup() by __(un)serialize() 2025-08-14 17:39:15 +02:00
Nicolas Grekas
62d60a43a2 Merge branch '7.4' into 8.0
* 7.4:
  [Mime] Deprecate implementing `__sleep/wakeup()` on `AbstractPart` implementations
  [Validator] Deprecate implementing `__sleep/wakeup()` on GenericMetadata implementations
  [String] Deprecate implementing `__sleep/wakeup()` on string implementations
  More cleanups related to internal sleep/wakeup usages
  [HttpKernel] Deprecate `__sleep/wakeup()` on kernels and data collectors and make `Profile` final
  [Serializer] Make `AttributeMetadata` and `ClassMetadata` final
  Replace __sleep/wakeup() by __(un)serialize() when BC isn't a concern
  chore: PHP CS Fixer - simplify config
2025-08-14 16:56:53 +02:00
Nicolas Grekas
dfa835d9f3 [Mime] Deprecate implementing __sleep/wakeup() on AbstractPart implementations 2025-08-14 16:54:10 +02:00
Nicolas Grekas
0c0fcbdaad [Validator] Deprecate implementing __sleep/wakeup() on GenericMetadata implementations 2025-08-14 15:24:33 +02:00
Nicolas Grekas
5345db52c1 [Ldap][Messenger][Validator][Workflow] Add methods to interfaces as planned 2025-08-04 14:43:48 +02:00
Nicolas Grekas
93c1adac35 Merge branch '7.4' into 8.0
* 7.4:
  run tests using PHPUnit 11.5
  make data provider static
  [Lock] Fix using fractional TTLs on all platforms
  [Lock] Fixes an issue with PostgreSQL when using fractional TTLs
  [Console][Table] Fix unnecessary wrapping
  [DependencyInjection] Deprecate registering a service without a class when its id is a non-existing FQCN
  disable detecting modified indexes with DBAL 4.3
  [cache] RedisTrait::doFetch should use pipeline instead of mget for Relay\Cluster
  relax assertions for forward compatibility with Symfony 7.4
  [Console][Table] Fix invalid UTF-8 due to text wrapping
2025-08-01 18:41:19 +02:00
Christian Flothmann
1d7117a57a remove support for generic constraint option handling 2025-07-30 10:22:29 +02:00
Nicolas Grekas
d2401db305 Remove legacy code paths that rely on feature checks 2025-07-19 11:21:01 +02:00
Mathias Arlaud
042e49c912 [PropertyInfo] Remove deprecated code 2025-06-06 14:49:07 +02:00
Christian Flothmann
bc4d9ebae0 fix the version constaints not supporting named arguments are deprecated in 2025-01-24 20:47:25 +01:00
Christian Flothmann
bf6aecc2f8 deprecate the use of option arrays to configure validation constraints 2025-01-18 10:24:59 +01:00
Mathias Arlaud
41af3ca1f1 [TypeInfo][Serializer][PropertyInfo][Validator] TypeInfo 7.1 compatibility 2024-11-15 11:15:51 +01:00
Nicolas Grekas
5bf5687bba Merge branch '7.1' into 7.2
* 7.1:
  Removed body size limit
  prevent failures around not existing TypeInfo classes
  fix version check to include dev versions
2024-11-14 22:27:14 +01:00
Nicolas Grekas
0e64f87d7a bug #58870 [Serializer][Validator] prevent failures around not existing TypeInfo classes (xabbuh)
This PR was merged into the 7.1 branch.

Discussion
----------

[Serializer][Validator] prevent failures around not existing TypeInfo classes

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

Having a `getType()` method on an extractor is not enough. Such a method may exist to be forward-compatible with the TypeInfo component. We still must not call it if the TypeInfo component is not installed to prevent running into errors for not-defined classes when the TypeInfo component is not installed.

Commits
-------

386453ee77b prevent failures around not existing TypeInfo classes
2024-11-14 22:24:44 +01:00
Mathias Arlaud
39a0d0b92f [Serializer][PropertyInfo][Validator] TypeInfo 7.2 compatibility 2024-11-14 13:23:58 +01:00
Christian Flothmann
2e3ef85a97 prevent failures around not existing TypeInfo classes
Having a getType() method on an extractor is not enough. Such a method may
exist to be forward-compatible with the TypeInfo component. We still must
not call it if the TypeInfo component is not installed to prevent running into
errors for not-defined classes when the TypeInfo component is not installed.
2024-11-14 11:06:52 +01:00
Mathias Arlaud
9cc24fc67f [TypeInfo] Redesign Type methods and nullability 2024-10-22 15:04:00 +02:00
Alexandre Daubois
948cd1bea6 Reduce common control flows 2024-10-14 20:16:08 +02:00
Alexandre Daubois
651feaea32 Remove a few unnecessary full qualifier 2024-10-02 08:33:23 +02:00
Christian Flothmann
524bcb7676 Merge branch '7.1' into 7.2
* 7.1:
  fix merge
  [AssetMapper] Split test dirs in tests
  Fix typo
  Change incorrect check for the `stateless` request attribute
  [Validator] add setGroupProvider to AttributeLoader
  use copy() instead of rename() on Windows
  test: kebab-case to snake_case
  [PropertyInfo] Handle collection in PhpStan same as PhpDoc
  [Messenger] Passing to `WorkerMessageRetriedEvent` envelope with actual stamps after sent
2024-07-09 22:36:12 +02:00
Christian Flothmann
15203f90cd Merge branch '7.0' into 7.1
* 7.0:
  fix merge
  [AssetMapper] Split test dirs in tests
  Fix typo
  Change incorrect check for the `stateless` request attribute
  [Validator] add setGroupProvider to AttributeLoader
  use copy() instead of rename() on Windows
  test: kebab-case to snake_case
  [PropertyInfo] Handle collection in PhpStan same as PhpDoc
  [Messenger] Passing to `WorkerMessageRetriedEvent` envelope with actual stamps after sent
2024-07-09 21:36:07 +02:00
Maximilian Zumbansen
aa3e93a680 [Validator] add setGroupProvider to AttributeLoader 2024-07-08 15:09:05 +02:00
Alexander M. Turek
2050a6a1f5 Prefix all sprintf() calls 2024-06-20 17:52:34 +02:00
Alexander M. Turek
b8ab23c282 Merge branch '7.0' into 7.1
* 7.0:
  fix compatibility with Twig 3.10
  [Strings][EnglishInflector] Fix incorrect pluralisation of 'Album'
  handle union and intersection types for cascaded validations
  move wiring of the property info extractor to the ObjectNormalizer
  restore deprecated properties
  move Process component dep to require-dev
  Remove calls to `onConsecutiveCalls()`
  fix: remove unwanted type cast
  accept AbstractAsset instances when filtering schemas
  better distinguish URL schemes and windows drive letters
  handle edge cases when constructing constraints with named arguments
  convert empty CSV header names into numeric keys
2024-05-02 10:41:59 +02:00
Alexander M. Turek
0edd0a59df Merge branch '6.4' into 7.0
* 6.4:
  fix compatibility with Twig 3.10
  [Strings][EnglishInflector] Fix incorrect pluralisation of 'Album'
  handle union and intersection types for cascaded validations
  move wiring of the property info extractor to the ObjectNormalizer
  restore deprecated properties
  move Process component dep to require-dev
  Remove calls to `onConsecutiveCalls()`
  fix: remove unwanted type cast
  accept AbstractAsset instances when filtering schemas
  better distinguish URL schemes and windows drive letters
  handle edge cases when constructing constraints with named arguments
  convert empty CSV header names into numeric keys
2024-05-02 10:35:16 +02:00
Alexander M. Turek
afc96eebea Merge branch '5.4' into 6.4
* 5.4:
  fix compatibility with Twig 3.10
  [Strings][EnglishInflector] Fix incorrect pluralisation of 'Album'
  handle union and intersection types for cascaded validations
  move wiring of the property info extractor to the ObjectNormalizer
  move Process component dep to require-dev
  Remove calls to `onConsecutiveCalls()`
  fix: remove unwanted type cast
  accept AbstractAsset instances when filtering schemas
  better distinguish URL schemes and windows drive letters
  convert empty CSV header names into numeric keys
2024-05-02 10:32:52 +02:00
Christian Flothmann
d05268ea54 handle union and intersection types for cascaded validations 2024-04-30 16:58:29 +02:00
Christian Flothmann
271b2986cf handle edge cases when constructing constraints with named arguments 2024-04-29 09:59:29 +02:00
Mathias Arlaud
be567a340d [PropertyInfo] Deprecate PropertyInfo Type
Co-authored-by: Baptiste Leduc <baptiste.leduc@gmail.com>
2024-04-04 08:15:09 +02:00
Aurelien Pillevesse
50b3d816ad use cpp 2024-03-13 19:59:33 +01:00
Nicolas Grekas
802d75cc4a Merge branch '6.4' into 7.0
* 6.4:
  Fix implicitly-required parameters
  minor #53524 [Messenger] [AmazonSqs] Allow `async-aws/sqs` version 2 (smoench)
  Fix bad merge
  List CS fix in .git-blame-ignore-revs
  Fix implicitly-required parameters
  List CS fix in .git-blame-ignore-revs
  Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value
  [Messenger][AmazonSqs] Allow async-aws/sqs version 2
2024-01-23 16:02:46 +01:00