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

Trex Reflection Laravel Package

raphhh/trex-reflection

Lightweight PHP reflection helper focused on analyzing types, classes and members with a cleaner API than native Reflection. Great for tooling, static analysis, and code generation tasks—extract signatures, docblocks, visibility, and metadata with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

Getting Started

This package provides lightweight, utility-focused reflection helpers—ideal for inspecting classes, methods, properties, and attributes (annotations) in a more expressive, chainable way. Since it hasn’t been updated since 2020, assume PHP ≤8.0 compatibility (no native attributes support for newer PHP). Start by installing via Composer:

composer require raphhh/trex-reflection

The entry point is typically \Trex\Reflection\ReflectionHelper, offering static methods like forClass(), forMethod(), forProperty() to build fluent reflection objects. Your first use case might be safely retrieving docblock annotations (e.g., @var, custom @SWG\Property) without writing preg_match or ReflectionMethod::getDocComment() boilerplate.

Implementation Patterns

  • Fluent inspection chains: Use ReflectionHelper::forClass(MyClass::class)->getMethods()->filterByVisibility('public') to chain operations.
  • Annotation extraction: Extract metadata like @Route("/api/users") from docblocks using getMethodDocblockAnnotation('route', $method)—useful for custom routing, serialization, or validation layers.
  • Property type inference: Where native types aren’t available (PHP < 7.4), infer type from @var annotations:
    $type = ReflectionHelper::forProperty($object, 'name')->getDocblockType();
    
  • Integration in macros/IDE-like tools: Embed into service containers or factories to generate DTO schemas, hydrators, or API documentation generators without external dependencies.

Gotchas and Tips

  • No PSR-19 or modern attribute support: Won’t parse PHP 8 native attributes—use PhpDocParser or nikic/php-parser if you need modern metadata handling.
  • Case sensitivity: Method/property name lookups may be case-sensitive depending on underlying reflection; ensure consistent casing in code and annotations.
  • Static analysis risk: PHPDoc types (@var, @param) are not verified—invalid or missing tags return null or defaults silently. Always validate assumptions with hasDocblock() first.
  • Fork for modern PHP: If targeting PHP ≥8.0, consider branching and adding support for native attributes—e.g., getMethodAttributes() as a wrapper around ReflectionMethod::getAttributes().
  • Performance: Avoid calling heavy methods (e.g., forClass()->getPropertiesWithDocblocks()) in hot loops—cache results or delegate to builder classes.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport