-
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: FEATURE: Overhaul NodeTypeManager #4999
Draft
bwaidelich
wants to merge
13
commits into
9.0
Choose a base branch
from
feature/4228-overhaul-nodetypemanager
base: 9.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,442
−728
Draft
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ac3080
WIP: FEATURE: Overhaul NodeTypeManager
bwaidelich 904fe70
Merge branch '9.0' into feature/4228-overhaul-nodetypemanager
bwaidelich 125e391
WIP
bwaidelich 585716b
WIP
bwaidelich 3c7c170
Merge branch '9.0' into feature/4228-overhaul-nodetypemanager
bwaidelich fb4284c
WIP
bwaidelich 3af6cdb
Merge remote-tracking branch 'origin/9.0' into feature/4228-overhaul-…
mhsdesign 5e04763
TASK: Remove NodeLabel functionality again (merge #5020)
mhsdesign e5f5073
TASK: Adjust types to please phpstan
mhsdesign f089274
Merge remote-tracking branch 'origin/9.0' into feature/4228-overhaul-…
mhsdesign f31ff2e
TASK: Fixup wrongly up-merged code
mhsdesign d0f1115
Merge remote-tracking branch 'origin/9.0' into feature/4228-overhaul-…
mhsdesign f0de762
WIP: Add todos as well as remove `NodeTypeProvider::isNodeTypeAllowed…
mhsdesign File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
156 changes: 156 additions & 0 deletions
156
Neos.ContentRepository.Core/Classes/NodeType/ClosureNodeTypeProvider.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,156 @@ | ||
<?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\Exception\NodeConfigurationException; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeIsFinalException; | ||
use Neos\ContentRepository\Core\SharedModel\Exception\NodeTypeNotFoundException; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ClosureNodeTypeProvider implements NodeTypeProviderInterface | ||
{ | ||
private NodeTypes $cachedNodeTypes; | ||
|
||
public function __construct( | ||
private readonly \Closure $nodeTypeConfigLoader, | ||
) { | ||
$this->cachedNodeTypes = NodeTypes::fromArray([]); | ||
} | ||
|
||
public function getNodeTypes(): NodeTypes | ||
{ | ||
if ($this->cachedNodeTypes->isEmpty()) { | ||
$completeNodeTypeConfiguration = ($this->nodeTypeConfigLoader)(); | ||
// the root node type must always exist | ||
$completeNodeTypeConfiguration[NodeTypeName::ROOT_NODE_TYPE_NAME] ??= []; | ||
foreach (array_keys($completeNodeTypeConfiguration) as $nodeTypeName) { | ||
if (!is_string($nodeTypeName)) { | ||
continue; | ||
} | ||
if (!is_array($completeNodeTypeConfiguration[$nodeTypeName])) { | ||
continue; | ||
} | ||
$this->loadNodeType($nodeTypeName, $completeNodeTypeConfiguration); | ||
} | ||
} | ||
return $this->cachedNodeTypes; | ||
} | ||
|
||
/** | ||
* Load one node type, if it is not loaded yet. | ||
* | ||
* @param array<string,mixed> $completeNodeTypeConfiguration the full node type configuration for all node types | ||
* @throws NodeConfigurationException | ||
* @throws NodeTypeIsFinalException | ||
* @throws NodeTypeNotFoundException | ||
*/ | ||
private function loadNodeType(string $nodeTypeName, array &$completeNodeTypeConfiguration): NodeType | ||
{ | ||
$cachedNodeType = $this->cachedNodeTypes->get($nodeTypeName); | ||
if ($cachedNodeType !== null) { | ||
return $cachedNodeType; | ||
} | ||
|
||
if (!isset($completeNodeTypeConfiguration[$nodeTypeName])) { | ||
throw new NodeTypeNotFoundException('Node type "' . $nodeTypeName . '" does not exist', 1316451800); | ||
} | ||
|
||
$nodeTypeConfiguration = $completeNodeTypeConfiguration[$nodeTypeName]; | ||
try { | ||
$superTypes = isset($nodeTypeConfiguration['superTypes']) | ||
? $this->evaluateSuperTypesConfiguration( | ||
$nodeTypeConfiguration['superTypes'], | ||
$completeNodeTypeConfiguration | ||
) | ||
: []; | ||
} catch (NodeConfigurationException $exception) { | ||
throw new NodeConfigurationException('Node type "' . $nodeTypeName . '" sets super type with a non-string key to NULL.', 1416578395, $exception); | ||
} catch (NodeTypeIsFinalException $exception) { | ||
throw new NodeTypeIsFinalException('Node type "' . $nodeTypeName . '" has a super type "' . $exception->getMessage() . '" which is final.', 1316452423, $exception); | ||
} | ||
|
||
// Remove unset properties | ||
$nodeTypeConfiguration['properties'] = array_filter($nodeTypeConfiguration['properties'] ?? [], static fn ($propertyConfiguration) => $propertyConfiguration !== null); | ||
if ($nodeTypeConfiguration['properties'] === []) { | ||
unset($nodeTypeConfiguration['properties']); | ||
} | ||
|
||
$nodeType = new NodeType( | ||
NodeTypeName::fromString($nodeTypeName), | ||
$superTypes, | ||
$nodeTypeConfiguration, | ||
$this->nodeLabelGeneratorFactory | ||
); | ||
|
||
$this->cachedNodeTypes = $this->cachedNodeTypes->with($nodeType); | ||
return $nodeType; | ||
} | ||
|
||
/** | ||
* Evaluates the given superTypes configuation and returns the array of effective superTypes. | ||
* | ||
* @param array<string,mixed> $superTypesConfiguration | ||
* @param array<string,mixed> $completeNodeTypeConfiguration | ||
* @return array<string,NodeType|null> | ||
*/ | ||
private function evaluateSuperTypesConfiguration( | ||
array $superTypesConfiguration, | ||
array $completeNodeTypeConfiguration | ||
): array { | ||
$superTypes = []; | ||
foreach ($superTypesConfiguration as $superTypeName => $enabled) { | ||
if (!is_string($superTypeName)) { | ||
throw new NodeConfigurationException( | ||
'superTypes must be a dictionary; the array format was deprecated since Neos 2.0', | ||
1651821391 | ||
); | ||
} | ||
$superTypes[$superTypeName] = $this->evaluateSuperTypeConfiguration( | ||
$superTypeName, | ||
$enabled, | ||
$completeNodeTypeConfiguration | ||
); | ||
} | ||
|
||
return $superTypes; | ||
} | ||
|
||
/** | ||
* Evaluates a single superType configuration and returns the NodeType if enabled. | ||
* | ||
* @param array<string,mixed> $completeNodeTypeConfiguration | ||
* @throws NodeConfigurationException | ||
* @throws NodeTypeIsFinalException | ||
*/ | ||
private function evaluateSuperTypeConfiguration( | ||
string $superTypeName, | ||
?bool $enabled, | ||
array &$completeNodeTypeConfiguration | ||
): ?NodeType { | ||
// Skip unset node types | ||
if ($enabled === false || $enabled === null) { | ||
return null; | ||
} | ||
|
||
$superType = $this->loadNodeType($superTypeName, $completeNodeTypeConfiguration); | ||
if ($superType->isFinal() === true) { | ||
throw new NodeTypeIsFinalException($superType->name->value, 1444944148); | ||
} | ||
|
||
return $superType; | ||
} | ||
} |
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
26 changes: 0 additions & 26 deletions
26
Neos.ContentRepository.Core/Classes/NodeType/DefaultNodeLabelGeneratorFactory.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would suggest
LazyNodeTypeProvider::fromClosure