PHP code example of raphhh / trex-parser

1. Go to this page and download the library: Download raphhh/trex-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raphhh / trex-parser example snippets


$code = 'class Foo{}';

$analyzer = new ClassAnalyzer();
$classReflections = $analyzer->getClassReflections($code);

$filePath = 'MyClass.php';

$analyzer = new ClassAnalyzer();
$classReflections = $analyzer->getClassReflectionsFromFile($filePath);

$objects = [];
foreach($classReflections as $className => $classReflection){
    $objects[$className] = $classReflection->newInstance();
}        

$className = new ClassName('\Foo\Qux\Bar');
$className->getBaseName(); //"Bar"

$className = new ClassName('\Foo\Qux\Bar');
$className->getNamespace(); //"Foo\Qux"

$className = new ClassName('\Foo\Qux\Bar');
$className->split(); //["Foo", "Qux", "Bar"]