GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - php-type-language/reader: [READ ONLY] 📰 Library for reading TypeLang AST nodes from types exposed by PHP Reflection objects

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

PHP 8.1+ Latest Stable Version Latest Unstable Version License MIT


Converts native PHP types exposed by Reflection objects into TypeLang TypeLang\Type\* AST nodes.

Given a ReflectionClassConstant, ReflectionProperty, ReflectionParameter or ReflectionFunctionAbstract, it returns the matching type node (or null when no type is declared).

Full documentation is available at typelang.dev.

Installation

Install the package via Composer:

composer require type-lang/reader

Requirements:

  • PHP 8.1+

Usage

TypeLang\Reader\ReflectionReader exposes a find*Type() method for every kind of Reflection object:

$reader = new TypeLang\Reader\ReflectionReader();

$node = $reader->findFunctionType(
    new ReflectionFunction(function (): void {}),
);

var_dump($node);
// object(TypeLang\Type\NamedTypeNode) {
//   ["name"] => "void"
//   ...
// }

Combine it with type-lang/printer to dump the resolved types of a whole class:

$class = new ReflectionClass(Path\To\Example::class);
$reader = new TypeLang\Reader\ReflectionReader();
$printer = new TypeLang\Printer\PrettyTypePrinter();

foreach ($class->getProperties() as $property) {
    if ($type = $reader->findPropertyType($property)) {
        echo "property {$property->name}: {$printer->print($type)}\n";
    }
}

foreach ($class->getMethods() as $method) {
    if ($type = $reader->findFunctionType($method)) {
        echo "method {$method->name}(): {$printer->print($type)}\n";
    }
}

Constants (findConstantType()) and parameters (findParameterType()) are read the same way.

About

[READ ONLY] 📰 Library for reading TypeLang AST nodes from types exposed by PHP Reflection objects

typelang.dev

Topics

astconverterphpreaderreflectiontypes

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

6 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.