Weave 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

Liberator Laravel Package

eloquent/liberator

Auto-generate RESTful CRUD controllers, routes, and API resources for Laravel apps from Eloquent models. Liberator helps you scaffold consistent endpoints quickly, reducing boilerplate while keeping generated code editable and aligned with your existing models and conventions.

View on GitHub
Deep Wiki
Context7

No longer maintained

This package is no longer maintained. See this statement for more info.

Liberator

A proxy for circumventing PHP access modifier restrictions.

Installation and documentation

What is Liberator?

Liberator allows access to protected and private methods and properties of objects as if they were marked public. It can do so for both objects and classes (i.e. static methods and properties).

Liberator's primary use is as a testing tool, allowing direct access to methods that would otherwise require complicated test harnesses or mocking to test.

Usage

For objects

Take the following class:

class SeriousBusiness
{
    private function foo($adjective)
    {
        return 'foo is ' . $adjective;
    }

    private $bar = 'mind';
}

Normally there is no way to call foo() or access $bar from outside the SeriousBusiness class, but Liberator allows this to be achieved:

use Eloquent\Liberator\Liberator;

$object = new SeriousBusiness;
$liberator = Liberator::liberate($object);

echo $liberator->foo('not so private...'); // outputs 'foo is not so private...'
echo $liberator->bar . ' = blown';         // outputs 'mind = blown'

For classes

The same concept applies for static methods and properties:

class SeriousBusiness
{
    static private function baz($adjective)
    {
        return 'baz is ' . $adjective;
    }

    static private $qux = 'mind';
}

To access these, a class liberator must be used instead of an object liberator, but they operate in a similar manner:

use Eloquent\Liberator\Liberator;

$liberator = Liberator::liberateClass('SeriousBusiness');

echo $liberator->baz('not so private...'); // outputs 'baz is not so private...'
echo $liberator->qux . ' = blown';         // outputs 'mind = blown'

Alternatively, Liberator can generate a class that can be used statically:

use Eloquent\Liberator\Liberator;

$liberatorClass = Liberator::liberateClassStatic('SeriousBusiness');

echo $liberatorClass::baz('not so private...');      // outputs 'baz is not so private...'
echo $liberatorClass::liberator()->qux . ' = blown'; // outputs 'mind = blown'

Unfortunately, there is (currently) no __getStatic() or __setStatic() in PHP, so accessing static properties in this way is a not as elegant as it could be.

Applications for Liberator

  • Writing white-box style unit tests (testing protected/private methods).
  • Modifying behavior of poorly designed third-party libraries.
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.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route