<?php

	/** 
	 *
	 * \ingroup File
	 *
	 * Iterator that recursively loops through the contents of the given folder
	 *
	 * @author The LifeType Project	
	 */
	class DirectoryTreeIterator extends RecursiveIteratorIterator
	{
	    /** 
	     * Construct from a path.
	     * @param $path directory to iterate
	     */
	    function __construct($path)
	    {
			try {
				parent::__construct(
	            	new RecursiveCachingIterator(
	                	new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME
	                		),
	                		CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD
	            	),
	            	parent::SELF_FIRST
	        	);
	     	} 
			catch(Exception $e) {
	       		echo $e->getMessage();
	       		exit;
	     	}
	    }

	    function current()
	    {
			if ($this->hasChildren())
				$this->next(); 
	      	return $this->key();
	    }

	    function __call($func, $params)
	    {
	      return call_user_func_array(array($this->getSubIterator(), $func), $params);
	    }
	}
?>