diff options
Diffstat (limited to 'vendor/myclabs/deep-copy/src/DeepCopy/Filter')
7 files changed, 180 insertions, 0 deletions
diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineCollectionFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineCollectionFilter.php new file mode 100644 index 000000000..e6d937710 --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineCollectionFilter.php @@ -0,0 +1,33 @@ +<?php + +namespace DeepCopy\Filter\Doctrine; + +use DeepCopy\Filter\Filter; +use DeepCopy\Reflection\ReflectionHelper; + +/** + * @final + */ +class DoctrineCollectionFilter implements Filter +{ + /** + * Copies the object property doctrine collection. + * + * {@inheritdoc} + */ + public function apply($object, $property, $objectCopier) + { + $reflectionProperty = ReflectionHelper::getProperty($object, $property); + + $reflectionProperty->setAccessible(true); + $oldCollection = $reflectionProperty->getValue($object); + + $newCollection = $oldCollection->map( + function ($item) use ($objectCopier) { + return $objectCopier($item); + } + ); + + $reflectionProperty->setValue($object, $newCollection); + } +} diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineEmptyCollectionFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineEmptyCollectionFilter.php new file mode 100644 index 000000000..7b33fd547 --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineEmptyCollectionFilter.php @@ -0,0 +1,28 @@ +<?php + +namespace DeepCopy\Filter\Doctrine; + +use DeepCopy\Filter\Filter; +use DeepCopy\Reflection\ReflectionHelper; +use Doctrine\Common\Collections\ArrayCollection; + +/** + * @final + */ +class DoctrineEmptyCollectionFilter implements Filter +{ + /** + * Sets the object property to an empty doctrine collection. + * + * @param object $object + * @param string $property + * @param callable $objectCopier + */ + public function apply($object, $property, $objectCopier) + { + $reflectionProperty = ReflectionHelper::getProperty($object, $property); + $reflectionProperty->setAccessible(true); + + $reflectionProperty->setValue($object, new ArrayCollection()); + } +}
\ No newline at end of file diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineProxyFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineProxyFilter.php new file mode 100644 index 000000000..8bee8f769 --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Doctrine/DoctrineProxyFilter.php @@ -0,0 +1,22 @@ +<?php + +namespace DeepCopy\Filter\Doctrine; + +use DeepCopy\Filter\Filter; + +/** + * @final + */ +class DoctrineProxyFilter implements Filter +{ + /** + * Triggers the magic method __load() on a Doctrine Proxy class to load the + * actual entity from the database. + * + * {@inheritdoc} + */ + public function apply($object, $property, $objectCopier) + { + $object->__load(); + } +} diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Filter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Filter.php new file mode 100644 index 000000000..85ba18ce1 --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/Filter.php @@ -0,0 +1,18 @@ +<?php + +namespace DeepCopy\Filter; + +/** + * Filter to apply to a property while copying an object + */ +interface Filter +{ + /** + * Applies the filter to the object. + * + * @param object $object + * @param string $property + * @param callable $objectCopier + */ + public function apply($object, $property, $objectCopier); +} diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/KeepFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/KeepFilter.php new file mode 100644 index 000000000..4b11a081b --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/KeepFilter.php @@ -0,0 +1,16 @@ +<?php + +namespace DeepCopy\Filter; + +class KeepFilter implements Filter +{ + /** + * Keeps the value of the object property. + * + * {@inheritdoc} + */ + public function apply($object, $property, $objectCopier) + { + // Nothing to do + } +} diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/ReplaceFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/ReplaceFilter.php new file mode 100644 index 000000000..7aca593bb --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/ReplaceFilter.php @@ -0,0 +1,39 @@ +<?php + +namespace DeepCopy\Filter; + +use DeepCopy\Reflection\ReflectionHelper; + +/** + * @final + */ +class ReplaceFilter implements Filter +{ + /** + * @var callable + */ + protected $callback; + + /** + * @param callable $callable Will be called to get the new value for each property to replace + */ + public function __construct(callable $callable) + { + $this->callback = $callable; + } + + /** + * Replaces the object property by the result of the callback called with the object property. + * + * {@inheritdoc} + */ + public function apply($object, $property, $objectCopier) + { + $reflectionProperty = ReflectionHelper::getProperty($object, $property); + $reflectionProperty->setAccessible(true); + + $value = call_user_func($this->callback, $reflectionProperty->getValue($object)); + + $reflectionProperty->setValue($object, $value); + } +} diff --git a/vendor/myclabs/deep-copy/src/DeepCopy/Filter/SetNullFilter.php b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/SetNullFilter.php new file mode 100644 index 000000000..bea86b884 --- /dev/null +++ b/vendor/myclabs/deep-copy/src/DeepCopy/Filter/SetNullFilter.php @@ -0,0 +1,24 @@ +<?php + +namespace DeepCopy\Filter; + +use DeepCopy\Reflection\ReflectionHelper; + +/** + * @final + */ +class SetNullFilter implements Filter +{ + /** + * Sets the object property to null. + * + * {@inheritdoc} + */ + public function apply($object, $property, $objectCopier) + { + $reflectionProperty = ReflectionHelper::getProperty($object, $property); + + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($object, null); + } +} |