File tree Expand file tree Collapse file tree 6 files changed +34
-11
lines changed
Expand file tree Collapse file tree 6 files changed +34
-11
lines changed Original file line number Diff line number Diff line change 1111/**
1212 * @template TClassName of object
1313 */
14- final readonly class ClassReflector implements Reflector
14+ final class ClassReflector implements Reflector
1515{
1616 use HasAttributes;
17+ use HasMemoization;
1718
18- private PHPReflectionClass $ reflectionClass ;
19+ private readonly PHPReflectionClass $ reflectionClass ;
1920
2021 /**
2122 * @param class-string<TClassName>|TClassName|PHPReflectionClass<TClassName> $reflectionClass
@@ -77,9 +78,12 @@ public function getProperties(): array
7778 /** @return \Tempest\Reflection\MethodReflector[] */
7879 public function getPublicMethods (): array
7980 {
80- return array_map (
81- fn (PHPReflectionMethod $ method ) => new MethodReflector ($ method ),
82- $ this ->reflectionClass ->getMethods (PHPReflectionMethod::IS_PUBLIC ),
81+ return $ this ->memoize (
82+ 'public_methods ' ,
83+ fn () => array_map (
84+ fn (PHPReflectionMethod $ method ) => new MethodReflector ($ method ),
85+ $ this ->reflectionClass ->getMethods (PHPReflectionMethod::IS_PUBLIC ),
86+ ),
8387 );
8488 }
8589
Original file line number Diff line number Diff line change 1313
1414trait HasAttributes
1515{
16+ use HasMemoization;
17+
1618 abstract public function getReflection (): PHPReflectionClass |PHPReflectionMethod |PHPReflectionProperty |PHPReflectionParameter ;
1719
1820 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tempest \Reflection ;
4+
5+ use Closure ;
6+
7+ trait HasMemoization
8+ {
9+ private array $ memoize = [];
10+
11+ private function memoize (string $ key , Closure $ closure ): mixed
12+ {
13+ $ this ->memoize [$ key ] ??= $ closure ();
14+
15+ return $ this ->memoize [$ key ];
16+ }
17+ }
Original file line number Diff line number Diff line change 77use Generator ;
88use ReflectionMethod as PHPReflectionMethod ;
99
10- final readonly class MethodReflector implements Reflector
10+ final class MethodReflector implements Reflector
1111{
1212 use HasAttributes;
1313
1414 public function __construct (
15- private PHPReflectionMethod $ reflectionMethod ,
15+ private readonly PHPReflectionMethod $ reflectionMethod ,
1616 ) {}
1717
1818 public static function fromParts (string |object $ class , string $ name ): self
Original file line number Diff line number Diff line change 66
77use ReflectionParameter as PHPReflectionParameter ;
88
9- final readonly class ParameterReflector implements Reflector
9+ final class ParameterReflector implements Reflector
1010{
1111 use HasAttributes;
1212
1313 public function __construct (
14- private PHPReflectionParameter $ reflectionParameter ,
14+ private readonly PHPReflectionParameter $ reflectionParameter ,
1515 ) {}
1616
1717 public function getReflection (): PHPReflectionParameter
Original file line number Diff line number Diff line change 77use Error ;
88use ReflectionProperty as PHPReflectionProperty ;
99
10- final readonly class PropertyReflector implements Reflector
10+ final class PropertyReflector implements Reflector
1111{
1212 use HasAttributes;
1313
1414 public function __construct (
15- private PHPReflectionProperty $ reflectionProperty ,
15+ private readonly PHPReflectionProperty $ reflectionProperty ,
1616 ) {}
1717
1818 public static function fromParts (string |object $ class , string $ name ): self
You can’t perform that action at this time.
0 commit comments