Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Better Reflection Laravel Package

roave/better-reflection

Enhanced PHP reflection for static analysis: reflect classes without loading them, from PHP code strings or closures, extract AST from functions/methods, and read type declarations and docblocks. Feature-rich but slower than native reflection.

View on GitHub
Deep Wiki
Context7

How does Better Reflection work?

Reflection Process

1. Reflector

There are 3 "entry points" to begin using Better Reflection:

1.1 The BetterReflection bootstrapper

The first entry point is a minimal service locator provided by the library:

<?php

$betterReflection = new \Roave\BetterReflection\BetterReflection();

$reflector = $betterReflection->reflector();
$class     = $reflector->reflectClass('ClassName');
$function  = $reflector->reflectFunction('functionName');

1.2 The Reflection* static methods

The second entry point is the static constructors on the Reflection* classes:

  • ReflectionClass::createFromName(string $name)
  • ReflectionClass::createFromInstance(object $instance)
  • ReflectionMethod::createFromName(string $className, string $methodName)
  • ReflectionMethod::createFromInstance(object $instance, string $methodName)
  • ReflectionParameter::createFromClassNameAndMethod(string $className, string $methodName, string $parameterName)
  • ReflectionParameter::createFromClassInstanceAndMethod(object $instance, string $methodName, string $parameterName)
  • ReflectionParameter::createFromSpec([string $className, string $methodName], string $parameterName)
  • ReflectionParameter::createFromSpec([object $instance, string $methodName], string $parameterName)
  • ReflectionParameter::createFromSpec(string $functionName, string $parameterName)
  • ReflectionProperty::createFromName(string $className, string $propertyName)
  • ReflectionProperty::createFromInstance(object $instance, string $propertyName)

Using these is documented in a bit more detail within the Usage documentation. These methods use a default set of pre-configured Source Locators:

  • PhpInternalSourceLocator
  • EvaledCodeSourceLocator
  • AutoloadSourceLocator

1.3 Manually instantiating *Reflector objects

The second entry point is the Reflector objects, to which you must provide specific instructions on how Better Reflection is to find code, in the form of the Source Locators.

2. Source Locators

Source Locators are instructions on finding source code for Better Reflection to examine to create the reflections. A detailed list of each source locator and how they work can be found in the Usage documentation - Source Locators section.

3. PhpParser

Using Nikita Popov's PHP-Parser library, the source code located by the Source Locators is loaded into an AST format, forming the core foundation on which the reflection is based. Using the AST, we are able to examine the structure of the code, finding out things like what methods and properties are on a class, and what parameters belong to a method or function for example.

4. Reflection

Internally to the Reflection* classes in Better Reflection, we cleverly hold the AST as the main property. All reflection, analysis and modification is done directly to this AST. Therefore it is possible to unparse or export the AST back into code.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope