Skip to content

Commit

Permalink
minor #17468 [Validator] Removal code-block php-annotation (mdoutrelu…
Browse files Browse the repository at this point in the history
…ingne)

This PR was merged into the 6.1 branch.

Discussion
----------

[Validator] Removal code-block php-annotation

Following #17223

Commits
-------

f61ca2a [Validator] Removal code-block php-annotations
  • Loading branch information
javiereguiluz committed Nov 26, 2022
2 parents 3a76000 + f61ca2a commit 367bf3c
Showing 1 changed file with 15 additions and 42 deletions.
57 changes: 15 additions & 42 deletions validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,27 @@ use it as an annotation/attribute in other classes.

The ``#[HasNamedArguments]`` attribute was introduced in Symfony 6.1.

You can use ``#[HasNamedArguments]`` or ``getRequiredOptions()`` to make some constraint options required:
You can use ``#[HasNamedArguments]`` or ``getRequiredOptions()`` to make some constraint options required::

.. configuration-block::

.. code-block:: php-annotations
// src/Validator/ContainsAlphanumeric.php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class ContainsAlphanumeric extends Constraint
{
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
public $mode;
public function getRequiredOptions(): array
{
return ['mode'];
}
}
.. code-block:: php-attributes
// src/Validator/ContainsAlphanumeric.php
namespace App\Validator;

// src/Validator/ContainsAlphanumeric.php
namespace App\Validator;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;
#[\Attribute]
class ContainsAlphanumeric extends Constraint
{
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
public string $mode;

#[\Attribute]
class ContainsAlphanumeric extends Constraint
#[HasNamedArguments]
public function __construct(string $mode, array $groups = null, mixed $payload = null)
{
public $message = 'The string "{{ string }}" contains an illegal character: it can only contain letters or numbers.';
public string $mode;
#[HasNamedArguments]
public function __construct(string $mode, array $groups = null, mixed $payload = null)
{
parent::__construct([], $groups, $payload);
$this->mode = $mode;
}
parent::__construct([], $groups, $payload);
$this->mode = $mode;
}
}

Creating the Validator itself
-----------------------------
Expand Down

0 comments on commit 367bf3c

Please sign in to comment.