Compare commits
No commits in common. "main" and "v1.0.24" have entirely different histories.
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Отключаю несущественные инспекции (из-за Attribute)
|
||||
*
|
||||
* @noinspection PhpMultipleClassDeclarationsInspection
|
||||
*/
|
||||
|
||||
namespace goodboyalex\php_components_pack\attributes;
|
||||
|
||||
use Attribute;
|
||||
|
||||
/**
|
||||
* Атрибут указания, что параметр является параметром только для чтения и не подлежит маппингу.
|
||||
*
|
||||
* @author Александр Бабаев
|
||||
* @package php_components_pack
|
||||
* @version 1.0
|
||||
* @since 1.0.25
|
||||
*/
|
||||
#[Attribute(flags: Attribute::TARGET_PROPERTY)]
|
||||
final readonly class GetOnly
|
||||
{
|
||||
/**
|
||||
* Конструктор
|
||||
*/
|
||||
public function __construct ()
|
||||
{
|
||||
}
|
||||
}
|
@ -5,10 +5,8 @@ namespace goodboyalex\php_components_pack\classes;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use goodboyalex\php_components_pack\attributes\GetOnly;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionProperty;
|
||||
use stdClass;
|
||||
use UnitEnum;
|
||||
|
||||
@ -17,7 +15,7 @@ use UnitEnum;
|
||||
*
|
||||
* @author Александр Бабаев
|
||||
* @package php_components_pack
|
||||
* @version 1.0.1
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
final class ClassMapper
|
||||
@ -61,11 +59,6 @@ final class ClassMapper
|
||||
// -- пропускаю
|
||||
continue;
|
||||
|
||||
// - если свойство маркируется как GetOnly
|
||||
if (self::HasGetOnlyAttributes($from, $name))
|
||||
// -- пропускаю
|
||||
continue;
|
||||
|
||||
// - если свойство не разрешено
|
||||
if (count($options['allowed']) > 0 && !in_array($name, $options['allowed']))
|
||||
// -- пропускаю
|
||||
@ -78,32 +71,6 @@ 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::class);
|
||||
|
||||
// Возвращаем true, если атрибут найден, иначе false
|
||||
return !empty($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Подготавливает значения свойств класса.
|
||||
*
|
||||
|
@ -27,7 +27,6 @@ class ClassMapperTest extends TestCase
|
||||
{
|
||||
require_once __DIR__ . '/../data/A.php';
|
||||
require_once __DIR__ . '/../data/B.php';
|
||||
require_once __DIR__ . '/../../sources/attributes/GetOnly.php';
|
||||
require_once __DIR__ . '/../../sources/classes/classMapper.php';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user