PHP Classes
Icontem

File: core/classes/Resource.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/Resource.class.php  
File: core/classes/Resource.class.php
Role: Class source
Content type: text/plain
Description: General resource file
Class: PAX
Interpret XML command scripts with PHP classes
 

Contents

Class file image Download
<?php


/**
 * Page DocBlock definition
 * @package org.zadara.marius.pax
 */

/**
 * General resource 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
 * @abstract 
 * @see PAXObject
 * @see IResource
 * @version 6.0
 * @since 5.0
 */
abstract class Resource extends PAXObject implements IResource 
{
    
/**
     * The path of the resource.
     *
     * @var string
     * @access protected
     */
    
protected  $path;
        
    
    
/**
     * Class constructor.
     * 
     * @access public
     */
    
public function __construct()
    {
        
// init the parent first
        
parent::__construct();
        
        
// init the path of the resource
        
$this->path null;        
    }
    
    
/**
     * Method to set the path of the resource.
     * Throws exception in case of error.
     *
     * @access public
     * @final 
     * @param string <b>$path</b> The path of the resource
     * @return void
     */
    
public final function setPath($path)
    {
        
// check the path
        
if (!is_string($path))
            
throw new PAXException(Messages::$MSG_0011);
        
        
// remove any extra-spaces from the path
        // in order to see if is really empty
        
$path trim($path);

        
// check the path again
        
if ($path == "")
            
throw new PAXException(Messages::$MSG_0022);

        
// set the path of the resource
        
$this->path $path;
    }    
    
    
/**
     * Method to check if the resource exists.
     * It assumes that its path has been already set.
     * Throws exception in case of error
     * 
     * @access public
     * @final 
     * @return boolean
     */
    
public final function exists()
    {
        
// check to see if the resource path has been set
        // if not, throw exception
        
if (is_null($this->path))
            
throw new PAXException(Messages::$MSG_0033);                    
        
        
// check existence 
        
return @file_exists($this->path);                        
    }
    
    
    
/**
     * Method to check if the resource is readable.
     * Throws exception in case of error.
     *
     * @access public
     * @final 
     * @return boolean
     */
    
public final function isReadable()
    {        
        
try 
        
{
            
// in order to check if is readable,
            // the resource must already exists
            
$exists $this->exists();
            
            if (!
$exists)
                
throw new PAXException(Messages::$MSG_0044);
            
            
// since this status is cached, 
            // clear it before checking 
            
clearstatcache();
            
            
// check if is readable
            
return @is_readable($this->path);
        }
        
catch (PAXException $pe)
        {
            
// in case of specific error,
            // send the exception further
            
throw $pe;
        }
        
catch (Exception $e)
        {
            
// in case of general error,
            // send it further
            
throw $e;
        }
    }
    
    
    
/**
     * Method to check if the resource is writable.
     * It throws exception in case of error
     *
     * @access public
     * @final 
     * @return boolean
     */
    
public final function isWritable()
    {
        
try 
        
{
            
// in order to check if is writable,
            // the resource must already exists
            
$exists $this->exists();
            
            if (!
$exists)
                
throw new PAXException(Messages::$MSG_0044);
            
            
// clear the status cache
            // before checking
            
clearstatcache();
            
            return @
is_writable($this->path);
        }
        
catch (PAXException $pe)
        {
            
// in case of error, 
            // send the exception further
            
throw $pe;
        }
        
catch (Exception $e)
        {
            
// in case of general error,
            // send 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