/**
  * Filters the iterator values.
  *
  * @return bool true if the value should be kept, false otherwise
  */
 public function accept()
 {
     /** @var Directory|File $handler */
     $handler = $this->iterator->current();
     if ($this->isRecursive && isset($this->excludedDirs[$handler->getFilename()]) && $handler->isDir()) {
         return false;
     }
     if ($this->excludedPattern) {
         $path = $handler->isDir() ? $handler->getPath() : $handler->getDirname();
         $path = str_replace('\\', '/', $path);
         return !preg_match($this->excludedPattern, $path);
     }
     return true;
 }
 /**
  * constructor
  *
  * @param RecursiveIterator $iterator
  * @param string $filter
  */
 public function __construct(\RecursiveIterator $iterator, $filter, $topDirectory = null)
 {
     $this->_filter = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $filter);
     if ($topDirectory == null) {
         $iterator->rewind();
         $this->_topDirectory = (string) $iterator->current()->getPath();
     } else {
         $this->_topDirectory = $topDirectory;
     }
     parent::__construct($iterator);
 }
 protected function createViewModelForMenuItemIterator(\RecursiveIterator $rit)
 {
     $itemsViews = array();
     $rit->rewind();
     while ($rit->valid()) {
         $item = $rit->current();
         $view = $this->createViewModelForMenuItem($item);
         if ($rit->hasChildren()) {
             $childrenView = $this->createViewModelForMenuItemIterator($rit->getChildren());
             $view->set('children', $childrenView);
         }
         $itemsViews[] = $view;
         $rit->next();
     }
     return $itemsViews;
 }
Exemple #4
0
 /**
  * Walks recursivly throught an array and concatinates the found info to a string.
  *
  * @param \RecursiveIterator $iterator
  *
  * @return string
  */
 protected static function traverseStructure($iterator)
 {
     $children = '';
     while ($iterator->valid()) {
         if ($iterator->hasChildren()) {
             $current = 'array (' . self::traverseStructure($iterator->getChildren()) . '), ';
         } else {
             $current = "'" . $iterator->current() . "', ";
         }
         $key = $iterator->key();
         if (is_numeric($key)) {
             $children .= $key . " => " . $current;
         } else {
             $children .= "'" . $key . "' => " . $current;
         }
         $iterator->next();
     }
     return $children;
 }