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

Reflection Laravel Package

fsi/reflection

Optimized Reflection for PHP 5.3 that caches ReflectionClass/Method/Property objects via factory() so they’re never created twice. Returned methods/properties are pre-set accessible for private/protected access; some uncached operations throw exceptions.

View on GitHub
Deep Wiki
Context7

Reflection - Optimized reflection package for PHP 5.3

FSi Reflection component is an extension of built-in reflection classes in PHP 5.3. Some of their methods are rewritten in such way that reflection objects are cached and never created twice for the same class/method/property/function or extension. This is achieved by usage of factory pattern. Some of the methods that cannot be rewriten to use such a cache throw an exception. All ReflectionProperty and ReflectionMethod objects returned from this library are previously set as accessible so they can be used even if they're private or protected.

Setup and autoloading

We highly recommend to use autoloader generated by composer.phar

Adding reflection into composer.json

{
    ... 
    "require": {
        ... 
        "fsi/reflection": "0.9.*" 
        ...
    },
    ...
}

Usage example

The key idea of using this reflection library is not to contruct reflection classes by their constructors but through the factory() methods added to each reflection class. Let's assume we have a class named ClassA:

<?php
class ClassA
{
    private $privateProperty;

    protected $protectedProperty;

    public $publicProperty;

    public function __construct($constructorParam)
    {

    }

    private function privateMethod($paramA, $paramB)
    {
        return $paramA . '-' .$paramB;
    }

    protected function protectedMethod($paramC, $paramD)
    {
        return $paramC . '+' .$paramD;
    }

    public function publicMethod($paramE, $paramF)
    {
        return $paramE . '=' .$paramF;
    }
}

In order to create reflection objects you can:

<?php
use FSi\Reflection\ReflectionClass;
use FSi\Reflection\ReflectionProperty;
use FSi\Reflection\ReflectionMethod;

$reflectionClassA = ReflectionClass::factory('ClassA');
$reflectionPropertyPrivate = $reflectionClassA->getProperty('privateProperty');
$reflectionPropertyPrivate = ReflectionProperty::factory('ClassA', 'privateProperty');
$reflectionMethodPrivate = $reflectionClassA->getMethod('privateMethod');
$reflectionMethodPrivate = ReflectionMethod::factory('ClassA', 'privateMethod');

You must remember that using any reflection class' constructor directly in your code will throw an exception.

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.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky