ClassInvoker.php 837 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Support\Reflection;
  12. use ReflectionClass;
  13. class ClassInvoker
  14. {
  15. protected ReflectionClass $reflection;
  16. public function __construct(protected object $instance)
  17. {
  18. $this->reflection = new ReflectionClass($instance);
  19. }
  20. public function __get($name)
  21. {
  22. $property = $this->reflection->getProperty($name);
  23. return $property->getValue($this->instance);
  24. }
  25. public function __call($name, $arguments)
  26. {
  27. $method = $this->reflection->getMethod($name);
  28. return $method->invokeArgs($this->instance, $arguments);
  29. }
  30. }