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

Commitfcae3cd

Browse files
sprainweaverryan
authored andcommitted
Updated ISBN validator
1 parent1efcdba commitfcae3cd

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

‎reference/constraints/Isbn.rst‎

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ Isbn
44
..versionadded::2.3
55
The Isbn constraint was introduced in Symfony 2.3.
66

7+
..caution::
8+
9+
The ``isbn10`` and ``isbn13`` options are deprecated since Symfony 2.5
10+
and will be removed in Symfony 3.0. Use the ``type`` option instead.
11+
Furthermore, when using the ``type`` option, lowercase characters are no
12+
longer supported starting in Symfony 2.5, as they are not allowed in ISBNs.
13+
714
This constraint validates that an `International Standard Book Number (ISBN)`_
8-
is either a valid ISBN-10,a valid ISBN-13 or both.
15+
is either a valid ISBN-10 ora valid ISBN-13.
916

1017
+----------------+----------------------------------------------------------------------+
1118
| Applies to|:ref:`property or method<validation-property-target>`|
1219
+----------------+----------------------------------------------------------------------+
13-
| Options| - `isbn10`_|
14-
|| - `isbn13`_|
20+
| Options| - `type`_|
21+
|| - `message`_|
1522
|| - `isbn10Message`_|
1623
|| - `isbn13Message`_|
1724
|| - `bothIsbnMessage`_|
@@ -25,7 +32,7 @@ Basic Usage
2532
-----------
2633

2734
To use the ``Isbn`` validator, simply apply it to a property or method
28-
on an object that will containa ISBN number.
35+
on an object that will containan ISBN.
2936

3037
..configuration-block::
3138

@@ -36,9 +43,8 @@ on an object that will contain a ISBN number.
3643
properties:
3744
isbn:
3845
-Isbn:
39-
isbn10:true
40-
isbn13:true
41-
bothIsbnMessage:This value is neither a valid ISBN-10 nor a valid ISBN-13.
46+
type:isbn10
47+
message:This value is not valid.
4248
4349
..code-block::php-annotations
4450
@@ -49,9 +55,8 @@ on an object that will contain a ISBN number.
4955
{
5056
/**
5157
* @Assert\Isbn(
52-
* isbn10 = true,
53-
* isbn13 = true,
54-
* bothIsbnMessage = "This value is neither a valid ISBN-10 nor a valid ISBN-13."
58+
* type = isbn10,
59+
* message: This value is not valid.
5560
* )
5661
*/
5762
protected $isbn;
@@ -63,9 +68,8 @@ on an object that will contain a ISBN number.
6368
<classname="Acme\BookcaseBundle\Entity\Book">
6469
<propertyname="isbn">
6570
<constraintname="Isbn">
66-
<optionname="isbn10">true</option>
67-
<optionname="isbn13">true</option>
68-
<optionname="bothIsbnMessage">This value is neither a valid ISBN-10 nor a valid ISBN-13.</option>
71+
<optionname="type">isbn10</option>
72+
<optionname="message">This value is not valid.</option>
6973
</constraint>
7074
</property>
7175
</class>
@@ -85,54 +89,53 @@ on an object that will contain a ISBN number.
8589
public static function loadValidatorMetadata(ClassMetadata $metadata)
8690
{
8791
$metadata->addPropertyConstraint('isbn', new Assert\Isbn(array(
88-
'isbn10' => true,
89-
'isbn13' => true,
90-
'bothIsbnMessage' => 'This value is neither a valid ISBN-10 nor a valid ISBN-13.'
92+
'type' => isbn10,
93+
'message' => 'This value is not valid.'
9194
)));
9295
}
9396
}
9497
9598
Available Options
9699
-----------------
97100

98-
isbn10
99-
~~~~~~
101+
type
102+
~~~~
100103

101-
**type**: ``boolean``
104+
**type**: ``string`` **default**: ``null``
102105

103-
If this required option is setto``true`` the constraint will check if the
104-
code is a valid ISBN-10 code.
106+
The type of ISBNtovalidate against.
107+
Valid values are ``isbn10``, ``isbn13`` and ``null`` to accept any kind of ISBN.
105108

106-
isbn13
107-
~~~~~~
109+
message
110+
~~~~~~~
108111

109-
**type**: ``boolean``
112+
**type**: ``string`` **default**: ``null``
110113

111-
If this required option is set to ``true``theconstraint will check if the
112-
code is a valid ISBN-13 code.
114+
The message that will be shown ifthevalue is not valid.
115+
If not ``null``, this message has priority over all the other messages.
113116

114117
isbn10Message
115118
~~~~~~~~~~~~~
116119

117120
**type**: ``string`` **default**: ``This value is not a valid ISBN-10.``
118121

119-
The message that will be shown if the `isbn10`_ option istrue and the given
122+
The message that will be shown if the `type`_ option is``isbn10`` and the given
120123
value does not pass the ISBN-10 check.
121124

122125
isbn13Message
123126
~~~~~~~~~~~~~
124127

125128
**type**: ``string`` **default**: ``This value is not a valid ISBN-13.``
126129

127-
The message that will be shown if the `isbn13`_ option istrue and the given
130+
The message that will be shown if the `type`_ option is``isbn13`` and the given
128131
value does not pass the ISBN-13 check.
129132

130133
bothIsbnMessage
131134
~~~~~~~~~~~~~~~
132135

133136
**type**: ``string`` **default**: ``This value is neither a valid ISBN-10 nor a valid ISBN-13.``
134137

135-
The message that will be shown ifboththe `isbn10`_and `isbn13`_ options
136-
are true and the givenvalue does not passthe ISBN-13 northe ISBN-13 check.
138+
The message that will be shown if the `type`_option is ``null`` and the given
139+
value does not passany ofthe ISBN checks.
137140

138141
.. _`International Standard Book Number (ISBN)`:http://en.wikipedia.org/wiki/Isbn

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp