-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2768 from dpfaffenbauer/issue/version-marshalling
[ResourceBundle] Version Marshalling for FieldCollections
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/CoreShop/Bundle/ResourceBundle/DeepCopy/PimcoreFieldCollectionDefinitionMatcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* CoreShop | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - CoreShop Commercial License (CCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org) | ||
* @license https://www.coreshop.org/license GPLv3 and CCL | ||
* | ||
*/ | ||
|
||
namespace CoreShop\Bundle\ResourceBundle\DeepCopy; | ||
|
||
use DeepCopy\Matcher\Matcher; | ||
use Pimcore\Model\DataObject\Fieldcollection; | ||
|
||
class PimcoreFieldCollectionDefinitionMatcher implements Matcher | ||
{ | ||
public function __construct(private string $matchType) | ||
{ | ||
} | ||
|
||
public function matches(mixed $object, mixed $property): bool | ||
{ | ||
if ($object instanceof Fieldcollection\Data\AbstractData) { | ||
$collectionDef = Fieldcollection\Definition::getByKey($object->getType()); | ||
|
||
if ($collectionDef instanceof Fieldcollection\Definition) { | ||
return $collectionDef->getFieldDefinition($property) instanceof $this->matchType; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...CoreShop/Bundle/ResourceBundle/DeepCopy/PimcoreFieldCollectionDefinitionReplaceFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* CoreShop | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - CoreShop Commercial License (CCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org) | ||
* @license https://www.coreshop.org/license GPLv3 and CCL | ||
* | ||
*/ | ||
|
||
namespace CoreShop\Bundle\ResourceBundle\DeepCopy; | ||
|
||
use DeepCopy\Filter\Filter; | ||
use DeepCopy\Reflection\ReflectionHelper; | ||
use Pimcore\Model\DataObject\Concrete; | ||
use Pimcore\Model\DataObject\Fieldcollection; | ||
|
||
class PimcoreFieldCollectionDefinitionReplaceFilter implements Filter | ||
{ | ||
public function __construct(protected \Closure $callback) | ||
{ | ||
} | ||
|
||
public function apply($object, $property, $objectCopier) | ||
{ | ||
if (!$object instanceof Fieldcollection\Data\AbstractData) { | ||
return; | ||
} | ||
|
||
$fieldDefinition = $object->getDefinition()->getFieldDefinition($property); | ||
|
||
if (!$fieldDefinition) { | ||
return; | ||
} | ||
|
||
$reflectionProperty = ReflectionHelper::getProperty($object, $property); | ||
$reflectionProperty->setAccessible(true); | ||
|
||
$value = ($this->callback)($object, $fieldDefinition, $property, $reflectionProperty->getValue($object)); | ||
|
||
$reflectionProperty->setValue($object, $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters