/** * @param DeepCopy $deepCopy * @param EntityManager $entityManager * @return DeepCopy */ private function addDeepCopyCommonFilters(DeepCopy $deepCopy, EntityManager $entityManager) { $keepFilter = new KeepFilter(); $nullifyFilter = new SetNullFilter(); // Matches RedirectTargetPage::$page property. // Keeps the $page property redirect target is referencing to. $deepCopy->addFilter($keepFilter, new PropertyMatcher(RedirectTargetPage::CN(), 'page')); // Matches PageLocalization::$template. // Prevents the template to be cloned. $deepCopy->addFilter($keepFilter, new PropertyMatcher(PageLocalization::CN(), 'template')); // Matches Localization::$path // Keeps the value since it is cloned manually (see PageLocalization::__clone()); $deepCopy->addFilter($keepFilter, new PropertyMatcher(Localization::CN(), 'path')); // Matches Block::$blockProperties collection. // Replaces with empty collection, since block properties can be obtained via Localization::$blockProperties. $deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher(Block::CN(), 'blockProperties')); // Matches Localization::$lock. // Nullifies editing lock entity. $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'lock')); // Matches Localization::$publishedRevision. $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishedRevision')); // Matches Localization::$publishTime. $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishTime')); // Matches Entity Collection. // Creates Copy and persists the elements in it. $deepCopy->addFilter(new DoctrineCollectionFilter($entityManager), new PropertyTypeMatcher('Doctrine\\Common\\Collections\\Collection')); // Matches any Entity. // Creates copy and persists it. $deepCopy->addFilter(new DoctrineEntityFilter($entityManager), new PropertyTypeMatcher(Entity::CN())); }