1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<?php
namespace ICanBoogie\Accessor;
class AccessorReflection
{
static private $private_properties_cache = [];
static private $facade_properties_cache = [];
static private function resolve_reference($reference)
{
if (is_object($reference))
{
return get_class($reference);
}
return $reference;
}
static public function resolve_private_properties($reference)
{
$reference = self::resolve_reference($reference);
if (isset(self::$private_properties_cache[$reference]))
{
return self::$private_properties_cache[$reference];
}
$private_properties = [];
$class_reflection = new \ReflectionClass($reference);
while ($class_reflection)
{
$private_properties[] = $class_reflection->getProperties(\ReflectionProperty::IS_PRIVATE);
$class_reflection = $class_reflection->getParentClass();
}
return self::$private_properties_cache[$reference] = $private_properties
? call_user_func_array('array_merge', $private_properties)
: [];
}
static public function resolve_facade_properties($reference)
{
$reference = self::resolve_reference($reference);
if (isset(self::$facade_properties_cache[$reference]))
{
return self::$facade_properties_cache[$reference];
}
$facade_properties = [];
foreach (self::resolve_private_properties($reference) as $property)
{
$name = $property->name;
if (!method_exists($reference, $reference::accessor_format($name, HasAccessor::ACCESSOR_TYPE_GETTER))
|| !method_exists($reference, $reference::accessor_format($name, HasAccessor::ACCESSOR_TYPE_SETTER)))
{
continue;
}
$facade_properties[$name] = $property;
}
return self::$facade_properties_cache[$reference] = $facade_properties;
}
}