PHP_Archive
[ class tree: PHP_Archive ] [ index: PHP_Archive ] [ all elements ]

Source for file Exception.php

Documentation is available at Exception.php

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

Documentation generated on Mon, 19 May 2008 11:30:13 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.