filesystem
[ class tree: filesystem ] [ index: filesystem ] [ all elements ]

Source for file Folder.class.php

Documentation is available at Folder.class.php

  1. <?
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package filesystem
  9.  */
  10. if!defined"CLASSPATH" ) )
  11. {
  12.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  13.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  14.   exit();
  15. }
  16.  
  17. /**
  18.  *
  19.  */
  20. require_onceCLASSPATH."filesystem/Files.class.php" );
  21.  
  22. /**
  23.  * A class to manage folder in a filesystemtree.
  24.  *
  25.  * @package   filesystem
  26.  * @version   0.1.25
  27.  * @author    Daniel Plücken <daniel@debakel.net>
  28.  * @license   http://www.gnu.org/copyleft/lesser.html
  29.  *             GNU Lesser General Public License
  30.  * @copyright Copyright (c) 2003 Daniel Plücken <daniel@debakel.net>
  31.  *
  32.  *  This library is free software; you can redistribute it and/or
  33.  *  modify it under the terms of the GNU Lesser General Public
  34.  *  License as published by the Free Software Foundation; either
  35.  *  version 2.1 of the License.
  36.  *
  37.  *  This library is distributed in the hope that it will be useful,
  38.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  39.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40.  *  GNU Lesser General Public License for more details.
  41.  *
  42.  *  You should have received a copy of the GNU Lesser General
  43.  *  Public License along with this library; if not, write to the
  44.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  45.  *  Boston, MA 02111-1307 USA
  46.  */
  47. class Folder
  48. {
  49.    /**
  50.     * @access public
  51.     * @var    string $path 
  52.     */
  53.    var $path;
  54.    /**
  55.     * @access public
  56.     * @var    string $name 
  57.     */
  58.    var $name;
  59.    /**
  60.     * @access public
  61.     * @var    Folder $parentfolder 
  62.     */
  63.    var $parentfolder;
  64.    /**
  65.     * @access public
  66.     * @var    array  $folder 
  67.     */
  68.    var $folder;
  69.    /**
  70.     * @access public
  71.     * @var    array  $files 
  72.     */
  73.    var $files;
  74.  
  75.  
  76.  
  77.  
  78.    /**
  79.     * Constructor
  80.     *
  81.     * @version 1.0
  82.     * @since   0.1.0
  83.     * @author  Daniel Plücken <daniel@debakel.net>
  84.     * @access  public
  85.     * @param   string  $name 
  86.     * @param   object  $parent 
  87.     */
  88.    function Folder$name$parent )
  89.    {
  90.      $this->name = $name;
  91.      $this->path = $parent->path."/".$name;
  92.    }
  93.  
  94.  
  95.  
  96.   /**
  97.     * Sets the parent folder of this folder object that there is a back reference
  98.     * up to the root of the filesystem tree,
  99.     *
  100.     * @version 1.0
  101.     * @since   0.1.0
  102.     * @author  Daniel Plücken <daniel@debakel.net>
  103.     * @access  protected
  104.     * @param   Folder     $objRef  The reference to the folder object that
  105.     *                               contains this folder.
  106.     */
  107.   function setParentFolder&$objRef )
  108.   $this->parentfolder = &$objRef}
  109.  
  110.  
  111.  
  112.  
  113.   /**
  114.     * Returns the names of folder that this folder contains by an array.
  115.     *
  116.     * @version 1.0
  117.     * @since   0.1.0
  118.     * @author  Daniel Plücken <daniel@debakel.net>
  119.     * @access  public
  120.     * @return  array 
  121.     */
  122.    function getFoldernames()
  123.    {
  124.       for$i 0$i count$this->folder )$i++ )
  125.          $outputArr[$this->folder[$i]->getName();
  126.  
  127.       return $outputArr;
  128.    }
  129.  
  130.  
  131.  
  132.  
  133.   /**
  134.     * Returns the names of files that this folder contains by an array.
  135.     *
  136.     * @version 1.0
  137.     * @since   0.1.0
  138.     * @author  Daniel Plücken <daniel@debakel.net>
  139.     * @access  public
  140.     * @return  array 
  141.     */
  142.    function getFilenames()
  143.    {
  144.       for$i 0$i count$this->files )$i++ )
  145.          $outputArr[$this->files[$i]->getName();
  146.  
  147.       return $outputArr;
  148.    }
  149.  
  150.  
  151.  
  152.  
  153.   /**
  154.     * Returns the path to the folder of this folder object including
  155.     * it selfs name.
  156.     *
  157.     * @version 1.0
  158.     * @since   0.1.0
  159.     * @author  Daniel Plücken <daniel@debakel.net>
  160.     * @access  public
  161.     * @return  string 
  162.     */
  163.    function getPath()
  164.    return $this->path}
  165.  
  166.  
  167.  
  168.  
  169.   /**
  170.     * Returns the foldername of this folder object.
  171.     *
  172.     * @version 1.0
  173.     * @since   0.1.0
  174.     * @author  Daniel Plücken <daniel@debakel.net>
  175.     * @access  public
  176.     * @return  string 
  177.     */
  178.    function getName()
  179.    return $this->name}
  180.  
  181.  
  182.  
  183.  
  184.   /**
  185.     * Returns the file objects of this folder object in pre-order.
  186.     *
  187.     * @version 1.0
  188.     * @since   0.1.25
  189.     * @author  Daniel Plücken <daniel@debakel.net>
  190.     * @access  public
  191.     * @return  array 
  192.     */
  193.    function &getFilesArray()
  194.    {
  195.        $out_arr array();
  196.        foreach $this->files as $key => $value )
  197.            $out_arr[=$this->files[$key];
  198.  
  199.        foreach $this->folder as $key => $value )
  200.        {
  201.            $tmp_arr =$this->folder[$key]->getFilesArray();
  202.  
  203.            // array_merge doesn't keep references alive!
  204.            foreach $tmp_arr as $key2 => $value2 )
  205.                $out_arr[=$tmp_arr[$key2];
  206.  
  207.            unset$tmp_arr );
  208.        }
  209.  
  210.        return $out_arr;
  211.    }
  212.  
  213.  
  214.  
  215.  
  216.   /**
  217.     * Prints out a dirty formatted list of all folder and files that this
  218.     * folder contains. All contents of containing folder will be printed too
  219.     * because of recursive invocation.
  220.     *
  221.     * @version 1.0
  222.     * @since   0.1.0
  223.     * @author  Daniel Plücken <daniel@debakel.net>
  224.     * @access  public
  225.     */
  226.    function echoNameQueque()
  227.    {
  228.       echo "<blockquote>\n";
  229.       for$i 0$i count$this->folder )$i++ )
  230.       {
  231.          echo $this->folder[$i]->getName()."<br>\n";
  232.          $this->folder[$i]->echoNameQueque();
  233.       }
  234.       for$i 0$i count$this->files )$i++ )
  235.          echo $this->files[$i]->getName()."<br>\n";
  236.       echo "</blockquote>\n";
  237.    }
  238. // END of class Folder
  239. ?>

Documentation generated on Thu, 05 Jun 2008 19:11:40 +0200 by phpDocumentor 1.4.1