Add write support for ID3v2 frames

git-svn-id: http://php-reader.googlecode.com/svn/trunk@65 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-04-02 15:22:46 +00:00
parent 458335dc9f
commit ad6a722bae
88 changed files with 1857 additions and 337 deletions

View File

@@ -68,42 +68,47 @@ final class ID3_Frame_POPM extends ID3_Frame
private $_id;
/** @var integer */
private $_rating;
private $_rating = 0;
/** @var integer */
private $_counter;
private $_counter = 0;
/**
* Constructs the class with given parameters and parses object related data.
*
* @param Reader $reader The reader object.
*/
public function __construct($reader)
public function __construct($reader = null)
{
parent::__construct($reader);
if ($reader === null)
return;
list($this->_id, $this->_data) = preg_split("/\\x00/", $this->_data, 2);
$this->_rating = substr($this->_data, 0, 1);
$this->_rating = Transform::fromInt8($this->_data[0]);
$this->_data = substr($this->_data, 1);
switch (strlen($this->_data)) {
case 8:
if (strlen($this->_data) > 4)
$this->_counter = Transform::fromInt64BE($this->_data);
break;
case 4:
$this->_counter = Transform::fromInt32BE($this->_data);
break;
}
else if (strlen($this->_data) > 0)
$this->_counter = Transform::fromUInt32BE($this->_data);
}
/**
* Returns the user identifier string.
*
* @return string
*/
public function getIdentifier() { return $this->_id; }
/**
* Sets the user identifier string.
*
* @param string $id The user identifier string.
*/
public function setIdentifier($id) { return $this->_id = $id; }
/**
* Returns the user rating.
*
@@ -111,10 +116,44 @@ final class ID3_Frame_POPM extends ID3_Frame
*/
public function getRating() { return $this->_rating; }
/**
* Sets the user rating.
*
* @param integer $rating The user rating.
*/
public function setRating($rating) { $this->_rating = $rating; }
/**
* Returns the counter.
*
* @return integer
*/
public function getCounter() { return $this->_counter; }
/**
* Adds counter by one.
*/
public function addCounter() { $this->_counter++; }
/**
* Sets the counter value.
*
* @param integer $counter The counter value.
*/
public function setCounter($counter) { $this->_counter = $counter; }
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$this->setData
($this->_id . "\0" . Transform::toInt8($this->_rating) .
($this->_counter > 4294967295 ?
Transform::toInt64BE($this->_counter) :
($this->_counter > 0 ? Transform::toInt32BE($this->_counter) : 0)));
return parent::__toString();
}
}