00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 final class InfoZipArchive extends FileArchive
00019 {
00020 private $zipArchive = null;
00021
00022 public function __construct($cmdBinPath = '/usr/bin/unzip')
00023 {
00024 $usingCmd = $cmdBinPath;
00025
00026 if (class_exists('ZipArchive', false)) {
00027
00028 $this->zipArchive = new ZipArchive();
00029 $usingCmd = null;
00030
00031 } elseif ($usingCmd === null)
00032 throw
00033 new UnsupportedMethodException(
00034 'no built-in support for zip'
00035 );
00036
00037 parent::__construct($usingCmd);
00038 }
00039
00040 public function open($sourceFile)
00041 {
00042 parent::open($sourceFile);
00043
00044 if ($this->zipArchive) {
00045 $resultCode = $this->zipArchive->open($sourceFile);
00046
00047 if ($resultCode !== true)
00048 throw new ArchiverException(
00049 'ZipArchive::open() returns error code == '.$resultCode
00050 );
00051 }
00052
00053 return $this;
00054 }
00055
00056 public function readFile($fileName)
00057 {
00058 if (!$this->sourceFile)
00059 throw
00060 new WrongStateException(
00061 'dude, open an archive first.'
00062 );
00063
00064 if ($this->zipArchive) {
00065 $result = $this->zipArchive->getFromName($fileName);
00066
00067 if ($result === false)
00068 throw new ArchiverException(
00069 'ZipArchive::getFromName() failed'
00070 );
00071
00072 return $result;
00073 }
00074
00075 $options = '-c -q'
00076 .' '.escapeshellarg($this->sourceFile)
00077 .' '.escapeshellarg($fileName);
00078
00079 return $this->execStdoutOptions($options);
00080 }
00081 }
00082 ?>