Skip to content

Commit 6a9d052

Browse files
committed
[TypeInfo] Add accepts method
1 parent e4f8ff8 commit 6a9d052

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/type_info.rst

Lines changed: 13 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,18 @@ 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+
144156
Using callables for **complex checks**::
145157

146158
class Foo

0 commit comments

Comments
 (0)