PageRenderTime 25ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

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