BaseMediaSource.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_MediaSource
  23. */
  24. require_once 'Zend/Gdata/App/MediaSource.php';
  25. /**
  26. * Concrete class to use a file handle as an attachment within a MediaEntry.
  27. *
  28. * @category Zend
  29. * @package Zend_Gdata
  30. * @subpackage App
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. abstract class Zend_Gdata_App_BaseMediaSource implements Zend_Gdata_App_MediaSource
  35. {
  36. /**
  37. * The content type for the attached file (example image/png)
  38. *
  39. * @var string
  40. */
  41. protected $_contentType = null;
  42. /**
  43. * The slug header value representing the attached file title, or null if
  44. * no slug should be used. The slug header is only necessary in some cases,
  45. * usually when a multipart upload is not being performed.
  46. *
  47. * @var string
  48. */
  49. protected $_slug = null;
  50. /**
  51. * The content type for the attached file (example image/png)
  52. *
  53. * @return string The content type
  54. */
  55. public function getContentType()
  56. {
  57. return $this->_contentType;
  58. }
  59. /**
  60. * Set the content type for the file attached (example image/png)
  61. *
  62. * @param string $value The content type
  63. * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface
  64. */
  65. public function setContentType($value)
  66. {
  67. $this->_contentType = $value;
  68. return $this;
  69. }
  70. /**
  71. * Returns the Slug header value. Used by some services to determine the
  72. * title for the uploaded file. Returns null if no slug should be used.
  73. *
  74. * @return string
  75. */
  76. public function getSlug(){
  77. return $this->_slug;
  78. }
  79. /**
  80. * Sets the Slug header value. Used by some services to determine the
  81. * title for the uploaded file. A null value indicates no slug header.
  82. *
  83. * @var string The slug value
  84. * @return Zend_Gdata_App_MediaSource Provides a fluent interface
  85. */
  86. public function setSlug($value){
  87. $this->_slug = $value;
  88. return $this;
  89. }
  90. /**
  91. * Magic getter to allow acces like $source->foo to call $source->getFoo()
  92. * Alternatively, if no getFoo() is defined, but a $_foo protected variable
  93. * is defined, this is returned.
  94. *
  95. * TODO Remove ability to bypass getFoo() methods??
  96. *
  97. * @param string $name The variable name sought
  98. */
  99. public function __get($name)
  100. {
  101. $method = 'get'.ucfirst($name);
  102. if (method_exists($this, $method)) {
  103. return call_user_func(array(&$this, $method));
  104. } else if (property_exists($this, "_${name}")) {
  105. return $this->{'_' . $name};
  106. } else {
  107. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  108. throw new Zend_Gdata_App_InvalidArgumentException(
  109. 'Property ' . $name . ' does not exist');
  110. }
  111. }
  112. /**
  113. * Magic setter to allow acces like $source->foo='bar' to call
  114. * $source->setFoo('bar') automatically.
  115. *
  116. * Alternatively, if no setFoo() is defined, but a $_foo protected variable
  117. * is defined, this is returned.
  118. *
  119. * @param string $name
  120. * @param string $value
  121. */
  122. public function __set($name, $val)
  123. {
  124. $method = 'set'.ucfirst($name);
  125. if (method_exists($this, $method)) {
  126. return call_user_func(array(&$this, $method), $val);
  127. } else if (isset($this->{'_' . $name}) || ($this->{'_' . $name} === null)) {
  128. $this->{'_' . $name} = $val;
  129. } else {
  130. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  131. throw new Zend_Gdata_App_InvalidArgumentException(
  132. 'Property ' . $name . ' does not exist');
  133. }
  134. }
  135. /**
  136. * Magic __isset method
  137. *
  138. * @param string $name
  139. */
  140. public function __isset($name)
  141. {
  142. $rc = new ReflectionClass(get_class($this));
  143. $privName = '_' . $name;
  144. if (!($rc->hasProperty($privName))) {
  145. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  146. throw new Zend_Gdata_App_InvalidArgumentException(
  147. 'Property ' . $name . ' does not exist');
  148. } else {
  149. if (isset($this->{$privName})) {
  150. if (is_array($this->{$privName})) {
  151. if (count($this->{$privName}) > 0) {
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. } else {
  157. return true;
  158. }
  159. } else {
  160. return false;
  161. }
  162. }
  163. }
  164. }