2 declare(strict_types = 1);
43 $persistedCollectionConfig = empty($jsonString) ? [] : json_decode($jsonString,
true);
44 if (empty($persistedCollectionConfig) && empty($tcaConfig)) {
48 if ($tcaConfig === []) {
49 $tcaConfig = (array)$persistedCollectionConfig;
51 if (!is_array($persistedCollectionConfig)) {
52 $persistedCollectionConfig = [];
55 reset($persistedCollectionConfig);
56 foreach ($tcaConfig as $id => &$cropVariantConfig) {
57 if (!isset($persistedCollectionConfig[$id])) {
58 $id = key($persistedCollectionConfig);
59 next($persistedCollectionConfig);
61 if (isset($persistedCollectionConfig[$id][
'cropArea'])) {
62 $cropVariantConfig[
'cropArea'] = $persistedCollectionConfig[$id][
'cropArea'];
64 if (isset($persistedCollectionConfig[$id][
'focusArea'], $cropVariantConfig[
'focusArea'])) {
65 $cropVariantConfig[
'focusArea'] = $persistedCollectionConfig[$id][
'focusArea'];
67 if (isset($persistedCollectionConfig[$id][
'selectedRatio'], $cropVariantConfig[
'allowedAspectRatios'][$persistedCollectionConfig[$id][
'selectedRatio']])) {
68 $cropVariantConfig[
'selectedRatio'] = $persistedCollectionConfig[$id][
'selectedRatio'];
71 unset($cropVariantConfig);
74 foreach ($tcaConfig as $id => $cropVariantConfig) {
78 }
catch (\Throwable $throwable) {
89 $cropVariantsAsArray = [];
90 foreach ($this->cropVariants as $id => $cropVariant) {
91 $cropVariantsAsArray[$id] = $cropVariant->asArray();
93 return $cropVariantsAsArray;
102 $newCollection = clone $this;
103 foreach ($this->cropVariants as $id => $cropVariant) {
106 return $newCollection;
111 $filterNonPersistentKeys =
function ($key) {
112 if (in_array($key, [
'id',
'title',
'allowedAspectRatios',
'coverAreas'],
true)) {
117 $cropVariantsAsArray = [];
118 foreach ($this->cropVariants as $id => $cropVariant) {
119 $cropVariantsAsArray[$id] = array_filter($cropVariant->asArray(), $filterNonPersistentKeys, ARRAY_FILTER_USE_KEY);
121 return json_encode($cropVariantsAsArray) ?:
'[]';
130 if (isset($this->cropVariants[$id])) {
131 return $this->cropVariants[$id]->getCropArea();
142 if (isset($this->cropVariants[$id]) && $this->cropVariants[$id]->
getFocusArea() !==
null) {
143 return $this->cropVariants[$id]->getFocusArea();
151 protected static function createEmpty(): CropVariantCollection
162 $this->cropVariants = [];
174 if (isset($this->cropVariants[$cropVariant->getId()])) {
175 throw new InvalidConfigurationException(sprintf(
'Crop variant with with duplicate ID (%s) is configured. Make sure all configured cropVariants have different ids.', $cropVariant->getId()), 1485284352);
177 $this->cropVariants[$cropVariant->getId()] = $cropVariant;