Skip to content

[Validator] added BIC validator #5623

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 9 commits into from
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be added to reference/constraints.map.rst.inc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I can't find such file. Did you mean reference/constraints/map.rst.inc instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion. That's indeed the file I meant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But let's do that in another PR, which is based on 2.3. For now, only update the newly added code examples

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean updating the code examples, right? And yes, I agree with you then.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure why, but this part is not in the 2.8 branch:
https://github.com/symfony/symfony-docs/blob/2.8/reference/constraints/Iban.rst

any idea @javiereguiluz... confused... 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Upwards branch merging" is done from time to time in a non-formal schedule. Sometimes 2.8 and master are behind the other branchs, but at the end our doc managers always merge upwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you guys 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OskarStark don't rely on GitHub's reStructuredText rendering. It doesn't support lots of the things that we use.


.. _`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