PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/zend/Zend/Gdata/App/BaseMediaSource.php

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