Location: PHPKode > projects > iF.SVNAdmin > svnadmin/ifphplib/IF_File.class.php
<?php
/**
 * iF.SVNAdmin
 * Copyright (c) 2010 by Manuel Freiholz
 * http://www.insanefactory.com/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.
 */
/**
 * Represents a file or directory of the filesystem.
 * @author Manuel Freiholz / www.gainwar.de
 */
class IF_File
{
  // Holds the path which the user used with constructor.
  private $m_path = NULL;
  
  /**
   * Creates a new instance of this class.
   *
   */
  public function __construct( $path )
  {
    $this->m_path = $path;
  }
  
  /**
   * Gets the path which the user used for the constructor.
   *
   * @return String   
   */        
  public function getPath()
  {
    return $this->m_path;
  }
  
  /**
   * Gets the absolute path of this file.
   * 
   * @return String
   */
  public function getAbsolutePath()
  {
    return realpath( $this->m_path );
  }
  
  /**
   * Gets the file-name part of this file.
   * 
   * @return String
   */           
  public function getName()
  {
    return basename( $this->getAbsolutePath() );
  }
  
  /**
   * Gets to know whether this IF_File object points to a folder.
   *
   * @return bool   
   */        
  public function isDirectory()
  {
    if( is_dir( $this->m_path ) )
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  /**
   * Gets to know whether this IF_File object points to a regular file.
   *
   * @return bool   
   */        
  public function isFile()
  {
    if( is_file( $this->m_path ) )
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  /**
   * Gets to know whether this IF_File object points to a symbolic link.
   *
   * @return bool   
   */        
  public function isLink()
  {
    if( is_link( $this->m_path ) )
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  /**
   * Gets the length, in bytes, of a file and returns it.
   * 
   * @return int
   */           
  public function length()
  {
    return filesize( $this->m_path );
  }
  
  /**
   * Gets the owner ID of this file.
   * 
   * @return int
   */           
  public function getOwner()
  {
    return fileowner( $this->m_path );
  }
  
  /**
   * Gets the group ID of this file.
   * 
   * @return int
   */           
  public function getGroup()
  {
    return filegroup( $this->m_path );
  }

  /**
   * Gets the timestamp of the last access to this file.
   * 
   * @return int
   */             
  public function getLastAccess()
  {
    return fileatime( $this->m_path );
  }
  
  /**
   * Gets the timestamp of the last modification to this file.
   * 
   * @return int
   */             
  public function getLastModified()
  {
    return filemtime( $this->m_path );
  }
  
  /**
   * Gets the permission for this file in octal representation.
   * Examples (seperated by comma): 0664, 0777, 0774
   * 
   * @return int
   */              
  public function getPermissions()
  {
   return fileperms( $this->m_path );
  }
  
  /**
   * Deletes this file or directory.
   * Note that if this object points to a directory, the directory
   * must be empty, otherwise a error occurs.
   * 
   * @return bool      
   */           
  public function delete()
  {
    if( $this->isDirectory() )
    {
      return rmdir( $this->m_path );
    }
    else
    {
      return unlink( $this->m_path );
    }
  }
  
  /**
   * Checks whether this file exists.
   * 
   * @return bool
   */           
  public function exists()
  {
    if( file_exists( $this->m_path ) )
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  
  public function listFiles()
  {
    // The results array which contains the IF_File's
    $files = array();
    
    // This function only can be called on directories.
    if( $this->isDirectory() )
    {
      // Open directory.
      $dirHandle = opendir( $this->m_path );
      
      // Check whether we have open the directory and got a resource.
      if( $dirHandle )
      {
        
      }
    }
  }
  
  /**
   * Enter description here...
   *
   * @param IF_File $oDestFile
   */
  public function copyTo( $oDestFile )
  {
  	return copy( self::getAbsolutePath() , $oDestFile->getAbsolutePath() );
  }
  
}
?>
Return current item: iF.SVNAdmin