mailpoet
/
vendor-prefixed
/
doctrine
/
persistence
/
src
/
Persistence
/
Mapping
/
RuntimeReflectionService.php
Driver
9 months ago
AbstractClassMetadataFactory.php
8 months ago
ClassMetadata.php
9 months ago
ClassMetadataFactory.php
9 months ago
MappingException.php
9 months ago
ProxyClassNameResolver.php
9 months ago
ReflectionService.php
9 months ago
RuntimeReflectionService.php
9 months ago
StaticReflectionService.php
9 months ago
index.php
3 years ago
RuntimeReflectionService.php
68 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\Persistence\Mapping; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Persistence\Reflection\RuntimeReflectionProperty; |
| 6 | use MailPoetVendor\Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty; |
| 7 | use ReflectionClass; |
| 8 | use ReflectionException; |
| 9 | use ReflectionMethod; |
| 10 | use function array_key_exists; |
| 11 | use function assert; |
| 12 | use function class_exists; |
| 13 | use function class_parents; |
| 14 | use function phpversion; |
| 15 | use function version_compare; |
| 16 | use const PHP_VERSION_ID; |
| 17 | class RuntimeReflectionService implements ReflectionService |
| 18 | { |
| 19 | private $supportsTypedPropertiesWorkaround; |
| 20 | public function __construct() |
| 21 | { |
| 22 | $this->supportsTypedPropertiesWorkaround = version_compare(phpversion(), '7.4.0') >= 0; |
| 23 | } |
| 24 | public function getParentClasses(string $class) |
| 25 | { |
| 26 | if (!class_exists($class)) { |
| 27 | throw MappingException::nonExistingClass($class); |
| 28 | } |
| 29 | $parents = class_parents($class); |
| 30 | assert($parents !== \false); |
| 31 | return $parents; |
| 32 | } |
| 33 | public function getClassShortName(string $class) |
| 34 | { |
| 35 | $reflectionClass = new ReflectionClass($class); |
| 36 | return $reflectionClass->getShortName(); |
| 37 | } |
| 38 | public function getClassNamespace(string $class) |
| 39 | { |
| 40 | $reflectionClass = new ReflectionClass($class); |
| 41 | return $reflectionClass->getNamespaceName(); |
| 42 | } |
| 43 | public function getClass(string $class) |
| 44 | { |
| 45 | return new ReflectionClass($class); |
| 46 | } |
| 47 | public function getAccessibleProperty(string $class, string $property) |
| 48 | { |
| 49 | $reflectionProperty = new RuntimeReflectionProperty($class, $property); |
| 50 | if ($this->supportsTypedPropertiesWorkaround && !array_key_exists($property, $this->getClass($class)->getDefaultProperties())) { |
| 51 | $reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property); |
| 52 | } |
| 53 | if (PHP_VERSION_ID < 80100) { |
| 54 | $reflectionProperty->setAccessible(\true); |
| 55 | } |
| 56 | return $reflectionProperty; |
| 57 | } |
| 58 | public function hasPublicMethod(string $class, string $method) |
| 59 | { |
| 60 | try { |
| 61 | $reflectionMethod = new ReflectionMethod($class, $method); |
| 62 | } catch (ReflectionException $e) { |
| 63 | return \false; |
| 64 | } |
| 65 | return $reflectionMethod->isPublic(); |
| 66 | } |
| 67 | } |
| 68 |