Skip to content

Commit

Permalink
feature symfony#5623 [Validator] added BIC validator (mvhirsch)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.8 branch (closes symfony#5623).

Discussion
----------

[Validator] added BIC validator

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes, PR: symfony/symfony#15519
| Applies to    | 2.8
| Fixed tickets | none

Commits
-------

7911fe1 [Validator] added BIC validator
  • Loading branch information
xabbuh committed Oct 12, 2015
2 parents 3da6681 + 7911fe1 commit f64d406
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions reference/constraints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Validation Constraints Reference
constraints/Currency
constraints/Luhn
constraints/Iban
constraints/Bic
constraints/Isbn
constraints/Issn

Expand Down
105 changes: 105 additions & 0 deletions reference/constraints/Bic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Bic
===

.. versionadded:: 2.8
The Bic constraint was introduced in Symfony 2.8.

This constraint is used to ensure that a value has the proper format of a
`Business Identifier Code (BIC)`_. BIC is an internationally agreed means to
uniquely identify both financial and non-financial institutions.

+----------------+-----------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+-----------------------------------------------------------------------+
| Options | - `message`_ |
| | - `payload`_ |
+----------------+-----------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Bic` |
+----------------+-----------------------------------------------------------------------+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\BicValidator` |
+----------------+-----------------------------------------------------------------------+

Basic Usage
-----------

To use the Bic validator, simply apply it to a property on an object that
will contain a Business Identifier Code (BIC).

.. configuration-block::

.. code-block:: php-annotations
// src/AppBundle/Entity/Transaction.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Transaction
{
/**
* @Assert\Bic()
*/
protected $businessIdentifierCode;
}
.. code-block:: yaml
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Transaction:
properties:
businessIdentifierCode:
- Bic:
message: This is not a valid Business Identifier Code (BIC).
.. code-block:: xml
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="AppBundle\Entity\Transaction">
<property name="businessIdentifierCode">
<constraint name="Bic">
<option name="message">
This is not a valid Business Identifier Code (BIC).
</option>
</constraint>
</property>
</class>
</constraint-mapping>
.. code-block:: php
// src/AppBundle/Entity/Transaction.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
class Transaction
{
protected $businessIdentifierCode;
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic(array(
'message' => 'This is not a valid Business Identifier Code (BIC).',
)));
}
}
Available Options
-----------------

message
~~~~~~~

**type**: ``string`` **default**: ``This is not a valid Business Identifier Code (BIC).``

The default message supplied when the value does not pass the BIC check.

.. include:: /reference/constraints/_payload-option.rst.inc

.. _`Business Identifier Code (BIC)`: https://en.wikipedia.org/wiki/Business_Identifier_Code
1 change: 1 addition & 0 deletions reference/constraints/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ File Constraints
Financial and other Number Constraints
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* :doc:`Bic </reference/constraints/Bic>`
* :doc:`CardScheme </reference/constraints/CardScheme>`
* :doc:`Currency </reference/constraints/Currency>`
* :doc:`Luhn </reference/constraints/Luhn>`
Expand Down

0 comments on commit f64d406

Please sign in to comment.