PHP Classes

File: core/classes/File.class.php

Recommend this page to a friend!
  Classes of Marius Zadara   PAX   core/classes/File.class.php   Download  
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
Author: By
Last change: New version
Date: 15 years ago
Size: 2,347 bytes
 

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_001, 1);
               
           
// .. and is readable
           
if (!$this->isReadable())
                throw new
PAXException(Messages::$MSG_005, 5);
               
           
// 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_006, 6);
                               
            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()
    {
    }
}

?>