Skip to content

Commit b378dbd

Browse files
Merge branch 'release/0.5.0'
2 parents 0f55603 + 2e3a38e commit b378dbd

33 files changed

+1134
-64
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## v0.5.0 - [2023/09/01]
4+
5+
- Added ProccessIsolation implementation
6+
- Added Upstream class
7+
- Added phpstan
8+
- Updated RouteAction and RouteMatch. Added toArray methods
9+
- Updated Config class
10+
- Updated Unit class
11+
312
## v0.4.0 - [2023/08/02]
413

514
- Added more Applications, Requests and Connection Statistics classes

README.md

+47-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
# PHP SDK for Nginx Unit
21

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/Pavlusha311245/unit-php-sdk?labelColor=%231e293b&color=%23702963&link=https%3A%2F%2Fpackagist.org%2Fpackages%2Fpavlusha311245%2Funit-php-sdk)](https://packagist.org/packages/pavlusha311245/unit-php-sdk)
4-
[![Documentation](https://img.shields.io/website?url=https%3A%2F%2Funit-sdk.pavlusha.me%2F&label=documentation&link=https%3A%2F%2Funit-sdk.pavlusha.me%2F)](https://unit-sdk.pavlusha.me/)
2+
<p align="center">
3+
<img style="text-aligh: center" src="https://15804523-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F77F3kdmGsRkZFelMUJq1%2Ficon%2FnsTZCyEjC1z8LJWkzLro%2F%D1%8B.svg?alt=media&token=ce321f03-8fdf-4c4d-aaef-888183f713f6" width="200" alt="Company logo">
4+
</p>
55

6-
_THIS PROJECT IN DEVELOPMENT. DON'T USE IT IN PRODUCTION_
6+
<p align="center">
7+
<b style="font-size: 2rem">PHP SDK for Nginx Unit</b>
8+
</p>
9+
10+
<p align="center">
11+
<a href="https://packagist.org/packages/pavlusha311245/unit-php-sdk"><img src="https://img.shields.io/packagist/v/Pavlusha311245/unit-php-sdk?labelColor=%231e293b&color=%23702963&link=https%3A%2F%2Fpackagist.org%2Fpackages%2Fpavlusha311245%2Funit-php-sdk"></a>
12+
<a href="https://unit-sdk.pavlusha.me/"><img src="https://img.shields.io/website?url=https%3A%2F%2Funit-sdk.pavlusha.me%2F&label=documentation&link=https%3A%2F%2Funit-sdk.pavlusha.me%2F"></a>
13+
</p>
14+
15+
## About
16+
17+
SDK allows developers to interact with the Nginx Unit web server through php classes. This project will help embed web server management into your projects
718

819
## Supported Versions
920

10-
| Version | Supported |
11-
|---------|--------------------|
12-
| 0.4.x | :white_check_mark: |
13-
| < 0.3.x | :x: |
21+
| Version | Nginx Unit Capability | Supported |
22+
|---------|:----------------------|--------------------|
23+
| 0.5.x | 1.30.0 | :white_check_mark: |
24+
| < 0.4.x | 1.30.0 | :x: |
25+
26+
_THIS PROJECT IN DEVELOPMENT. DON'T USE IT IN PRODUCTION_
1427

1528
## Quick start
1629

@@ -24,13 +37,35 @@ _THIS PROJECT IN DEVELOPMENT. DON'T USE IT IN PRODUCTION_
2437
### Installation
2538

2639
1. Create folder `mkdir example-php-project`
27-
2. Open folder cd `example-php-project`
28-
3. Init composer `composer init`
29-
4. Add package `composer require pavlusha311245/unit-php-sdk`
40+
2. Open folder `cd example-php-project`
41+
3. Crate composer.json file. Example below:
42+
```shell
43+
{
44+
"name": "pavlusha311245/example-php-project",
45+
"require": {
46+
"pavlusha311245/unit-php-sdk": "0.5.0"
47+
},
48+
"autoload": {
49+
"psr-4": {
50+
"Pavlusha\\ExamplePhpProject\\": "src/"
51+
}
52+
},
53+
"authors": [
54+
{
55+
"name": "Paul Zavadski",
56+
"email": "[email protected]"
57+
}
58+
]
59+
}
60+
```
61+
4. Install packages `composer install`
3062

3163
Congratulations! You installed package. Now you can use the full power of this SDK.
3264

33-
* Create `index.php` file
65+
* Create `src/index.php` file
66+
1. `cd src` (`mkdir src` if doesn't exist)
67+
2. `touch src/index.php`
68+
3. `nano src/index.php`
3469
* Paste code and change this line `socket: <your socket path to Nginx Unit>` for your configuration
3570

3671
```php

SECURITY.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
## Security Policy
22

3+
## Versioning
4+
We use SemVer for versioning. For the versions available, see the tags on this repository.
5+
36
## Supported Versions
47

58
| Version | Nginx Unit Capability | Supported |
69
|---------|:----------------------|--------------------|
7-
| 0.4.x | 1.30.0 | :white_check_mark: |
8-
| < 0.3.x | 1.30.0 | :x: |
10+
| 0.5.x | 1.30.0 | :white_check_mark: |
11+
| < 0.4.x | 1.30.0 | :x: |
912

1013
## Vulnerability Report
1114

composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pavlusha311245/unit-php-sdk",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"type": "sdk",
55
"description": "This project allows developers to interact with the Nginx Unit web server through PHP classes",
66
"license": "Apache-2.0",
@@ -34,15 +34,19 @@
3434
"ext-curl": "*"
3535
},
3636
"require-dev": {
37-
"pestphp/pest": "^2.8"
37+
"pestphp/pest": "^2.8",
38+
"phpstan/phpstan": "^1.10"
3839
},
3940
"config": {
4041
"allow-plugins": {
4142
"pestphp/pest-plugin": true
4243
}
4344
},
4445
"scripts": {
45-
"test": "./vendor/bin/pest",
46+
"test": [
47+
"./vendor/bin/pest",
48+
"./vendor/bin/phpstan analyse -c phpstan.neon"
49+
],
4650
"lint": "./vendor/bin/php-cs-fixer fix --rules=@PSR12 ."
4751
}
4852
}

composer.lock

+63-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 1
3+
paths:
4+
- src

src/Abstract/ApplicationAbstract.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
namespace Pavlusha311245\UnitPhpSdk\Abstract;
44

5-
use Pavlusha311245\UnitPhpSdk\Config\Application\ProcessManagement\ApplicationProcess;
6-
use Pavlusha311245\UnitPhpSdk\Config\Application\ProcessManagement\ProcessIsolation;
7-
use Pavlusha311245\UnitPhpSdk\Config\Application\ProcessManagement\RequestLimit;
5+
use Pavlusha311245\UnitPhpSdk\Config\Application\{
6+
ProcessManagement\ApplicationProcess,
7+
ProcessManagement\ProcessIsolation,
8+
ProcessManagement\RequestLimit
9+
};
810
use Pavlusha311245\UnitPhpSdk\Exceptions\UnitException;
9-
use Pavlusha311245\UnitPhpSdk\Interfaces\ApplicationControlInterface;
10-
use Pavlusha311245\UnitPhpSdk\Interfaces\ApplicationInterface;
11+
use Pavlusha311245\UnitPhpSdk\Interfaces\{ApplicationControlInterface, ApplicationInterface};
1112
use Pavlusha311245\UnitPhpSdk\Traits\HasListeners;
1213
use Pavlusha311245\UnitPhpSdk\UnitRequest;
1314

1415
abstract class ApplicationAbstract implements ApplicationInterface, ApplicationControlInterface
1516
{
1617
use HasListeners;
1718

19+
/**
20+
* @var string
21+
*/
1822
private string $_type;
1923

24+
/**
25+
* @var UnitRequest
26+
*/
2027
private UnitRequest $_unitRequest;
2128

2229
/**
@@ -87,7 +94,7 @@ abstract class ApplicationAbstract implements ApplicationInterface, ApplicationC
8794
/**
8895
* @throws UnitException
8996
*/
90-
public function __construct(array $data = null)
97+
public function __construct($data = null)
9198
{
9299
if (!empty($data)) {
93100
$this->parseFromArray($data);
@@ -264,10 +271,9 @@ public function parseFromArray(array $data): void
264271
$this->setStdOut($data['stdout']);
265272
}
266273

267-
// TODO: implement isolation object
268-
// if (array_key_exists('isolation', $data)) {
269-
// $this->setIsolation($data['isolation']);
270-
// }
274+
if (array_key_exists('isolation', $data)) {
275+
$this->setIsolation(new ProcessIsolation($data['isolation']));
276+
}
271277

272278
if (array_key_exists('processes', $data)) {
273279
if (is_array($data['processes'])) {

src/Abstract/IdmapAbstract.php

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace Pavlusha311245\UnitPhpSdk\Abstract;
4+
5+
class IdmapAbstract
6+
{
7+
/**
8+
* @var int
9+
*/
10+
private int $_container;
11+
12+
/**
13+
* @var int
14+
*/
15+
private int $_host;
16+
17+
/**
18+
* @var int
19+
*/
20+
private int $_size;
21+
22+
public function __construct(array $data)
23+
{
24+
$this->parseFromArray($data);
25+
}
26+
27+
/**
28+
* Return container
29+
*
30+
* @return int
31+
*/
32+
public function getContainer(): int
33+
{
34+
return $this->_container;
35+
}
36+
37+
/**
38+
* Return host
39+
*
40+
* @return int
41+
*/
42+
public function getHost(): int
43+
{
44+
return $this->_host;
45+
}
46+
47+
/**
48+
* Return size
49+
*
50+
* @return int
51+
*/
52+
public function getSize(): int
53+
{
54+
return $this->_size;
55+
}
56+
57+
/**
58+
* @param int $container
59+
*/
60+
public function setContainer(int $container): void
61+
{
62+
$this->_container = $container;
63+
}
64+
65+
/**
66+
* @param int $size
67+
*/
68+
public function setSize(int $size): void
69+
{
70+
$this->_size = $size;
71+
}
72+
73+
/**
74+
* @param int $host
75+
*/
76+
public function setHost(int $host): void
77+
{
78+
$this->_host = $host;
79+
}
80+
81+
public function parseFromArray(array $data): void
82+
{
83+
if (array_key_exists('container', $data)) {
84+
$this->setContainer($data['container']);
85+
}
86+
87+
if (array_key_exists('host', $data)) {
88+
$this->setHost($data['host']);
89+
}
90+
91+
if (array_key_exists('size', $data)) {
92+
$this->setSize($data['size']);
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)