PHP code example of codememory / reflection

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

    

codememory / reflection example snippets




use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Codememory\Reflection\ReflectorManager;
use Attribute;

// Let's create a cache adapter
// Read more about the cache in the documentation https://symfony.com/doc/current/components/cache.html
$cache = new FilesystemAdapter('codememory', directory: 'cache');

// Create a reflection manager
$rm = new ReflectorManager($cache, false); // The second argument specifies the application environment (isDev), dev mode is enabled by default

#[Attribute(Attribute::TARGET_PROPERTY)]
final class MyAttribute {
    public function __construct(
        public readonly mixed $value
    ) {}
}

// Let's create a class from which we will receive information
class First {
    private ?string $name = null;
    
    #[MyAttribute('example')]
    private ?string $surname = null;
}

// Get class reflection
$classReflector = $rm->getReflector(First::class); // Codememory\Reflection\Reflectors\ClassReflector

echo $classReflector->getName(); // First