30 private $formKey =
null;
44 private $cookies =
'';
51 private $customerEmail;
58 private $customerPassword;
68 public function __construct($customerEmail, $customerPassWord)
70 if (!isset(parent::$baseUrl)) {
71 parent::resolveBaseUrl();
74 $this->customerEmail = $customerEmail;
75 $this->customerPassword = $customerPassWord;
85 private function authorize()
87 $url = parent::$baseUrl .
'customer/account/login/';
88 $this->transport->write(
$url);
91 $url = parent::$baseUrl .
'customer/account/loginPost/';
93 'login[username]' => $this->customerEmail,
94 'login[password]' => $this->customerPassword,
95 'form_key' => $this->formKey,
98 $response = $this->
read();
99 if (strpos($response,
'customer/account/login')) {
109 private function setFormKey()
111 $str = substr($this->response, strpos($this->response,
'form_key'));
112 preg_match(
'/value="(.*)" \/>/', $str, $matches);
113 if (!empty($matches[1])) {
114 $this->formKey = $matches[1];
125 preg_match_all(
'|Set-Cookie: (.*);|U', $this->response, $matches);
126 if (!empty($matches[1])) {
127 $this->cookies = implode(
'; ', $matches[1]);
143 if (isset(
$data[
'customer_email'])) {
144 unset(
$data[
'customer_email']);
146 if (isset(
$data[
'customer_password'])) {
147 unset(
$data[
'customer_password']);
149 $apiUrl = parent::$baseUrl .
$url;
150 if ($this->formKey) {
151 $data[
'form_key'] = $this->formKey;
154 sprintf(
'Form key is absent! Url: "%s" Response: "%s"', $apiUrl, $this->response)
157 $headers = [
'Set-Cookie:' . $this->cookies];
158 $this->transport->write($apiUrl, str_replace(
'null',
'', http_build_query(
$data)),
$method, $headers);
169 public function read($successRegex =
null, $returnRegex =
null)
171 $this->response = $this->transport->read();
175 if (!empty($successRegex)) {
176 preg_match($successRegex, $this->response, $successMatches);
177 if (empty($successMatches)) {
182 if (!empty($returnRegex)) {
183 preg_match($returnRegex, $this->response, $returnMatches);
184 if (!empty($returnMatches)) {
185 return $returnMatches;
188 return $this->response;
210 $this->transport->close();
read($successRegex=null, $returnRegex=null)
__construct($customerEmail, $customerPassWord)
write($url, $data=[], $method=CurlInterface::POST, $headers=[])
addOption($option, $value)