Skip to content

Commit 62c059b

Browse files
committed
patch: modification de l'invader
1 parent 9f53aeb commit 62c059b

1 file changed

Lines changed: 4 additions & 27 deletions

File tree

Support/Invader.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace BlitzPHP\Utilities\Support;
1313

14-
use ReflectionClass;
15-
1614
/**
1715
* Cette classe offre une fonction d'envahissement qui vous permettra de lire/écrire les propriétés privées d'un objet.
1816
* Elle vous permettra également de définir, d'obtenir et d'appeler des méthodes privées.
@@ -25,20 +23,11 @@
2523
*/
2624
class Invader
2725
{
28-
/**
29-
* @var T
30-
*/
31-
public object $obj;
32-
33-
public ReflectionClass $reflected;
34-
3526
/**
3627
* @param T $obj
3728
*/
38-
public function __construct(object $obj)
29+
public function __construct(public object $obj)
3930
{
40-
$this->obj = $obj;
41-
$this->reflected = new ReflectionClass($obj);
4231
}
4332

4433
/**
@@ -53,28 +42,16 @@ public static function make(object $obj)
5342

5443
public function __get(string $name): mixed
5544
{
56-
$property = $this->reflected->getProperty($name);
57-
58-
$property->setAccessible(true);
59-
60-
return $property->getValue($this->obj);
45+
return (fn () => $this->{$name})->call($this->obj);
6146
}
6247

6348
public function __set(string $name, mixed $value): void
6449
{
65-
$property = $this->reflected->getProperty($name);
66-
67-
$property->setAccessible(true);
68-
69-
$property->setValue($this->obj, $value);
50+
(fn () => $this->{$name} = $value)->call($this->obj);
7051
}
7152

7253
public function __call(string $name, array $params = []): mixed
7354
{
74-
$method = $this->reflected->getMethod($name);
75-
76-
$method->setAccessible(true);
77-
78-
return $method->invoke($this->obj, ...$params);
55+
return (fn () => $this->{$name}(...$params))->call($this->obj);
7956
}
8057
}

0 commit comments

Comments
 (0)