Exception class loaded only when needed

git-svn-id: http://php-reader.googlecode.com/svn/trunk@143 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2009-02-21 18:32:53 +00:00
parent 72ad79e344
commit aeadea825d
9 changed files with 65 additions and 25 deletions

View File

@@ -36,9 +36,6 @@
* @version $Id$
*/
/**#@+ @ignore */
/**#@-*/
/**
* The base unit of organization for ASF files is called the ASF object. It
* consists of a 128-bit GUID for the object, a 64-bit integer object size, and

View File

@@ -84,8 +84,10 @@ final class ID3_Frame_ASPI extends ID3_Frame
{
parent::__construct($reader, $options);
if ($reader === null)
if ($reader === null) {
require_once("ID3/Exception.php");
throw new ID3_Exception("Write not supported yet");
}
$this->_dataStart = Transform::fromInt32BE(substr($this->_data, 0, 4));
$this->_dataLength = Transform::fromInt32BE(substr($this->_data, 4, 4));

View File

@@ -74,9 +74,11 @@ final class ID3_Frame_EQUA extends ID3_Frame
return;
$adjustmentBits = Transform::fromInt8($this->_data[0]);
if ($adjustmentBits <= 8 || $adjustmentBits > 16)
if ($adjustmentBits <= 8 || $adjustmentBits > 16) {
require_once("ID3/Exception.php");
throw new ID3_Exception
("Unsupported adjustment bit size of: " . $adjustmentBits);
}
for ($i = 1; $i < strlen($this->_data); $i += 4) {
$frequency = Transform::fromUInt16BE(substr($this->_data, $i, 2));

View File

@@ -92,8 +92,10 @@ final class ID3_Frame_MLLT extends ID3_Frame
{
parent::__construct($reader, $options);
if ($reader === null)
if ($reader === null) {
require_once("ID3/Exception.php");
throw new ID3_Exception("Write not supported yet");
}
$this->_frames = Transform::fromInt16BE(substr($this->_data, 0, 2));
$this->_bytes = Transform::fromInt32BE(substr($this->_data, 2, 3));

View File

@@ -120,9 +120,11 @@ final class ID3_Frame_RVAD extends ID3_Frame
$flags = Transform::fromInt8($this->_data[0]);
$descriptionBits = Transform::fromInt8($this->_data[1]);
if ($descriptionBits <= 8 || $descriptionBits > 16)
if ($descriptionBits <= 8 || $descriptionBits > 16) {
require_once("ID3/Exception.php");
throw new ID3_Exception
("Unsupported description bit size of: " . $descriptionBits);
}
$this->_adjustments[self::right] =
($flags & 0x1) == 0x1 ?

View File

@@ -124,7 +124,10 @@ abstract class ID3_Object
{
if (method_exists($this, "get" . ucfirst($name)))
return call_user_func(array($this, "get" . ucfirst($name)));
else throw new ID3_Exception("Unknown field: " . $name);
else {
require_once("ID3/Exception.php");
throw new ID3_Exception("Unknown field: " . $name);
}
}
/**
@@ -139,7 +142,10 @@ abstract class ID3_Object
if (method_exists($this, "set" . ucfirst($name)))
call_user_func
(array($this, "set" . ucfirst($name)), $value);
else throw new ID3_Exception("Unknown field: " . $name);
else {
require_once("ID3/Exception.php");
throw new ID3_Exception("Unknown field: " . $name);
}
}
/**

View File

@@ -38,10 +38,7 @@
/**#@+ @ignore */
require_once("Reader.php");
require_once("ID3/Exception.php");
require_once("ID3/Header.php");
require_once("ID3/ExtendedHeader.php");
require_once("ID3/Frame.php");
/**#@-*/
/**
@@ -61,6 +58,7 @@ require_once("ID3/Frame.php");
* unique and predefined identifier which allows software to skip unknown
* frames.
*
* @todo Unsynchronisation not supported for ID3v2.3 tag
* @package php-reader
* @subpackage ID3
* @author Sven Vollbehr <svollbehr@gmail.com>
@@ -138,23 +136,32 @@ final class ID3v2
$startOffset = $this->_reader->getOffset();
if ($this->_reader->readString8(3) != "ID3")
if ($this->_reader->readString8(3) != "ID3") {
require_once("ID3/Exception.php");
throw new ID3_Exception("File does not contain ID3v2 tag");
}
$this->_header = new ID3_Header($this->_reader, $options);
if ($this->_header->getVersion() < 3 || $this->_header->getVersion() > 4)
if ($this->_header->getVersion() < 3 ||
$this->_header->getVersion() > 4) {
require_once("ID3/Exception.php");
throw new ID3_Exception
("File does not contain ID3v2 tag of supported version");
}
if ($this->_header->getVersion() < 4 &&
$this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
$this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION)) {
require_once("ID3/Exception.php");
throw new ID3_Exception
("Unsynchronisation not supported for this version of ID3v2 tag");
}
unset($this->_options["unsyncronisation"]);
if ($this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
$this->_options["unsyncronisation"] = true;
if ($this->_header->hasFlag(ID3_Header::EXTENDEDHEADER))
if ($this->_header->hasFlag(ID3_Header::EXTENDEDHEADER)) {
require_once("ID3/ExtendedHeader.php");
$this->_extendedHeader =
new ID3_ExtendedHeader($this->_reader, $options);
}
if ($this->_header->hasFlag(ID3_Header::FOOTER))
$this->_footer = &$this->_header; // skip footer, and rather copy header
@@ -240,7 +247,10 @@ final class ID3v2
$this->_header->flags | ID3_Header::EXTENDEDHEADER;
$this->_extendedHeader->setOptions($this->_options);
$this->_extendedHeader = $extendedHeader;
} else throw new ID3_Exception("Invalid argument");
} else {
require_once("ID3/Exception.php");
throw new ID3_Exception("Invalid argument");
}
}
/**
@@ -398,17 +408,23 @@ final class ID3v2
*/
public function write($filename = false)
{
if ($filename === false && ($filename = $this->_filename) === false)
if ($filename === false && ($filename = $this->_filename) === false) {
require_once("ID3/Exception.php");
throw new ID3_Exception("No file given to write the tag to");
}
else if ($filename !== false && $this->_filename !== false &&
realpath($filename) != realpath($this->_filename) &&
!copy($this->_filename, $filename))
!copy($this->_filename, $filename)) {
require_once("ID3/Exception.php");
throw new ID3_Exception("Unable to copy source to destination: " .
realpath($this->_filename) . "->" . realpath($filename));
}
if (($fd = fopen
($filename, file_exists($filename) ? "r+b" : "wb")) === false)
($filename, file_exists($filename) ? "r+b" : "wb")) === false) {
require_once("ID3/Exception.php");
throw new ID3_Exception("Unable to open file for writing: " . $filename);
}
$oldTagSize = $this->_header->getSize();
$tag = $this->__toString();
@@ -455,6 +471,7 @@ final class ID3v2
require_once($filename);
if (class_exists($classname = "ID3_Frame_" . strtoupper($name)))
return $this->addFrame(new $classname());
require_once("ID3/Exception.php");
throw new ID3_Exception("Unknown frame/field: " . $name);
}

View File

@@ -254,6 +254,7 @@ final class ISO14496_Box_DATA extends ISO14496_Box_Full
return $this;
if (method_exists($this, "get" . ucfirst($name)))
return call_user_func(array($this, "get" . ucfirst($name)));
require_once("ISO14496/Exception.php");
throw new ISO14496_Exception("Unknown box/field: " . $name);
}

View File

@@ -38,7 +38,6 @@
/**#@+ @ignore */
require_once("Reader.php");
require_once("MPEG/Exception.php");
/**#@-*/
/**
@@ -132,8 +131,11 @@ abstract class MPEG_Object
$buffer = " ";
for ($i = 0; $i < 4; $i++) {
$start = $this->_reader->getOffset();
if (($buffer = substr($buffer, -4) . $this->_reader->read(512)) === false)
if (($buffer = substr($buffer, -4) .
$this->_reader->read(512)) === false) {
require_once("MPEG/Exception.php");
throw new MPEG_Exception("Invalid data");
}
$limit = strlen($buffer);
$pos = 0;
while ($pos < $limit - 3) {
@@ -151,6 +153,7 @@ abstract class MPEG_Object
}
/* No start code found within 2048 bytes, the maximum size of a pack */
require_once("MPEG/Exception.php");
throw new MPEG_Exception("Invalid data");
}
@@ -171,8 +174,10 @@ abstract class MPEG_Object
while ($position > 0) {
$start = 0;
$position = $position - 512;
if ($position < 0)
if ($position < 0) {
require_once("MPEG/Exception.php");
throw new MPEG_Exception("Invalid data");
}
$this->_reader->setOffset($position);
$buffer = $this->_reader->read(512) . substr($buffer, 0, 4);
$pos = 512 - 8;
@@ -227,7 +232,10 @@ abstract class MPEG_Object
{
if (method_exists($this, "get" . ucfirst($name)))
return call_user_func(array($this, "get" . ucfirst($name)));
else throw new MPEG_Exception("Unknown field: " . $name);
else {
require_once("MPEG/Exception.php");
throw new MPEG_Exception("Unknown field: " . $name);
}
}
/**
@@ -242,6 +250,9 @@ abstract class MPEG_Object
if (method_exists($this, "set" . ucfirst($name)))
call_user_func
(array($this, "set" . ucfirst($name)), $value);
else throw new MPEG_Exception("Unknown field: " . $name);
else {
require_once("MPEG/Exception.php");
throw new MPEG_Exception("Unknown field: " . $name);
}
}
}