From f6f3c89dc822da00800434408e89d45cd197883e Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Tue, 22 Dec 2015 14:59:04 +0000 Subject: [PATCH] Add SSViewer_Scope constants to make it easier to work with item stacks --- view/SSViewer.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/view/SSViewer.php b/view/SSViewer.php index 970c0a882..34c3b7148 100644 --- a/view/SSViewer.php +++ b/view/SSViewer.php @@ -24,8 +24,16 @@ */ class SSViewer_Scope { + const ITEM = 0; + const ITEM_ITERATOR = 1; + const ITEM_ITERATOR_TOTAL = 2; + const POP_INDEX = 3; + const UP_INDEX = 4; + const CURRENT_INDEX = 5; + const ITEM_OVERLAY = 6; + // The stack of previous "global" items - // And array of item, itemIterator, itemIteratorTotal, pop_index, up_index, current_index, parent_overlay + // An indexed array of item, item iterator, item iterator total, pop index, up index, current index & parent overlay private $itemStack = array(); // The current "global" item (the one any lookup starts from) @@ -135,12 +143,12 @@ class SSViewer_Scope { public function pushScope(){ $newLocalIndex = count($this->itemStack)-1; - $this->popIndex = $this->itemStack[$newLocalIndex][3] = $this->localIndex; + $this->popIndex = $this->itemStack[$newLocalIndex][SSViewer_Scope::POP_INDEX] = $this->localIndex; $this->localIndex = $newLocalIndex; // We normally keep any previous itemIterator around, so local $Up calls reference the right element. But // once we enter a new global scope, we need to make sure we use a new one - $this->itemIterator = $this->itemStack[$newLocalIndex][1] = null; + $this->itemIterator = $this->itemStack[$newLocalIndex][SSViewer_Scope::ITEM_ITERATOR] = null; return $this; } @@ -159,9 +167,9 @@ class SSViewer_Scope { if (is_array($this->item)) $this->itemIterator = new ArrayIterator($this->item); else $this->itemIterator = $this->item->getIterator(); - $this->itemStack[$this->localIndex][1] = $this->itemIterator; + $this->itemStack[$this->localIndex][SSViewer_Scope::ITEM_ITERATOR] = $this->itemIterator; $this->itemIteratorTotal = iterator_count($this->itemIterator); //count the total number of items - $this->itemStack[$this->localIndex][2] = $this->itemIteratorTotal; + $this->itemStack[$this->localIndex][SSViewer_Scope::ITEM_ITERATOR_TOTAL] = $this->itemIteratorTotal; $this->itemIterator->rewind(); } else { @@ -552,7 +560,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope { $scope = parent::pushScope(); $itemStack = $this->getItemStack(); - $itemStack[$this->getUpIndex()][6] = $this->overlay; + $itemStack[$this->getUpIndex()][SSViewer_Scope::ITEM_OVERLAY] = $this->overlay; $this->setItemStack($itemStack); $this->overlay = array(); @@ -568,7 +576,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope { */ public function popScope() { $itemStack = $this->getItemStack(); - $this->overlay = $itemStack[$this->getUpIndex()][6]; + $this->overlay = $itemStack[$this->getUpIndex()][SSViewer_Scope::ITEM_OVERLAY]; return parent::popScope(); } @@ -596,8 +604,8 @@ class SSViewer_DataPresenter extends SSViewer_Scope { if ($overlayIndex !== false) { $itemStack = $this->getItemStack(); - if (!$this->overlay && isset($itemStack[$overlayIndex][6])) { - $this->overlay = $itemStack[$overlayIndex][6]; + if (!$this->overlay && isset($itemStack[$overlayIndex][SSViewer_Scope::ITEM_OVERLAY])) { + $this->overlay = $itemStack[$overlayIndex][SSViewer_Scope::ITEM_OVERLAY]; } }