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.
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
25 * @see Zend_Gdata_App_Entry
27 require_once 'Zend/Gdata/App/Entry.php';
30 * @see Zend_Gdata_App_MediaSource
32 require_once 'Zend/Gdata/App/MediaSource.php';
35 * @see Zend_Gdata_MediaMimeStream
37 require_once 'Zend/Gdata/MediaMimeStream.php';
40 * Concrete class for working with Atom entries containing multi-part data.
45 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
46 * @license http://framework.zend.com/license/new-bsd New BSD License
48 class Zend_Gdata_App_MediaEntry extends Zend_Gdata_App_Entry
51 * The attached MediaSource/file
53 * @var Zend_Gdata_App_MediaSource
55 protected $_mediaSource = null;
58 * Constructs a new MediaEntry, representing XML data and optional
61 * @param DOMElement $element (optional) DOMElement from which this
62 * object should be constructed.
64 public function __construct($element = null, $mediaSource = null)
66 parent::__construct($element);
67 $this->_mediaSource = $mediaSource;
71 * Return the MIME multipart representation of this MediaEntry.
73 * @return string|Zend_Gdata_MediaMimeStream The MIME multipart
74 * representation of this MediaEntry. If the entry consisted only
75 * of XML, a string is returned.
77 public function encode()
79 $xmlData = $this->saveXML();
80 $mediaSource = $this->getMediaSource();
81 if ($mediaSource === null) {
82 // No attachment, just send XML for entry
85 return new Zend_Gdata_MediaMimeStream($xmlData,
86 $mediaSource->getFilename(), $mediaSource->getContentType());
91 * Return the MediaSource object representing the file attached to this
94 * @return Zend_Gdata_App_MediaSource The attached MediaSource/file
96 public function getMediaSource()
98 return $this->_mediaSource;
102 * Set the MediaSource object (file) for this MediaEntry
104 * @param Zend_Gdata_App_MediaSource $value The attached MediaSource/file
105 * @return Zend_Gdata_App_MediaEntry Provides a fluent interface
107 public function setMediaSource($value)
109 if ($value instanceof Zend_Gdata_App_MediaSource) {
110 $this->_mediaSource = $value;
112 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
113 throw new Zend_Gdata_App_InvalidArgumentException(
114 'You must specify the media data as a class that conforms to Zend_Gdata_App_MediaSource.');