Download the PHP package vedavith/liberator-fork without Composer
On this page you can find all versions of the php package vedavith/liberator-fork. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vedavith/liberator-fork
More information about vedavith/liberator-fork
Files in vedavith/liberator-fork
Package liberator-fork
Short Description A proxy for circumventing PHP access modifier restrictions.
License MIT
Homepage https://github.com/vedavith/liberator-fork
Informations about the package liberator-fork
Liberator
A proxy for circumventing PHP access modifier restrictions.
- This is a maintained fork of the unmaintained
eloquent/liberator. Package name isvedavith/liberator-forkand it targets PHP 8.2+ with PHPUnit 11/12 for development.- This is a maintained fork of [eloquent/liberator] originally created by Erin Millard.
Installation and documentation
- Available as Composer package vedavith/liberator-fork: (maintained fork of
eloquent/liberator). - Requires PHP 8.2 or later.
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:
Normally there is no way to call foo() or access $bar from outside the
SeriousBusiness class, but Liberator allows this to be achieved:
For classes
The same concept applies for static methods and properties:
To access these, a class liberator must be used instead of an object liberator, but they operate in a similar manner:
Alternatively, Liberator can generate a class that can be used statically:
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.