Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -3,14 +3,16 @@
namespace DeepCopy\Matcher\Doctrine;
use DeepCopy\Matcher\Matcher;
use Doctrine\Common\Persistence\Proxy;
use Doctrine\Persistence\Proxy;
/**
* Match a Doctrine Proxy class.
* @final
*/
class DoctrineProxyMatcher implements Matcher
{
/**
* Matches a Doctrine Proxy class.
*
* {@inheritdoc}
*/
public function matches($object, $property)

View File

@@ -2,14 +2,12 @@
namespace DeepCopy\Matcher;
/**
* Matcher interface
*/
interface Matcher
{
/**
* @param object $object
* @param string $property
*
* @return boolean
*/
public function matches($object, $property);

View File

@@ -3,7 +3,7 @@
namespace DeepCopy\Matcher;
/**
* Match a specific property of a specific class
* @final
*/
class PropertyMatcher implements Matcher
{
@@ -28,10 +28,12 @@ class PropertyMatcher implements Matcher
}
/**
* Matches a specific property of a specific class.
*
* {@inheritdoc}
*/
public function matches($object, $property)
{
return ($object instanceof $this->class) && ($property == $this->property);
return ($object instanceof $this->class) && $property == $this->property;
}
}

View File

@@ -3,7 +3,7 @@
namespace DeepCopy\Matcher;
/**
* Match a property by its name
* @final
*/
class PropertyNameMatcher implements Matcher
{
@@ -21,6 +21,8 @@ class PropertyNameMatcher implements Matcher
}
/**
* Matches a property by its name.
*
* {@inheritdoc}
*/
public function matches($object, $property)

View File

@@ -2,13 +2,16 @@
namespace DeepCopy\Matcher;
use ReflectionProperty;
use DeepCopy\Reflection\ReflectionHelper;
use ReflectionException;
/**
* Match a property by its type
* Matches a property by its type.
*
* It is recommended to use {@see DeepCopy\TypeFilter\TypeFilter} 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
{
@@ -30,9 +33,20 @@ class PropertyTypeMatcher implements Matcher
*/
public function matches($object, $property)
{
$reflectionProperty = new ReflectionProperty($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;
}
}