-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[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
Changes from all commits
238e201
8b04d1b
6726882
51126fa
b69f48d
f952885
8ca96a4
0543699
6bbfaf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: any idea @javiereguiluz... confused... 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you guys 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.