PHP code example of entelisteam / lbaf-reflection

1. Go to this page and download the library: Download entelisteam/lbaf-reflection 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/ */

    

entelisteam / lbaf-reflection example snippets


use EntelisTeam\Lbaf\Reflection\TypeCaster;

TypeCaster::cast('42', 'int');        // 42
TypeCaster::cast('1', 'bool');        // true
TypeCaster::cast('true', 'bool');     // true (case-insensitive)
TypeCaster::cast(3.14, 'string');     // "3.14"

use EntelisTeam\Lbaf\Reflection\EnumHelper;

enum Status: string { case Active = 'active'; case Inactive = 'inactive'; }
EnumHelper::formatEnumValue(Status::class, 'active'); // Status::Active

enum Priority { case Low; case High; }
EnumHelper::formatEnumValue(Priority::class, 'Low');  // Priority::Low

use EntelisTeam\Lbaf\Reflection\ClassNameHelper;

ClassNameHelper::getShortClassName(\App\Foo\Bar::class); // "Bar"

use EntelisTeam\Lbaf\Reflection\MethodParameters;

$method = new ReflectionMethod(MyController::class, 'handle');

MethodParameters::getReflection($method, 'id');   // ReflectionParameter for $id
MethodParameters::getTypeName($method, 'id');     // "int" (or "mixed" if untyped)
MethodParameters::getList($method);               // ['id' => ReflectionParameter, ...]