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

@@ -59,10 +59,10 @@ final class ID3_Frame_USER extends ID3_Frame
implements ID3_Encoding, ID3_Language
{
/** @var integer */
private $_encoding;
private $_encoding = ID3_Encoding::UTF8;
/** @var string */
private $_language;
private $_language = "eng";
/** @var string */
private $_text;
@@ -72,11 +72,14 @@ final class ID3_Frame_USER extends ID3_Frame
*
* @param Reader $reader The reader object.
*/
public function __construct($reader)
public function __construct($reader = null)
{
parent::__construct($reader);
$this->_encoding = ord($this->_data{0});
if ($reader === null)
return;
$this->_encoding = Transform::fromInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3);
$this->_data = substr($this->_data, 4);
@@ -91,7 +94,7 @@ final class ID3_Frame_USER extends ID3_Frame
$this->_text = Transform::fromString8($this->_data);
}
}
/**
* Returns the text encoding.
*
@@ -99,19 +102,76 @@ final class ID3_Frame_USER extends ID3_Frame
*/
public function getEncoding() { return $this->_encoding; }
/**
* Sets the text encoding.
*
* @see ID3_Encoding
* @param integer $encoding The text encoding.
*/
public function setEncoding($encoding) { $this->_encoding = $encoding; }
/**
* Returns the language code as specified in the
* {@link http://www.loc.gov/standards/iso639-2/ ISO-639-2} standard.
*
* @see ID3_Language#ISO_639_2
* @return string
*/
public function getLanguage() { return $this->_language; }
/**
* Sets the text language code as specified in the
* {@link http://www.loc.gov/standards/iso639-2/ ISO-639-2} standard.
*
* @see ID3_Language
* @param string $language The language code.
*/
public function setLanguage($language) { $this->_language = $language; }
/**
* Returns the text.
*
* @return string
*/
public function getText() { return $this->_text; }
/**
* Sets the text using given language and encoding.
*
* @param string $text The text.
* @param string $language The language code.
* @param integer $encoding The text encoding.
*/
public function setText($text, $language = false, $encoding = false)
{
$this->_text = $text;
if ($language !== false)
$this->_language = $language;
if ($encoding !== false)
$this->_encoding = $encoding;
}
/**
* Returns the frame raw data.
*
* @return string
*/
public function __toString()
{
$data = Transform::toInt8($this->_encoding) . $this->_language;
switch ($this->_encoding) {
case self::UTF16:
$data .= Transform::toString16($this->_text);
break;
case self::UTF16BE:
$data .= Transform::toString16BE($this->_text);
break;
case self::UTF16LE:
$data .= Transform::toString16LE($this->_text);
break;
default:
$data .= $this->_text;
}
$this->setData($data);
return parent::__toString();
}
}