web/Zend/Gdata/YouTube/Extension/Duration.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Zend Framework
       
     5  *
       
     6  * LICENSE
       
     7  *
       
     8  * This source file is subject to the new BSD license that is bundled
       
     9  * with this package in the file LICENSE.txt.
       
    10  * It is also available through the world-wide-web at this URL:
       
    11  * http://framework.zend.com/license/new-bsd
       
    12  * If you did not receive a copy of the license and are unable to
       
    13  * obtain it through the world-wide-web, please send an email
       
    14  * to license@zend.com so we can send you a copy immediately.
       
    15  *
       
    16  * @category   Zend
       
    17  * @package    Zend_Gdata
       
    18  * @subpackage YouTube
       
    19  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    21  * @version    $Id: Duration.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    22  */
       
    23 
       
    24 /**
       
    25  * @see Zend_Gdata_Extension
       
    26  */
       
    27 require_once 'Zend/Gdata/Extension.php';
       
    28 
       
    29 /**
       
    30  * Represents the yt:duration element used by the YouTube data API
       
    31  *
       
    32  * @category   Zend
       
    33  * @package    Zend_Gdata
       
    34  * @subpackage YouTube
       
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    37  */
       
    38 class Zend_Gdata_YouTube_Extension_Duration extends Zend_Gdata_Extension
       
    39 {
       
    40 
       
    41     protected $_rootNamespace = 'yt';
       
    42     protected $_rootElement = 'duration';
       
    43     protected $_seconds = null;
       
    44 
       
    45     /**
       
    46      * Constructs a new Zend_Gdata_YouTube_Extension_Duration object.
       
    47      * @param bool $seconds(optional) The seconds value of the element.
       
    48      */
       
    49     public function __construct($seconds = null)
       
    50     {
       
    51         $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
       
    52         parent::__construct();
       
    53         $this->_seconds = $seconds;
       
    54     }
       
    55 
       
    56     /**
       
    57      * Retrieves a DOMElement which corresponds to this element and all
       
    58      * child properties.  This is used to build an entry back into a DOM
       
    59      * and eventually XML text for sending to the server upon updates, or
       
    60      * for application storage/persistence.
       
    61      *
       
    62      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
       
    63      * @return DOMElement The DOMElement representing this element and all
       
    64      * child properties.
       
    65      */
       
    66     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
       
    67     {
       
    68         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
       
    69         if ($this->_seconds !== null) {
       
    70             $element->setAttribute('seconds', $this->_seconds);
       
    71         }
       
    72         return $element;
       
    73     }
       
    74 
       
    75     /**
       
    76      * Given a DOMNode representing an attribute, tries to map the data into
       
    77      * instance members.  If no mapping is defined, the name and valueare
       
    78      * stored in an array.
       
    79      *
       
    80      * @param DOMNode $attribute The DOMNode attribute needed to be handled
       
    81      */
       
    82     protected function takeAttributeFromDOM($attribute)
       
    83     {
       
    84         switch ($attribute->localName) {
       
    85         case 'seconds':
       
    86             $this->_seconds = $attribute->nodeValue;
       
    87             break;
       
    88         default:
       
    89             parent::takeAttributeFromDOM($attribute);
       
    90         }
       
    91     }
       
    92 
       
    93     /**
       
    94      * Get the value for this element's seconds attribute.
       
    95      *
       
    96      * @return int The value associated with this attribute.
       
    97      */
       
    98     public function getSeconds()
       
    99     {
       
   100         return $this->_seconds;
       
   101     }
       
   102 
       
   103     /**
       
   104      * Set the value for this element's seconds attribute.
       
   105      *
       
   106      * @param int $value The desired value for this attribute.
       
   107      * @return Zend_Gdata_YouTube_Extension_Duration The element being modified.
       
   108      */
       
   109     public function setSeconds($value)
       
   110     {
       
   111         $this->_seconds = $value;
       
   112         return $this;
       
   113     }
       
   114 
       
   115     /**
       
   116      * Magic toString method allows using this directly via echo
       
   117      * Works best in PHP >= 4.2.0
       
   118      *
       
   119      * @return string The duration in seconds
       
   120      */
       
   121     public function __toString()
       
   122     {
       
   123         return $this->_seconds;
       
   124     }
       
   125 
       
   126 }