Skip to content

[Validator] Removal code-block php-annotation #17468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Validator] Removal code-block php-annotations
  • Loading branch information
mdoutreluingne committed Nov 26, 2022
commit f61ca2aece1126eece00ac4f70e17aa208396c4c
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::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we really should mention this method any longer if we do not have an example for it anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that this method is no longer used. Thanks
I have created a PR #17476


.. 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