Download the PHP package eloquent/liberator without Composer
On this page you can find all versions of the php package eloquent/liberator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eloquent/liberator
More information about eloquent/liberator
Files in eloquent/liberator
Package liberator
Short Description A proxy for circumventing PHP access modifier restrictions.
License MIT
Homepage https://github.com/eloquent/liberator
Informations about the package liberator
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
- Available as Composer package eloquent/liberator.
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.