PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/GData/App/BaseMediaSource.php

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