Build the directory tree

@param  \DirectoryIterator $it
@return array
494899
protected function buildTree(\DirectoryIterator $it)
    {
        $result = [];

        foreach ($it as $key => $child) {
            if ($child->isDot()) {
                continue;
            }

            $name = $child->getBasename();

            if ($child->isDir()) {
                $subdir = new \DirectoryIterator($child->getPathname());
                $result[DIRECTORY_SEPARATOR . $name] = $this->buildTree($subdir);
            } else {
                $result[] = $name;
            }
        }

        return $result;
    }
1361613
public function getTree(): array
    {
        $tree = [];
        $size = count($this->segments);

        for ($index = 0; $index < $size; $index = $index + 1) {
            $temp = array_slice($this->segments, 0, $index + 1);
            $path = implode(DIRECTORY_SEPARATOR, $temp);

            $tree[] = Path::normalize($path);
        }

        return $tree;
    }
1099121
public function getIterator()
    {
        $iterator   = parent::getIterator();
        $content    = $this->getDependentContent();

        if ( $content )
        {
            $iterator->append( new ArrayIterator( array(
                'rootTitle' => $content->title,
            ) ) );
        }

        return $iterator;
    }
641353
public function getIterator()
    {
        if ($this->iteratorCreator) {
            return call_user_func($this->iteratorCreator, $this, $this->filesystem);
        }

        return $this->createIterator();
    }
1094277
public function all()
	{
		$path = $this->directory;

		$data = array();

		$dirIterator = new DirectoryIterator($path);
		foreach ($dirIterator as $folder)
		{
			if ($folder->isDot() || !$folder->isDir())
			{
				continue;
			}

			$name = $folder->getFilename();

			$item = new Auditor($name);

			$files = new DirectoryIterator($path . DIRECTORY_SEPARATOR . $name);

			foreach ($files as $file)
			{
				if ($file->isDot() || $file->isDir() || in_array(strtolower($file->getFilename()), static::$skip))
				{
					continue;
				}

				$item->tally(filesize($path . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . $file->getFilename()) / 1024);
			}

			$data[$name] = $item;
		}

		return $data;
	}
741786
public static function getDirTree($dir, $self = false)
    {
        if (!is_dir($dir)) {
            throw new RuntimeException(sprintf(
                'Can not build directory tree because of invalid path "%s"', $dir
            ));
        }

        $target = array();
        $tree = array();

        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), 
            RecursiveIteratorIterator::SELF_FIRST
        );

        if ($self !== false) {
            array_push($target, $dir);
        }

        foreach ($iterator as $file) {
            array_push ($target, $file);
        }

        foreach ($target as $index => $file) {
            array_push($tree, (string) $file);
        }

        return $tree;
    }
667278
public function directories($directory = null, $recursive = false)
    {

        $directories = [ ];

        foreach (Finder::create()->in($directory)->directories() as $dir) {
            $directories[] = $dir->getPathname();
        }

        return $directories;
    }
785908
public function listNested($dir = 'desc', $nestingKey = 'children')
    {
        $dir = strtolower($dir);
        $modes = [
            'desc' => TreeIterator::SELF_FIRST,
            'asc' => TreeIterator::CHILD_FIRST,
            'leaves' => TreeIterator::LEAVES_ONLY
        ];

        return new TreeIterator(
            new NestIterator($this, $nestingKey),
            isset($modes[$dir]) ? $modes[$dir] : $dir
        );
    }
506442
public function getPathTree(): array
    {
        $tree = [];
        foreach ($this->getTree() as $branch) {
            $tree[] = Path::make($branch);
        }

        return $tree;
    }
575147
private function getDirectories($dir, $directoryName = null)
    {
        $finder = new Finder();
        $finder->directories()->in($dir);

        if (null !== $directoryName) {
            $finder->name($directoryName);
        }

        if (iterator_count($finder) > 0) {
            return iterator_to_array($finder);
        }

        return false;
    }
725167
protected function getArrayFromXml(SimpleXmlIterator $iterator)
    {
        $result = [];

        for($iterator->rewind(); $iterator->valid(); $iterator->next())
        {
            if($iterator->hasChildren())
            {
                foreach($iterator->getChildren() as $key => $value)
                {
                    if(1 <= $value->count())
                    {
                        $result[$iterator->key()][][$key] = $this->getArrayFromXml($value);
                    }
                    else
                    {
                        if(true === $value->hasChildren())
                        {
                            $result[$iterator->key()][$key] = $this->getArrayFromXml($value);
                        }
                        else
                        {
                            $result[$iterator->key()] = $this->getArrayFromXml($iterator->current());
                        }
                    }
                }
            }
            else
            {
                $result[$iterator->key()] = $this->convertToStringOrBoolean($iterator->current());
            }
        }

        return $result;
    }
525110
public function loadDirectory($directory) {
        $iterator = new DirectoryIterator($directory);
        foreach($iterator as $file) {
            if($file->isFile() && ends_with($file->getFilename(), '.php')) {
                require $directory . '/' . $file->getFilename();
            }
        }
    }
596912
public function items($directory)
    {
        $directory = ltrim($directory, "/");

        $iterator = new FilesystemIterator($this->pathRoot.$directory);

        $files = array();

        foreach ($iterator as $file) {
            $files[] = strval($file);
        }
        
        return $files;
    }
1041557
private static function AtomizeIterator( $iter )
	{
		/**
		 * @var XPathNavigator $item
		 */
		foreach ( $iter as $item )
		{
			if ( $item->getIsNode() )
			{
				if ( $item->getNodeType() == XPathNodeType::Comment )
				{
					continue;
				}

				if ( $item->getNodeType() == XPathNodeType::Element )
				{
					$child = $item->CloneInstance();
					$result = $child->MoveToFirstChild();

					$items = array();

					if ( $child->getNodeType() == XPathNodeType::Text )
					{
						$items[] = $item->getTypedValue();
					}
					else
					{
						while ( $result )
						{
							$data = ExtFuncs::GetData( XPath2NodeIterator::Create( $child->CloneInstance() ) );
							if ( $data->MoveNext() )
							{
								$items[] = $data->getCurrent(); // ->getValue();
							}

							$result = $child->MoveToNext();
						}
					}

					if ( ! count( $items ) )
					{
						yield Undefined::getValue();
					}
					else if ( count( $items ) == 1 )
					{
						yield $items[0];
					}
					else
					{
						yield XPath2Item::fromValueAndType( implode( "", $items ), XmlSchema::$String );
					}

					return false;
				}
				else
				if ( is_null( $item->getTypedValue() ) )
				{
			    	if ( $item instanceof XPathNavigator )
					{
						/**
						 * @var XPathNavigator $nav
						 */
						$nav = $item;
						if ( ! is_null( $nav->getSchemaInfo() ) &&
							 ! is_null( $nav->getSchemaInfo()->getSchemaType() ) &&
							 ! ( $nav->getSchemaInfo()->getSchemaType() instanceof XmlSchemaSimpleType ) )
						{
							throw XPath2Exception::withErrorCodeAndParam( "FOTY0012", Resources::FOTY0012, new XmlQualifiedName( $nav->LocalName, $nav->NamespaceURI, false ) );
						}
					}
				}
			}

		    yield $item instanceof XPath2Item
		    	? $item
		    	: XPath2Item::fromValue( $item->GetTypedValue() );
		}
	}
956623
public static function files(\RecursiveDirectoryIterator $directory): array
    {
        if (!$directory instanceof \RecursiveDirectoryIterator) {
            $directory = new \RecursiveDirectoryIterator($directory);
        }
        $files = [];
        for (; $directory->valid(); $directory->next()) {
            if ($directory->isDir() && !$directory->isDot()) {
                if ($directory->haschildren()) {
                    $files = array_merge($files, static::files($directory->getChildren()));
                };
            } else if ($directory->isFile()) {
                $files[] = $directory->getPathName();
            }
        }
        return $files;
    }
260823
public function getAllDirectories(): array
    {
        $directories = [];

        foreach ($this->filesystem->listContents('/'.$this->path) as $info) {
            $id = $info['filename'];

            if ($this->hasDirectory($id)) {
                $directories[$id] = $this->getDirectory($id);
            }
        }

        return $directories;
    }
987335
public function getChildren(): \RecursiveIterator {
        $nodes = [];

        if ($this->valid()) {
            $nodes = $this->current()->childNodes;
        }

        return new static($nodes);
    }