You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
3 years ago
|
<?php
|
||
|
/**
|
||
|
* @license MIT
|
||
|
* Copyright 2017 Dustin Wilson, J. King, et al.
|
||
|
* See LICENSE and AUTHORS files for details
|
||
|
*/
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
namespace MensBeam\HTML\DOM\InnerNode;
|
||
|
|
||
|
|
||
3 years ago
|
class Reflection {
|
||
3 years ago
|
public static function createFromProtectedConstructor(string $className, ...$arguments): mixed {
|
||
3 years ago
|
$reflector = new \ReflectionClass($className);
|
||
3 years ago
|
$result = $reflector->newInstanceWithoutConstructor();
|
||
|
$constructor = new \ReflectionMethod($result, '__construct');
|
||
|
$constructor->setAccessible(true);
|
||
|
$constructor->invoke($result, ...$arguments);
|
||
|
return $result;
|
||
|
}
|
||
3 years ago
|
|
||
|
public static function getProtectedProperty(mixed $instance, string $propertyName): mixed {
|
||
|
$reflector = new \ReflectionClass($instance::class);
|
||
|
$property = new \ReflectionProperty($instance, $propertyName);
|
||
|
$property->setAccessible(true);
|
||
|
return $property->getValue($instance);
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
public static function setProtectedProperty(mixed $instance, string $propertyName, mixed $value): void {
|
||
3 years ago
|
$reflector = new \ReflectionClass($instance::class);
|
||
|
$property = new \ReflectionProperty($instance, $propertyName);
|
||
|
$property->setAccessible(true);
|
||
3 years ago
|
$property->setValue($instance, $value);
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|