8000 Don't use deprecated functions in Callback.rst by Rootie · Pull Request #4105 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update custom_contraint.rst to meet the new 2.5 api
  • Loading branch information
Rootie committed Aug 8, 2014
commit ea9a16b5db0a0b23a2c7e244587a23b59475e257
22 changes: 14 additions & 8 deletions cookbook/validation/custom_constraint.rst
Original file line number Diff line number Diff 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
0