vedavith/liberator-fork
Composer 安装命令:
composer require vedavith/liberator-fork
包简介
A proxy for circumventing PHP access modifier restrictions.
README 文档
README
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.
composer require vedavith/liberator-fork
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.
vedavith/liberator-fork 适用场景与选型建议
vedavith/liberator-fork 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.96k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「reflection」 「object」 「proxy」 「access」 「modifier」 「private」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vedavith/liberator-fork 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vedavith/liberator-fork 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vedavith/liberator-fork 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
A set of useful PHP classes.
Library emulating the PHP internal reflection using just the tokenized source code.
Runn Me! Value Objects Library
Parse use statements for a reflection object
Laravel SDK mapping data in object
统计信息
- 总下载量: 1.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-09