Services_Ebay
[ class tree: Services_Ebay ] [ index: Services_Ebay ] [ all elements ]

Source for file Call.php

Documentation is available at Call.php

  1. <?PHP
  2. /**
  3.  * base class for API call objects
  4.  *
  5.  * $Id: Call.php,v 1.2 2004/10/29 21:16:49 schst Exp $
  6.  *
  7.  * @package     Services_Ebay
  8.  * @author      Stephan Schmidt <schst@php.net
  9.  *
  10.  * @todo        implement __toString()
  11.  * @todo        allow rules for parameters
  12.  */
  13. abstract class Services_Ebay_Call
  14. {
  15.    /**
  16.     * verb of the API call
  17.     *
  18.     * @var  string 
  19.     */
  20.     protected $verb = null;
  21.  
  22.    /**
  23.     * arguments of the call
  24.     *
  25.     * @var  array 
  26.     */
  27.     protected $args = array();
  28.  
  29.    /**
  30.     * authentication type of the call
  31.     *
  32.     * @var  int 
  33.     */
  34.     protected $authType = Services_Ebay::AUTH_TYPE_TOKEN;
  35.  
  36.    /**
  37.     * parameter map that is used, when scalar parameters are passed
  38.     *
  39.     * @var  array 
  40.     */
  41.     protected $paramMap = array();
  42.  
  43.    /**
  44.     * options that will be passed to the serializer
  45.     *
  46.     * @var  array 
  47.     */
  48.     protected $serializerOptions = array();
  49.     
  50.    /**
  51.     * constructor
  52.     *
  53.     * @param    array   arguments to the call
  54.     */
  55.     public function __construct($args = null)
  56.     {
  57.         if ($this->verb === null{
  58.             $this->verb = substr(get_class($this)19);
  59.         }
  60.  
  61.         // no arguments
  62.         if (is_null($args)) {
  63.             return;
  64.         }
  65.     
  66.         // arguments have been passed as assoc array
  67.         if (isset($args[0]&& is_array($args[0])) {
  68.             $this->args = $args[0];
  69.             return;
  70.         }
  71.  
  72.         $cnt count($args);
  73.         if ($cnt count($this->paramMap)) {
  74.             throw new Services_Ebay_Exception('To many parameters have been passed');
  75.         }
  76.  
  77.         for ($i = 0; $i $cnt$i++{
  78.             $this->args[$this->paramMap[$i]] $args[$i];
  79.         }
  80.     }
  81.  
  82.    /**
  83.     * make the API call
  84.     *
  85.     * @param  object Services_Ebay_Session 
  86.     * @return array 
  87.     */
  88.     public function call(Services_Ebay_Session $session)
  89.     {
  90.         $session->setSerializerOptions($this->serializerOptions);
  91.         $return $session->sendRequest($this->verb$this->args$this->authType);
  92.         return $return;
  93.     }
  94.     
  95.    /**
  96.     * set arguments for the API call
  97.     *
  98.     * @param    array 
  99.     * @return   boolean 
  100.     */
  101.     public function setArgs($args)
  102.     {
  103.         $this->args = $args;
  104.         return true;
  105.     }
  106.  
  107.    /**
  108.     * set the detail level for this call
  109.     *
  110.     * @param    integer 
  111.     * @return   boolean 
  112.     */
  113.     public function setDetailLevel($level)
  114.     {
  115.         $this->args['DetailLevel'$level;
  116.         return true;
  117.     }
  118.  
  119.    /**
  120.     * describe the call
  121.     *
  122.     * This returns information about the possible parameters
  123.     */
  124.     public function describeCall()
  125.     {
  126.         echo 'API-Call : '.$this->verb."\n";
  127.         echo 'Parameters (max. '.count($this->paramMap).')'."\n";
  128.         foreach ($this->paramMap as $param{
  129.             echo ' '.$param;
  130.             if (isset($this->args[$param])) {
  131.                 echo '('.$this->args[$param].')';
  132.             else {
  133.                 echo '(no default value)';
  134.             }
  135.             echo "\n";
  136.         }
  137.     }
  138. }
  139. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.