Skip to content

Commit

Permalink
!!! TASK Make NodeType::getPropertyType throw if property not declared
Browse files Browse the repository at this point in the history
Resolves #4477
mhsdesign committed Sep 18, 2023
1 parent 96e4257 commit ac88f59
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions Neos.ContentRepository.Core/Classes/NodeType/NodeType.php
Original file line number Diff line number Diff line change
@@ -409,22 +409,32 @@ public function getProperties(): array
}

/**
* Returns the configured type of the specified property
* Check if the property is configured in the schema.
*/
public function hasProperty(string $propertyName): bool
{
$this->initialize();

return isset($this->fullConfiguration['properties'][$propertyName]);
}

/**
* Returns the configured type of the specified property, and falls back to 'string'.
*
* @param string $propertyName Name of the property
* @throws \InvalidArgumentException if the property is not configured
*/
public function getPropertyType(string $propertyName): string
{
$this->initialize();

if (
!isset($this->fullConfiguration['properties'])
|| !isset($this->fullConfiguration['properties'][$propertyName])
|| !isset($this->fullConfiguration['properties'][$propertyName]['type'])
) {
return 'string';
if (!$this->hasProperty($propertyName)) {
throw new \InvalidArgumentException(
sprintf('NodeType schema has no property "%s" configured. Cannot read its type.', $propertyName),
1695062252040
);
}
return $this->fullConfiguration['properties'][$propertyName]['type'];

return $this->fullConfiguration['properties'][$propertyName]['type'] ?? 'string';
}

/**

0 comments on commit ac88f59

Please sign in to comment.