Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -3,7 +3,7 @@
/*
* This file is part of Psy Shell.
*
* (c) 2012-2022 Justin Hileman
* (c) 2012-2023 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -27,7 +27,7 @@ class Sudo
*/
public static function fetchProperty($object, string $property)
{
$prop = static::getProperty(new \ReflectionObject($object), $property);
$prop = self::getProperty(new \ReflectionObject($object), $property);
return $prop->getValue($object);
}
@@ -43,7 +43,7 @@ class Sudo
*/
public static function assignProperty($object, string $property, $value)
{
$prop = static::getProperty(new \ReflectionObject($object), $property);
$prop = self::getProperty(new \ReflectionObject($object), $property);
$prop->setValue($object, $value);
return $value;
@@ -58,12 +58,8 @@ class Sudo
*
* @return mixed
*/
public static function callMethod($object, string $method, $args = null)
public static function callMethod($object, string $method, ...$args)
{
$args = \func_get_args();
$object = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionObject($object);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
@@ -81,7 +77,7 @@ class Sudo
*/
public static function fetchStaticProperty($class, string $property)
{
$prop = static::getProperty(new \ReflectionClass($class), $property);
$prop = self::getProperty(new \ReflectionClass($class), $property);
$prop->setAccessible(true);
return $prop->getValue();
@@ -98,8 +94,14 @@ class Sudo
*/
public static function assignStaticProperty($class, string $property, $value)
{
$prop = static::getProperty(new \ReflectionClass($class), $property);
$prop->setValue($value);
$prop = self::getProperty(new \ReflectionClass($class), $property);
$refl = $prop->getDeclaringClass();
if (\method_exists($refl, 'setStaticPropertyValue')) {
$refl->setStaticPropertyValue($property, $value);
} else {
$prop->setValue($value);
}
return $value;
}
@@ -113,12 +115,8 @@ class Sudo
*
* @return mixed
*/
public static function callStatic($class, string $method, $args = null)
public static function callStatic($class, string $method, ...$args)
{
$args = \func_get_args();
$class = \array_shift($args);
$method = \array_shift($args);
$refl = new \ReflectionClass($class);
$reflMethod = $refl->getMethod($method);
$reflMethod->setAccessible(true);
@@ -138,6 +136,11 @@ class Sudo
{
$refl = new \ReflectionClass($class);
// Special case the ::class magic constant, because `getConstant` does the wrong thing here.
if ($const === 'class') {
return $refl->getName();
}
do {
if ($refl->hasConstant($const)) {
return $refl->getConstant($const);
@@ -149,6 +152,24 @@ class Sudo
return false;
}
/**
* Construct an instance of a class, bypassing private constructors.
*
* @param string $class class name
* @param mixed $args...
*/
public static function newInstance(string $class, ...$args)
{
$refl = new \ReflectionClass($class);
$instance = $refl->newInstanceWithoutConstructor();
$constructor = $refl->getConstructor();
$constructor->setAccessible(true);
$constructor->invokeArgs($instance, $args);
return $instance;
}
/**
* Get a ReflectionProperty from an object (or its parent classes).
*