diff --git a/components/console/helpers/questionhelper.rst b/components/console/helpers/questionhelper.rst index 3dc97d5c0d3..c7e064b16ca 100644 --- a/components/console/helpers/questionhelper.rst +++ b/components/console/helpers/questionhelper.rst @@ -480,10 +480,10 @@ invalid answer and will only be able to proceed if their input is valid. use Symfony\Component\Validator\Validation; $question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle'); - $validation = Validation::createCallable(new Regex([ - 'pattern' => '/^[a-zA-Z]+Bundle$/', - 'message' => 'The name of the bundle should be suffixed with \'Bundle\'', - ])); + $validation = Validation::createCallable(new Regex( + pattern: '/^[a-zA-Z]+Bundle$/', + message: 'The name of the bundle should be suffixed with \'Bundle\'', + )); $question->setValidator($validation); Validating a Hidden Response diff --git a/components/options_resolver.rst b/components/options_resolver.rst index 95741a7e372..65685106c13 100644 --- a/components/options_resolver.rst +++ b/components/options_resolver.rst @@ -394,7 +394,7 @@ returns ``true`` for acceptable values and ``false`` for invalid values:: // ... $resolver->setAllowedValues('transport', Validation::createIsValidCallable( - new Length(['min' => 10 ]) + new Length(min: 10) )); In sub-classes, you can use :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::addAllowedValues` diff --git a/components/validator.rst b/components/validator.rst index 085c77a7946..12c61507257 100644 --- a/components/validator.rst +++ b/components/validator.rst @@ -36,7 +36,7 @@ characters long:: $validator = Validation::createValidator(); $violations = $validator->validate('Bernhard', [ - new Length(['min' => 10]), + new Length(min: 10), new NotBlank(), ]); diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst index 3aa05b1d2d0..bfcea0dd1b5 100644 --- a/reference/constraints/All.rst +++ b/reference/constraints/All.rst @@ -79,12 +79,12 @@ entry in that array: { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('favoriteColors', new Assert\All([ - 'constraints' => [ + $metadata->addPropertyConstraint('favoriteColors', new Assert\All( + constraints: [ new Assert\NotBlank(), - new Assert\Length(['min' => 5]), + new Assert\Length(min: 5), ], - ])); + )); } } diff --git a/reference/constraints/AtLeastOneOf.rst b/reference/constraints/AtLeastOneOf.rst index 0a6ab618aa5..5c568987ec4 100644 --- a/reference/constraints/AtLeastOneOf.rst +++ b/reference/constraints/AtLeastOneOf.rst @@ -115,23 +115,23 @@ The following constraints ensure that: { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('password', new Assert\AtLeastOneOf([ - 'constraints' => [ - new Assert\Regex(['pattern' => '/#/']), - new Assert\Length(['min' => 10]), + $metadata->addPropertyConstraint('password', new Assert\AtLeastOneOf( + constraints: [ + new Assert\Regex(pattern: '/#/'), + new Assert\Length(min: 10), ], - ])); + )); - $metadata->addPropertyConstraint('grades', new Assert\AtLeastOneOf([ - 'constraints' => [ - new Assert\Count(['min' => 3]), - new Assert\All([ - 'constraints' => [ + $metadata->addPropertyConstraint('grades', new Assert\AtLeastOneOf( + constraints: [ + new Assert\Count(min: 3), + new Assert\All( + constraints: [ new Assert\GreaterThanOrEqual(5), ], - ]), + ), ], - ])); + )); } } diff --git a/reference/constraints/CardScheme.rst b/reference/constraints/CardScheme.rst index 6e98e6fab98..bb3e9e797ad 100644 --- a/reference/constraints/CardScheme.rst +++ b/reference/constraints/CardScheme.rst @@ -77,12 +77,12 @@ on an object that will contain a credit card number. { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme([ - 'schemes' => [ + $metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme( + schemes: [ Assert\CardScheme::VISA, ], - 'message' => 'Your credit card number is invalid.', - ])); + message: 'Your credit card number is invalid.', + )); } } diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 5a9c365be37..bb7150adc8f 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -100,10 +100,10 @@ If your valid choice list is simple, you can pass them in directly via the new Assert\Choice(['New York', 'Berlin', 'Tokyo']) ); - $metadata->addPropertyConstraint('genre', new Assert\Choice([ - 'choices' => ['fiction', 'non-fiction'], - 'message' => 'Choose a valid genre.', - ])); + $metadata->addPropertyConstraint('genre', new Assert\Choice( + choices: ['fiction', 'non-fiction'], + message: 'Choose a valid genre.', + )); } } @@ -182,9 +182,9 @@ constraint. public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('genre', new Assert\Choice([ - 'callback' => 'getGenres', - ])); + $metadata->addPropertyConstraint('genre', new Assert\Choice( + callback: 'getGenres', + )); } } @@ -250,9 +250,9 @@ you can pass the class name and the method as an array. public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('genre', new Assert\Choice([ - 'callback' => [Genre::class, 'getGenres'], - ])); + $metadata->addPropertyConstraint('genre', new Assert\Choice( + callback: [Genre::class, 'getGenres'], + )); } } diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index 2d16d201b17..557c6c02380 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -139,8 +139,8 @@ following: public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('profileData', new Assert\Collection([ - 'fields' => [ + $metadata->addPropertyConstraint('profileData', new Assert\Collection( + fields: [ 'personal_email' => new Assert\Email(), 'short_bio' => [ new Assert\NotBlank(), @@ -150,8 +150,8 @@ following: ]), ], ], - 'allowMissingFields' => true, - ])); + allowMissingFields: true, + )); } } @@ -267,15 +267,15 @@ you can do the following: public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('profileData', new Assert\Collection([ - 'fields' => [ + $metadata->addPropertyConstraint('profileData', new Assert\Collection( + fields: [ 'personal_email' => new Assert\Required([ new Assert\NotBlank(), new Assert\Email(), ]), 'alternate_email' => new Assert\Optional(new Assert\Email()), ], - ])); + )); } } @@ -291,28 +291,28 @@ groups. Take the following example:: use Symfony\Component\Validator\Constraints as Assert; - $constraint = new Assert\Collection([ - 'fields' => [ + $constraint = new Assert\Collection( + fields: [ 'name' => new Assert\NotBlank(['groups' => 'basic']), 'email' => new Assert\NotBlank(['groups' => 'contact']), ], - ]); + ); This will result in the following configuration:: - $constraint = new Assert\Collection([ - 'fields' => [ - 'name' => new Assert\Required([ - 'constraints' => new Assert\NotBlank(['groups' => 'basic']), - 'groups' => ['basic', 'strict'], - ]), - 'email' => new Assert\Required([ - "constraints" => new Assert\NotBlank(['groups' => 'contact']), - 'groups' => ['basic', 'strict'], - ]), + $constraint = new Assert\Collection( + fields: [ + 'name' => new Assert\Required( + constraints: new Assert\NotBlank(groups: ['basic']), + groups: ['basic', 'strict'], + ), + 'email' => new Assert\Required( + constraints: new Assert\NotBlank(groups: ['contact']), + groups: ['basic', 'strict'], + ), ], - 'groups' => ['basic', 'strict'], - ]); + groups: ['basic', 'strict'], + ); The default ``allowMissingFields`` option requires the fields in all groups. So when validating in ``contact`` group, ``$name`` can be empty but the key is diff --git a/reference/constraints/Compound.rst b/reference/constraints/Compound.rst index 0d0dc933ae0..4d2c7743176 100644 --- a/reference/constraints/Compound.rst +++ b/reference/constraints/Compound.rst @@ -35,9 +35,9 @@ you can create your own named set or requirements to be reused consistently ever return [ new Assert\NotBlank(), new Assert\Type('string'), - new Assert\Length(['min' => 12]), + new Assert\Length(min: 12), new Assert\NotCompromisedPassword(), - new Assert\PasswordStrength(['minScore' => 4]), + new Assert\PasswordStrength(minScore: 4), ]; } } diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst index 0bf40aca8e9..d33c54c0812 100644 --- a/reference/constraints/Count.rst +++ b/reference/constraints/Count.rst @@ -82,12 +82,12 @@ you might add the following: public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('emails', new Assert\Count([ - 'min' => 1, - 'max' => 5, - 'minMessage' => 'You must specify at least one email', - 'maxMessage' => 'You cannot specify more than {{ limit }} emails', - ])); + $metadata->addPropertyConstraint('emails', new Assert\Count( + min: 1, + max: 5, + minMessage: 'You must specify at least one email', + maxMessage: 'You cannot specify more than {{ limit }} emails', + )); } } diff --git a/reference/constraints/CssColor.rst b/reference/constraints/CssColor.rst index 88a4eb4be9f..b617ebf1c42 100644 --- a/reference/constraints/CssColor.rst +++ b/reference/constraints/CssColor.rst @@ -110,15 +110,15 @@ the named CSS colors: { $metadata->addPropertyConstraint('defaultColor', new Assert\CssColor()); - $metadata->addPropertyConstraint('accentColor', new Assert\CssColor([ - 'formats' => Assert\CssColor::HEX_LONG, - 'message' => 'The accent color must be a 6-character hexadecimal color.', - ])); - - $metadata->addPropertyConstraint('currentColor', new Assert\CssColor([ - 'formats' => [Assert\CssColor::BASIC_NAMED_COLORS, Assert\CssColor::EXTENDED_NAMED_COLORS], - 'message' => 'The color "{{ value }}" is not a valid CSS color name.', - ])); + $metadata->addPropertyConstraint('accentColor', new Assert\CssColor( + formats: Assert\CssColor::HEX_LONG, + message: 'The accent color must be a 6-character hexadecimal color.', + )); + + $metadata->addPropertyConstraint('currentColor', new Assert\CssColor( + formats: [Assert\CssColor::BASIC_NAMED_COLORS, Assert\CssColor::EXTENDED_NAMED_COLORS], + message: 'The color "{{ value }}" is not a valid CSS color name.', + )); } } diff --git a/reference/constraints/DivisibleBy.rst b/reference/constraints/DivisibleBy.rst index dd90ad9a0fd..23b36023cff 100644 --- a/reference/constraints/DivisibleBy.rst +++ b/reference/constraints/DivisibleBy.rst @@ -92,9 +92,9 @@ The following constraints ensure that: { $metadata->addPropertyConstraint('weight', new Assert\DivisibleBy(0.25)); - $metadata->addPropertyConstraint('quantity', new Assert\DivisibleBy([ - 'value' => 5, - ])); + $metadata->addPropertyConstraint('quantity', new Assert\DivisibleBy( + value: 5, + )); } } diff --git a/reference/constraints/Email.rst b/reference/constraints/Email.rst index 516d6d07dca..41012e5e935 100644 --- a/reference/constraints/Email.rst +++ b/reference/constraints/Email.rst @@ -70,9 +70,9 @@ Basic Usage public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('email', new Assert\Email([ - 'message' => 'The email "{{ value }}" is not a valid email.', - ])); + $metadata->addPropertyConstraint('email', new Assert\Email( + message: 'The email "{{ value }}" is not a valid email.', + )); } } diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst index d5d78f60a0f..fdc402b1a97 100644 --- a/reference/constraints/EqualTo.rst +++ b/reference/constraints/EqualTo.rst @@ -91,9 +91,9 @@ and that the ``age`` is ``20``, you could do the following: { $metadata->addPropertyConstraint('firstName', new Assert\EqualTo('Mary')); - $metadata->addPropertyConstraint('age', new Assert\EqualTo([ - 'value' => 20, - ])); + $metadata->addPropertyConstraint('age', new Assert\EqualTo( + value: 20, + )); } } diff --git a/reference/constraints/Expression.rst b/reference/constraints/Expression.rst index bf015d17573..d5a78f71d5e 100644 --- a/reference/constraints/Expression.rst +++ b/reference/constraints/Expression.rst @@ -111,10 +111,10 @@ One way to accomplish this is with the Expression constraint: { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addConstraint(new Assert\Expression([ - 'expression' => 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()', - 'message' => 'If this is a tech post, the category should be either php or symfony!', - ])); + $metadata->addConstraint(new Assert\Expression( + expression: 'this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()', + message: 'If this is a tech post, the category should be either php or symfony!', + )); } // ... @@ -200,10 +200,10 @@ assert that the expression must return ``true`` for validation to fail. { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression([ - 'expression' => 'this.getCategory() in ["php", "symfony"] or value == false', - 'message' => 'If this is a tech post, the category should be either php or symfony!', - ])); + $metadata->addPropertyConstraint('isTechnicalPost', new Assert\Expression( + expression: 'this.getCategory() in ["php", "symfony"] or value == false', + message: 'If this is a tech post, the category should be either php or symfony!', + )); } // ... @@ -343,10 +343,10 @@ type (numeric, boolean, strings, null, etc.) { public static function loadValidatorMetadata(ClassMetadata $metadata): void { - $metadata->addPropertyConstraint('metric', new Assert\Expression([ - 'expression' => 'value + error_margin < threshold', - 'values' => ['error_margin' => 0.25, 'threshold' => 1.5], - ])); + $metadata->addPropertyConstraint('metric', new Assert\Expression( + expression: 'value + error_margin < threshold', + values: ['error_margin' => 0.25, 'threshold' => 1.5], + )); } // ... diff --git a/reference/constraints/ExpressionSyntax.rst b/reference/constraints/ExpressionSyntax.rst index c1d086790c1..37e0ad7de4a 100644 --- a/reference/constraints/ExpressionSyntax.rst +++ b/reference/constraints/ExpressionSyntax.rst @@ -90,9 +90,9 @@ The following constraints ensure that: { $metadata->addPropertyConstraint('promotion', new Assert\ExpressionSyntax()); - $metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax([ - 'allowedVariables' => ['user', 'shipping_centers'], - ])); + $metadata->addPropertyConstraint('shippingOptions', new Assert\ExpressionSyntax( + allowedVariables: ['user', 'shipping_centers'], + )); } }