Skip to content

Instantly share code, notes, and snippets.

@breadlesscode
Created October 14, 2019 07:59
Show Gist options
  • Save breadlesscode/10992e6ad2d3ae0a64b210eecbf01944 to your computer and use it in GitHub Desktop.
Save breadlesscode/10992e6ad2d3ae0a64b210eecbf01944 to your computer and use it in GitHub Desktop.
Property Mapping
/**
* @param NodeInterface $node
* @return Calendar
* @throws Exception
* @throws \Neos\ContentRepository\Exception\NodeException
*/
protected function generateIcsFileByNode(NodeInterface $node): Calendar
{
$calendar = new Calendar('www.example.com');
$event = new Event($node->getNodeAggregateIdentifier());
foreach ($this->nodePropertyMapping as $nodePropertyName => $classAndMethod) {
$classAndMethod = explode('->', $classAndMethod);
$classAndMethod[1] = 'set'.ucfirst($classAndMethod[1]);
if (!isset(${$classAndMethod[0]})) {
throw new Exception('Wrong object name in mapping. Allowed object names are calendar and event.');
}
if (!method_exists(${$classAndMethod[0]}, $classAndMethod[1])) {
throw new Exception('Wrong property name in mapping. There is no corresponding setter method.');
}
if (!$node->hasProperty($nodePropertyName)) {
throw new Exception('Wrong node property name. This node has no '.$nodePropertyName.' property.');
}
${$classAndMethod[0]}->{$classAndMethod[1]}($node->getProperty($nodePropertyName));
}
$calendar->addComponent($event);
return $calendar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment