Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite00ba57

Browse files
committed
Documented Currency constraint
1 parent5b872d0 commite00ba57

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

‎reference/constraints.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Validation Constraints Reference
4646
constraints/Image
4747

4848
constraints/CardScheme
49+
constraints/Currency
4950
constraints/Luhn
5051
constraints/Iban
5152
constraints/Isbn

‎reference/constraints/Currency.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Currency
2+
========
3+
4+
..versionadded::2.3
5+
This constraint is new in version 2.3.
6+
7+
Validates that a value is a valid `3-letter ISO 4217`_ currency name.
8+
9+
+----------------+---------------------------------------------------------------------------+
10+
| Applies to|:ref:`property or method<validation-property-target>`|
11+
+----------------+---------------------------------------------------------------------------+
12+
| Options| - `message`_|
13+
+----------------+---------------------------------------------------------------------------+
14+
| Class|:class:`Symfony\\Component\\Validator\\Constraints\\Currency`|
15+
+----------------+---------------------------------------------------------------------------+
16+
| Validator|:class:`Symfony\\Component\\Validator\\Constraints\\CurrencyValidator`|
17+
+----------------+---------------------------------------------------------------------------+
18+
19+
Basic Usage
20+
-----------
21+
22+
If you want to ensure that the ``currency`` property of an ``Order`` is a valid
23+
currency, you could do the following:
24+
25+
..configuration-block::
26+
27+
..code-block::yaml
28+
29+
# src/EcommerceBundle/Resources/config/validation.yml
30+
Acme\EcommerceBundle\Entity\Order:
31+
properties:
32+
currency:
33+
-Currency:~
34+
35+
..code-block::php-annotations
36+
37+
// src/Acme/EcommerceBundle/Entity/Order.php
38+
namespace Acme\EcommerceBundle\Entity;
39+
40+
use Symfony\Component\Validator\Constraints as Assert;
41+
42+
class Order
43+
{
44+
/**
45+
* @Assert\Currency
46+
*/
47+
protected $currency;
48+
}
49+
50+
..code-block::xml
51+
52+
<!-- src/Acme/EcommerceBundle/Resources/config/validation.xml-->
53+
<classname="Acme\EcommerceBundle\Entity\Order">
54+
<propertyname="currency">
55+
<constraintname="Currency" />
56+
</property>
57+
</class>
58+
59+
..code-block::php
60+
61+
// src/Acme/EcommerceBundle/Entity/Order.php
62+
namespace Acme\SocialBundle\Entity;
63+
64+
use Symfony\Component\Validator\Mapping\ClassMetadata;
65+
use Symfony\Component\Validator\Constraints as Assert;
66+
67+
class Order
68+
{
69+
public static function loadValidatorMetadata(ClassMetadata $metadata)
70+
{
71+
$metadata->addPropertyConstraint('currency', new Assert\Currency());
72+
}
73+
}
74+
75+
Options
76+
-------
77+
78+
message
79+
~~~~~~~
80+
81+
**type**: ``string`` **default**: ``This value is not a valid currency.``
82+
83+
This is the message that will be shown if the value is not a valid currency.
84+
85+
.. _`3-letter ISO 4217`:http://en.wikipedia.org/wiki/ISO_4217

‎reference/constraints/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Financial and other Number Constraints
6666
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6767

6868
* :doc:`CardScheme</reference/constraints/CardScheme>`
69+
* :doc:`Currency</reference/constraints/Currency>`
6970
* :doc:`Luhn</reference/constraints/Luhn>`
7071
* :doc:`Iban</reference/constraints/Iban>`
7172
* :doc:`Isbn</reference/constraints/Isbn>`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp