mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
Merge branch 'MDL-70319-311' of git://github.com/ilyatregubov/moodle into MOODLE_311_STABLE
This commit is contained in:
commit
e4527dc68f
2 changed files with 18 additions and 7 deletions
|
@ -37,6 +37,14 @@ abstract class Enum implements \JsonSerializable
|
|||
*/
|
||||
protected static $cache = [];
|
||||
|
||||
/**
|
||||
* Cache of instances of the Enum class
|
||||
*
|
||||
* @var array
|
||||
* @psalm-var array<class-string, array<string, static>>
|
||||
*/
|
||||
protected static $instances = [];
|
||||
|
||||
/**
|
||||
* Creates a new value of some type
|
||||
*
|
||||
|
@ -211,17 +219,20 @@ abstract class Enum implements \JsonSerializable
|
|||
* @param array $arguments
|
||||
*
|
||||
* @return static
|
||||
* @psalm-pure
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
$array = static::toArray();
|
||||
if (isset($array[$name]) || \array_key_exists($name, $array)) {
|
||||
return new static($array[$name]);
|
||||
$class = static::class;
|
||||
if (!isset(self::$instances[$class][$name])) {
|
||||
$array = static::toArray();
|
||||
if (!isset($array[$name]) && !\array_key_exists($name, $array)) {
|
||||
$message = "No static method or enum constant '$name' in class " . static::class;
|
||||
throw new \BadMethodCallException($message);
|
||||
}
|
||||
return self::$instances[$class][$name] = new static($array[$name]);
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException("No static method or enum constant '$name' in class " . static::class);
|
||||
return clone self::$instances[$class][$name];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -349,7 +349,7 @@
|
|||
<location>php-enum</location>
|
||||
<name>php-enum</name>
|
||||
<license>MIT</license>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.7</version>
|
||||
</library>
|
||||
<library>
|
||||
<location>http-message</location>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue