darling/php-reflection-utilities

A collection of php classes that can be used to aide in reflection with PHP

v1.1.2 2023-11-22 22:27 UTC

README

A collection of php classes that can be used to aide in reflection with PHP.

This library makes use of the following libraries:

Darling\PHPUnitTestUtilities

Darling\PHPTextTypes

Overview

Installation

composer require darling/php-reflection-utilities

Classes

The following classes are provided by the PHPReflectionUtilities library.

These classes can be used as is, or extended.

Darling\PHPReflectionUtilities\classes\utilities\Reflection

A Reflection can be used to get information about a reflected class or object instance.

For example:

<?php

require __DIR__ . '/vendor/autoload.php';

use \Darling\PHPReflectionUtilities\classes\utilities\Reflection;
use \Darling\PHPTextTypes\classes\strings\ClassString;

$reflection = new Reflection(new ClassString(Reflection::class));

var_dump($reflection->type()->__toString());

var_dump($reflection->methodNames(Reflection::IS_PUBLIC));

var_dump($reflection->methodParameterNames('methodParameterNames'));

var_dump($reflection->methodParameterTypes('methodParameterTypes'));

var_dump($reflection->propertyNames(Reflection::IS_PRIVATE));

var_dump($reflection->propertyTypes(Reflection::IS_PRIVATE));

var_dump($reflection->type());

Darling\PHPReflectionUtilities\classes\utilities\ObjectReflection

An ObjectReflection is a Reflection that specifically reflects an object instance.

For example:

<?php

require __DIR__ . '/vendor/autoload.php';

use \Darling\PHPReflectionUtilities\classes\utilities\ObjectReflection;

$instanceToReflect = new ArrayIterator(array('test1', 'test2', 'test3'));

$objectReflection = new ObjectReflection($instanceToReflect);

var_dump($objectReflection->propertyValues());

var_dump($objectReflection->methodNames());