MediaEntry.php 3.5 KB

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