Skip to content

Commit 9afd7fb

Browse files
committed
[TypeInfo] Fix outdated README
1 parent 31f22b8 commit 9afd7fb

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/Symfony/Component/TypeInfo/README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ TypeInfo Component
33

44
The TypeInfo component extracts PHP types information.
55

6-
**This Component is experimental**.
7-
[Experimental features](https://symfony.com/doc/current/contributing/code/experimental.html)
8-
are not covered by Symfony's
9-
[Backward Compatibility Promise](https://symfony.com/doc/current/contributing/code/bc.html).
10-
116
Getting Started
127
---------------
138

@@ -20,6 +15,7 @@ composer require phpstan/phpdoc-parser # to support raw string resolving
2015
<?php
2116

2217
use Symfony\Component\TypeInfo\Type;
18+
use Symfony\Component\TypeInfo\TypeIdentifier;
2319
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver;
2420

2521
// Instantiate a new resolver
@@ -32,10 +28,21 @@ $typeResolver->resolve('bool'); // returns a "bool" Type instance
3228
// Types can be instantiated thanks to static factories
3329
$type = Type::list(Type::nullable(Type::bool()));
3430

35-
// Type instances have several helper methods
36-
$type->getBaseType(); // returns an "array" Type instance
37-
$type->getCollectionKeyType(); // returns an "int" Type instance
38-
$type->getCollectionValueType()->isNullable(); // returns true
31+
// Type classes has their specific methods
32+
Type::object(FooClass::class)->getClassName();
33+
Type::enum(FooEnum::class, Type::int())->getBackingType();
34+
Type::list(Type::int())->isList();
35+
36+
// Every type can be cast to string
37+
(string) Type::generic(Type::object(Collection::class), Type::int()) // returns "Collection<int>"
38+
39+
// You can check that a type (or one of its wrapped/composed parts) is identified by one of some identifiers.
40+
$type->isIdentifiedBy(Foo::class, Bar::class);
41+
$type->isIdentifiedBy(TypeIdentifier::OBJECT);
42+
$type->isIdentifiedBy('float');
43+
44+
// You can also check that a type satifies specific conditions
45+
$type->isSatisfiedBy(fn (Type $type): bool => !$type->isNullable() && $type->isIdentifiedBy(TypeIdentifier::INT));
3946
```
4047

4148
Resources

0 commit comments

Comments
 (0)