/src/Zend/Media/Id3/Header.php

http://php-reader.googlecode.com/ · PHP · 178 lines · 57 code · 19 blank · 102 comment · 2 complexity · 8327d872df6aa2429a700e76526f33fa MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Media
  17. * @subpackage ID3
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Header.php 216 2011-05-02 14:59:16Z svollbehr $
  21. */
  22. /**#@+ @ignore */
  23. require_once 'Zend/Media/Id3/Object.php';
  24. /**#@-*/
  25. /**
  26. * The first part of the ID3v2 tag is the 10 byte tag header. The header
  27. * contains information about the tag version and options.
  28. *
  29. * @category Zend
  30. * @package Zend_Media
  31. * @subpackage ID3
  32. * @author Sven Vollbehr <sven@vollbehr.eu>
  33. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @version $Id: Header.php 216 2011-05-02 14:59:16Z svollbehr $
  36. */
  37. final class Zend_Media_Id3_Header extends Zend_Media_Id3_Object
  38. {
  39. /** A flag to denote whether or not unsynchronisation is applied on all
  40. frames */
  41. const UNSYNCHRONISATION = 128;
  42. /** A flag to denote whether or not the header is followed by an extended
  43. header */
  44. const EXTENDED_HEADER = 64;
  45. /** A flag used as an experimental indicator. This flag shall always be set
  46. when the tag is in an experimental stage. */
  47. const EXPERIMENTAL = 32;
  48. /**
  49. * A flag to denote whether a footer is present at the very end of the tag.
  50. *
  51. * @since ID3v2.4.0
  52. */
  53. const FOOTER = 16;
  54. /** @var integer */
  55. private $_version = 4.0;
  56. /** @var integer */
  57. private $_flags = 0;
  58. /** @var integer */
  59. private $_size;
  60. /**
  61. * Constructs the class with given parameters and reads object related data
  62. * from the ID3v2 tag.
  63. *
  64. * @param Zend_Io_Reader $reader The reader object.
  65. * @param Array $options The options array.
  66. */
  67. public function __construct($reader = null, &$options = array())
  68. {
  69. parent::__construct($reader, $options);
  70. if ($reader === null)
  71. return;
  72. $this->_version = $options['version'] =
  73. $this->_reader->readUInt8() + $this->_reader->readUInt8() / 10;
  74. $this->_flags = $this->_reader->readUInt8();
  75. $this->_size = $this->_decodeSynchsafe32($this->_reader->readUInt32BE());
  76. }
  77. /**
  78. * Returns the tag version number. The version number is in the form of
  79. * major.revision.
  80. *
  81. * @return integer
  82. */
  83. public function getVersion()
  84. {
  85. return $this->_version;
  86. }
  87. /**
  88. * Sets the tag version number. Supported version numbers are 3.0 and 4.0
  89. * for ID3v2.3.0 and ID3v2.4.0 standards, respectively.
  90. *
  91. * @param integer $version The tag version number in the form of
  92. * major.revision.
  93. */
  94. public function setVersion($version)
  95. {
  96. $this->setOption('version', $this->_version = $version);
  97. }
  98. /**
  99. * Checks whether or not the flag is set. Returns <var>true</var> if the
  100. * flag is set, <var>false</var> otherwise.
  101. *
  102. * @param integer $flag The flag to query.
  103. * @return boolean
  104. */
  105. public function hasFlag($flag)
  106. {
  107. return ($this->_flags & $flag) == $flag;
  108. }
  109. /**
  110. * Returns the flags byte.
  111. *
  112. * @return integer
  113. */
  114. public function getFlags()
  115. {
  116. return $this->_flags;
  117. }
  118. /**
  119. * Sets the flags byte.
  120. *
  121. * @param string $flags The flags byte.
  122. */
  123. public function setFlags($flags)
  124. {
  125. $this->_flags = $flags;
  126. }
  127. /**
  128. * Returns the tag size, excluding the header and the footer.
  129. *
  130. * @return integer
  131. */
  132. public function getSize()
  133. {
  134. return $this->_size;
  135. }
  136. /**
  137. * Sets the tag size, excluding the header and the footer. Called
  138. * automatically upon tag generation to adjust the tag size.
  139. *
  140. * @param integer $size The size of the tag, in bytes.
  141. */
  142. public function setSize($size)
  143. {
  144. $this->_size = $size;
  145. }
  146. /**
  147. * Writes the header/footer data without the identifier.
  148. *
  149. * @param Zend_Io_Writer $writer The writer object.
  150. * @return void
  151. */
  152. public function write($writer)
  153. {
  154. $writer->writeUInt8(floor($this->_version))
  155. ->writeUInt8(($this->_version - floor($this->_version)) * 10)
  156. ->writeUInt8($this->_flags)
  157. ->writeUInt32BE($this->_encodeSynchsafe32($this->_size));
  158. }
  159. }