source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/App/MediaEntry.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 3.5 KB
Line 
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 App
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * @see Zend_Gdata_App_Entry
25 */
26require_once 'Zend/Gdata/App/Entry.php';
27
28/**
29 * @see Zend_Gdata_App_MediaSource
30 */
31require_once 'Zend/Gdata/App/MediaSource.php';
32
33/**
34 * @see Zend_Gdata_MediaMimeStream
35 */
36require_once 'Zend/Gdata/MediaMimeStream.php';
37
38/**
39 * Concrete class for working with Atom entries containing multi-part data.
40 *
41 * @category Zend
42 * @package Zend_Gdata
43 * @subpackage App
44 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
45 * @license http://framework.zend.com/license/new-bsd New BSD License
46 */
47class Zend_Gdata_App_MediaEntry extends Zend_Gdata_App_Entry
48{
49 /**
50 * The attached MediaSource/file
51 *
52 * @var Zend_Gdata_App_MediaSource
53 */
54 protected $_mediaSource = null;
55
56 /**
57 * Constructs a new MediaEntry, representing XML data and optional
58 * file to upload
59 *
60 * @param DOMElement $element (optional) DOMElement from which this
61 * object should be constructed.
62 */
63 public function __construct($element = null, $mediaSource = null)
64 {
65 parent::__construct($element);
66 $this->_mediaSource = $mediaSource;
67 }
68
69 /**
70 * Return the MIME multipart representation of this MediaEntry.
71 *
72 * @return string|Zend_Gdata_MediaMimeStream The MIME multipart
73 * representation of this MediaEntry. If the entry consisted only
74 * of XML, a string is returned.
75 */
76 public function encode()
77 {
78 $xmlData = $this->saveXML();
79 $mediaSource = $this->getMediaSource();
80 if ($mediaSource === null) {
81 // No attachment, just send XML for entry
82 return $xmlData;
83 } else {
84 return new Zend_Gdata_MediaMimeStream($xmlData,
85 $mediaSource->getFilename(), $mediaSource->getContentType());
86 }
87 }
88
89 /**
90 * Return the MediaSource object representing the file attached to this
91 * MediaEntry.
92 *
93 * @return Zend_Gdata_App_MediaSource The attached MediaSource/file
94 */
95 public function getMediaSource()
96 {
97 return $this->_mediaSource;
98 }
99
100 /**
101 * Set the MediaSource object (file) for this MediaEntry
102 *
103 * @param Zend_Gdata_App_MediaSource $value The attached MediaSource/file
104 * @return Zend_Gdata_App_MediaEntry Provides a fluent interface
105 */
106 public function setMediaSource($value)
107 {
108 if ($value instanceof Zend_Gdata_App_MediaSource) {
109 $this->_mediaSource = $value;
110 } else {
111 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
112 throw new Zend_Gdata_App_InvalidArgumentException(
113 'You must specify the media data as a class that conforms to Zend_Gdata_App_MediaSource.');
114 }
115 return $this;
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.