Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't use deprecated functions in Callback.rst#4105

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Rootie wants to merge3 commits intosymfony:masterfromRootie:patch-1
Closed
Show file tree
Hide file tree
Changes fromall 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
22 changes: 14 additions & 8 deletionscookbook/validation/custom_constraint.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,9 +65,9 @@ The validator class is also simple, and only has one required method ``validate(
public function validate($value, Constraint $constraint)
{
if (!preg_match('/^[a-zA-Za0-9]+$/', $value, $matches)) {
$this->context->addViolation(
$constraint->message,
array('%string%' => $value)
$this->context->buildViolation($constraint->message)
->setParameter('%string%', $value)
->addViolation();
);
}
}
Expand All@@ -76,11 +76,17 @@ The validator class is also simple, and only has one required method ``validate(
.. note::

The ``validate`` method does not return a value; instead, it adds violations
to the validator's ``context`` property with an ``addViolation`` method
call if there are validation failures. Therefore, a value could be considered
as being valid if it causes no violations to be added to the context.
The first parameter of the ``addViolation`` call is the error message to
use for that violation.
to the validator's ``context`` property. Therefore, a value could be considered
as being valid if it causes no violations to be added to the context.The
violation is constructed and added to the context using a
``ConstraintViolationBuilder`` returned by the ``buildViolation`` method
call. The parameter given to the ``buildViolation`` call is the error message
to use for that violation. The ``addViolation`` method call finally adds the
violation to the context.

.. versionadded:: 2.5
The ``buildViolation`` method was added in Symfony 2.5. For usage examples with
older Symfony versions, see the corresponding versions of this documentation page.

Using the new Validator
-----------------------
Expand Down
22 changes: 10 additions & 12 deletionsreference/constraints/Callback.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -114,16 +114,17 @@ those errors should be attributed::

// check if the name is actually a fake name
if (in_array($this->getFirstName(), $fakeNames)) {
$context->addViolationAt(
'firstName',
'This name sounds totally fake!',
array(),
null
);
$context->buildViolation('This name sounds totally fake!')
->atPath('firstName')
->addViolation();
}
}
}

.. versionadded:: 2.5
The ``buildViolation`` method was added in Symfony 2.5. For usage examples with
older Symfony versions, see the corresponding versions of this documentation page.

Static Callbacks
----------------

Expand All@@ -137,12 +138,9 @@ have access to the object instance, they receive the object as the first argumen

// check if the name is actually a fake name
if (in_array($object->getFirstName(), $fakeNames)) {
$context->addViolationAt(
'firstName',
'This name sounds totally fake!',
array(),
null
);
$context->buildViolation('This name sounds totally fake!')
->atPath('firstName')
->addViolation();
}
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp