From e6d6532d503ee356a06e72916a4177473bdaba68 Mon Sep 17 00:00:00 2001 From: Manuel Reinhard Date: Sat, 20 Apr 2013 18:28:11 +0200 Subject: [PATCH] Improved Luhn validator doc Based on feedback from @WouterJ on the Iban validator doc. See https://github.com/symfony/symfony-docs/pull/2521 --- reference/constraints/Luhn.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/reference/constraints/Luhn.rst b/reference/constraints/Luhn.rst index f2103cc2a62..8d6e789d0d3 100644 --- a/reference/constraints/Luhn.rst +++ b/reference/constraints/Luhn.rst @@ -1,5 +1,5 @@ Luhn -====== +==== .. versionadded:: 2.2 The Luhn validation is new in Symfony 2.2. @@ -49,6 +49,8 @@ will contain a credit card number. .. code-block:: php-annotations // src/Acme/SubscriptionBundle/Entity/Transaction.php + namespace Acme\SubscriptionBundle\Entity\Transaction; + use Symfony\Component\Validator\Constraints as Assert; class Transaction @@ -62,8 +64,10 @@ will contain a credit card number. .. code-block:: php // src/Acme/SubscriptionBundle/Entity/Transaction.php + namespace Acme\SubscriptionBundle\Entity\Transaction; + use Symfony\Component\Validator\Mapping\ClassMetadata; - use Symfony\Component\Validator\Constraints\Luhn; + use Symfony\Component\Validator\Constraints as Assert; class Transaction { @@ -71,7 +75,7 @@ will contain a credit card number. public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('luhn', new Luhn(array( + $metadata->addPropertyConstraint('cardNumber', new Assert\Luhn(array( 'message' => 'Please check your credit card number', ))); } @@ -87,4 +91,4 @@ message The default message supplied when the value does not pass the Luhn check. -.. _`Luhn algorithm`: http://en.wikipedia.org/wiki/Luhn_algorithm \ No newline at end of file +.. _`Luhn algorithm`: http://en.wikipedia.org/wiki/Luhn_algorithm