Refactoring the code
git-svn-id: http://php-reader.googlecode.com/svn/trunk@140 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
@@ -52,7 +52,7 @@ require_once("ID3/Object.php");
|
||||
* @license http://code.google.com/p/php-reader/wiki/License New BSD License
|
||||
* @version $Rev$
|
||||
*/
|
||||
class ID3_Frame extends ID3_Object
|
||||
abstract class ID3_Frame extends ID3_Object
|
||||
{
|
||||
/**
|
||||
* This flag tells the tag parser what to do with this frame if it is unknown
|
||||
@@ -171,13 +171,14 @@ class ID3_Frame extends ID3_Object
|
||||
|
||||
/* ID3v2.4.0 size and flags */
|
||||
else {
|
||||
$this->_size = $this->decodeSynchsafe32($this->_reader->readUInt32BE());
|
||||
$this->_size =
|
||||
$this->_decodeSynchsafe32($this->_reader->readUInt32BE());
|
||||
$this->_flags = $this->_reader->readUInt16BE();
|
||||
}
|
||||
|
||||
$dataLength = $this->_size;
|
||||
if ($this->hasFlag(self::DATA_LENGTH_INDICATOR)) {
|
||||
$dataLength = $this->decodeSynchsafe32($this->_reader->readUInt32BE());
|
||||
$dataLength = $this->_decodeSynchsafe32($this->_reader->readUInt32BE());
|
||||
$this->_size -= 4;
|
||||
}
|
||||
$this->_data = $this->_reader->read($this->_size);
|
||||
@@ -185,7 +186,7 @@ class ID3_Frame extends ID3_Object
|
||||
|
||||
if ($this->hasFlag(self::UNSYNCHRONISATION) ||
|
||||
$this->getOption("unsynchronisation", false) === true)
|
||||
$this->_data = $this->decodeUnsynchronisation($this->_data);
|
||||
$this->_data = $this->_decodeUnsynchronisation($this->_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +222,10 @@ class ID3_Frame extends ID3_Object
|
||||
* @param integer $flag The flag to query.
|
||||
* @return boolean
|
||||
*/
|
||||
public final function hasFlag($flag) { return ($this->_flags & $flag) == $flag; }
|
||||
public final function hasFlag($flag)
|
||||
{
|
||||
return ($this->_flags & $flag) == $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frame flags byte.
|
||||
@@ -238,18 +242,14 @@ class ID3_Frame extends ID3_Object
|
||||
public final function setFlags($flags) { $this->_flags = $flags; }
|
||||
|
||||
/**
|
||||
* Sets the frame raw data.
|
||||
* Returns the frame raw data without the header.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
protected function setData($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
$this->_size = strlen($data);
|
||||
}
|
||||
abstract protected function _getData();
|
||||
|
||||
/**
|
||||
* Returns the frame raw data.
|
||||
* Returns the frame data with the header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -275,15 +275,17 @@ class ID3_Frame extends ID3_Object
|
||||
/* ID3v2.4.0 Flags */
|
||||
else
|
||||
$flags = $this->_flags;
|
||||
|
||||
$size = $this->_size;
|
||||
if ($this->getOption("version", 4) < 4)
|
||||
$data = $this->_data;
|
||||
else {
|
||||
$data = $this->encodeUnsynchronisation($this->_data);
|
||||
|
||||
if ($this->getOption("version", 4) < 4) {
|
||||
$data = $this->_data = $this->_getData();
|
||||
$size = $this->_size = strlen($data);
|
||||
} else {
|
||||
$data = $this->_data = $this->_getData();
|
||||
$size = $this->_size = strlen($data);
|
||||
$data = $this->_encodeUnsynchronisation($data);
|
||||
if (($dataLength = strlen($data)) != $size) {
|
||||
$size = 4 + $dataLength;
|
||||
$data = Transform::toUInt32BE($this->encodeSynchsafe32($this->_size)) .
|
||||
$data = Transform::toUInt32BE($this->_encodeSynchsafe32($this->_size)) .
|
||||
$data;
|
||||
$flags |= self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION;
|
||||
$this->setOption("unsynchronisation", true);
|
||||
@@ -291,7 +293,7 @@ class ID3_Frame extends ID3_Object
|
||||
$flags &= ~(self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION);
|
||||
}
|
||||
return Transform::toString8(substr($this->_identifier, 0, 4), 4) .
|
||||
Transform::toUInt32BE($this->encodeSynchsafe32($size)) .
|
||||
Transform::toUInt32BE($this->_encodeSynchsafe32($size)) .
|
||||
Transform::toUInt16BE($flags) . $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user