Search by

webservco / reflection

ariademur

A PHP component/library. Small reflection helpers for inspecting a class and its constructor parameters.

Package info

github.com/webservco/reflection

Homepage

pkg:composer/webservco/reflection

Statistics

Installs: 89

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v2.3.0 2026-10-11 16:34 UTC

This package is auto-updated.

Last update: 2026-10-11 16:45:40 UTC


README

A PHP component/library. Please see webservco/sandbox for an example project using these types of components.

Small reflection helpers for inspecting a class and its constructor parameters.

  • Related: webservco/controller (checks controller constructors with it)

Installation

composer require webservco/reflection

Usage

use WebServCo\Reflection\Factory\ReflectionClassFactory;
use WebServCo\Reflection\Service\ReflectionService;

// \WebServCo\Reflection\Contract\ReflectionServiceInterface
$reflectionService = new ReflectionService(new ReflectionClassFactory());

// Type of the second constructor parameter. Indexes start at 1.
$type = $reflectionService->getConstructorParameterTypeAtIndex(TestController::class, 2);

// \ReflectionClass
$reflectionClass = $reflectionService->getReflectionClass(TestController::class);

Contracts

Interface Implementation Purpose
Contract\ReflectionServiceInterface Service\ReflectionService Class, constructor, and constructor parameters by index.
Contract\ReflectionClassFactoryInterface Factory\ReflectionClassFactory Creates ReflectionClass objects.

Namespaces are relative to WebServCo\Reflection\.

Notes

The service caches each ReflectionClass it creates and reuses it for the same class. Parameter indexes start at 1, like the parameter's position in the code. A missing constructor or parameter throws an exception instead of returning null, and so does a union or intersection type.

Development

# Start project.
ddev start
# Install dependencies.
ddev c u
# Run all validations.
ddev c c
# Run unit tests.
ddev c test:dox

License

MIT