Skip to content

Commit

Permalink
Improved README example
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Sep 21, 2023
1 parent 9054387 commit dc0ebe0
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ Without stubs native PHP classes are reflected via native reflector that does no
namespace My\Awesome\App;

use Typhoon\Reflection\TyphoonReflector;
use Typhoon\Type\types;

/**
* @template T
*/
final readonly class Article
{
/**
* @param non-empty-list<non-empty-string> $tags
* @param T $data
*/
public function __construct(
private array $tags,
public mixed $data,
) {}
}

Expand All @@ -38,17 +44,22 @@ var_dump($articleReflection->getNamespaceName()); // 'My\Awesome\App'
$tagsReflection = $articleReflection->getProperty('tags');

var_dump($tagsReflection->isReadOnly()); // true

var_dump($tagsReflection->getType()->getNative());
// class Typhoon\Type\ArrayType (2) {
// $keyType => enum Typhoon\Type\ArrayKeyType;
// $valueType => enum Typhoon\Type\MixedType;
// }

var_dump($tagsReflection->getType()->getPhpDoc());
// class Typhoon\Type\NonEmptyListType (1) {
// $valueType => enum Typhoon\Type\NonEmptyStringType;
// }
var_dump($tagsReflection->getType()->getNative()); // object representation of array<array-key, mixed> type
var_dump($tagsReflection->getType()->getPhpDoc()); // object representation of non-empty-list<non-empty-string> type

$dataReflection = $articleReflection->getProperty('data');

var_dump($dataReflection->isPublic()); // true
var_dump($dataReflection->getType()->getNative()); // object representation of mixed type
var_dump($dataReflection->getType()->getPhpDoc()); // object representation of T:Article type

var_dump(
$articleReflection
->withResolvedTemplates(['T' => types::nonEmptyString])
->getProperty('data')
->getType()
->getPhpDoc(),
); // object representation of non-empty-string type
```

## Compatibility
Expand Down

0 comments on commit dc0ebe0

Please sign in to comment.