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$
  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.     * options that will be passed to the unserializer
  52.     *
  53.     * @var  array 
  54.     */
  55.     protected $unserializerOptions = array();
  56.  
  57.    /**
  58.     * compatibility level this method was introduced
  59.     *
  60.     * @var  integer 
  61.     */
  62.     protected $since = null;
  63.  
  64.    /**
  65.     * deprecated since API version
  66.     *
  67.     * @var  integer 
  68.     */
  69.     protected $deprecated = null;
  70.  
  71.    /**
  72.     * constructor
  73.     *
  74.     * @param    array   arguments to the call
  75.     */
  76.     public function __construct($args = null)
  77.     {
  78.         if ($this->verb === null{
  79.             $this->verb = substr(get_class($this)19);
  80.         }
  81.  
  82.         // no arguments
  83.         if (is_null($args)) {
  84.             return;
  85.         }
  86.     
  87.         // arguments have been passed as assoc array
  88.         if (isset($args[0]&& is_array($args[0])) {
  89.             $this->args = $args[0];
  90.             return;
  91.         }
  92.  
  93.         $cnt count($args);
  94.         if ($cnt count($this->paramMap)) {
  95.             throw new Services_Ebay_Exception('To many parameters have been passed');
  96.         }
  97.  
  98.         for ($i = 0; $i $cnt$i++{
  99.             $this->args[$this->paramMap[$i]] $args[$i];
  100.         }
  101.     }
  102.  
  103.    /**
  104.     * make the API call
  105.     *
  106.     * @param  object Services_Ebay_Session 
  107.     * @param  boolean  flag to indicate, whether the result should be parsed using XML_Serializer
  108.     * @return array 
  109.     */
  110.     public function call(Services_Ebay_Session $session$parseResult = true)
  111.     {
  112.         $session->setSerializerOptions($this->serializerOptions);
  113.         $session->setUnserializerOptions($this->unserializerOptions);
  114.         if (!is_null($this->since)) {
  115.             $session->setCompatLevel($this->since);
  116.         }
  117.         $return $session->sendRequest($this->verb$this->args$this->authType$parseResult);
  118.         return $return;
  119.     }
  120.     
  121.    /**
  122.     * set arguments for the API call
  123.     *
  124.     * @param    array 
  125.     * @return   boolean 
  126.     */
  127.     public function setArgs($args)
  128.     {
  129.         $this->args = $args;
  130.         return true;
  131.     }
  132.  
  133.    /**
  134.     * set the detail level for this call
  135.     *
  136.     * @param    integer 
  137.     * @return   boolean 
  138.     */
  139.     public function setDetailLevel($level)
  140.     {
  141.         $this->args['DetailLevel'$level;
  142.         return true;
  143.     }
  144.  
  145.    /**
  146.     * describe the call
  147.     *
  148.     * This returns information about the possible parameters
  149.     */
  150.     public function describeCall()
  151.     {
  152.         echo 'API Call : '.$this->verb."\n";
  153.         if ($this->since !== null{
  154.             echo 'Added in API version : ' $this->since . "\n";
  155.         }
  156.         if ($this->deprecated !== null{
  157.             echo 'Deprecated in API version : ' $this->deprecated . "\n";
  158.         }
  159.         echo "\n";
  160.         echo 'Parameters (max. '.count($this->paramMap).')'."\n";
  161.         $i = 0;
  162.         foreach ($this->paramMap as $param{
  163.             echo ' '.++$i.'. '.$param;
  164.             if (isset($this->args[$param])) {
  165.                 echo '('.$this->args[$param].')';
  166.             else {
  167.                 echo '(no default value)';
  168.             }
  169.             echo "\n";
  170.         }
  171.         $rc = new ReflectionClass($this);
  172.         $dc $rc->getDocComment();
  173.         if (preg_match('/@link +(.+)/'$dc$matches)) {
  174.             echo 'API Documentation : '.$matches[1]."\n";            
  175.         }
  176.     }
  177. }
  178. ?>

Documentation generated on Mon, 11 Mar 2019 15:49:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.