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:
@@ -36,9 +36,6 @@
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**#@+ @ignore */
|
|
||||||
/**#@-*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base unit of organization for ASF files is called the ASF object. It
|
* 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
|
* consists of a 128-bit GUID for the object, a 64-bit integer object size, and
|
||||||
|
|||||||
@@ -84,8 +84,10 @@ final class ID3_Frame_ASPI extends ID3_Frame
|
|||||||
{
|
{
|
||||||
parent::__construct($reader, $options);
|
parent::__construct($reader, $options);
|
||||||
|
|
||||||
if ($reader === null)
|
if ($reader === null) {
|
||||||
|
require_once("ID3/Exception.php");
|
||||||
throw new ID3_Exception("Write not supported yet");
|
throw new ID3_Exception("Write not supported yet");
|
||||||
|
}
|
||||||
|
|
||||||
$this->_dataStart = Transform::fromInt32BE(substr($this->_data, 0, 4));
|
$this->_dataStart = Transform::fromInt32BE(substr($this->_data, 0, 4));
|
||||||
$this->_dataLength = Transform::fromInt32BE(substr($this->_data, 4, 4));
|
$this->_dataLength = Transform::fromInt32BE(substr($this->_data, 4, 4));
|
||||||
|
|||||||
@@ -74,9 +74,11 @@ final class ID3_Frame_EQUA extends ID3_Frame
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
$adjustmentBits = Transform::fromInt8($this->_data[0]);
|
$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
|
throw new ID3_Exception
|
||||||
("Unsupported adjustment bit size of: " . $adjustmentBits);
|
("Unsupported adjustment bit size of: " . $adjustmentBits);
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 1; $i < strlen($this->_data); $i += 4) {
|
for ($i = 1; $i < strlen($this->_data); $i += 4) {
|
||||||
$frequency = Transform::fromUInt16BE(substr($this->_data, $i, 2));
|
$frequency = Transform::fromUInt16BE(substr($this->_data, $i, 2));
|
||||||
|
|||||||
@@ -92,8 +92,10 @@ final class ID3_Frame_MLLT extends ID3_Frame
|
|||||||
{
|
{
|
||||||
parent::__construct($reader, $options);
|
parent::__construct($reader, $options);
|
||||||
|
|
||||||
if ($reader === null)
|
if ($reader === null) {
|
||||||
|
require_once("ID3/Exception.php");
|
||||||
throw new ID3_Exception("Write not supported yet");
|
throw new ID3_Exception("Write not supported yet");
|
||||||
|
}
|
||||||
|
|
||||||
$this->_frames = Transform::fromInt16BE(substr($this->_data, 0, 2));
|
$this->_frames = Transform::fromInt16BE(substr($this->_data, 0, 2));
|
||||||
$this->_bytes = Transform::fromInt32BE(substr($this->_data, 2, 3));
|
$this->_bytes = Transform::fromInt32BE(substr($this->_data, 2, 3));
|
||||||
|
|||||||
@@ -120,9 +120,11 @@ final class ID3_Frame_RVAD extends ID3_Frame
|
|||||||
|
|
||||||
$flags = Transform::fromInt8($this->_data[0]);
|
$flags = Transform::fromInt8($this->_data[0]);
|
||||||
$descriptionBits = Transform::fromInt8($this->_data[1]);
|
$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
|
throw new ID3_Exception
|
||||||
("Unsupported description bit size of: " . $descriptionBits);
|
("Unsupported description bit size of: " . $descriptionBits);
|
||||||
|
}
|
||||||
|
|
||||||
$this->_adjustments[self::right] =
|
$this->_adjustments[self::right] =
|
||||||
($flags & 0x1) == 0x1 ?
|
($flags & 0x1) == 0x1 ?
|
||||||
|
|||||||
@@ -124,7 +124,10 @@ abstract class ID3_Object
|
|||||||
{
|
{
|
||||||
if (method_exists($this, "get" . ucfirst($name)))
|
if (method_exists($this, "get" . ucfirst($name)))
|
||||||
return call_user_func(array($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)))
|
if (method_exists($this, "set" . ucfirst($name)))
|
||||||
call_user_func
|
call_user_func
|
||||||
(array($this, "set" . ucfirst($name)), $value);
|
(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,10 +38,7 @@
|
|||||||
|
|
||||||
/**#@+ @ignore */
|
/**#@+ @ignore */
|
||||||
require_once("Reader.php");
|
require_once("Reader.php");
|
||||||
require_once("ID3/Exception.php");
|
|
||||||
require_once("ID3/Header.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
|
* unique and predefined identifier which allows software to skip unknown
|
||||||
* frames.
|
* frames.
|
||||||
*
|
*
|
||||||
|
* @todo Unsynchronisation not supported for ID3v2.3 tag
|
||||||
* @package php-reader
|
* @package php-reader
|
||||||
* @subpackage ID3
|
* @subpackage ID3
|
||||||
* @author Sven Vollbehr <svollbehr@gmail.com>
|
* @author Sven Vollbehr <svollbehr@gmail.com>
|
||||||
@@ -138,23 +136,32 @@ final class ID3v2
|
|||||||
|
|
||||||
$startOffset = $this->_reader->getOffset();
|
$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");
|
throw new ID3_Exception("File does not contain ID3v2 tag");
|
||||||
|
}
|
||||||
|
|
||||||
$this->_header = new ID3_Header($this->_reader, $options);
|
$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
|
throw new ID3_Exception
|
||||||
("File does not contain ID3v2 tag of supported version");
|
("File does not contain ID3v2 tag of supported version");
|
||||||
|
}
|
||||||
if ($this->_header->getVersion() < 4 &&
|
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
|
throw new ID3_Exception
|
||||||
("Unsynchronisation not supported for this version of ID3v2 tag");
|
("Unsynchronisation not supported for this version of ID3v2 tag");
|
||||||
|
}
|
||||||
unset($this->_options["unsyncronisation"]);
|
unset($this->_options["unsyncronisation"]);
|
||||||
if ($this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
|
if ($this->_header->hasFlag(ID3_Header::UNSYNCHRONISATION))
|
||||||
$this->_options["unsyncronisation"] = true;
|
$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 =
|
$this->_extendedHeader =
|
||||||
new ID3_ExtendedHeader($this->_reader, $options);
|
new ID3_ExtendedHeader($this->_reader, $options);
|
||||||
|
}
|
||||||
if ($this->_header->hasFlag(ID3_Header::FOOTER))
|
if ($this->_header->hasFlag(ID3_Header::FOOTER))
|
||||||
$this->_footer = &$this->_header; // skip footer, and rather copy header
|
$this->_footer = &$this->_header; // skip footer, and rather copy header
|
||||||
|
|
||||||
@@ -240,7 +247,10 @@ final class ID3v2
|
|||||||
$this->_header->flags | ID3_Header::EXTENDEDHEADER;
|
$this->_header->flags | ID3_Header::EXTENDEDHEADER;
|
||||||
$this->_extendedHeader->setOptions($this->_options);
|
$this->_extendedHeader->setOptions($this->_options);
|
||||||
$this->_extendedHeader = $extendedHeader;
|
$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)
|
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");
|
throw new ID3_Exception("No file given to write the tag to");
|
||||||
|
}
|
||||||
else if ($filename !== false && $this->_filename !== false &&
|
else if ($filename !== false && $this->_filename !== false &&
|
||||||
realpath($filename) != realpath($this->_filename) &&
|
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: " .
|
throw new ID3_Exception("Unable to copy source to destination: " .
|
||||||
realpath($this->_filename) . "->" . realpath($filename));
|
realpath($this->_filename) . "->" . realpath($filename));
|
||||||
|
}
|
||||||
|
|
||||||
if (($fd = fopen
|
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);
|
throw new ID3_Exception("Unable to open file for writing: " . $filename);
|
||||||
|
}
|
||||||
|
|
||||||
$oldTagSize = $this->_header->getSize();
|
$oldTagSize = $this->_header->getSize();
|
||||||
$tag = $this->__toString();
|
$tag = $this->__toString();
|
||||||
@@ -455,6 +471,7 @@ final class ID3v2
|
|||||||
require_once($filename);
|
require_once($filename);
|
||||||
if (class_exists($classname = "ID3_Frame_" . strtoupper($name)))
|
if (class_exists($classname = "ID3_Frame_" . strtoupper($name)))
|
||||||
return $this->addFrame(new $classname());
|
return $this->addFrame(new $classname());
|
||||||
|
require_once("ID3/Exception.php");
|
||||||
throw new ID3_Exception("Unknown frame/field: " . $name);
|
throw new ID3_Exception("Unknown frame/field: " . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ final class ISO14496_Box_DATA extends ISO14496_Box_Full
|
|||||||
return $this;
|
return $this;
|
||||||
if (method_exists($this, "get" . ucfirst($name)))
|
if (method_exists($this, "get" . ucfirst($name)))
|
||||||
return call_user_func(array($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);
|
throw new ISO14496_Exception("Unknown box/field: " . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
/**#@+ @ignore */
|
/**#@+ @ignore */
|
||||||
require_once("Reader.php");
|
require_once("Reader.php");
|
||||||
require_once("MPEG/Exception.php");
|
|
||||||
/**#@-*/
|
/**#@-*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,8 +131,11 @@ abstract class MPEG_Object
|
|||||||
$buffer = " ";
|
$buffer = " ";
|
||||||
for ($i = 0; $i < 4; $i++) {
|
for ($i = 0; $i < 4; $i++) {
|
||||||
$start = $this->_reader->getOffset();
|
$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");
|
throw new MPEG_Exception("Invalid data");
|
||||||
|
}
|
||||||
$limit = strlen($buffer);
|
$limit = strlen($buffer);
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
while ($pos < $limit - 3) {
|
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 */
|
/* No start code found within 2048 bytes, the maximum size of a pack */
|
||||||
|
require_once("MPEG/Exception.php");
|
||||||
throw new MPEG_Exception("Invalid data");
|
throw new MPEG_Exception("Invalid data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,8 +174,10 @@ abstract class MPEG_Object
|
|||||||
while ($position > 0) {
|
while ($position > 0) {
|
||||||
$start = 0;
|
$start = 0;
|
||||||
$position = $position - 512;
|
$position = $position - 512;
|
||||||
if ($position < 0)
|
if ($position < 0) {
|
||||||
|
require_once("MPEG/Exception.php");
|
||||||
throw new MPEG_Exception("Invalid data");
|
throw new MPEG_Exception("Invalid data");
|
||||||
|
}
|
||||||
$this->_reader->setOffset($position);
|
$this->_reader->setOffset($position);
|
||||||
$buffer = $this->_reader->read(512) . substr($buffer, 0, 4);
|
$buffer = $this->_reader->read(512) . substr($buffer, 0, 4);
|
||||||
$pos = 512 - 8;
|
$pos = 512 - 8;
|
||||||
@@ -227,7 +232,10 @@ abstract class MPEG_Object
|
|||||||
{
|
{
|
||||||
if (method_exists($this, "get" . ucfirst($name)))
|
if (method_exists($this, "get" . ucfirst($name)))
|
||||||
return call_user_func(array($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)))
|
if (method_exists($this, "set" . ucfirst($name)))
|
||||||
call_user_func
|
call_user_func
|
||||||
(array($this, "set" . ucfirst($name)), $value);
|
(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user