PHP Classes
Icontem

File: core/classes/File.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Marius Zadara  >  PAX  >  core/classes/File.class.php  
File: core/classes/File.class.php
Role: Class source
Content type: text/plain
Description: File class
Class: PAX
Interpret XML command scripts with PHP classes
 

Contents

Class file image Download
<?php
/**
 * Page DocBlock definition
 * @package org.zadara.marius.pax
 */

/**
 * General file class definition.
 * 
 * @author Marius Zadara <marius@zadara.org>
 * @category Classes
 * @copyright (C) 2008-2009 Marius Zadara
 * @license Free for non-comercial use
 * @package org.zadara.marius.pax
 * @see Resource
 * @see IFile
 * @version 6.0
 * @since 5.0
 */
class File extends Resource implements IFile 
{
    
/**
     * Class constructor.
     * 
     * @access public
     */
    
public function __construct()
    {
        
// call the parent contructor
        
parent::__construct();    
    }

    
/**
     * Method to check if the file is ordinary.
     * Throws exception if error encountered.
     *
     * @access public
     * @final 
     * @return boolean
     * 
     * @see Resource#exists() 
     */
    
public final function isOrdinary()
    {
        
try
        
{
            
// to check if the file is ordinary,
            // it must already exists
            
$this->exists();

            
// since the result is cached, 
            // clear before checking it 
            
clearstatcache();
            
            return @
is_file($this->path);
        }
        
catch (PAXException $pe)
        {
            
// in case of pax exception, 
            // throw it further
            
throw $pe;
        }
        
catch (Exception $e)
        {
            
// in case of general exception, 
            // throw it further
            
throw $e;
        }
    }
    
    
/**
     * Method to get the content of the file.
     * Throws exception in case of error.
     *
     * @access public
     * @final
     * @return string
     */
    
public final function getContent()
    {
        
try 
        
{
            
// check to see if the file is ordinary
            
if (!$this->isOrdinary())
                
throw new PAXException(Messages::$MSG_0011);
                
            
// .. and is readable
            
if (!$this->isReadable())
                
throw new PAXException(Messages::$MSG_0055);
                
            
// try to get the file content
            
$content = @file_get_contents($this->path);
            
            
// if failed getting the file content, 
            // throw exception
            
if ($content === false)
                
throw new PAXException(Messages::$MSG_0066);
                                
            return 
$content;
        }
        
catch (PAXException $pe)
        {
            
// in case of exception, 
            // throw it further
            
throw $pe;
        }
        
catch (Exception $e)
        {
            
// in case of exception,
            // throw it further
            
throw $e;
        }        
    }
    
    
/**
     * Class destructor.
     * 
     * @access private
     */
    
function __destruct()
    {
    }    
}

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products