Initial Commit
This commit is contained in:
21
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/Doctrine/DoctrineProxyMatcher.php
vendored
Normal file
21
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/Doctrine/DoctrineProxyMatcher.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\DeepCopy\Matcher\Doctrine;
|
||||
|
||||
use WP_Ultimo\Dependencies\DeepCopy\Matcher\Matcher;
|
||||
use WP_Ultimo\Dependencies\Doctrine\Persistence\Proxy;
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class DoctrineProxyMatcher implements Matcher
|
||||
{
|
||||
/**
|
||||
* Matches a Doctrine Proxy class.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matches($object, $property)
|
||||
{
|
||||
return $object instanceof Proxy;
|
||||
}
|
||||
}
|
14
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/Matcher.php
vendored
Normal file
14
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/Matcher.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\DeepCopy\Matcher;
|
||||
|
||||
interface Matcher
|
||||
{
|
||||
/**
|
||||
* @param object $object
|
||||
* @param string $property
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function matches($object, $property);
|
||||
}
|
36
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyMatcher.php
vendored
Normal file
36
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyMatcher.php
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\DeepCopy\Matcher;
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class PropertyMatcher implements Matcher
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $class;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $property;
|
||||
/**
|
||||
* @param string $class Class name
|
||||
* @param string $property Property name
|
||||
*/
|
||||
public function __construct($class, $property)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->property = $property;
|
||||
}
|
||||
/**
|
||||
* Matches a specific property of a specific class.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matches($object, $property)
|
||||
{
|
||||
return $object instanceof $this->class && $property == $this->property;
|
||||
}
|
||||
}
|
30
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyNameMatcher.php
vendored
Normal file
30
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyNameMatcher.php
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\DeepCopy\Matcher;
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class PropertyNameMatcher implements Matcher
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $property;
|
||||
/**
|
||||
* @param string $property Property name
|
||||
*/
|
||||
public function __construct($property)
|
||||
{
|
||||
$this->property = $property;
|
||||
}
|
||||
/**
|
||||
* Matches a property by its name.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function matches($object, $property)
|
||||
{
|
||||
return $property == $this->property;
|
||||
}
|
||||
}
|
46
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyTypeMatcher.php
vendored
Normal file
46
dependencies/myclabs/deep-copy/src/DeepCopy/Matcher/PropertyTypeMatcher.php
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\DeepCopy\Matcher;
|
||||
|
||||
use WP_Ultimo\Dependencies\DeepCopy\Reflection\ReflectionHelper;
|
||||
use ReflectionException;
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user