johnpbloch/invade

从 Livewire 中复制的 invade 函数

v1.0.0 2022-02-11 16:53 UTC

This package is auto-updated.

Last update: 2024-09-11 23:18:49 UTC


README

Invade 是一个从 Laravel 的 Livewire 中无耻剽窃的工具库。使用 invade(),你可以轻松访问类的所有私有和受保护属性和方法。这并不是革命性的或复杂的,但它非常方便。我创建这个包有两个原因

  1. 我想将这个函数作为开发依赖项要求,因为我不喜欢这个函数在非开发安装中可用
  2. 我想在非 Laravel 代码库中使用它

安装

composer require --dev johnpbloch/invade

用法

# supposing there is a class like this:
class StateManager {
    private $dataYouAreDebugging = [];
    /* ... */
}

# and supposing you have an instance of StateManager and you need to see that data:
/** @var StateManager $instance */
\var_dump(\invade($instance)->dataYouAreDebugging);

invade() 还将赋予你设置非公共属性和调用非公共方法的能力。