2
0

MediaEntry.php 3.5 KB

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