You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
788 B
33 lines
788 B
<?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);
|
|
}
|
|
}
|
|
|