예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function setIterator(IIterator $iterator)
 {
     $this->iterator = $iterator;
     $iterator->setDescendCallback(array($this, 'onStepDown'));
     $iterator->setAscendCallback(array($this, 'onStepUp'));
     return $this;
 }
예제 #2
0
 /**
  * Builds fake item structure by looping through iterator.
  *
  * @param IIterator $iterator
  * @param IItem $root
  *
  * @return IItem
  */
 public function getProxy(IIterator $iterator, IItem $root)
 {
     $depth = 0;
     // Set iterator callbacks
     $stepDown = function () use(&$depth) {
         $depth++;
     };
     $stepUp = function () use(&$depth) {
         $depth--;
     };
     $iterator->setDescendCallback($stepDown);
     $iterator->setAscendCallback($stepUp);
     // Create root item
     $proxyRoot = $root->isolatedClone();
     // Setup loop starting values
     $currentItem = $proxyRoot;
     $lastItem = $proxyRoot;
     $lastDepth = $depth;
     foreach ($iterator as $item) {
         /** @var $item IItem */
         $proxy = $item->isolatedClone();
         // Descended
         if ($lastDepth < $depth) {
             $currentItem = $lastItem;
         }
         // Ascended
         if ($lastDepth > $depth) {
             for ($i = 0; $i < $lastDepth - $depth; $i++) {
                 $currentItem = $currentItem->getParent();
             }
         }
         $currentItem->addChild($proxy);
         $lastItem = $proxy;
         $lastDepth = $depth;
     }
     return $proxyRoot;
 }
예제 #3
0
 /**
  * Gets current item
  *
  * @return IItem
  */
 public function current()
 {
     return $this->currentIterator->current();
 }