|
| 1 | +Bic |
| 2 | +=== |
| 3 | + |
| 4 | +.. versionadded:: 2.8 |
| 5 | + The Bic constraint was introduced in Symfony 2.8. |
| 6 | + |
| 7 | +This constraint is used to ensure that a value has the proper format of a |
| 8 | +`Business Identifier Code (BIC)`_. BIC is an internationally agreed means to |
| 9 | +uniquely identify both financial and non-financial institutions. |
| 10 | + |
| 11 | ++----------------+-----------------------------------------------------------------------+ |
| 12 | +| Applies to | :ref:`property or method <validation-property-target>` | |
| 13 | ++----------------+-----------------------------------------------------------------------+ |
| 14 | +| Options | - `message`_ | |
| 15 | +| | - `payload`_ | |
| 16 | ++----------------+-----------------------------------------------------------------------+ |
| 17 | +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Bic` | |
| 18 | ++----------------+-----------------------------------------------------------------------+ |
| 19 | +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\BicValidator` | |
| 20 | ++----------------+-----------------------------------------------------------------------+ |
| 21 | + |
| 22 | +Basic Usage |
| 23 | +----------- |
| 24 | + |
| 25 | +To use the Bic validator, simply apply it to a property on an object that |
| 26 | +will contain a Business Identifier Code (BIC). |
| 27 | + |
| 28 | +.. configuration-block:: |
| 29 | + |
| 30 | + .. code-block:: php-annotations |
| 31 | +
|
| 32 | + // src/AppBundle/Entity/Transaction.php |
| 33 | + namespace AppBundle\Entity; |
| 34 | +
|
| 35 | + use Symfony\Component\Validator\Constraints as Assert; |
| 36 | +
|
| 37 | + class Transaction |
| 38 | + { |
| 39 | + /** |
| 40 | + * @Assert\Bic() |
| 41 | + */ |
| 42 | + protected $businessIdentifierCode; |
| 43 | + } |
| 44 | +
|
| 45 | + .. code-block:: yaml |
| 46 | +
|
| 47 | + # src/AppBundle/Resources/config/validation.yml |
| 48 | + AppBundle\Entity\Transaction: |
| 49 | + properties: |
| 50 | + businessIdentifierCode: |
| 51 | + - Bic: ~ |
| 52 | +
|
| 53 | + .. code-block:: xml |
| 54 | +
|
| 55 | + <!-- src/AppBundle/Resources/config/validation.xml --> |
| 56 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 57 | + <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" |
| 58 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 59 | + xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> |
| 60 | +
|
| 61 | + <class name="AppBundle\Entity\Transaction"> |
| 62 | + <property name="businessIdentifierCode"> |
| 63 | + <constraint name="Bic" /> |
| 64 | + </property> |
| 65 | + </class> |
| 66 | + </constraint-mapping> |
| 67 | +
|
| 68 | + .. code-block:: php |
| 69 | +
|
| 70 | + // src/AppBundle/Entity/Transaction.php |
| 71 | + namespace AppBundle\Entity; |
| 72 | +
|
| 73 | + use Symfony\Component\Validator\Mapping\ClassMetadata; |
| 74 | + use Symfony\Component\Validator\Constraints as Assert; |
| 75 | +
|
| 76 | + class Transaction |
| 77 | + { |
| 78 | + protected $businessIdentifierCode; |
| 79 | +
|
| 80 | + public static function loadValidatorMetadata(ClassMetadata $metadata) |
| 81 | + { |
| 82 | + $metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic()); |
| 83 | + } |
| 84 | + } |
| 85 | +
|
| 86 | +Available Options |
| 87 | +----------------- |
| 88 | + |
| 89 | +message |
| 90 | +~~~~~~~ |
| 91 | + |
| 92 | +**type**: ``string`` **default**: ``This is not a valid Business Identifier Code (BIC).`` |
| 93 | + |
| 94 | +The default message supplied when the value does not pass the BIC check. |
| 95 | + |
| 96 | +.. include:: /reference/constraints/_payload-option.rst.inc |
| 97 | + |
| 98 | +.. _`Business Identifier Code (BIC)`: https://en.wikipedia.org/wiki/Business_Identifier_Code |
0 commit comments