|
1 <?php |
|
2 |
|
3 /** |
|
4 * Zend Framework |
|
5 * |
|
6 * LICENSE |
|
7 * |
|
8 * This source file is subject to the new BSD license that is bundled |
|
9 * with this package in the file LICENSE.txt. |
|
10 * It is also available through the world-wide-web at this URL: |
|
11 * http://framework.zend.com/license/new-bsd |
|
12 * If you did not receive a copy of the license and are unable to |
|
13 * obtain it through the world-wide-web, please send an email |
|
14 * to license@zend.com so we can send you a copy immediately. |
|
15 * |
|
16 * @category Zend |
|
17 * @package Zend_Gdata |
|
18 * @subpackage App |
|
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 * @version $Id: BaseMediaSource.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @see Zend_Gdata_App_MediaSource |
|
26 */ |
|
27 require_once 'Zend/Gdata/App/MediaSource.php'; |
|
28 |
|
29 /** |
|
30 * Concrete class to use a file handle as an attachment within a MediaEntry. |
|
31 * |
|
32 * @category Zend |
|
33 * @package Zend_Gdata |
|
34 * @subpackage App |
|
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
37 */ |
|
38 abstract class Zend_Gdata_App_BaseMediaSource implements Zend_Gdata_App_MediaSource |
|
39 { |
|
40 |
|
41 /** |
|
42 * The content type for the attached file (example image/png) |
|
43 * |
|
44 * @var string |
|
45 */ |
|
46 protected $_contentType = null; |
|
47 |
|
48 /** |
|
49 * The slug header value representing the attached file title, or null if |
|
50 * no slug should be used. The slug header is only necessary in some cases, |
|
51 * usually when a multipart upload is not being performed. |
|
52 * |
|
53 * @var string |
|
54 */ |
|
55 protected $_slug = null; |
|
56 |
|
57 /** |
|
58 * The content type for the attached file (example image/png) |
|
59 * |
|
60 * @return string The content type |
|
61 */ |
|
62 public function getContentType() |
|
63 { |
|
64 return $this->_contentType; |
|
65 } |
|
66 |
|
67 /** |
|
68 * Set the content type for the file attached (example image/png) |
|
69 * |
|
70 * @param string $value The content type |
|
71 * @return Zend_Gdata_App_MediaFileSource Provides a fluent interface |
|
72 */ |
|
73 public function setContentType($value) |
|
74 { |
|
75 $this->_contentType = $value; |
|
76 return $this; |
|
77 } |
|
78 |
|
79 /** |
|
80 * Returns the Slug header value. Used by some services to determine the |
|
81 * title for the uploaded file. Returns null if no slug should be used. |
|
82 * |
|
83 * @return string |
|
84 */ |
|
85 public function getSlug(){ |
|
86 return $this->_slug; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Sets the Slug header value. Used by some services to determine the |
|
91 * title for the uploaded file. A null value indicates no slug header. |
|
92 * |
|
93 * @var string The slug value |
|
94 * @return Zend_Gdata_App_MediaSource Provides a fluent interface |
|
95 */ |
|
96 public function setSlug($value){ |
|
97 $this->_slug = $value; |
|
98 return $this; |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * Magic getter to allow acces like $source->foo to call $source->getFoo() |
|
104 * Alternatively, if no getFoo() is defined, but a $_foo protected variable |
|
105 * is defined, this is returned. |
|
106 * |
|
107 * TODO Remove ability to bypass getFoo() methods?? |
|
108 * |
|
109 * @param string $name The variable name sought |
|
110 */ |
|
111 public function __get($name) |
|
112 { |
|
113 $method = 'get'.ucfirst($name); |
|
114 if (method_exists($this, $method)) { |
|
115 return call_user_func(array(&$this, $method)); |
|
116 } else if (property_exists($this, "_${name}")) { |
|
117 return $this->{'_' . $name}; |
|
118 } else { |
|
119 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
|
120 throw new Zend_Gdata_App_InvalidArgumentException( |
|
121 'Property ' . $name . ' does not exist'); |
|
122 } |
|
123 } |
|
124 |
|
125 /** |
|
126 * Magic setter to allow acces like $source->foo='bar' to call |
|
127 * $source->setFoo('bar') automatically. |
|
128 * |
|
129 * Alternatively, if no setFoo() is defined, but a $_foo protected variable |
|
130 * is defined, this is returned. |
|
131 * |
|
132 * @param string $name |
|
133 * @param string $value |
|
134 */ |
|
135 public function __set($name, $val) |
|
136 { |
|
137 $method = 'set'.ucfirst($name); |
|
138 if (method_exists($this, $method)) { |
|
139 return call_user_func(array(&$this, $method), $val); |
|
140 } else if (isset($this->{'_' . $name}) || ($this->{'_' . $name} === null)) { |
|
141 $this->{'_' . $name} = $val; |
|
142 } else { |
|
143 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
|
144 throw new Zend_Gdata_App_InvalidArgumentException( |
|
145 'Property ' . $name . ' does not exist'); |
|
146 } |
|
147 } |
|
148 |
|
149 /** |
|
150 * Magic __isset method |
|
151 * |
|
152 * @param string $name |
|
153 */ |
|
154 public function __isset($name) |
|
155 { |
|
156 $rc = new ReflectionClass(get_class($this)); |
|
157 $privName = '_' . $name; |
|
158 if (!($rc->hasProperty($privName))) { |
|
159 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; |
|
160 throw new Zend_Gdata_App_InvalidArgumentException( |
|
161 'Property ' . $name . ' does not exist'); |
|
162 } else { |
|
163 if (isset($this->{$privName})) { |
|
164 if (is_array($this->{$privName})) { |
|
165 if (count($this->{$privName}) > 0) { |
|
166 return true; |
|
167 } else { |
|
168 return false; |
|
169 } |
|
170 } else { |
|
171 return true; |
|
172 } |
|
173 } else { |
|
174 return false; |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 } |