Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * base class for API call objects
4
 *
5
 * $Id: Call.php,v 1.6 2005/01/01 15:48:46 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
    * 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
        $return = $session->sendRequest($this->verb, $this->args, $this->authType, $parseResult);
115
        return $return;
116
    }
117
 
118
   /**
119
    * set arguments for the API call
120
    *
121
    * @param    array
122
    * @return   boolean
123
    */
124
    public function setArgs($args)
125
    {
126
        $this->args = $args;
127
        return true;
128
    }
129
 
130
   /**
131
    * set the detail level for this call
132
    *
133
    * @param    integer
134
    * @return   boolean
135
    */
136
    public function setDetailLevel($level)
137
    {
138
        $this->args['DetailLevel'] = $level;
139
        return true;
140
    }
141
 
142
   /**
143
    * describe the call
144
    *
145
    * This returns information about the possible parameters
146
    */
147
    public function describeCall()
148
    {
149
        echo 'API Call : '.$this->verb."\n";
150
        if ($this->since !== null) {
151
        	echo 'Added in API version : ' . $this->since . "\n";
152
        }
153
        if ($this->deprecated !== null) {
154
        	echo 'Deprecated in API version : ' . $this->deprecated . "\n";
155
        }
156
        echo "\n";
157
        echo 'Parameters (max. '.count($this->paramMap).')'."\n";
158
        $i = 0;
159
        foreach ($this->paramMap as $param) {
160
            echo ' '.++$i.'. '.$param;
161
            if (isset($this->args[$param])) {
162
                echo '('.$this->args[$param].')';
163
            } else {
164
                echo '(no default value)';
165
            }
166
            echo "\n";
167
        }
168
        $rc = new ReflectionClass($this);
169
        $dc = $rc->getDocComment();
170
        if (preg_match('/@link +(.+)/', $dc, $matches)) {
171
            echo 'API Documentation : '.$matches[1]."\n";
172
        }
173
    }
174
}
175
?>