Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
request.php
1<?php
2
3namespace Bitrix\Seo\Checkout;
4
9
14abstract class Request
15{
16 const TYPE_CODE = '';
17
19 protected $adapter;
20
22 protected $client;
23
25 protected $response;
26
28 protected $type;
29
33 public function __construct()
34 {
35 $this->type = static::TYPE_CODE;
36
37 $options = array(
38 'socketTimeout' => 5
39 );
40 $this->client = new AdsHttpClient($options);
41 }
42
48 public function getAuthAdapter()
49 {
50 return $this->adapter;
51 }
52
60 {
61 $this->adapter = $adapter;
62 return $this;
63 }
64
70 public function getResponse()
71 {
72 return $this->response;
73 }
74
80 public function getClient()
81 {
82 return $this->client;
83 }
84
92 {
93 $this->client = $client;
94 return $this;
95 }
96
104 public static function create($type)
105 {
106 return Factory::create(get_called_class(), $type);
107 }
108
116 public function send(array $params = array())
117 {
118 if (!$this->adapter)
119 {
120 throw new SystemException('AuthAdapter not applied.');
121 }
122
123 $options = [
124 'socketTimeout' => 5
125 ];
126 $this->client = new AdsHttpClient($options);
127
128 $data = $this->query($params);
129 $response = Response::create($this->type);
130 $response->setRequest($this);
131 $response->setResponseText($data);
132 try
133 {
134 $response->parse($data);
135 }
136 catch (\Exception $exception)
137 {
138 $response->addError(new Error($exception->getMessage(), $exception->getCode()));
139 }
140
141 if ($response->getErrorCollection()->count() > 0)
142 {
143 $errors = $response->getErrors();
144 foreach ($errors as $error)
145 {
146 if (!$error->getMessage())
147 {
148 continue;
149 }
150
151 ServiceLogTable::add(array(
152 'GROUP_ID' => 'checkout',
153 'TYPE' => static::TYPE_CODE,
154 'CODE' => $error->getCode(),
155 'MESSAGE' => $error->getMessage()
156 ));
157 }
158 }
159
160 return $response;
161 }
162
169 abstract public function query(array $params = array());
170}
static create($object, $type, $parameters=null)
Definition factory.php:20
send(array $params=array())
Definition request.php:116
setAuthAdapter(AuthAdapter $adapter)
Definition request.php:59
setClient(AdsHttpClient $client)
Definition request.php:91
query(array $params=array())