Skip to content

Commit ed2612b

Browse files
committed
fixes
1 parent 6b0bb48 commit ed2612b

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

src/Func/AbstractFunc.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace IspApi\Func;
44

5+
use function array_merge;
6+
57
/**
68
* Class AbstractFunc
79
* @package IspApi\Func
@@ -16,17 +18,17 @@ abstract class AbstractFunc implements FuncInterface
1618
/**
1719
* @var string
1820
*/
19-
protected $func = '';
21+
protected $func;
2022

2123
/**
2224
* @var string
2325
*/
24-
protected $elid = '';
26+
protected $elid;
2527

2628
/**
2729
* @var string
2830
*/
29-
protected $plid = '';
31+
protected $plid;
3032

3133
/**
3234
* @var array
@@ -38,7 +40,7 @@ abstract class AbstractFunc implements FuncInterface
3840
* @param string $elid
3941
* @param string $plid
4042
*/
41-
public function __construct(string $elid = '', string $plid = '')
43+
public function __construct(string $elid = null, string $plid = null)
4244
{
4345
if ($elid) {
4446
$this->elid = $elid;
@@ -58,38 +60,38 @@ public function setAdditional(array $additional): self
5860
$this->additional = $additional;
5961
return $this;
6062
}
61-
$this->additional = \array_merge($this->additional, $additional);
63+
$this->additional = array_merge($this->additional, $additional);
6264
return $this;
6365
}
6466

6567
/**
66-
* @return string
68+
* @return string|null
6769
*/
68-
final public function getFunc(): string
70+
final public function getFunc(): ?string
6971
{
7072
return $this->func;
7173
}
7274

7375
/**
74-
* @return string
76+
* @return string|null
7577
*/
76-
final public function getElid(): string
78+
final public function getElid(): ?string
7779
{
7880
return $this->elid;
7981
}
8082

8183
/**
82-
* @return string
84+
* @return string|null
8385
*/
84-
final public function getPlid(): string
86+
final public function getPlid(): ?string
8587
{
8688
return $this->plid;
8789
}
8890

8991
/**
9092
* @return bool
9193
*/
92-
final public function isSaveAction(): bool
94+
final public function getIsSaveAction(): bool
9395
{
9496
return $this->isSaveAction;
9597
}

src/Func/FuncInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ interface FuncInterface
1111
/**
1212
* @return string
1313
*/
14-
public function getFunc(): string ;
14+
public function getFunc(): ?string ;
1515
/**
1616
* @return string
1717
*/
18-
public function getElid(): string ;
18+
public function getElid(): ?string ;
1919

2020
/**
2121
* @return string
2222
*/
23-
public function getPlid(): string ;
23+
public function getPlid(): ?string ;
2424

2525
/**
2626
* @return bool
2727
*/
28-
public function isSaveAction(): bool ;
28+
public function getIsSaveAction(): bool ;
2929

3030
/**
3131
* @return array

src/HttpClient/HttpClientParams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class HttpClientParams
3939
* @param array $header
4040
* @param null|array $content
4141
*/
42-
public function __construct(string $url, string $method = self::HTTP_METHOD_GET, array $header, ?array $content)
42+
public function __construct(string $url, string $method = self::HTTP_METHOD_GET, array $header, ?array $content = null)
4343
{
4444
$this->url = $url;
4545
$this->method = $method;

src/IspManager.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace IspApi;
44

5+
use Exception;
6+
use function http_build_query;
57
use IspApi\Format\FormatInterface;
68
use IspApi\Func\FuncInterface;
79
use IspApi\HttpClient\HttpClientInterface;
@@ -15,6 +17,8 @@
1517
*/
1618
class ispManager
1719
{
20+
const DEFAULT_HEADER = ["Content-type: application/x-www-form-urlencoded\r\n"];
21+
1822
/**
1923
* @var ServerInterface
2024
*/
@@ -128,14 +132,26 @@ public function setData(array $data): self
128132

129133
/**
130134
* @return mixed
131-
* @throws \Exception
135+
* @throws Exception
132136
*/
133137
public function execute()
134138
{
135139
$data = $this->httpClient->setParams($this->getHttpClientParams())->get();
136140
return $this->format->setData($data)->getOut();
137141
}
138142

143+
/**
144+
* @return HttpClientParams
145+
*/
146+
public function getHttpClientParams(): HttpClientParams
147+
{
148+
$this->buildUrl();
149+
$method = $this->func->getIsSaveAction() ? HttpClientParams::HTTP_METHOD_POST : HttpClientParams::HTTP_METHOD_GET;
150+
151+
$header = self::DEFAULT_HEADER;
152+
return new HttpClientParams($this->url, $method, $header);
153+
}
154+
139155
/**
140156
* @return self
141157
*/
@@ -147,7 +163,7 @@ private function buildUrl(): self
147163
$this->prepareUrlFormat();
148164
$this->prepareUrlFunc();
149165
$this->prepareUrlAdditional();
150-
$this->url .= \http_build_query($this->urlParts->toArray());
166+
$this->url .= http_build_query($this->urlParts->toArray());
151167
return $this;
152168
}
153169

@@ -207,17 +223,4 @@ private function prepareUrlFunc(): self
207223
}
208224
return $this;
209225
}
210-
211-
/**
212-
* @return HttpClientParams
213-
*/
214-
public function getHttpClientParams(): HttpClientParams
215-
{
216-
$this->buildUrl();
217-
$method = $this->func->isSaveAction() ? HttpClientParams::HTTP_METHOD_POST : HttpClientParams::HTTP_METHOD_GET;
218-
$content = null; //todo: Доделать...
219-
220-
$header = ["Content-type: application/x-www-form-urlencoded\r\n"];
221-
return new HttpClientParams($this->url, $method, $header, $content);
222-
}
223226
}

0 commit comments

Comments
 (0)