Modern DOM library written in PHP for HTML documents
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

<?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;
class Reflection {
public static function createFromProtectedConstructor(string $className, ...$arguments): mixed {
$reflector = new \ReflectionClass($className);
$result = $reflector->newInstanceWithoutConstructor();
$constructor = new \ReflectionMethod($result, '__construct');
$constructor->setAccessible(true);
$constructor->invoke($result, ...$arguments);
return $result;
}
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);
}
public static function setProtectedProperty(mixed $instance, string $propertyName, mixed $value): void {
$reflector = new \ReflectionClass($instance::class);
$property = new \ReflectionProperty($instance, $propertyName);
$property->setAccessible(true);
$property->setValue($instance, $value);
}
}