-
-
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
!!!TASK: Remove NodeTypeManager from NodeType #4520
Merged
mhsdesign
merged 15 commits into
neos:9.0
from
kitsunet:task/90-remove-nodetypemanager-from-node-4515
Oct 17, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ed2bb0f
!!!TASK: Remove NodeTypeManager from NodeType
kitsunet e9d2fac
Remove constructor injection of NodeTypeManager in NodeType
kitsunet 5acb733
TASK: Remove accidental `public` declaration of NodeType::$abstract
mhsdesign 23d715f
TASK: Declare construction of NodeType `@internal`
mhsdesign 5686898
Adjust signature of `populateNodeAggregateIds`
kitsunet 0a2a126
Fix linting errors
kitsunet 4222a9b
Address PR comments
kitsunet 667d1eb
Merge branch '9.0' into task/90-remove-nodetypemanager-from-node-4515
kitsunet 22b41cf
BUGFIX: Fix 4344 for Neos 9.0
mhsdesign 56e1b32
Merge branch '9.0' into task/90-remove-nodetypemanager-from-node-4515
kitsunet a2a0447
Rename methods to use tethered instead of child node
kitsunet 53a5ad7
Adjust new DefaultPropertyEditorPostProcessorTest
kitsunet c7aea4e
Fix syntactic error in DisallowedChildNodeAdjustment
kitsunet 6b28944
Fix TetheredNodeAdjustments after wrong merge
kitsunet 0742577
Fix merge error in DisallowedChildNodeAdjustment
kitsunet 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
137 changes: 137 additions & 0 deletions
137
Neos.ContentRepository.Core/Classes/NodeType/ConstraintCheck.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,137 @@ | ||
<?php | ||
|
||
namespace Neos\ContentRepository\Core\NodeType; | ||
|
||
/** | ||
* Performs node type constraint checks against a given set of constraints | ||
* @internal | ||
*/ | ||
class ConstraintCheck | ||
{ | ||
/** | ||
* @param array<string,mixed> $constraints | ||
*/ | ||
public function __construct( | ||
private readonly array $constraints | ||
) { | ||
} | ||
|
||
public function isNodeTypeAllowed(NodeType $nodeType): bool | ||
{ | ||
$directConstraintsResult = $this->isNodeTypeAllowedByDirectConstraints($nodeType); | ||
if ($directConstraintsResult !== null) { | ||
return $directConstraintsResult; | ||
} | ||
|
||
$inheritanceConstraintsResult = $this->isNodeTypeAllowedByInheritanceConstraints($nodeType); | ||
if ($inheritanceConstraintsResult !== null) { | ||
return $inheritanceConstraintsResult; | ||
} | ||
|
||
if (isset($this->constraints['*'])) { | ||
return (bool)$this->constraints['*']; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return boolean|null true if the passed $nodeType is allowed by the $constraints, null if couldn't be decided | ||
*/ | ||
protected function isNodeTypeAllowedByDirectConstraints(NodeType $nodeType): ?bool | ||
{ | ||
if ($this->constraints === []) { | ||
return true; | ||
} | ||
|
||
if ( | ||
array_key_exists($nodeType->name->value, $this->constraints) | ||
&& $this->constraints[$nodeType->name->value] === true | ||
) { | ||
return true; | ||
} | ||
|
||
if ( | ||
array_key_exists($nodeType->name->value, $this->constraints) | ||
&& $this->constraints[$nodeType->name->value] === false | ||
) { | ||
return false; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* This method loops over the constraints and finds node types that the given node type inherits from. For all | ||
* matched super types, their super types are traversed to find the closest super node with a constraint which | ||
* is used to evaluated if the node type is allowed. It finds the closest results for true and false, and uses | ||
* the distance to choose which one wins (lowest). If no result is found the node type is allowed. | ||
* | ||
* @return ?boolean (null if no constraint matched) | ||
*/ | ||
protected function isNodeTypeAllowedByInheritanceConstraints(NodeType $nodeType): ?bool | ||
{ | ||
$constraintDistanceForTrue = null; | ||
$constraintDistanceForFalse = null; | ||
foreach ($this->constraints as $superType => $constraint) { | ||
if ($nodeType->isOfType($superType)) { | ||
$distance = $this->traverseSuperTypes($nodeType, $superType, 0); | ||
|
||
if ( | ||
$constraint === true | ||
&& ($constraintDistanceForTrue === null || $constraintDistanceForTrue > $distance) | ||
) { | ||
$constraintDistanceForTrue = $distance; | ||
} | ||
if ( | ||
$constraint === false | ||
&& ($constraintDistanceForFalse === null || $constraintDistanceForFalse > $distance) | ||
) { | ||
$constraintDistanceForFalse = $distance; | ||
} | ||
} | ||
} | ||
|
||
if ($constraintDistanceForTrue !== null && $constraintDistanceForFalse !== null) { | ||
return $constraintDistanceForTrue < $constraintDistanceForFalse; | ||
} | ||
|
||
if ($constraintDistanceForFalse !== null) { | ||
return false; | ||
} | ||
|
||
if ($constraintDistanceForTrue !== null) { | ||
return true; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* This method traverses the given node type to find the first super type that matches the constraint node type. | ||
* In case the hierarchy has more than one way of finding a path to the node type it's not taken into account, | ||
* since the first matched is returned. This is accepted on purpose for performance reasons and due to the fact | ||
* that such hierarchies should be avoided. | ||
* | ||
* Returns null if no NodeType matched | ||
*/ | ||
protected function traverseSuperTypes( | ||
NodeType $currentNodeType, | ||
string $constraintNodeTypeName, | ||
int $distance | ||
): ?int { | ||
if ($currentNodeType->name->value === $constraintNodeTypeName) { | ||
return $distance; | ||
} | ||
|
||
$distance++; | ||
foreach ($currentNodeType->getDeclaredSuperTypes() as $superType) { | ||
$result = $this->traverseSuperTypes($superType, $constraintNodeTypeName, $distance); | ||
if ($result !== null) { | ||
return $result; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Neos.ContentRepository.Core/Classes/NodeType/Exception/TetheredNodeNotConfigured.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,10 @@ | ||
<?php | ||
|
||
namespace Neos\ContentRepository\Core\NodeType\Exception; | ||
|
||
/** | ||
* @api Might be encountered when childNode information is requested for a child node which was never configured. | ||
*/ | ||
class TetheredNodeNotConfigured extends \DomainException | ||
{ | ||
} |
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.
Would be neat to have this be a DTO with the constraints configuration.
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.
yes or at lest an example how this looks would be cool ^^
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.
+1 for DTO
Also there seem to be some overlaps with the
NodeTypeConstraints
DTO