Skip to content

Commit 96f4cd9

Browse files
committed
minor #20543 [TypeInfo] Add Type::accepts() method (mtarld)
This PR was merged into the 7.3 branch. Discussion ---------- [TypeInfo] Add `Type::accepts()` method Closes #20494 Add documentation about the `Type::accepts()` method. Commits ------- 951f461 [TypeInfo] Add `accepts` method
2 parents 66c0fd4 + 951f461 commit 96f4cd9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: components/type_info.rst

+18-1
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)