00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>