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