Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 8eafd2a

Browse files
Add linter script. Lint
1 parent e9dbd75 commit 8eafd2a

File tree

14 files changed

+42
-31
lines changed

14 files changed

+42
-31
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
}
4343
},
4444
"scripts": {
45-
"test": "./vendor/bin/pest"
45+
"test": "./vendor/bin/pest",
46+
"lint": "./vendor/bin/php-cs-fixer fix --rules=@PSR12 ."
4647
}
4748
}

src/Abstract/ApplicationAbstract.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
use Pavlusha311245\UnitPhpSdk\Config\Application\ProcessManagement\RequestLimit;
88
use Pavlusha311245\UnitPhpSdk\Config\Listener;
99
use Pavlusha311245\UnitPhpSdk\Enums\ApplicationTypeEnum;
10+
use Pavlusha311245\UnitPhpSdk\Enums\HttpMethodsEnum;
1011
use Pavlusha311245\UnitPhpSdk\Exceptions\UnitException;
12+
use Pavlusha311245\UnitPhpSdk\Interfaces\ApplicationControlInterface;
1113
use Pavlusha311245\UnitPhpSdk\Interfaces\ApplicationInterface;
1214
use Pavlusha311245\UnitPhpSdk\Traits\HasListeners;
15+
use Pavlusha311245\UnitPhpSdk\UnitRequest;
1316

14-
abstract class ApplicationAbstract implements ApplicationInterface
17+
abstract class ApplicationAbstract implements ApplicationInterface, ApplicationControlInterface
1518
{
1619
use HasListeners;
1720

21+
public const SOCKET = '/usr/local/var/run/unit/control.sock';
22+
public const ADDRESS = 'http://localhost';
23+
1824
private string $_type;
1925

2026
/**
@@ -248,10 +254,10 @@ public function parseFromArray(array $data): void
248254
$this->setStdOut($data['stdout']);
249255
}
250256

251-
// TODO: implement isolation object
252-
// if (array_key_exists('isolation', $data)) {
253-
// $this->setIsolation($data['isolation']);
254-
// }
257+
// TODO: implement isolation object
258+
// if (array_key_exists('isolation', $data)) {
259+
// $this->setIsolation($data['isolation']);
260+
// }
255261

256262
if (array_key_exists('processes', $data)) {
257263
if (is_array($data['processes'])) {
@@ -265,4 +271,20 @@ public function parseFromArray(array $data): void
265271
$this->setLimits(new RequestLimit($data['limits']));
266272
}
267273
}
274+
275+
/**
276+
* @inheritDoc
277+
*/
278+
public function restartApplication(): bool
279+
{
280+
try {
281+
$request = new UnitRequest(self::SOCKET, self::ADDRESS);
282+
$request->setMethod(HttpMethodsEnum::DELETE->value);
283+
$result = $request->send("/control/applications/{$this->getName()}/restart");
284+
} catch (UnitException $exception) {
285+
return false;
286+
}
287+
288+
return true;
289+
}
268290
}

src/Certificate.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
public function __construct(
1313
private array $_data,
1414
private readonly string $_name
15-
)
16-
{
15+
) {
1716
//
1817
}
1918

src/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
class Config implements ConfigInterface
1818
{
19-
const SOCKET = '/usr/local/var/run/unit/control.sock';
20-
const ADDRESS = 'http://localhost';
19+
public const SOCKET = '/usr/local/var/run/unit/control.sock';
20+
public const ADDRESS = 'http://localhost';
2121

2222
/**
2323
* Listeners accept requests

src/Config/AccessLog.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class AccessLog
99

1010
public function __construct(
1111
array $data
12-
)
13-
{
12+
) {
1413
$this->_path = $data['path'] ?? null;
1514
$this->_format = $data['format'] ?? null;
1615
}

src/Config/Application/ProcessManagement/ProcessIsolation.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
class ProcessIsolation
66
{
7-
87
}

src/Config/Listener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function __construct(
1818
string $pass = '',
1919
private array $_tls = [],
2020
private array $_forwarded = [],
21-
)
22-
{
21+
) {
2322
$this->parsePort();
2423
$this->generateLink();
2524

src/Config/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Route implements RouteInterface
1919

2020
public function __construct(
2121
private readonly string $_name,
22-
$data)
23-
{
22+
$data
23+
) {
2424
foreach ($data as $routeBlock) {
2525
$this->_routeBlocks[] = new RouteBlock($routeBlock);
2626
}

src/Config/Routes/RouteBlock.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ class RouteBlock
66
{
77
private RouteAction $_action;
88

9-
private $_match;
9+
private RouteMatch $_match;
1010

1111
public function __construct(array $data)
1212
{
13-
// $this->_action = $data['action'];
14-
// $this->_match = $data['match'] ?? null;
15-
1613
$this->_action = new RouteAction($data['action']);
17-
if (isset($data['match']))
18-
{
14+
if (isset($data['match'])) {
1915
$this->_match = new RouteMatch($data['match']);
2016
}
2117
}

src/Config/Statistics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(array $data)
2424
{
2525
$this->_connections = new ConnectionsStatistics($data['connections']);
2626
$this->_requests = new RequestsStatistics($data['requests']);
27-
$this->_applications = array_map(fn($item) => new ApplicationsStatistics($item), $data['applications']);
27+
$this->_applications = array_map(fn ($item) => new ApplicationsStatistics($item), $data['applications']);
2828
}
2929

3030
/**

0 commit comments

Comments
 (0)