@@ -37,18 +37,11 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
37
37
private $ response ;
38
38
39
39
/**
40
- * Should executor remove backend_name from api url
40
+ * Flag describes whether the request is to Magento Base URL, removes backend_name from api url
41
41
* @var boolean
42
42
*/
43
43
private $ removeBackend ;
44
44
45
- /**
46
- * Backend url.
47
- *
48
- * @var string
49
- */
50
- private static $ adminUrl ;
51
-
52
45
/**
53
46
* Constructor.
54
47
* @param boolean $removeBackend
@@ -58,15 +51,21 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
58
51
*/
59
52
public function __construct ($ removeBackend )
60
53
{
61
- if (!isset (parent ::$ baseUrl )) {
62
- parent ::resolveBaseUrl ();
63
- }
64
- self ::$ adminUrl = parent ::$ baseUrl . getenv ('MAGENTO_BACKEND_NAME ' ) . '/ ' ;
65
54
$ this ->removeBackend = $ removeBackend ;
66
55
$ this ->transport = new CurlTransport ();
67
56
$ this ->authorize ();
68
57
}
69
58
59
+ /**
60
+ * Returns base URL for Magento backend instance
61
+ * @return string
62
+ */
63
+ public function getBaseUrl (): string
64
+ {
65
+ $ backendHost = getenv ('MAGENTO_BACKEND_BASE_URL ' ) ?: parent ::getBaseUrl ();
66
+ return $ backendHost . getenv ('MAGENTO_BACKEND_NAME ' ) . '/ ' ;
67
+ }
68
+
70
69
/**
71
70
* Authorize admin on backend.
72
71
*
@@ -76,11 +75,11 @@ public function __construct($removeBackend)
76
75
private function authorize ()
77
76
{
78
77
// Perform GET to backend url so form_key is set
79
- $ this ->transport ->write (self :: $ adminUrl , [], CurlInterface::GET );
78
+ $ this ->transport ->write ($ this -> getBaseUrl () , [], CurlInterface::GET );
80
79
$ this ->read ();
81
80
82
81
// Authenticate admin user
83
- $ authUrl = self :: $ adminUrl . 'admin/auth/login/ ' ;
82
+ $ authUrl = $ this -> getBaseUrl () . 'admin/auth/login/ ' ;
84
83
$ data = [
85
84
'login[username] ' => getenv ('MAGENTO_ADMIN_USERNAME ' ),
86
85
'login[password] ' => getenv ('MAGENTO_ADMIN_PASSWORD ' ),
@@ -119,10 +118,10 @@ private function setFormKey()
119
118
public function write ($ url , $ data = [], $ method = CurlInterface::POST , $ headers = [])
120
119
{
121
120
$ url = ltrim ($ url , "/ " );
122
- $ apiUrl = self :: $ adminUrl . $ url ;
121
+ $ apiUrl = $ this -> getBaseUrl () . $ url ;
123
122
124
123
if ($ this ->removeBackend ) {
125
- $ apiUrl = parent ::$ baseUrl . $ url ;
124
+ $ apiUrl = parent ::getBaseUrl () . $ url ;
126
125
}
127
126
128
127
if ($ this ->formKey ) {
0 commit comments