Вход Регистрация
Файл: vendor/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyTypeMatcher.php
Строк: 47
<?php

namespace DeepCopyMatcher;

use 
DeepCopyReflectionReflectionHelper;
use 
ReflectionException;

/**
 * Matches a property by its type.
 *
 * It is recommended to use {@see DeepCopyTypeFilterTypeFilter} instead, as it applies on all occurrences
 * of given type in copied context (eg. array elements), not just on object properties.
 *
 * @final
 */
class PropertyTypeMatcher implements Matcher
{
    
/**
     * @var string
     */
    
private $propertyType;

    
/**
     * @param string $propertyType Property type
     */
    
public function __construct($propertyType)
    {
        
$this->propertyType $propertyType;
    }

    
/**
     * {@inheritdoc}
     */
    
public function matches($object$property)
    {
        try {
            
$reflectionProperty ReflectionHelper::getProperty($object$property);
        } catch (
ReflectionException $exception) {
            return 
false;
        }

        
$reflectionProperty->setAccessible(true);

        
// Uninitialized properties (for PHP >7.4)
        
if (method_exists($reflectionProperty'isInitialized') && !$reflectionProperty->isInitialized($object)) {
            
// null instanceof $this->propertyType
            
return false;
        }

        return 
$reflectionProperty->getValue($object) instanceof $this->propertyType;
    }
}
Онлайн: 2
Реклама