Skip to content

Improved CardScheme validator doc #2523

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
May 3, 2013
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
10 changes: 7 additions & 3 deletions reference/constraints/CardScheme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ on an object that 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
Expand All @@ -67,16 +69,18 @@ on an object that 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\CardScheme;
use Symfony\Component\Validator\Constraints as Assert;

class Transaction
{
protected $cardNumber;

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('cardSchema', new CardScheme(array(
$metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme(array(
'schemes' => array(
'VISA'
),
Expand Down Expand Up @@ -117,4 +121,4 @@ message

The message shown when the value does not pass the ``CardScheme`` check.

.. _`Wikipedia: Issuer identification number (IIN)`: http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29
.. _`Wikipedia: Issuer identification number (IIN)`: http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29