-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
872f1ee
commit 47c9523
Showing
6 changed files
with
335 additions
and
3 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
Neos.ContentRepository.Core/Classes/Feature/NodeVariation/Dto/CoverageNodeVariantMapping.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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto; | ||
|
||
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated; | ||
|
||
/** | ||
* See the docs of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} for a full description. | ||
* | ||
* @api DTO of {@see NodeAggregateWasMoved} event | ||
*/ | ||
final class CoverageNodeVariantMapping implements \JsonSerializable | ||
{ | ||
private function __construct( | ||
public readonly DimensionSpacePoint $coveredDimensionSpacePoint, | ||
public readonly SucceedingSiblingVariantPosition|EndSiblingVariantPosition $destination, | ||
) { | ||
} | ||
|
||
public static function createForNewSucceedingSibling( | ||
DimensionSpacePoint $coveredDimensionSpacePoint, | ||
SucceedingSiblingVariantPosition $newSucceedingSibling | ||
): self { | ||
return new self($coveredDimensionSpacePoint, $newSucceedingSibling); | ||
} | ||
|
||
public static function createForNewEndSibling( | ||
DimensionSpacePoint $coveredDimensionSpacePoint, | ||
EndSiblingVariantPosition $newSucceedingSibling | ||
): self { | ||
return new self($coveredDimensionSpacePoint, $newSucceedingSibling); | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $array | ||
*/ | ||
public static function fromArray(array $array): self | ||
{ | ||
if (!empty($array['newSucceedingSibling'])) { | ||
return new self( | ||
DimensionSpacePoint::fromArray($array['coveredDimensionSpacePoint']), | ||
SucceedingSiblingVariantPosition::fromArray($array['newSucceedingSibling']), | ||
); | ||
} elseif (!empty($array['endSibling'])) { | ||
return new self( | ||
DimensionSpacePoint::fromArray($array['coveredDimensionSpacePoint']), | ||
EndSiblingVariantPosition::create(), | ||
); | ||
} else { | ||
throw new \RuntimeException('!!!'); | ||
} | ||
} | ||
|
||
/** | ||
* @return array<string,mixed> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
if ($this->destination instanceof SucceedingSiblingVariantPosition) { | ||
return [ | ||
'coveredDimensionSpacePoint' => $this->coveredDimensionSpacePoint, | ||
'newSucceedingSibling' => $this->destination | ||
]; | ||
} elseif ($this->destination instanceof EndSiblingVariantPosition) { | ||
return [ | ||
'endSibling' => true, | ||
]; | ||
} else { | ||
throw new \RuntimeException('!!!'); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
....ContentRepository.Core/Classes/Feature/NodeVariation/Dto/CoverageNodeVariantMappings.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,88 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository.Core package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto; | ||
|
||
/** | ||
* @implements \IteratorAggregate<int,CoverageNodeMoveMapping> | ||
* @api DTO of {@see NodeAggregateWasMoved} event | ||
*/ | ||
final class CoverageNodeVariantMappings implements \IteratorAggregate, \Countable, \JsonSerializable | ||
{ | ||
/** | ||
* @var array<int,CoverageNodeMoveMapping> | ||
*/ | ||
private array $mappings; | ||
|
||
/** | ||
* @param array<int,CoverageNodeMoveMapping> $values | ||
*/ | ||
private function __construct(array $values) | ||
{ | ||
$this->mappings = $values; | ||
} | ||
|
||
/** | ||
* @param array<int|string,array<string,mixed>|CoverageNodeMoveMapping> $mappings | ||
*/ | ||
public static function fromArray(array $mappings): self | ||
{ | ||
$processedMappings = []; | ||
foreach ($mappings as $mapping) { | ||
if (is_array($mapping)) { | ||
$processedMappings[] = CoverageNodeMoveMapping::fromArray($mapping); | ||
} elseif ($mapping instanceof CoverageNodeMoveMapping) { | ||
$processedMappings[] = $mapping; | ||
} else { | ||
/** @var mixed $mapping */ | ||
throw new \InvalidArgumentException( | ||
sprintf( | ||
'Invalid NodeMoveMapping. Expected instance of %s, got: %s', | ||
CoverageNodeMoveMapping::class, | ||
is_object($mapping) ? get_class($mapping) : gettype($mapping) | ||
), | ||
1547811318 | ||
); | ||
} | ||
} | ||
return new self($processedMappings); | ||
} | ||
|
||
public static function create(CoverageNodeMoveMapping ...$coverageNodeMoveMappings): self | ||
{ | ||
return new self(array_values($coverageNodeMoveMappings)); | ||
} | ||
|
||
|
||
/** | ||
* @return \Traversable<int,CoverageNodeMoveMapping> | ||
*/ | ||
public function getIterator(): \Traversable | ||
{ | ||
yield from $this->mappings; | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return count($this->mappings); | ||
} | ||
|
||
/** | ||
* @return array<int,CoverageNodeMoveMapping> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return $this->mappings; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
Neos.ContentRepository.Core/Classes/Feature/NodeVariation/Dto/EndSiblingVariantPosition.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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto; | ||
|
||
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated; | ||
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; | ||
|
||
/** | ||
* See the docs of {@see NodePeerVariantWasCreated} for a full description. | ||
* | ||
* @api DTO of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} event | ||
*/ | ||
final class EndSiblingVariantPosition implements \JsonSerializable | ||
{ | ||
private function __construct( | ||
) { | ||
} | ||
|
||
public static function create( | ||
): self { | ||
return new self( | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $array | ||
*/ | ||
public static function fromArray(array $array): self | ||
{ | ||
return new self( | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string,\JsonSerializable> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
|
||
public function toJson(): string | ||
{ | ||
return json_encode($this, JSON_THROW_ON_ERROR); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...entRepository.Core/Classes/Feature/NodeVariation/Dto/SucceedingSiblingVariantPosition.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,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Neos.ContentRepository package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto; | ||
|
||
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated; | ||
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated; | ||
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; | ||
|
||
/** | ||
* See the docs of {@see NodePeerVariantWasCreated} for a full description. | ||
* | ||
* @api DTO of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} event | ||
*/ | ||
final class SucceedingSiblingVariantPosition implements \JsonSerializable | ||
{ | ||
private function __construct( | ||
public readonly NodeAggregateId $nodeAggregateId, | ||
public readonly OriginDimensionSpacePoint $originDimensionSpacePoint, | ||
) { | ||
} | ||
|
||
public static function create( | ||
NodeAggregateId $nodeAggregateId, | ||
OriginDimensionSpacePoint $originDimensionSpacePoint, | ||
): self { | ||
return new self( | ||
$nodeAggregateId, | ||
$originDimensionSpacePoint, | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $array | ||
*/ | ||
public static function fromArray(array $array): self | ||
{ | ||
return new self( | ||
NodeAggregateId::fromString($array['nodeAggregateId']), | ||
OriginDimensionSpacePoint::fromArray($array['originDimensionSpacePoint']), | ||
); | ||
} | ||
|
||
/** | ||
* @return array<string,\JsonSerializable> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'nodeAggregateId' => $this->nodeAggregateId, | ||
'originDimensionSpacePoint' => $this->originDimensionSpacePoint, | ||
]; | ||
} | ||
|
||
public function toJson(): string | ||
{ | ||
return json_encode($this, JSON_THROW_ON_ERROR); | ||
} | ||
} |
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