30 private $formKey =
null;
43 private $removeBackend;
50 private static $adminUrl;
61 if (!isset(parent::$baseUrl)) {
62 parent::resolveBaseUrl();
64 self::$adminUrl = parent::$baseUrl . getenv(
'MAGENTO_BACKEND_NAME') .
'/';
65 $this->removeBackend = $removeBackend;
76 private function authorize()
83 $authUrl = self::$adminUrl .
'admin/auth/login/';
85 'login[username]' => getenv(
'MAGENTO_ADMIN_USERNAME'),
86 'login[password]' => getenv(
'MAGENTO_ADMIN_PASSWORD'),
87 'form_key' => $this->formKey,
90 $response = $this->
read();
91 if (strpos($response,
'login-form')) {
101 private function setFormKey()
103 preg_match(
'!var FORM_KEY = \'(\w+)\';!', $this->response, $matches);
104 if (!empty($matches[1])) {
105 $this->formKey = $matches[1];
122 $apiUrl = self::$adminUrl .
$url;
124 if ($this->removeBackend) {
125 $apiUrl = parent::$baseUrl .
$url;
128 if ($this->formKey) {
129 $data[
'form_key'] = $this->formKey;
132 sprintf(
'Form key is absent! Url: "%s" Response: "%s"', $apiUrl, $this->response)
136 $this->transport->write($apiUrl, str_replace(
'null',
'', http_build_query(
$data)),
$method, $headers);
147 public function read($successRegex =
null, $returnRegex =
null)
149 $this->response = $this->transport->read();
152 if (!empty($successRegex)) {
153 preg_match($successRegex, $this->response, $successMatches);
154 if (empty($successMatches)) {
159 if (!empty($returnRegex)) {
160 preg_match($returnRegex, $this->response, $returnMatches);
161 if (!empty($returnMatches)) {
162 return $returnMatches;
165 return $this->response;
187 $this->transport->close();
write($url, $data=[], $method=CurlInterface::POST, $headers=[])
addOption($option, $value)
read($successRegex=null, $returnRegex=null)
__construct($removeBackend)