Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Zend_XmlRpc_Request
  • Zend_XmlRpc_Response
  • Overview
  • Package
  • Class
  • Tree
  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_Controller
 17:  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 18:  * @license    http://framework.zend.com/license/new-bsd     New BSD License
 19:  */
 20: 
 21: /**
 22:  * Zend_XmlRpc_Value
 23:  */
 24: #require_once 'Zend/XmlRpc/Value.php';
 25: 
 26: /**
 27:  * Zend_XmlRpc_Fault
 28:  */
 29: #require_once 'Zend/XmlRpc/Fault.php';
 30: 
 31: /**
 32:  * XmlRpc Request object
 33:  *
 34:  * Encapsulates an XmlRpc request, holding the method call and all parameters.
 35:  * Provides accessors for these, as well as the ability to load from XML and to
 36:  * create the XML request string.
 37:  *
 38:  * Additionally, if errors occur setting the method or parsing XML, a fault is
 39:  * generated and stored in {@link $_fault}; developers may check for it using
 40:  * {@link isFault()} and {@link getFault()}.
 41:  *
 42:  * @category Zend
 43:  * @package  Zend_XmlRpc
 44:  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 45:  * @license    http://framework.zend.com/license/new-bsd     New BSD License
 46:  * @version $Id: Request.php 20208 2010-01-11 22:37:37Z lars $
 47:  */
 48: class Zend_XmlRpc_Request
 49: {
 50:     /**
 51:      * Request character encoding
 52:      * @var string
 53:      */
 54:     protected $_encoding = 'UTF-8';
 55: 
 56:     /**
 57:      * Method to call
 58:      * @var string
 59:      */
 60:     protected $_method;
 61: 
 62:     /**
 63:      * XML request
 64:      * @var string
 65:      */
 66:     protected $_xml;
 67: 
 68:     /**
 69:      * Method parameters
 70:      * @var array
 71:      */
 72:     protected $_params = array();
 73: 
 74:     /**
 75:      * Fault object, if any
 76:      * @var Zend_XmlRpc_Fault
 77:      */
 78:     protected $_fault = null;
 79: 
 80:     /**
 81:      * XML-RPC type for each param
 82:      * @var array
 83:      */
 84:     protected $_types = array();
 85: 
 86:     /**
 87:      * XML-RPC request params
 88:      * @var array
 89:      */
 90:     protected $_xmlRpcParams = array();
 91: 
 92:     /**
 93:      * Create a new XML-RPC request
 94:      *
 95:      * @param string $method (optional)
 96:      * @param array $params  (optional)
 97:      */
 98:     public function __construct($method = null, $params = null)
 99:     {
100:         if ($method !== null) {
101:             $this->setMethod($method);
102:         }
103: 
104:         if ($params !== null) {
105:             $this->setParams($params);
106:         }
107:     }
108: 
109: 
110:     /**
111:      * Set encoding to use in request
112:      *
113:      * @param string $encoding
114:      * @return Zend_XmlRpc_Request
115:      */
116:     public function setEncoding($encoding)
117:     {
118:         $this->_encoding = $encoding;
119:         Zend_XmlRpc_Value::setEncoding($encoding);
120:         return $this;
121:     }
122: 
123:     /**
124:      * Retrieve current request encoding
125:      *
126:      * @return string
127:      */
128:     public function getEncoding()
129:     {
130:         return $this->_encoding;
131:     }
132: 
133:     /**
134:      * Set method to call
135:      *
136:      * @param string $method
137:      * @return boolean Returns true on success, false if method name is invalid
138:      */
139:     public function setMethod($method)
140:     {
141:         if (!is_string($method) || !preg_match('/^[a-z0-9_.:\/]+$/i', $method)) {
142:             $this->_fault = new Zend_XmlRpc_Fault(634, 'Invalid method name ("' . $method . '")');
143:             $this->_fault->setEncoding($this->getEncoding());
144:             return false;
145:         }
146: 
147:         $this->_method = $method;
148:         return true;
149:     }
150: 
151:     /**
152:      * Retrieve call method
153:      *
154:      * @return string
155:      */
156:     public function getMethod()
157:     {
158:         return $this->_method;
159:     }
160: 
161:     /**
162:      * Add a parameter to the parameter stack
163:      *
164:      * Adds a parameter to the parameter stack, associating it with the type
165:      * $type if provided
166:      *
167:      * @param mixed $value
168:      * @param string $type Optional; type hinting
169:      * @return void
170:      */
171:     public function addParam($value, $type = null)
172:     {
173:         $this->_params[] = $value;
174:         if (null === $type) {
175:             // Detect type if not provided explicitly
176:             if ($value instanceof Zend_XmlRpc_Value) {
177:                 $type = $value->getType();
178:             } else {
179:                 $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($value);
180:                 $type        = $xmlRpcValue->getType();
181:             }
182:         }
183:         $this->_types[]  = $type;
184:         $this->_xmlRpcParams[] = array('value' => $value, 'type' => $type);
185:     }
186: 
187:     /**
188:      * Set the parameters array
189:      *
190:      * If called with a single, array value, that array is used to set the
191:      * parameters stack. If called with multiple values or a single non-array
192:      * value, the arguments are used to set the parameters stack.
193:      *
194:      * Best is to call with array of the format, in order to allow type hinting
195:      * when creating the XMLRPC values for each parameter:
196:      * <code>
197:      * $array = array(
198:      *     array(
199:      *         'value' => $value,
200:      *         'type'  => $type
201:      *     )[, ... ]
202:      * );
203:      * </code>
204:      *
205:      * @access public
206:      * @return void
207:      */
208:     public function setParams()
209:     {
210:         $argc = func_num_args();
211:         $argv = func_get_args();
212:         if (0 == $argc) {
213:             return;
214:         }
215: 
216:         if ((1 == $argc) && is_array($argv[0])) {
217:             $params     = array();
218:             $types      = array();
219:             $wellFormed = true;
220:             foreach ($argv[0] as $arg) {
221:                 if (!is_array($arg) || !isset($arg['value'])) {
222:                     $wellFormed = false;
223:                     break;
224:                 }
225:                 $params[] = $arg['value'];
226: 
227:                 if (!isset($arg['type'])) {
228:                     $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg['value']);
229:                     $arg['type'] = $xmlRpcValue->getType();
230:                 }
231:                 $types[] = $arg['type'];
232:             }
233:             if ($wellFormed) {
234:                 $this->_xmlRpcParams = $argv[0];
235:                 $this->_params = $params;
236:                 $this->_types  = $types;
237:             } else {
238:                 $this->_params = $argv[0];
239:                 $this->_types  = array();
240:                 $xmlRpcParams  = array();
241:                 foreach ($argv[0] as $arg) {
242:                     if ($arg instanceof Zend_XmlRpc_Value) {
243:                         $type = $arg->getType();
244:                     } else {
245:                         $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
246:                         $type        = $xmlRpcValue->getType();
247:                     }
248:                     $xmlRpcParams[] = array('value' => $arg, 'type' => $type);
249:                     $this->_types[] = $type;
250:                 }
251:                 $this->_xmlRpcParams = $xmlRpcParams;
252:             }
253:             return;
254:         }
255: 
256:         $this->_params = $argv;
257:         $this->_types  = array();
258:         $xmlRpcParams  = array();
259:         foreach ($argv as $arg) {
260:             if ($arg instanceof Zend_XmlRpc_Value) {
261:                 $type = $arg->getType();
262:             } else {
263:                 $xmlRpcValue = Zend_XmlRpc_Value::getXmlRpcValue($arg);
264:                 $type        = $xmlRpcValue->getType();
265:             }
266:             $xmlRpcParams[] = array('value' => $arg, 'type' => $type);
267:             $this->_types[] = $type;
268:         }
269:         $this->_xmlRpcParams = $xmlRpcParams;
270:     }
271: 
272:     /**
273:      * Retrieve the array of parameters
274:      *
275:      * @return array
276:      */
277:     public function getParams()
278:     {
279:         return $this->_params;
280:     }
281: 
282:     /**
283:      * Return parameter types
284:      *
285:      * @return array
286:      */
287:     public function getTypes()
288:     {
289:         return $this->_types;
290:     }
291: 
292:     /**
293:      * Load XML and parse into request components
294:      *
295:      * @param string $request
296:      * @return boolean True on success, false if an error occurred.
297:      */
298:     public function loadXml($request)
299:     {
300:         if (!is_string($request)) {
301:             $this->_fault = new Zend_XmlRpc_Fault(635);
302:             $this->_fault->setEncoding($this->getEncoding());
303:             return false;
304:         }
305: 
306:         $loadEntities = libxml_disable_entity_loader(true);
307:         try {
308:             $xml = new SimpleXMLElement($request);
309:             libxml_disable_entity_loader($loadEntities);
310:         } catch (Exception $e) {
311:             // Not valid XML
312:             $this->_fault = new Zend_XmlRpc_Fault(631);
313:             $this->_fault->setEncoding($this->getEncoding());
314:             libxml_disable_entity_loader($loadEntities);
315:             return false;
316:         }
317: 
318:         // Check for method name
319:         if (empty($xml->methodName)) {
320:             // Missing method name
321:             $this->_fault = new Zend_XmlRpc_Fault(632);
322:             $this->_fault->setEncoding($this->getEncoding());
323:             return false;
324:         }
325: 
326:         $this->_method = (string) $xml->methodName;
327: 
328:         // Check for parameters
329:         if (!empty($xml->params)) {
330:             $types = array();
331:             $argv  = array();
332:             foreach ($xml->params->children() as $param) {
333:                 if (!isset($param->value)) {
334:                     $this->_fault = new Zend_XmlRpc_Fault(633);
335:                     $this->_fault->setEncoding($this->getEncoding());
336:                     return false;
337:                 }
338: 
339:                 try {
340:                     $param   = Zend_XmlRpc_Value::getXmlRpcValue($param->value, Zend_XmlRpc_Value::XML_STRING);
341:                     $types[] = $param->getType();
342:                     $argv[]  = $param->getValue();
343:                 } catch (Exception $e) {
344:                     $this->_fault = new Zend_XmlRpc_Fault(636);
345:                     $this->_fault->setEncoding($this->getEncoding());
346:                     return false;
347:                 }
348:             }
349: 
350:             $this->_types  = $types;
351:             $this->_params = $argv;
352:         }
353: 
354:         $this->_xml = $request;
355: 
356:         return true;
357:     }
358: 
359:     /**
360:      * Does the current request contain errors and should it return a fault
361:      * response?
362:      *
363:      * @return boolean
364:      */
365:     public function isFault()
366:     {
367:         return $this->_fault instanceof Zend_XmlRpc_Fault;
368:     }
369: 
370:     /**
371:      * Retrieve the fault response, if any
372:      *
373:      * @return null|Zend_XmlRpc_Fault
374:      */
375:     public function getFault()
376:     {
377:         return $this->_fault;
378:     }
379: 
380:     /**
381:      * Retrieve method parameters as XMLRPC values
382:      *
383:      * @return array
384:      */
385:     protected function _getXmlRpcParams()
386:     {
387:         $params = array();
388:         if (is_array($this->_xmlRpcParams)) {
389:             foreach ($this->_xmlRpcParams as $param) {
390:                 $value = $param['value'];
391:                 $type  = isset($param['type']) ? $param['type'] : Zend_XmlRpc_Value::AUTO_DETECT_TYPE;
392: 
393:                 if (!$value instanceof Zend_XmlRpc_Value) {
394:                     $value = Zend_XmlRpc_Value::getXmlRpcValue($value, $type);
395:                 }
396:                 $params[] = $value;
397:             }
398:         }
399: 
400:         return $params;
401:     }
402: 
403:     /**
404:      * Create XML request
405:      *
406:      * @return string
407:      */
408:     public function saveXml()
409:     {
410:         $args   = $this->_getXmlRpcParams();
411:         $method = $this->getMethod();
412: 
413:         $generator = Zend_XmlRpc_Value::getGenerator();
414:         $generator->openElement('methodCall')
415:                   ->openElement('methodName', $method)
416:                   ->closeElement('methodName');
417: 
418:         if (is_array($args) && count($args)) {
419:             $generator->openElement('params');
420: 
421:             foreach ($args as $arg) {
422:                 $generator->openElement('param');
423:                 $arg->generateXml();
424:                 $generator->closeElement('param');
425:             }
426:             $generator->closeElement('params');
427:         }
428:         $generator->closeElement('methodCall');
429: 
430:         return $generator->flush();
431:     }
432: 
433:     /**
434:      * Return XML request
435:      *
436:      * @return string
437:      */
438:     public function __toString()
439:     {
440:         return $this->saveXML();
441:     }
442: }
443: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0