From 5b9b0d4f533dcf7a8e1059afdfd4bf07437fb7f0 Mon Sep 17 00:00:00 2001 From: Julian Kleinhans Date: Tue, 13 Dec 2016 15:59:38 +0100 Subject: [PATCH] #45 Add ExpandCslPort stage for tree preprocessor --- .../PreProcessor/Stage/Tree/ExpandCslPort.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/StackFormation/PreProcessor/Stage/Tree/ExpandCslPort.php diff --git a/src/StackFormation/PreProcessor/Stage/Tree/ExpandCslPort.php b/src/StackFormation/PreProcessor/Stage/Tree/ExpandCslPort.php new file mode 100644 index 0000000..ca091c6 --- /dev/null +++ b/src/StackFormation/PreProcessor/Stage/Tree/ExpandCslPort.php @@ -0,0 +1,43 @@ +parent(1); /* @var $parentRootlineItem RootlineItem */ + $parent = $parentRootlineItem->getValue(); /* @var $parent RecursiveArrayObject */ + + $grandParentRootlineItem = $rootLineReferences->parent(2); /* @var $grandParentRootlineItem RootlineItem */ + $grandParent = $grandParentRootlineItem->getValue(); /* @var $grandParent RecursiveArrayObject */ + + // remove original item + $grandParent->offsetUnset($parentRootlineItem->getKey()); + + // add a new line for every csl item + foreach (explode(',', $value) as $port) { + $newItem = clone $parent; + $newItem->FromPort = $port; + $newItem->ToPort = $port; + $newItem->offsetUnset('Port'); + $grandParent->append($newItem); + } + + return true; // indicate that something has changed + } +}