marcin-orlowski/lockpick 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marcin-orlowski/lockpick

最新稳定版本:1.4.0

Composer 安装命令:

composer require marcin-orlowski/lockpick

包简介

Helps accessing protected/private members/consts of foreign objects.

README 文档

README

 ▄█        ▄██████▄   ▄████████    ▄█   ▄█▄    ▄███████▄  ▄█   ▄████████    ▄█   ▄█▄
███       ███    ███ ███    ███   ███ ▄███▀   ███    ███ ███  ███    ███   ███ ▄███▀
███       ███    ███ ███    █▀    ███▐██▀     ███    ███ ███▌ ███    █▀    ███▐██▀  
███       ███    ███ ███         ▄█████▀      ███    ███ ███▌ ███         ▄█████▀  
███       ███    ███ ███        ▀▀█████▄    ▀█████████▀  ███▌ ███        ▀▀█████▄  
███       ███    ███ ███    █▄    ███▐██▄     ███        ███  ███    █▄    ███▐██▄  
███▌    ▄ ███    ███ ███    ███   ███ ▀███▄   ███        ███  ███    ███   ███ ▀███▄
█████▄▄██  ▀██████▀  ████████▀    ███   ▀█▀  ▄████▀      █▀   ████████▀    ███   ▀█▀
▀                                 ▀                                        ▀  

Lockpick

Latest Stable Version License

Collection of PHP helper methods allowing easy access to protected or private properties and constants of objects or classes as well as allowing to call such non-public methods. This library is mostly useful while creating unit tests for your code.

Installation

composer require marcin-orlowski/lockpick

Usage

As all methods come as set of static methods, so you just need to add related use to your code class and all methods should be simply available via static reference Lockpick::...:

use Lockpick\Lockpick;
use PHPUnit\Framework\Assert;

$obj = new Stronghold();
$actual = Lockpick::call($obj, 'openSessame', [ 'abracadabra' ]);
Assert::assertEquals($expected, $actual);
...

Available methods

Notes:

  • The $clsOrObj parameter can be either object or class name (string)
  • The Lockpick::call() argument $args now accepts single parameters w/o array wrapping (so call(..., $arg1) is now valid and equivalent to call(..., [ $arg1 ])) as it will be automatically wrapped under the hood.
  • If you want to actually pass array as single argument to called function you must wrap it into another array, like this: call(..., [[ $arg1, $arg2 ]]). Default is empty array which means no arguments will be passed to the called method.
Method Description
call($clsOrObj, string $methodName, mixed $args): mixed Calls object/class protected/private method
getProperty($clsOrObj, string $name): mixed Returns value of protected/private property
setProperty($clsOrObj, string $name, mixed $value): mixed Sets value of protected/private property
getConstant($clsOrObj, string $name): mixed Returns value of protected/private constant
getMethodVisibility($clsOrObj, string $name): Visibility Returns visibility of class method
getPropertyVisibility($clsOrObj, string $name): Visibility Returns visibility of class property
getConstantVisibility($clsOrObj, string $name): Visibility Returns visibility of class constant

License

统计信息

  • 总下载量: 3.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-13