1<?php 2/** 3 * PHP_Archive exception 4 * 5 * @package PHP_Archive 6 * @category PHP 7 */ 8/** 9 * base class for all PEAR exceptions 10 */ 11require_once 'PEAR/Exception.php'; 12/** 13 * PHP_Archive exception 14 * 15 * @package PHP_Archive 16 * @category PHP 17 */ 18class PHP_Archive_Exception extends PEAR_Exception {} 19class PHP_Archive_ExceptionExtended extends PHP_Archive_Exception 20{ 21 const NOOPEN = 1; 22 const NOTPHAR = 2; 23 const NOHALTCOMPILER = 3; 24 const MANIFESTOVERFLOW = 4; 25 const MANIFESTENTRIESOVERFLOW = 5; 26 const MANIFESTENTRIESUNDERFLOW = 6; 27 const MANIFESTENTRIESTRUNCATEDENTRY = 7; 28 const FILELOCATIONINVALID = 8; 29 const FILETRUNCATED = 9; 30 const UNKNOWNAPI = 10; 31 const FILECORRUPTEDGZ = 11; 32 const FILECORRUPTEDSIZE = 12; 33 const FILECORRUPTEDCRC = 13; 34 const NOSIGNATUREMAGIC = 14; 35 const BADSIGNATURE = 15; 36 const UNKNOWNSIGTYPE = 16; 37 private static $_messages = array( 38 'en' => array( 39 self::NOOPEN => 'Cannot open "%archive%"', 40 self::NOTPHAR => '"%archive%" is not a PHP_Archive-based phar', 41 self::NOHALTCOMPILER => '"%archive%" is not a phar, has no __HALT_COMPILER();', 42 self::MANIFESTOVERFLOW => '"%archive%" has a manifest larger than 1 MB, too large', 43 self::MANIFESTENTRIESOVERFLOW => '"%archive%" has too many manifest entries for the manifest size', 44 self::MANIFESTENTRIESUNDERFLOW => '"%archive%" has a truncated manifest', 45 self::MANIFESTENTRIESTRUNCATEDENTRY => '"%archive%" has a truncated manifest entry after last known entry "%last%" (%cur% of %size% entries) in entry "%current%"', 46 self::FILELOCATIONINVALID => '"%archive%" manifest entry "%file%" has a starting location that cannot be located "%loc%" in a file of size "%size%"', 47 self::FILETRUNCATED => '"%archive%" file "%file%" is truncated. File begins at "%loc%"', 48 self::FILECORRUPTEDGZ => '"%archive%" file "%file%" has corrupted gzipped content. File begins at "%loc%"', 49 self::FILECORRUPTEDSIZE => '"%archive%" file "%file%" is %actual% bytes, but size indicator at file start says it should be %expected% bytes', 50 self::FILECORRUPTEDCRC => '"%archive%" file "%file%" has a crc32 of "%actual%" but was expecting "%expected%"', 51 self::UNKNOWNAPI => '"%archive%" has unknown API version "%ver%"', 52 self::NOSIGNATUREMAGIC => '%archive% has a signature, but does not have the magic "GBMB" flags', 53 self::UNKNOWNSIGTYPE => '%archive% has unknown signature type "%type%"', 54 self::BADSIGNATURE => '%archive% is corrupted: signature does not match', 55 ) 56 ); 57 private static $_lang = 'en'; 58 private $_errorData = array(); 59 public function __construct($code, $errorData = array()) 60 { 61 $this->_errorData = $errorData; 62 if (isset(self::$_messages[self::$_lang][$code])) { 63 $message = self::$_messages[self::$_lang][$code]; 64 } else { 65 $message = "ERROR UNKNOWN PHP_Archive_Exception CODE: '$code'"; 66 } 67 foreach ($errorData as $var => $value) { 68 if (!is_string($value) && !is_int($value)) { 69 die('Fatal Error: only strings/ints can be used in errorData for PHP_Archive_ExceptionExtended'); 70 } 71 $message = str_replace('%' . $var . '%', $value, $message); 72 } 73 parent::__construct($message); 74 } 75 76 public static function setLang($lang) 77 { 78 if (!isset(self::$_messages[$lang])) { 79 throw new PHP_Archive_Exception('Error, unknown language "' . $lang . '", ' . 80 'must be one of ' . implode(', ', array_keys(self::$_messages))); 81 } 82 self::$_lang = $lang; 83 } 84 85 public function getErrorData() 86 { 87 return $this->_errorData; 88 } 89} 90?>