FileArchive.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Ivan Y. Khvostishkov                            *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: FileArchive.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00013     abstract class FileArchive
00014     {
00015         protected $cmdBinPath   = null;
00016         protected $sourceFile   = null;
00017 
00018         abstract public function readFile($fileName);
00019 
00020         public function __construct($cmdBinPath = null)
00021         {
00022             if ($cmdBinPath !== null) {
00023                 if (!is_executable($cmdBinPath))
00024                     throw new WrongStateException(
00025                         'cannot find executable '.$cmdBinPath
00026                     );
00027 
00028                 $this->cmdBinPath = $cmdBinPath;
00029             }
00030         }
00031         
00035         public function open($sourceFile)
00036         {
00037             if (!is_readable($sourceFile))
00038                 throw new WrongStateException(
00039                     'cannot open file '.$sourceFile
00040                 );
00041             
00042             $this->sourceFile = $sourceFile;
00043 
00044             return $this;
00045         }
00046 
00047         protected function execStdoutOptions($options)
00048         {
00049             if (!$this->cmdBinPath)
00050                 throw new WrongStateException(
00051                     'nothing to exec'
00052                 );
00053 
00054             $cmd = escapeshellcmd($this->cmdBinPath.' '.$options);
00055 
00056             ob_start();
00057             
00058             $exitStatus = null;
00059             
00060             passthru($cmd.' 2>/dev/null', $exitStatus);
00061             
00062             $output = ob_get_clean();
00063 
00064             if ($exitStatus != 0)
00065                 throw new ArchiverException(
00066                     $this->cmdBinPath.' failed with error code = '.$exitStatus
00067                 );
00068 
00069             return $output;
00070         }
00071     }
00072 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4