Skip to content

Commit 951f461

Browse files
committed
[TypeInfo] Add accepts method
1 parent e4f8ff8 commit 951f461

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

components/type_info.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Advanced Usages
114114
The TypeInfo component provides various methods to manipulate and check types,
115115
depending on your needs.
116116

117-
Checking a **simple type**::
117+
**Identify** a type::
118118

119119
// define a simple integer type
120120
$type = Type::int();
@@ -141,6 +141,23 @@ Checking a **simple type**::
141141
$type->isIdentifiedBy(DummyParent::class); // true
142142
$type->isIdentifiedBy(DummyInterface::class); // true
143143

144+
Checking if a type **accepts a value**::
145+
146+
$type = Type::int();
147+
// check if the type accepts a given value
148+
$type->accepts(123); // true
149+
$type->accepts('z'); // false
150+
151+
$type = Type::union(Type::string(), Type::int());
152+
// now the second check is true because the union type accepts either a int and a string value
153+
$type->accepts(123); // true
154+
$type->accepts('z'); // true
155+
156+
.. versionadded:: 7.3
157+
158+
The :method:`Symfony\\Component\\TypeInfo\\Type::accepts`
159+
method was introduced in Symfony 7.3.
160+
144161
Using callables for **complex checks**::
145162

146163
class Foo

0 commit comments

Comments
 (0)