Browse Source

Additional optimizations to magic properties

main
Dustin Wilson 3 years ago
parent
commit
07af6f6a0c
  1. 21
      lib/MagicProperties.php

21
lib/MagicProperties.php

@ -57,14 +57,25 @@ trait MagicProperties {
if (!isset($protectedMethodsList[$this::class])) { if (!isset($protectedMethodsList[$this::class])) {
$reflector = new \ReflectionClass($this); $reflector = new \ReflectionClass($this);
// Magic property methods are protected // Magic property methods are protected
$protectedMethodsList[$this::class] = $reflector->getMethods(\ReflectionMethod::IS_PROTECTED); $methodsList = $reflector->getMethods(\ReflectionMethod::IS_PROTECTED);
} $temp = [];
$valid = false;
// Only cache the magic methods
foreach ($methodsList as $m) {
if (str_starts_with($m->name, '__get_') || str_starts_with($m->name, '__set_')) {
$temp[] = $m->name;
foreach ($protectedMethodsList[$this::class] as $method) { if (!$valid && $m->name === $methodName) {
if ($method->name === $methodName) { $valid = true;
return $methodName; }
}
} }
$protectedMethodsList[$this::class] = $temp;
return ($valid) ? $methodName : null;
} }
return (in_array($methodName, $protectedMethodsList[$this::class])) ? $methodName : null;
} }
return null; return null;

Loading…
Cancel
Save