-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Introduce
TetheredNodeTypeDefinitions
VO
- Loading branch information
Showing
4 changed files
with
124 additions
and
9 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
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
29 changes: 29 additions & 0 deletions
29
Neos.ContentRepository.Core/Classes/NodeType/TetheredNodeTypeDefinition.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,29 @@ | ||
<?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\NodeType; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\Node\NodeName; | ||
|
||
/** | ||
* @api | ||
*/ | ||
final readonly class TetheredNodeTypeDefinition | ||
{ | ||
public function __construct( | ||
public NodeName $name, | ||
public NodeTypeName $nodeTypeName | ||
) { | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Neos.ContentRepository.Core/Classes/NodeType/TetheredNodeTypeDefinitions.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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\NodeType; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
use Neos\ContentRepository\Core\SharedModel\Node\NodeName; | ||
|
||
/** | ||
* @api | ||
* @implements \IteratorAggregate<TetheredNodeTypeDefinition> | ||
*/ | ||
final class TetheredNodeTypeDefinitions implements \IteratorAggregate | ||
{ | ||
/** | ||
* @var array<string, TetheredNodeTypeDefinition> | ||
*/ | ||
private array $tetheredNodeTypeDefinitions; | ||
|
||
private function __construct(TetheredNodeTypeDefinition ...$tetheredNodeTypeDefinitions) | ||
{ | ||
/** @var array<string, TetheredNodeTypeDefinition> $tetheredNodeTypeDefinitions */ | ||
$this->tetheredNodeTypeDefinitions = $tetheredNodeTypeDefinitions; | ||
} | ||
|
||
/** | ||
* @param array<TetheredNodeTypeDefinition> $tetheredNodeTypeDefinitions | ||
*/ | ||
public static function fromArray(array $tetheredNodeTypeDefinitions): self | ||
{ | ||
$tetheredNodeTypeDefinitionDefinitionByName = []; | ||
foreach ($tetheredNodeTypeDefinitions as $index => $tetheredNodeTypeDefinitionDefinition) { | ||
$tetheredNodeTypeDefinitionDefinition instanceof TetheredNodeTypeDefinition || throw new \InvalidArgumentException(sprintf('expected instance of %s, got: %s at index %s', TetheredNodeTypeDefinition::class, get_debug_type($tetheredNodeTypeDefinitionDefinition), $index), 1713549511); | ||
!array_key_exists($tetheredNodeTypeDefinitionDefinition->name->value, $tetheredNodeTypeDefinitionDefinitionByName) || throw new \InvalidArgumentException(sprintf('Tethered node type definition with name "%s" is already registered at index %s', $tetheredNodeTypeDefinitionDefinition->name->value, $index), 1713549527); | ||
$tetheredNodeTypeDefinitionDefinitionByName[$tetheredNodeTypeDefinitionDefinition->name->value] = $tetheredNodeTypeDefinitionDefinition; | ||
} | ||
return new self(...$tetheredNodeTypeDefinitionDefinitionByName); | ||
} | ||
|
||
public function contain(NodeName|string $nodeName): bool | ||
{ | ||
if ($nodeName instanceof NodeName) { | ||
$nodeName = $nodeName->value; | ||
} | ||
return array_key_exists($nodeName, $this->tetheredNodeTypeDefinitions); | ||
} | ||
|
||
public function get(NodeName|string $nodeName): ?TetheredNodeTypeDefinition | ||
{ | ||
if ($nodeName instanceof NodeName) { | ||
$nodeName = $nodeName->value; | ||
} | ||
return $this->tetheredNodeTypeDefinitions[$nodeName] ?? null; | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return yield from $this->tetheredNodeTypeDefinitions; | ||
} | ||
|
||
/** | ||
* @return array<TetheredNodeTypeDefinition> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return $this->tetheredNodeTypeDefinitions; | ||
} | ||
} |