File indexing completed on 2025-03-02 05:29:26
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage App 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata_App_Entry 0026 */ 0027 // require_once 'Zend/Gdata/App/Entry.php'; 0028 0029 /** 0030 * @see Zend_Gdata_App_MediaSource 0031 */ 0032 // require_once 'Zend/Gdata/App/MediaSource.php'; 0033 0034 /** 0035 * @see Zend_Gdata_MediaMimeStream 0036 */ 0037 // require_once 'Zend/Gdata/MediaMimeStream.php'; 0038 0039 /** 0040 * Concrete class for working with Atom entries containing multi-part data. 0041 * 0042 * @category Zend 0043 * @package Zend_Gdata 0044 * @subpackage App 0045 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0046 * @license http://framework.zend.com/license/new-bsd New BSD License 0047 */ 0048 class Zend_Gdata_App_MediaEntry extends Zend_Gdata_App_Entry 0049 { 0050 /** 0051 * The attached MediaSource/file 0052 * 0053 * @var Zend_Gdata_App_MediaSource 0054 */ 0055 protected $_mediaSource = null; 0056 0057 /** 0058 * Constructs a new MediaEntry, representing XML data and optional 0059 * file to upload 0060 * 0061 * @param DOMElement $element (optional) DOMElement from which this 0062 * object should be constructed. 0063 */ 0064 public function __construct($element = null, $mediaSource = null) 0065 { 0066 parent::__construct($element); 0067 $this->_mediaSource = $mediaSource; 0068 } 0069 0070 /** 0071 * Return the MIME multipart representation of this MediaEntry. 0072 * 0073 * @return string|Zend_Gdata_MediaMimeStream The MIME multipart 0074 * representation of this MediaEntry. If the entry consisted only 0075 * of XML, a string is returned. 0076 */ 0077 public function encode() 0078 { 0079 $xmlData = $this->saveXML(); 0080 $mediaSource = $this->getMediaSource(); 0081 if ($mediaSource === null) { 0082 // No attachment, just send XML for entry 0083 return $xmlData; 0084 } else { 0085 return new Zend_Gdata_MediaMimeStream($xmlData, 0086 $mediaSource->getFilename(), $mediaSource->getContentType()); 0087 } 0088 } 0089 0090 /** 0091 * Return the MediaSource object representing the file attached to this 0092 * MediaEntry. 0093 * 0094 * @return Zend_Gdata_App_MediaSource The attached MediaSource/file 0095 */ 0096 public function getMediaSource() 0097 { 0098 return $this->_mediaSource; 0099 } 0100 0101 /** 0102 * Set the MediaSource object (file) for this MediaEntry 0103 * 0104 * @param Zend_Gdata_App_MediaSource $value The attached MediaSource/file 0105 * @return Zend_Gdata_App_MediaEntry Provides a fluent interface 0106 */ 0107 public function setMediaSource($value) 0108 { 0109 if ($value instanceof Zend_Gdata_App_MediaSource) { 0110 $this->_mediaSource = $value; 0111 } else { 0112 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0113 throw new Zend_Gdata_App_InvalidArgumentException( 0114 'You must specify the media data as a class that conforms to Zend_Gdata_App_MediaSource.'); 0115 } 0116 return $this; 0117 } 0118 0119 }