1 | <?php |
||
16 | abstract class Service |
||
17 | { |
||
18 | const HTTP_GET = 'GET'; |
||
19 | const HTTP_POST = 'POST'; |
||
20 | const HTTP_PUT = 'PUT'; |
||
21 | const HTTP_DELETE = 'DELETE'; |
||
22 | const HTTP_PATCH = 'PATCH'; |
||
23 | |||
24 | protected $baseUrl; |
||
25 | protected $userid; |
||
26 | protected $password; |
||
27 | protected $parameters = array(); |
||
28 | protected $headers = array( |
||
29 | 'Accept-language'=> 'en-CA' |
||
30 | ); |
||
31 | |||
32 | 4 | public function __construct($baseUrl, $userid, $password) |
|
38 | |||
39 | public function setLanguage($value) |
||
40 | { |
||
41 | $this->setHeader('Accept-language', $value); |
||
42 | } |
||
43 | |||
44 | public function setHeader($name, $value) |
||
45 | { |
||
46 | $this->headers[$name] = $value; |
||
47 | return $this; |
||
48 | } |
||
49 | |||
50 | public function hasParameter($name) |
||
51 | { |
||
52 | return isset($this->parameters[$name]); |
||
53 | } |
||
54 | |||
55 | public function setParameter($name, $value) |
||
56 | { |
||
57 | $this->parameters[$name] = $value; |
||
58 | return $this; |
||
59 | } |
||
60 | |||
61 | public function getParameter($name, $default=null) |
||
62 | { |
||
63 | return $this->hasParameter($name) ? |
||
64 | $this->parameters[$name] : $default; |
||
65 | } |
||
66 | |||
67 | 3 | public function getBaseUrl() |
|
71 | |||
72 | /** |
||
73 | * @return Request |
||
74 | */ |
||
75 | abstract protected function buildRequest(); |
||
76 | |||
77 | /** |
||
78 | * @return Response |
||
79 | */ |
||
80 | 3 | public function send() |
|
81 | { |
||
97 | } |
||
98 |