diff --git a/sources/attributes/GetOnly.php b/sources/attributes/GetOnly.php new file mode 100644 index 0000000..354ca4e --- /dev/null +++ b/sources/attributes/GetOnly.php @@ -0,0 +1,29 @@ + 0 && !in_array($name, $options['allowed'])) // -- пропускаю @@ -71,6 +78,32 @@ final class ClassMapper } } + /** + * Проверяет, есть ли у свойства класса $class атрибуты GetOnly. + * + * @param object $class Объект класса. + * @param string $propertyName Имя свойства. + * + * @return bool true если у свойства есть атрибут GetOnly, иначе false. + */ + private static function HasGetOnlyAttributes (object $class, string $propertyName): bool + { + // Создаем отражение свойства класса + try { + $reflectionProperty = new ReflectionProperty(get_class($class), $propertyName); + } + catch (ReflectionException) { + // - возвращаю false, если произошла ошибка создания отражения свойства класса + return false; + } + + // Получаем список атрибутов у данного свойства + $attributes = $reflectionProperty->getAttributes('GetOnly', ReflectionAttribute::IS_INSTANCEOF); + + // Возвращаем true, если атрибут найден, иначе false + return !empty($attributes); + } + /** * Подготавливает значения свойств класса. *