diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
new file mode 100644
index 00000000..c7d0eb78
--- /dev/null
+++ b/.github/copilot-instructions.md
@@ -0,0 +1,32 @@
+# Everywhere within this repository:
+* **Always** use `null|` in favor of `?` for nullable types (e.g. `?string` instead of `string|null`).
+* **Always** use variadic parameters instead of `array` for lists of items (e.g. `string ...$items` instead
+ of `array $items`).
+* **Always** use `self` instead of the class name in method signatures (e.g.
+ `public function setFoo(string $foo): self` instead of `public function setFoo(string $foo): MyClass`).
+* **Always** always match casing of class properties when defining parameters and methods (e.g.
+ `public function setFooBar(string $FooBar)` if the class property is `$FooBar`).
+* **Always** define a phpdoc for `array` types that specifies the item type (e.g.
+ `/** @param string[] $items */` for `array $items`).
+* **Never** edit files using sed, awk, or other shell utilities.
+* **Always** limit yourself to POSIX shell syntax when executing shell scripts.
+* **Always** run phpstan with 512MB of memory when analyzing generated code
+ (e.g. `phpstan analyze -c phpstan.neon --memory-limit=512M src/`).
+* **Always** specify `: void` for methods that do not return a value (e.g. `public function setFoo(string $foo): void`).
+ * This includes unit test methods (e.g. `public function testFoo(): void`).
+* **Always** use `declare(strict_types=1);` at the top of all PHP files.
+ * Do not do this in PHPUnit test class files, as PHPUnit does not support strict types.
+* **Always** ensure that constructor parameters for enum fields also accept the enum value type
+ (e.g. `public function __construct(string $foo, string|MyEnum $bar)`).
+ * Write tests for both cases.
+* **Never** leave imports unused in generated code.
+* **Always** used named parameters wherever possible.
+* **Never** bother with docblocks unless they are necessary to specify types that cannot be expressed in code
+ (e.g. `/** @param string[] $items */` for `array $items`).
+
+# When generting code for concrete implementations of AbstractType:
+* **Always** ensure that class fields have an associated getter and setter method.
+* **Always** ensure the constructor has parameters for all class fields, and that the constructor parameters are
+ assigned to the class fields.
+* **Always** write unit tests that use both the constructor and the setter methods to set class fields,
+ and that use the getter methods and fields directly to verify that the fields were set correctly.
\ No newline at end of file
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index 8ed1b16e..44dbb4f6 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -1,5 +1,21 @@
name: "Tests"
+permissions:
+ actions: none
+ attestations: none
+ checks: none
+ contents: read
+ deployments: none
+ id-token: none
+ issues: none
+ models: none
+ discussions: none
+ packages: none
+ pages: none
+ pull-requests: none
+ security-events: none
+ statuses: none
+
on:
pull_request:
branches:
@@ -22,7 +38,7 @@ on:
env:
CONSUL_HTTP_ADDR: "127.0.0.1:8500"
- CONSUL_VERSION: '1.20.5'
+ CONSUL_VERSION: '1.22.2'
jobs:
tests:
@@ -34,6 +50,7 @@ jobs:
- '8.2'
- '8.3'
- '8.4'
+ - '8.5'
name: Tests - PHP ${{ matrix.php-version }}
steps:
@@ -48,8 +65,9 @@ jobs:
case "${{ matrix.php-version }}" in
8.1) _phpunit_version='10.5' ;;
8.2) _phpunit_version='11.1' ;;
- 8.3) _phpunit_version='11.1' ;;
- 8.4) _phpunit_version='11.1' ;;
+ 8.3) _phpunit_version='12.0' ;;
+ 8.4) _phpunit_version='12.0' ;;
+ 8.5) _phpunit_version='12.0' ;;
*) echo "Unsupported PHP version: ${{ matrix.php-version }}" && exit 1 ;;
esac
echo "phpunit-version=${_phpunit_version}" >> $GITHUB_OUTPUT
@@ -59,6 +77,7 @@ jobs:
php-version: ${{ matrix.php-version }}
extensions: json
ini-values: precision=14,serialize_precision=-1
+ ini-file: 'development'
- name: 'Install jq'
uses: dcarbone/install-jq-action@v3
diff --git a/README.md b/README.md
index 41bc3880..e815ef66 100644
--- a/README.md
+++ b/README.md
@@ -14,11 +14,27 @@ This library is loosely based upon the [official GO client](https://github.com/h
| 0.6.x | 0.7-0.8 |
| v1.x | 0.9-current |
| v2.x | 0.9-current |
+| v3.x | 0.9-current |
| dev-main | current |
Newer versions of the api lib will probably work in a limited capacity with older versions of Consul, but no guarantee
is made and backwards compatibility issues will not be addressed.
+### V3 Breaking Changes
+
+There are a couple breaking changes between v2 and v3:
+
+1. The `FakeMap` class has been removed.
+2. The `FakeSlice` class has been removed.
+3. The `ReadableDuration` class has been removed.
+4. All models now have parameterized constructors.
+ * For the life of V3 I will continue to support construction from associative arrays, but the parameterized
+ constructors are the preferred method of construction.
+ * Construction via associative array will be removed entirely in V4 (whenever I get around to that).
+5. All of that `Transcoding` nonsense has been removed.
+6. The root `Config` class may no longer be constructed with a map. You must use constructor parameters.
+7. All "map" fields are now defined as `\stdClass` objects.
+
## Composer
This lib is designed to be used with [Composer](https://getcomposer.org)
@@ -28,7 +44,7 @@ Require Entry:
```json
{
"require": {
- "dcarbone/php-consul-api": "^v2.0"
+ "dcarbone/php-consul-api": "^v3.0"
}
}
```
@@ -53,22 +69,28 @@ $config = \DCarbone\PHPConsulAPI\Config::newDefaultConfig();
You may alternatively define values yourself:
```php
-$config = new \DCarbone\PHPConsulAPI\Config([
- 'HttpClient' => $client, // [required] Client conforming to GuzzleHttp\ClientInterface
- 'Address' => 'address of server', // [required]
-
- 'Scheme' => 'http or https', // [optional] defaults to "http"
- 'Datacenter' => 'name of datacenter', // [optional]
- 'HttpAuth' => 'user:pass', // [optional]
- 'WaitTime' => '0s', // [optional] amount of time to wait on certain blockable endpoints. go time duration string format.
- 'Token' => 'auth token', // [optional] default auth token to use
- 'TokenFile' => 'file with auth token', // [optional] file containing auth token string
- 'InsecureSkipVerify' => false, // [optional] if set to true, ignores all SSL validation
- 'CAFile' => '', // [optional] path to ca cert file, see http://docs.guzzlephp.org/en/latest/request-options.html#verify
- 'CertFile' => '', // [optional] path to client public key. if set, requires KeyFile also be set
- 'KeyFile' => '', // [optional] path to client private key. if set, requires CertFile also be set
- 'JSONEncodeOpts'=> 0, // [optional] php json encode opt value to use when serializing requests
-]);
+$config = new \DCarbone\PHPConsulAPI\Config(
+ // required fields
+ HttpClient: $client, // [required] Client conforming to GuzzleHttp\ClientInterface
+ Address: 'address of server', // [required]
+
+ // optional fields
+ Scheme: 'http or https', // [optional] defaults to "http"
+ Datacenter: 'name of datacenter', // [optional]
+ HttpAuth: 'user:pass', // [optional]
+ WaitTime: '0s', // [optional] amount of time to wait on certain blockable endpoints. go time duration string format.
+ Token: 'auth token', // [optional] default auth token to use
+ TokenFile: 'file with auth token', // [optional] file containing auth token string
+ InsecureSkipVerify: false, // [optional] if set to true, ignores all SSL validation
+ CAFile: '', // [optional] path to ca cert file, see http://docs.guzzlephp.org/en/latest/request-options.html#verify
+ CertFile: '', // [optional] path to client public key. if set, requires KeyFile also be set
+ KeyFile: '', // [optional] path to client private key. if set, requires CertFile also be set
+
+ // php specific options
+ JSONEncodeOpts: JSON_UNESCAPED_SLASHES,
+ JSONDecodeMaxDepth: 512,
+ JSONDecodeOpts: 0,
+);
```
#### Configuration Note:
@@ -83,11 +105,11 @@ prior to constructing a PHPConsulAPI Config object.
As an example:
```php
-$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']]);
-$config = new \DCarbone\PHPConsulAPI\Config([
- 'HttpClient' => $proxyClient,
- 'Address' => 'address of server',
-]);
+$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']);
+$config = new \DCarbone\PHPConsulAPI\Config(
+ HttpClient: $proxyClient,
+ Address: 'address of server',
+);
```
When constructing your client, if you are using the `GuzzleHttp\Client` object directly or derivative thereof, you may
diff --git a/composer.json b/composer.json
index abff10c1..ba45d280 100644
--- a/composer.json
+++ b/composer.json
@@ -25,19 +25,18 @@
},
"autoload": {
"files": [
- "src/Coordinate/funcs.php",
- "src/funcs.php"
+ "src/PHPLib/funcs.php"
],
"psr-4": {
"DCarbone\\PHPConsulAPI\\": "src/"
}
},
"require-dev": {
- "phpunit/phpunit": "^10.5 || ^11.0"
+ "phpunit/phpunit": "^10.5 || ^11.0 || ^13.0",
+ "phpstan/phpstan": "~2.1.11"
},
"autoload-dev": {
"files": [
- "src/Coordinate/funcs.php",
"tests/funcs.php"
],
"psr-4": {
diff --git a/composer.lock b/composer.lock
index c2e968d1..dbea1932 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "01cc136766bba4c1a8f16d214945f536",
+ "content-hash": "86e172995bb9ccdc446f6a028d8ea25a",
"packages": [
{
"name": "dcarbone/gohttp",
@@ -638,16 +638,16 @@
},
{
"name": "symfony/deprecation-contracts",
- "version": "v3.5.1",
+ "version": "v3.6.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
- "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
+ "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
- "reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
+ "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
+ "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
"shasum": ""
},
"require": {
@@ -660,7 +660,7 @@
"name": "symfony/contracts"
},
"branch-alias": {
- "dev-main": "3.5-dev"
+ "dev-main": "3.6-dev"
}
},
"autoload": {
@@ -685,7 +685,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
+ "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
},
"funding": [
{
@@ -701,22 +701,22 @@
"type": "tidelift"
}
],
- "time": "2024-09-25T14:20:29+00:00"
+ "time": "2024-09-25T14:21:43+00:00"
}
],
"packages-dev": [
{
"name": "myclabs/deep-copy",
- "version": "1.13.0",
+ "version": "1.13.1",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "024473a478be9df5fdaca2c793f2232fe788e414"
+ "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/024473a478be9df5fdaca2c793f2232fe788e414",
- "reference": "024473a478be9df5fdaca2c793f2232fe788e414",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/1720ddd719e16cf0db4eb1c6eca108031636d46c",
+ "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c",
"shasum": ""
},
"require": {
@@ -755,7 +755,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.13.0"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.13.1"
},
"funding": [
{
@@ -763,20 +763,20 @@
"type": "tidelift"
}
],
- "time": "2025-02-12T12:17:51+00:00"
+ "time": "2025-04-29T12:36:36+00:00"
},
{
"name": "nikic/php-parser",
- "version": "v5.4.0",
+ "version": "v5.5.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "447a020a1f875a434d62f2a401f53b82a396e494"
+ "reference": "ae59794362fe85e051a58ad36b289443f57be7a9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494",
- "reference": "447a020a1f875a434d62f2a401f53b82a396e494",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ae59794362fe85e051a58ad36b289443f57be7a9",
+ "reference": "ae59794362fe85e051a58ad36b289443f57be7a9",
"shasum": ""
},
"require": {
@@ -819,9 +819,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v5.5.0"
},
- "time": "2024-12-30T11:07:19+00:00"
+ "time": "2025-05-31T08:24:38+00:00"
},
{
"name": "phar-io/manifest",
@@ -941,37 +941,95 @@
},
"time": "2022-02-21T01:04:05+00:00"
},
+ {
+ "name": "phpstan/phpstan",
+ "version": "2.1.17",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/phpstan/phpstan.git",
+ "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89b5ef665716fa2a52ecd2633f21007a6a349053",
+ "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.4|^8.0"
+ },
+ "conflict": {
+ "phpstan/phpstan-shim": "*"
+ },
+ "bin": [
+ "phpstan",
+ "phpstan.phar"
+ ],
+ "type": "library",
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "description": "PHPStan - PHP Static Analysis Tool",
+ "keywords": [
+ "dev",
+ "static analysis"
+ ],
+ "support": {
+ "docs": "https://phpstan.org/user-guide/getting-started",
+ "forum": "https://github.com/phpstan/phpstan/discussions",
+ "issues": "https://github.com/phpstan/phpstan/issues",
+ "security": "https://github.com/phpstan/phpstan/security/policy",
+ "source": "https://github.com/phpstan/phpstan-src"
+ },
+ "funding": [
+ {
+ "url": "https://github.com/ondrejmirtes",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/phpstan",
+ "type": "github"
+ }
+ ],
+ "time": "2025-05-21T20:55:28+00:00"
+ },
{
"name": "phpunit/php-code-coverage",
- "version": "11.0.9",
+ "version": "10.1.16",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "14d63fbcca18457e49c6f8bebaa91a87e8e188d7"
+ "reference": "7e308268858ed6baedc8704a304727d20bc07c77"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/14d63fbcca18457e49c6f8bebaa91a87e8e188d7",
- "reference": "14d63fbcca18457e49c6f8bebaa91a87e8e188d7",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7e308268858ed6baedc8704a304727d20bc07c77",
+ "reference": "7e308268858ed6baedc8704a304727d20bc07c77",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
- "nikic/php-parser": "^5.4.0",
- "php": ">=8.2",
- "phpunit/php-file-iterator": "^5.1.0",
- "phpunit/php-text-template": "^4.0.1",
- "sebastian/code-unit-reverse-lookup": "^4.0.1",
- "sebastian/complexity": "^4.0.1",
- "sebastian/environment": "^7.2.0",
- "sebastian/lines-of-code": "^3.0.1",
- "sebastian/version": "^5.0.2",
+ "nikic/php-parser": "^4.19.1 || ^5.1.0",
+ "php": ">=8.1",
+ "phpunit/php-file-iterator": "^4.1.0",
+ "phpunit/php-text-template": "^3.0.1",
+ "sebastian/code-unit-reverse-lookup": "^3.0.0",
+ "sebastian/complexity": "^3.2.0",
+ "sebastian/environment": "^6.1.0",
+ "sebastian/lines-of-code": "^2.0.2",
+ "sebastian/version": "^4.0.1",
"theseer/tokenizer": "^1.2.3"
},
"require-dev": {
- "phpunit/phpunit": "^11.5.2"
+ "phpunit/phpunit": "^10.1"
},
"suggest": {
"ext-pcov": "PHP extension that provides line coverage",
@@ -980,7 +1038,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "11.0.x-dev"
+ "dev-main": "10.1.x-dev"
}
},
"autoload": {
@@ -1009,7 +1067,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.9"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.16"
},
"funding": [
{
@@ -1017,32 +1075,32 @@
"type": "github"
}
],
- "time": "2025-02-25T13:26:39+00:00"
+ "time": "2024-08-22T04:31:57+00:00"
},
{
"name": "phpunit/php-file-iterator",
- "version": "5.1.0",
+ "version": "4.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
- "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6"
+ "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6",
- "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c",
+ "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "5.0-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -1070,7 +1128,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
- "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0"
+ "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0"
},
"funding": [
{
@@ -1078,28 +1136,28 @@
"type": "github"
}
],
- "time": "2024-08-27T05:02:59+00:00"
+ "time": "2023-08-31T06:24:48+00:00"
},
{
"name": "phpunit/php-invoker",
- "version": "5.0.1",
+ "version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-invoker.git",
- "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2"
+ "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2",
- "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7",
+ "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
"ext-pcntl": "*",
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"suggest": {
"ext-pcntl": "*"
@@ -1107,7 +1165,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "5.0-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -1133,8 +1191,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-invoker/issues",
- "security": "https://github.com/sebastianbergmann/php-invoker/security/policy",
- "source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.1"
+ "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0"
},
"funding": [
{
@@ -1142,32 +1199,32 @@
"type": "github"
}
],
- "time": "2024-07-03T05:07:44+00:00"
+ "time": "2023-02-03T06:56:09+00:00"
},
{
"name": "phpunit/php-text-template",
- "version": "4.0.1",
+ "version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
- "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964"
+ "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964",
- "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748",
+ "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "4.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -1194,7 +1251,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-text-template/issues",
"security": "https://github.com/sebastianbergmann/php-text-template/security/policy",
- "source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.1"
+ "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1"
},
"funding": [
{
@@ -1202,32 +1259,32 @@
"type": "github"
}
],
- "time": "2024-07-03T05:08:43+00:00"
+ "time": "2023-08-31T14:07:24+00:00"
},
{
"name": "phpunit/php-timer",
- "version": "7.0.1",
+ "version": "6.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
- "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3"
+ "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3",
- "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d",
+ "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "7.0-dev"
+ "dev-main": "6.0-dev"
}
},
"autoload": {
@@ -1253,8 +1310,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-timer/issues",
- "security": "https://github.com/sebastianbergmann/php-timer/security/policy",
- "source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.1"
+ "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0"
},
"funding": [
{
@@ -1262,20 +1318,20 @@
"type": "github"
}
],
- "time": "2024-07-03T05:09:35+00:00"
+ "time": "2023-02-03T06:57:52+00:00"
},
{
"name": "phpunit/phpunit",
- "version": "11.5.15",
+ "version": "10.5.47",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c"
+ "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c",
- "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3",
+ "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3",
"shasum": ""
},
"require": {
@@ -1285,26 +1341,26 @@
"ext-mbstring": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
- "myclabs/deep-copy": "^1.13.0",
+ "myclabs/deep-copy": "^1.13.1",
"phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1",
- "php": ">=8.2",
- "phpunit/php-code-coverage": "^11.0.9",
- "phpunit/php-file-iterator": "^5.1.0",
- "phpunit/php-invoker": "^5.0.1",
- "phpunit/php-text-template": "^4.0.1",
- "phpunit/php-timer": "^7.0.1",
- "sebastian/cli-parser": "^3.0.2",
- "sebastian/code-unit": "^3.0.3",
- "sebastian/comparator": "^6.3.1",
- "sebastian/diff": "^6.0.2",
- "sebastian/environment": "^7.2.0",
- "sebastian/exporter": "^6.3.0",
- "sebastian/global-state": "^7.0.2",
- "sebastian/object-enumerator": "^6.0.1",
- "sebastian/type": "^5.1.2",
- "sebastian/version": "^5.0.2",
- "staabm/side-effects-detector": "^1.0.5"
+ "php": ">=8.1",
+ "phpunit/php-code-coverage": "^10.1.16",
+ "phpunit/php-file-iterator": "^4.1.0",
+ "phpunit/php-invoker": "^4.0.0",
+ "phpunit/php-text-template": "^3.0.1",
+ "phpunit/php-timer": "^6.0.0",
+ "sebastian/cli-parser": "^2.0.1",
+ "sebastian/code-unit": "^2.0.0",
+ "sebastian/comparator": "^5.0.3",
+ "sebastian/diff": "^5.1.1",
+ "sebastian/environment": "^6.1.0",
+ "sebastian/exporter": "^5.1.2",
+ "sebastian/global-state": "^6.0.2",
+ "sebastian/object-enumerator": "^5.0.0",
+ "sebastian/recursion-context": "^5.0.0",
+ "sebastian/type": "^4.0.0",
+ "sebastian/version": "^4.0.1"
},
"suggest": {
"ext-soap": "To be able to generate mocks based on WSDL files"
@@ -1315,7 +1371,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "11.5-dev"
+ "dev-main": "10.5-dev"
}
},
"autoload": {
@@ -1347,7 +1403,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.15"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.47"
},
"funding": [
{
@@ -1358,37 +1414,45 @@
"url": "https://github.com/sebastianbergmann",
"type": "github"
},
+ {
+ "url": "https://liberapay.com/sebastianbergmann",
+ "type": "liberapay"
+ },
+ {
+ "url": "https://thanks.dev/u/gh/sebastianbergmann",
+ "type": "thanks_dev"
+ },
{
"url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit",
"type": "tidelift"
}
],
- "time": "2025-03-23T16:02:11+00:00"
+ "time": "2025-06-20T11:29:11+00:00"
},
{
"name": "sebastian/cli-parser",
- "version": "3.0.2",
+ "version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/cli-parser.git",
- "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180"
+ "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180",
- "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180",
+ "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/c34583b87e7b7a8055bf6c450c2c77ce32a24084",
+ "reference": "c34583b87e7b7a8055bf6c450c2c77ce32a24084",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "3.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1412,7 +1476,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/cli-parser/issues",
"security": "https://github.com/sebastianbergmann/cli-parser/security/policy",
- "source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.2"
+ "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.1"
},
"funding": [
{
@@ -1420,32 +1484,32 @@
"type": "github"
}
],
- "time": "2024-07-03T04:41:36+00:00"
+ "time": "2024-03-02T07:12:49+00:00"
},
{
"name": "sebastian/code-unit",
- "version": "3.0.3",
+ "version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit.git",
- "reference": "54391c61e4af8078e5b276ab082b6d3c54c9ad64"
+ "reference": "a81fee9eef0b7a76af11d121767abc44c104e503"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/54391c61e4af8078e5b276ab082b6d3c54c9ad64",
- "reference": "54391c61e4af8078e5b276ab082b6d3c54c9ad64",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503",
+ "reference": "a81fee9eef0b7a76af11d121767abc44c104e503",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.5"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "3.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1468,8 +1532,7 @@
"homepage": "https://github.com/sebastianbergmann/code-unit",
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit/issues",
- "security": "https://github.com/sebastianbergmann/code-unit/security/policy",
- "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.3"
+ "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0"
},
"funding": [
{
@@ -1477,32 +1540,32 @@
"type": "github"
}
],
- "time": "2025-03-19T07:56:08+00:00"
+ "time": "2023-02-03T06:58:43+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
- "version": "4.0.1",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
- "reference": "183a9b2632194febd219bb9246eee421dad8d45e"
+ "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e",
- "reference": "183a9b2632194febd219bb9246eee421dad8d45e",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d",
+ "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "4.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -1524,8 +1587,7 @@
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
"support": {
"issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues",
- "security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy",
- "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.1"
+ "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0"
},
"funding": [
{
@@ -1533,39 +1595,36 @@
"type": "github"
}
],
- "time": "2024-07-03T04:45:54+00:00"
+ "time": "2023-02-03T06:59:15+00:00"
},
{
"name": "sebastian/comparator",
- "version": "6.3.1",
+ "version": "5.0.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
- "reference": "24b8fbc2c8e201bb1308e7b05148d6ab393b6959"
+ "reference": "a18251eb0b7a2dcd2f7aa3d6078b18545ef0558e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/24b8fbc2c8e201bb1308e7b05148d6ab393b6959",
- "reference": "24b8fbc2c8e201bb1308e7b05148d6ab393b6959",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/a18251eb0b7a2dcd2f7aa3d6078b18545ef0558e",
+ "reference": "a18251eb0b7a2dcd2f7aa3d6078b18545ef0558e",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-mbstring": "*",
- "php": ">=8.2",
- "sebastian/diff": "^6.0",
- "sebastian/exporter": "^6.0"
+ "php": ">=8.1",
+ "sebastian/diff": "^5.0",
+ "sebastian/exporter": "^5.0"
},
"require-dev": {
- "phpunit/phpunit": "^11.4"
- },
- "suggest": {
- "ext-bcmath": "For comparing BcMath\\Number objects"
+ "phpunit/phpunit": "^10.5"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "6.3-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -1605,7 +1664,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/comparator/issues",
"security": "https://github.com/sebastianbergmann/comparator/security/policy",
- "source": "https://github.com/sebastianbergmann/comparator/tree/6.3.1"
+ "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.3"
},
"funding": [
{
@@ -1613,33 +1672,33 @@
"type": "github"
}
],
- "time": "2025-03-07T06:57:01+00:00"
+ "time": "2024-10-18T14:56:07+00:00"
},
{
"name": "sebastian/complexity",
- "version": "4.0.1",
+ "version": "3.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/complexity.git",
- "reference": "ee41d384ab1906c68852636b6de493846e13e5a0"
+ "reference": "68ff824baeae169ec9f2137158ee529584553799"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0",
- "reference": "ee41d384ab1906c68852636b6de493846e13e5a0",
+ "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68ff824baeae169ec9f2137158ee529584553799",
+ "reference": "68ff824baeae169ec9f2137158ee529584553799",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^5.0",
- "php": ">=8.2"
+ "nikic/php-parser": "^4.18 || ^5.0",
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "4.0-dev"
+ "dev-main": "3.2-dev"
}
},
"autoload": {
@@ -1663,7 +1722,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/complexity/issues",
"security": "https://github.com/sebastianbergmann/complexity/security/policy",
- "source": "https://github.com/sebastianbergmann/complexity/tree/4.0.1"
+ "source": "https://github.com/sebastianbergmann/complexity/tree/3.2.0"
},
"funding": [
{
@@ -1671,33 +1730,33 @@
"type": "github"
}
],
- "time": "2024-07-03T04:49:50+00:00"
+ "time": "2023-12-21T08:37:17+00:00"
},
{
"name": "sebastian/diff",
- "version": "6.0.2",
+ "version": "5.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
- "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544"
+ "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544",
- "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544",
+ "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/c41e007b4b62af48218231d6c2275e4c9b975b2e",
+ "reference": "c41e007b4b62af48218231d6c2275e4c9b975b2e",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0",
- "symfony/process": "^4.2 || ^5"
+ "phpunit/phpunit": "^10.0",
+ "symfony/process": "^6.4"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "6.0-dev"
+ "dev-main": "5.1-dev"
}
},
"autoload": {
@@ -1730,7 +1789,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/diff/issues",
"security": "https://github.com/sebastianbergmann/diff/security/policy",
- "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2"
+ "source": "https://github.com/sebastianbergmann/diff/tree/5.1.1"
},
"funding": [
{
@@ -1738,27 +1797,27 @@
"type": "github"
}
],
- "time": "2024-07-03T04:53:05+00:00"
+ "time": "2024-03-02T07:15:17+00:00"
},
{
"name": "sebastian/environment",
- "version": "7.2.0",
+ "version": "6.1.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5"
+ "reference": "8074dbcd93529b357029f5cc5058fd3e43666984"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5",
- "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/8074dbcd93529b357029f5cc5058fd3e43666984",
+ "reference": "8074dbcd93529b357029f5cc5058fd3e43666984",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"suggest": {
"ext-posix": "*"
@@ -1766,7 +1825,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "7.2-dev"
+ "dev-main": "6.1-dev"
}
},
"autoload": {
@@ -1794,7 +1853,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/environment/issues",
"security": "https://github.com/sebastianbergmann/environment/security/policy",
- "source": "https://github.com/sebastianbergmann/environment/tree/7.2.0"
+ "source": "https://github.com/sebastianbergmann/environment/tree/6.1.0"
},
"funding": [
{
@@ -1802,34 +1861,34 @@
"type": "github"
}
],
- "time": "2024-07-03T04:54:44+00:00"
+ "time": "2024-03-23T08:47:14+00:00"
},
{
"name": "sebastian/exporter",
- "version": "6.3.0",
+ "version": "5.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3"
+ "reference": "955288482d97c19a372d3f31006ab3f37da47adf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/3473f61172093b2da7de1fb5782e1f24cc036dc3",
- "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/955288482d97c19a372d3f31006ab3f37da47adf",
+ "reference": "955288482d97c19a372d3f31006ab3f37da47adf",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
- "php": ">=8.2",
- "sebastian/recursion-context": "^6.0"
+ "php": ">=8.1",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
- "phpunit/phpunit": "^11.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "6.1-dev"
+ "dev-main": "5.1-dev"
}
},
"autoload": {
@@ -1872,7 +1931,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/exporter/issues",
"security": "https://github.com/sebastianbergmann/exporter/security/policy",
- "source": "https://github.com/sebastianbergmann/exporter/tree/6.3.0"
+ "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.2"
},
"funding": [
{
@@ -1880,35 +1939,35 @@
"type": "github"
}
],
- "time": "2024-12-05T09:17:50+00:00"
+ "time": "2024-03-02T07:17:12+00:00"
},
{
"name": "sebastian/global-state",
- "version": "7.0.2",
+ "version": "6.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
- "reference": "3be331570a721f9a4b5917f4209773de17f747d7"
+ "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7",
- "reference": "3be331570a721f9a4b5917f4209773de17f747d7",
+ "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/987bafff24ecc4c9ac418cab1145b96dd6e9cbd9",
+ "reference": "987bafff24ecc4c9ac418cab1145b96dd6e9cbd9",
"shasum": ""
},
"require": {
- "php": ">=8.2",
- "sebastian/object-reflector": "^4.0",
- "sebastian/recursion-context": "^6.0"
+ "php": ">=8.1",
+ "sebastian/object-reflector": "^3.0",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
"ext-dom": "*",
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "7.0-dev"
+ "dev-main": "6.0-dev"
}
},
"autoload": {
@@ -1934,7 +1993,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/global-state/issues",
"security": "https://github.com/sebastianbergmann/global-state/security/policy",
- "source": "https://github.com/sebastianbergmann/global-state/tree/7.0.2"
+ "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.2"
},
"funding": [
{
@@ -1942,33 +2001,33 @@
"type": "github"
}
],
- "time": "2024-07-03T04:57:36+00:00"
+ "time": "2024-03-02T07:19:19+00:00"
},
{
"name": "sebastian/lines-of-code",
- "version": "3.0.1",
+ "version": "2.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/lines-of-code.git",
- "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a"
+ "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a",
- "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a",
+ "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/856e7f6a75a84e339195d48c556f23be2ebf75d0",
+ "reference": "856e7f6a75a84e339195d48c556f23be2ebf75d0",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^5.0",
- "php": ">=8.2"
+ "nikic/php-parser": "^4.18 || ^5.0",
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "3.0-dev"
+ "dev-main": "2.0-dev"
}
},
"autoload": {
@@ -1992,7 +2051,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/lines-of-code/issues",
"security": "https://github.com/sebastianbergmann/lines-of-code/security/policy",
- "source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.1"
+ "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.2"
},
"funding": [
{
@@ -2000,34 +2059,34 @@
"type": "github"
}
],
- "time": "2024-07-03T04:58:38+00:00"
+ "time": "2023-12-21T08:38:20+00:00"
},
{
"name": "sebastian/object-enumerator",
- "version": "6.0.1",
+ "version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
- "reference": "f5b498e631a74204185071eb41f33f38d64608aa"
+ "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa",
- "reference": "f5b498e631a74204185071eb41f33f38d64608aa",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906",
+ "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906",
"shasum": ""
},
"require": {
- "php": ">=8.2",
- "sebastian/object-reflector": "^4.0",
- "sebastian/recursion-context": "^6.0"
+ "php": ">=8.1",
+ "sebastian/object-reflector": "^3.0",
+ "sebastian/recursion-context": "^5.0"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "6.0-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -2049,8 +2108,7 @@
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-enumerator/issues",
- "security": "https://github.com/sebastianbergmann/object-enumerator/security/policy",
- "source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.1"
+ "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0"
},
"funding": [
{
@@ -2058,32 +2116,32 @@
"type": "github"
}
],
- "time": "2024-07-03T05:00:13+00:00"
+ "time": "2023-02-03T07:08:32+00:00"
},
{
"name": "sebastian/object-reflector",
- "version": "4.0.1",
+ "version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-reflector.git",
- "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9"
+ "reference": "24ed13d98130f0e7122df55d06c5c4942a577957"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9",
- "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957",
+ "reference": "24ed13d98130f0e7122df55d06c5c4942a577957",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "4.0-dev"
+ "dev-main": "3.0-dev"
}
},
"autoload": {
@@ -2105,8 +2163,7 @@
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
"support": {
"issues": "https://github.com/sebastianbergmann/object-reflector/issues",
- "security": "https://github.com/sebastianbergmann/object-reflector/security/policy",
- "source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.1"
+ "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0"
},
"funding": [
{
@@ -2114,32 +2171,32 @@
"type": "github"
}
],
- "time": "2024-07-03T05:01:32+00:00"
+ "time": "2023-02-03T07:06:18+00:00"
},
{
"name": "sebastian/recursion-context",
- "version": "6.0.2",
+ "version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "694d156164372abbd149a4b85ccda2e4670c0e16"
+ "reference": "05909fb5bc7df4c52992396d0116aed689f93712"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/694d156164372abbd149a4b85ccda2e4670c0e16",
- "reference": "694d156164372abbd149a4b85ccda2e4670c0e16",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712",
+ "reference": "05909fb5bc7df4c52992396d0116aed689f93712",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.0"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "6.0-dev"
+ "dev-main": "5.0-dev"
}
},
"autoload": {
@@ -2169,8 +2226,7 @@
"homepage": "https://github.com/sebastianbergmann/recursion-context",
"support": {
"issues": "https://github.com/sebastianbergmann/recursion-context/issues",
- "security": "https://github.com/sebastianbergmann/recursion-context/security/policy",
- "source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.2"
+ "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0"
},
"funding": [
{
@@ -2178,32 +2234,32 @@
"type": "github"
}
],
- "time": "2024-07-03T05:10:34+00:00"
+ "time": "2023-02-03T07:05:40+00:00"
},
{
"name": "sebastian/type",
- "version": "5.1.2",
+ "version": "4.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
- "reference": "a8a7e30534b0eb0c77cd9d07e82de1a114389f5e"
+ "reference": "462699a16464c3944eefc02ebdd77882bd3925bf"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/a8a7e30534b0eb0c77cd9d07e82de1a114389f5e",
- "reference": "a8a7e30534b0eb0c77cd9d07e82de1a114389f5e",
+ "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf",
+ "reference": "462699a16464c3944eefc02ebdd77882bd3925bf",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"require-dev": {
- "phpunit/phpunit": "^11.3"
+ "phpunit/phpunit": "^10.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "5.1-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -2226,8 +2282,7 @@
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
- "security": "https://github.com/sebastianbergmann/type/security/policy",
- "source": "https://github.com/sebastianbergmann/type/tree/5.1.2"
+ "source": "https://github.com/sebastianbergmann/type/tree/4.0.0"
},
"funding": [
{
@@ -2235,29 +2290,29 @@
"type": "github"
}
],
- "time": "2025-03-18T13:35:50+00:00"
+ "time": "2023-02-03T07:10:45+00:00"
},
{
"name": "sebastian/version",
- "version": "5.0.2",
+ "version": "4.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
- "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874"
+ "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874",
- "reference": "c687e3387b99f5b03b6caa64c74b63e2936ff874",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17",
+ "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17",
"shasum": ""
},
"require": {
- "php": ">=8.2"
+ "php": ">=8.1"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "5.0-dev"
+ "dev-main": "4.0-dev"
}
},
"autoload": {
@@ -2280,8 +2335,7 @@
"homepage": "https://github.com/sebastianbergmann/version",
"support": {
"issues": "https://github.com/sebastianbergmann/version/issues",
- "security": "https://github.com/sebastianbergmann/version/security/policy",
- "source": "https://github.com/sebastianbergmann/version/tree/5.0.2"
+ "source": "https://github.com/sebastianbergmann/version/tree/4.0.1"
},
"funding": [
{
@@ -2289,59 +2343,7 @@
"type": "github"
}
],
- "time": "2024-10-09T05:16:32+00:00"
- },
- {
- "name": "staabm/side-effects-detector",
- "version": "1.0.5",
- "source": {
- "type": "git",
- "url": "https://github.com/staabm/side-effects-detector.git",
- "reference": "d8334211a140ce329c13726d4a715adbddd0a163"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163",
- "reference": "d8334211a140ce329c13726d4a715adbddd0a163",
- "shasum": ""
- },
- "require": {
- "ext-tokenizer": "*",
- "php": "^7.4 || ^8.0"
- },
- "require-dev": {
- "phpstan/extension-installer": "^1.4.3",
- "phpstan/phpstan": "^1.12.6",
- "phpunit/phpunit": "^9.6.21",
- "symfony/var-dumper": "^5.4.43",
- "tomasvotruba/type-coverage": "1.0.0",
- "tomasvotruba/unused-public": "1.0.0"
- },
- "type": "library",
- "autoload": {
- "classmap": [
- "lib/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "A static analysis tool to detect side effects in PHP code",
- "keywords": [
- "static analysis"
- ],
- "support": {
- "issues": "https://github.com/staabm/side-effects-detector/issues",
- "source": "https://github.com/staabm/side-effects-detector/tree/1.0.5"
- },
- "funding": [
- {
- "url": "https://github.com/staabm",
- "type": "github"
- }
- ],
- "time": "2024-10-20T05:08:20+00:00"
+ "time": "2023-02-07T11:34:05+00:00"
},
{
"name": "theseer/tokenizer",
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 00000000..50495918
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,6 @@
+parameters:
+ level: 6
+ paths:
+ - src
+ - tests
+ treatPhpDocTypesAsCertain: false
diff --git a/phpunit.xml b/phpunit.xml
index 0699e390..d324fb9b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -8,11 +8,15 @@
>
-
-
+
+
+
+ ./tests/Unit
+
+
./tests/Usage/ConfigUsageTest.php
@@ -20,9 +24,9 @@
./tests/Usage/RequestUsageTest.php
-
-
-
+
+ ./tests/Usage/ACL
+
./tests/Usage/Agent
diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php
index bb7d2d9d..95ba7e33 100644
--- a/src/ACL/ACLAuthMethod.php
+++ b/src/ACL/ACLAuthMethod.php
@@ -21,67 +21,56 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLAuthMethod extends AbstractModel
+class ACLAuthMethod extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_DISPLAY_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DESCRIPTION => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_MAX_TOKEN_TTL => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_MARSHAL_AS => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_TOKEN_LOCALITY => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE_RULES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLAuthMethodNamespaceRule::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_DISPLAY_NAME = 'DisplayName';
- private const FIELD_DESCRIPTION = 'Description';
- private const FIELD_MAX_TOKEN_TTL = 'MaxTokenTTL';
- private const FIELD_TOKEN_LOCALITY = 'TokenLocality';
- private const FIELD_NAMESPACE_RULES = 'NamespaceRules';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Name = '';
- public string $Type = '';
- public string $DisplayName = '';
- public string $Description = '';
+ public string $Name;
+ public string $Type;
+ public string $DisplayName;
+ public string $Description;
public Time\Duration $MaxTokenTTL;
- public string $TokenLocality = '';
- public array $config = [];
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public array $NamespaceRules = [];
- public string $Namespace = '';
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->MaxTokenTTL)) {
- $this->MaxTokenTTL = new Time\Duration();
- }
- }
-
- public function getID(): string
- {
- return $this->ID;
- }
-
- public function setID(string $ID): ACLAuthMethod
- {
- $this->ID = $ID;
- return $this;
- }
+ public string $TokenLocality;
+ /** @var array */
+ public array $Config;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule[] */
+ public array $NamespaceRules;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array $Config
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules
+ */
+ public function __construct(
+ string $Name = '',
+ string $Type = '',
+ string $DisplayName = '',
+ string $Description = '',
+ null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null,
+ string $TokenLocality = '',
+ array $Config = [],
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ array $NamespaceRules = [],
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->Name = $Name;
+ $this->Type = $Type;
+ $this->DisplayName = $DisplayName;
+ $this->Description = $Description;
+ $this->MaxTokenTTL = Time::Duration($MaxTokenTTL);
+ $this->TokenLocality = $TokenLocality;
+ $this->setConfig($Config);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->setNamespaceRules(...$NamespaceRules);
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+}
public function getName(): string
{
@@ -132,9 +121,9 @@ public function getMaxTokenTTL(): Time\Duration
return $this->MaxTokenTTL;
}
- public function setMaxTokenTTL(int|string|Time\Duration $MaxTokenTTL): self
+ public function setMaxTokenTTL(null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL): self
{
- $this->MaxTokenTTL = Time::ParseDuration($MaxTokenTTL);
+ $this->MaxTokenTTL = Time::Duration($MaxTokenTTL);
return $this;
}
@@ -149,14 +138,26 @@ public function setTokenLocality(string $TokenLocality): self
return $this;
}
+ /**
+ * @return array
+ */
public function getConfig(): array
{
- return $this->config;
+ return $this->Config;
}
- public function setConfig(array $config): self
+ /**
+ * @param null|\stdClass|array $Config
+ * @return $this
+ */
+ public function setConfig(null|\stdClass|array $Config): self
{
- $this->config = $config;
+ $this->Config = [];
+ if (null !== $Config) {
+ foreach ($Config as $k => $v) {
+ $this->Config[$k] = $v;
+ }
+ }
return $this;
}
@@ -182,14 +183,23 @@ public function setModifyIndex(int $ModifyIndex): self
return $this;
}
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule>
+ */
public function getNamespaceRules(): array
{
return $this->NamespaceRules;
}
- public function setNamespaceRules(array $NamespaceRules): self
+ public function addNamespaceRule(ACLAuthMethodNamespaceRule $rule): self
+ {
+ $this->NamespaceRules[] = $rule;
+ return $this;
+ }
+
+ public function setNamespaceRules(ACLAuthMethodNamespaceRule ...$rules): self
{
- $this->NamespaceRules = $NamespaceRules;
+ $this->NamespaceRules = $rules;
return $this;
}
@@ -203,4 +213,66 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('MaxTokenTTL' === $k) {
+ $n->setMaxTokenTTL($v);
+ } elseif ('NamespaceRules' === $k) {
+ $n->NamespaceRules = [];
+ foreach ($v as $vv) {
+ $n->NamespaceRules[] = ACLAuthMethodNamespaceRule::jsonUnserialize($vv);
+ }
+ } elseif ('Config' === $k) {
+ $n->setConfig($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ('' !== $this->DisplayName) {
+ $out->DisplayName = $this->DisplayName;
+ }
+ if ('' !== $this->Description) {
+ $out->Description = $this->Description;
+ }
+ if (0 !== $this->MaxTokenTTL->Nanoseconds()) {
+ $out->MaxTokenTTL = (string)$this->MaxTokenTTL;
+ }
+ if ('' !== $this->TokenLocality) {
+ $out->TokenLocality = $this->TokenLocality;
+ }
+ $out->Config = $this->Config;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ([] !== $this->NamespaceRules) {
+ $out->NamespaceRules = $this->NamespaceRules;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php
index 3a54d9f7..d0cc6670 100644
--- a/src/ACL/ACLAuthMethodListEntry.php
+++ b/src/ACL/ACLAuthMethodListEntry.php
@@ -21,43 +21,41 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLAuthMethodListEntry extends AbstractModel
+class ACLAuthMethodListEntry extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_DISPLAY_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DESCRIPTION => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_MAX_TOKEN_TTL => [
- Transcoding::FIELD_MARSHAL_AS => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- ],
- self::FIELD_TOKEN_LOCALITY => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_DISPLAY_NAME = 'DisplayName';
- private const FIELD_DESCRIPTION = 'Description';
- private const FIELD_MAX_TOKEN_TTL = 'MaxTokenTTL';
- private const FIELD_TOKEN_LOCALITY = 'TokenLocality';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Name = '';
- public string $Type = '';
- public string $DisplayName = '';
- public string $Description = '';
+ public string $Name;
+ public string $Type;
+ public string $DisplayName;
+ public string $Description;
public Time\Duration $MaxTokenTTL;
- /**
- * TokenLocality defines the kind of token that this auth method produces.
- * This can be either 'local' or 'global'. If empty 'local' is assumed.
- * @var string
- */
public string $TokenLocality;
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Namespace;
+
+ public function __construct(
+ string $Name = '',
+ string $Type = '',
+ string $DisplayName = '',
+ string $Description = '',
+ null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null,
+ string $TokenLocality = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Namespace = ''
+ ) {
+ $this->Name = $Name;
+ $this->Type = $Type;
+ $this->DisplayName = $DisplayName;
+ $this->Description = $Description;
+ $this->setMaxTokenTTL($MaxTokenTTL);
+ $this->TokenLocality = $TokenLocality;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+}
public function getName(): string
{
@@ -108,30 +106,17 @@ public function getMaxTokenTTL(): Time\Duration
return $this->MaxTokenTTL;
}
- public function setMaxTokenTTL(Time\Duration $MaxTokenTTL): self
+ public function setMaxTokenTTL(null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL): self
{
- $this->MaxTokenTTL = $MaxTokenTTL;
+ $this->MaxTokenTTL = Time::Duration($MaxTokenTTL);
return $this;
}
- /**
- * TokenLocality defines the kind of token that this auth method produces.
- * This can be either 'local' or 'global'. If empty 'local' is assumed.
- *
- * @return string
- */
public function getTokenLocality(): string
{
return $this->TokenLocality;
}
- /**
- * TokenLocality defines the kind of token that this auth method produces.
- * This can be either 'local' or 'global'. If empty 'local' is assumed.
- *
- * @param string $TokenLocality
- * @return \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry
- */
public function setTokenLocality(string $TokenLocality): self
{
$this->TokenLocality = $TokenLocality;
@@ -171,13 +156,40 @@ public function setNamespace(string $Namespace): self
return $this;
}
- public function jsonSerialize(): array
+ public static function jsonUnserialize(\stdClass $decoded): self
{
- $out = parent::jsonSerialize();
- if (!isset($this->MaxTokenTTL) || 0 === $this->MaxTokenTTL->Nanoseconds()) {
- $out[self::FIELD_MAX_TOKEN_TTL] = '';
- } else {
- $out[self::FIELD_MAX_TOKEN_TTL] = (string)$this->MaxTokenTTL;
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('MaxTokenTTL' === $k) {
+ $n->setMaxTokenTTL($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Type = $this->Type;
+ if ('' !== $this->DisplayName) {
+ $out->DisplayName = $this->DisplayName;
+ }
+ if ('' !== $this->Description) {
+ $out->Description = $this->Description;
+ }
+ if (0 !== $this->MaxTokenTTL->Nanoseconds()) {
+ $out->MaxTokenTTL = (string)$this->MaxTokenTTL;
+ }
+ if ('' !== $this->TokenLocality) {
+ $out->TokenLocality = $this->TokenLocality;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
}
return $out;
}
diff --git a/src/ACL/ACLAuthMethodListEntryQueryResponse.php b/src/ACL/ACLAuthMethodListEntryQueryResponse.php
index 7233b6c2..deb6902b 100644
--- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php
+++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php
@@ -20,23 +20,26 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ACLAuthMethodListEntries = [];
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry[] */
+ public array $ACLAuthMethodListEntries = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry[]
+ */
+ public function getValue(): array
{
return $this->ACLAuthMethodListEntries;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLAuthMethodListEntries = [];
- foreach ($decodedData as $datum) {
- $this->ACLAuthMethodListEntries[] = new ACLAuthMethodListEntry($datum);
+ foreach ($decoded as $datum) {
+ $this->ACLAuthMethodListEntries[] = ACLAuthMethodListEntry::jsonUnserialize($datum);
}
}
}
diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php
index c6b76694..e5172b98 100644
--- a/src/ACL/ACLAuthMethodNamespaceRule.php
+++ b/src/ACL/ACLAuthMethodNamespaceRule.php
@@ -20,21 +20,18 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLAuthMethodNamespaceRule extends AbstractModel
+class ACLAuthMethodNamespaceRule extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SELECTOR => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_BIND_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
+ public string $Selector;
+ public string $BindNamespace;
- private const FIELD_SELECTOR = 'Selector';
- private const FIELD_BIND_NAMESPACE = 'BindNamespace';
-
- public string $Selector = '';
- public string $BindNamespace = '';
+ public function __construct(string $Selector = '', string $BindNamespace = '')
+ {
+ $this->Selector = $Selector;
+ $this->BindNamespace = $BindNamespace;
+ }
public function getSelector(): string
{
@@ -57,4 +54,25 @@ public function setBindNamespace(string $BindNamespace): self
$this->BindNamespace = $BindNamespace;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Selector) {
+ $out->Selector = $this->Selector;
+ }
+ if ('' !== $this->BindNamespace) {
+ $out->BindNamespace = $this->BindNamespace;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLAuthMethodQueryResponse.php b/src/ACL/ACLAuthMethodQueryResponse.php
index a3a26039..265d0716 100644
--- a/src/ACL/ACLAuthMethodQueryResponse.php
+++ b/src/ACL/ACLAuthMethodQueryResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLAuthMethodQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLAuthMethod $ACLAuthMethod = null;
+ public null|ACLAuthMethod $ACLAuthMethod = null;
- public function getValue(): ?ACLAuthMethod
+ public function getValue(): null|ACLAuthMethod
{
return $this->ACLAuthMethod;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLAuthMethod = new ACLAuthMethod((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLAuthMethod = null;
+ return;
+ }
+ $this->ACLAuthMethod = $this->ACLAuthMethod::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLAuthMethodWriteResponse.php b/src/ACL/ACLAuthMethodWriteResponse.php
index 0a609b71..0f9ad031 100644
--- a/src/ACL/ACLAuthMethodWriteResponse.php
+++ b/src/ACL/ACLAuthMethodWriteResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLAuthMethodWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?ACLAuthMethod $ACLAuthMethod = null;
+ public null|ACLAuthMethod $ACLAuthMethod = null;
- public function getValue(): ?ACLAuthMethod
+ public function getValue(): null|ACLAuthMethod
{
return $this->ACLAuthMethod;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLAuthMethod = new ACLAuthMethod((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLAuthMethod = null;
+ return;
+ }
+ $this->ACLAuthMethod = ACLAuthMethod::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php
index 0a359399..2eb4cc88 100644
--- a/src/ACL/ACLBindingRule.php
+++ b/src/ACL/ACLBindingRule.php
@@ -20,26 +20,41 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLBindingRule extends AbstractModel
+class ACLBindingRule extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Description = '';
- public string $AuthMethod = '';
- public string $Selector = '';
- public string $BindType = '';
- public string $BindName = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public string $ID;
+ public string $Description;
+ public string $AuthMethod;
+ public string $Selector;
+ public BindingRuleBindType $BindType;
+ public string $BindName;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Namespace;
+
+ public function __construct(
+ string $ID = '',
+ string $Description = '',
+ string $AuthMethod = '',
+ string $Selector = '',
+ string|BindingRuleBindType $BindType = BindingRuleBindType::UNDEFINED,
+ string $BindName = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Namespace = ''
+ ) {
+ $this->ID = $ID;
+ $this->Description = $Description;
+ $this->AuthMethod = $AuthMethod;
+ $this->Selector = $Selector;
+ $this->BindType = ($BindType instanceof BindingRuleBindType) ? $BindType : BindingRuleBindType::from($BindType);
+ $this->BindName = $BindName;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+}
public function getID(): string
{
@@ -85,14 +100,14 @@ public function setSelector(string $Selector): self
return $this;
}
- public function getBindType(): string
+ public function getBindType(): BindingRuleBindType
{
return $this->BindType;
}
- public function setBindType(string $BindType): self
+ public function setBindType(string|BindingRuleBindType $BindType): self
{
- $this->BindType = $BindType;
+ $this->BindType = ($BindType instanceof BindingRuleBindType) ? $BindType : BindingRuleBindType::from($BindType);
return $this;
}
@@ -139,4 +154,30 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Description = $this->Description;
+ $out->AuthMethod = $this->AuthMethod;
+ $out->Selector = $this->Selector;
+ $out->BindType = $this->BindType;
+ $out->BindName = $this->BindName;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLBindingRuleQueryResponse.php b/src/ACL/ACLBindingRuleQueryResponse.php
index ee85a37d..7259cbb6 100644
--- a/src/ACL/ACLBindingRuleQueryResponse.php
+++ b/src/ACL/ACLBindingRuleQueryResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLBindingRuleQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLBindingRule $ACLBindingRule = null;
+ public null|ACLBindingRule $ACLBindingRule = null;
- public function getValue(): ?ACLBindingRule
+ public function getValue(): null|ACLBindingRule
{
return $this->ACLBindingRule;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLBindingRule = new ACLBindingRule((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLBindingRule = null;
+ return;
+ }
+ $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLBindingRuleWriteResponse.php b/src/ACL/ACLBindingRuleWriteResponse.php
index c1ba51c1..b636850c 100644
--- a/src/ACL/ACLBindingRuleWriteResponse.php
+++ b/src/ACL/ACLBindingRuleWriteResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLBindingRuleWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?ACLBindingRule $ACLBindingRule = null;
+ public null|ACLBindingRule $ACLBindingRule = null;
- public function getValue(): ?ACLBindingRule
+ public function getValue(): null|ACLBindingRule
{
return $this->ACLBindingRule;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLBindingRule = new ACLBindingRule((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLBindingRule = null;
+ return;
+ }
+ $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php
index 59d77a58..f8480204 100644
--- a/src/ACL/ACLBindingRulesQueryResponse.php
+++ b/src/ACL/ACLBindingRulesQueryResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLBindingRulesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ACLBindingRules = [];
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLBindingRule[] */
+ public array $ACLBindingRules = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLBindingRule[]
+ */
+ public function getValue(): array
{
return $this->ACLBindingRules;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->ACLBindingRules = [];
- foreach ($decodedData as $datum) {
- $this->ACLBindingRules[] = new ACLBindingRule($datum);
+ foreach ($decoded as $datum) {
+ $this->ACLBindingRules[] = ACLBindingRule::jsonUnserialize($datum);
}
}
}
diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php
index 79e3daa0..781573cb 100644
--- a/src/ACL/ACLClient.php
+++ b/src/ACL/ACLClient.php
@@ -20,12 +20,12 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractClient;
-use DCarbone\PHPConsulAPI\Error;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedWriteStringResponse;
+use DCarbone\PHPConsulAPI\PHPLib\WriteResponse;
use DCarbone\PHPConsulAPI\QueryOptions;
-use DCarbone\PHPConsulAPI\ValuedWriteStringResponse;
use DCarbone\PHPConsulAPI\WriteOptions;
-use DCarbone\PHPConsulAPI\WriteResponse;
class ACLClient extends AbstractClient
{
@@ -34,27 +34,27 @@ public function Bootstrap(): ValuedWriteStringResponse
return $this->_executePutValuedStr('v1/acl/bootstrap', null, null);
}
- public function Create(ACLEntry $acl, ?WriteOptions $opts = null): ValuedWriteStringResponse
+ public function Create(ACLEntry $acl, null|WriteOptions $opts = null): ValuedWriteStringResponse
{
return $this->_executePutValuedStr('v1/acl/create', $acl, $opts);
}
- public function Update(ACLEntry $acl, ?WriteOptions $opts = null): WriteResponse
+ public function Update(ACLEntry $acl, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePut('v1/acl/update', $acl, $opts);
}
- public function Destroy(string $id, ?WriteOptions $opts = null): WriteResponse
+ public function Destroy(string $id, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePut(sprintf('v1/acl/destroy/%s', $id), null, $opts);
}
- public function Clone(string $id, ?WriteOptions $opts = null): ValuedWriteStringResponse
+ public function Clone(string $id, null|WriteOptions $opts = null): ValuedWriteStringResponse
{
return $this->_executePutValuedStr(sprintf('v1/acl/clone/%s', $id), null, $opts);
}
- public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
+ public function Info(string $id, null|QueryOptions $opts = null): ACLEntriesResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/acl/info/%s', $id), $opts));
$ret = new ACLEntriesResponse();
@@ -62,7 +62,7 @@ public function Info(string $id, ?QueryOptions $opts = null): ACLEntriesResponse
return $ret;
}
- public function List(?QueryOptions $opts = null): ACLEntriesResponse
+ public function List(null|QueryOptions $opts = null): ACLEntriesResponse
{
$resp = $this->_requireOK($this->_doGet('v1/acl/list', $opts));
$ret = new ACLEntriesResponse();
@@ -70,7 +70,7 @@ public function List(?QueryOptions $opts = null): ACLEntriesResponse
return $ret;
}
- public function Replication(?QueryOptions $opts = null): ACLReplicationStatusResponse
+ public function Replication(null|QueryOptions $opts = null): ACLReplicationStatusResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/replication', $opts));
$ret = new ACLReplicationStatusResponse();
@@ -78,7 +78,7 @@ public function Replication(?QueryOptions $opts = null): ACLReplicationStatusRes
return $ret;
}
- public function TokenCreate(ACLToken $token, ?WriteOptions $opts = null): ACLTokenWriteResponse
+ public function TokenCreate(ACLToken $token, null|WriteOptions $opts = null): ACLTokenWriteResponse
{
$resp = $this->_requireOK($this->_doPut('/v1/acl/token', $token, $opts));
$ret = new ACLTokenWriteResponse();
@@ -86,7 +86,7 @@ public function TokenCreate(ACLToken $token, ?WriteOptions $opts = null): ACLTok
return $ret;
}
- public function TokenUpdate(ACLToken $token, ?WriteOptions $opts = null): ACLTokenWriteResponse
+ public function TokenUpdate(ACLToken $token, null|WriteOptions $opts = null): ACLTokenWriteResponse
{
$ret = new ACLTokenWriteResponse();
if ('' === $token->AccessorID) {
@@ -98,34 +98,44 @@ public function TokenUpdate(ACLToken $token, ?WriteOptions $opts = null): ACLTok
return $ret;
}
- public function TokenClone(string $tokenID, string $description, ?WriteOptions $opts = null): ACLTokenWriteResponse
+ public function TokenClone(string $accessorID, string $description, null|WriteOptions $opts = null): ACLTokenWriteResponse
{
$ret = new ACLTokenWriteResponse();
- if ('' === $tokenID) {
+ if ('' === $accessorID) {
$ret->Err = new Error('must specify tokenID for Token Cloning');
return $ret;
}
$resp = $this->_requireOK(
- $this->_doPut(sprintf('/v1/acl/token/%s/clone', $tokenID), ['description' => $description], $opts)
+ $this->_doPut(sprintf('/v1/acl/token/%s/clone', $accessorID), ['description' => $description], $opts)
);
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function TokenDelete(string $tokenID, ?WriteOptions $opts = null): WriteResponse
+ public function TokenDelete(string $accessorID, null|WriteOptions $opts = null): WriteResponse
{
- return $this->_executeDelete(sprintf('/v1/acl/token/%s', $tokenID), $opts);
+ return $this->_executeDelete(sprintf('/v1/acl/token/%s', $accessorID), $opts);
}
- public function TokenRead(string $tokenID, ?QueryOptions $opts = null): ACLTokenQueryResponse
+ public function TokenRead(string $accessorID, null|QueryOptions $opts = null): ACLTokenQueryResponse
{
- $resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/token/%s', $tokenID), $opts));
+ $resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/token/%s', $accessorID), $opts));
$ret = new ACLTokenQueryResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function TokenReadSelf(?QueryOptions $opts = null): ACLTokenQueryResponse
+ public function TokenReadExpanded(string $accessorID, null|QueryOptions $opts = null): ACLTokenExpandedQueryResponse
+ {
+ $req = $this->_newGetRequest(sprintf('/v1/acl/token/%s', $accessorID), $opts);
+ $req->params->set('expanded', 'true');
+ $resp = $this->_requireOK($this->_do($req));
+ $ret = new ACLTokenExpandedQueryResponse();
+ $this->_unmarshalResponse($resp, $ret);
+ return $ret;
+ }
+
+ public function TokenReadSelf(null|QueryOptions $opts = null): ACLTokenQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/token/self', $opts));
$ret = new ACLTokenQueryResponse();
@@ -133,7 +143,7 @@ public function TokenReadSelf(?QueryOptions $opts = null): ACLTokenQueryResponse
return $ret;
}
- public function TokenList(?QueryOptions $opts = null): ACLTokenListEntryQueryResponse
+ public function TokenList(null|QueryOptions $opts = null): ACLTokenListEntryQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/tokens', $opts));
$ret = new ACLTokenListEntryQueryResponse();
@@ -141,7 +151,7 @@ public function TokenList(?QueryOptions $opts = null): ACLTokenListEntryQueryRes
return $ret;
}
- public function PolicyCreate(ACLPolicy $policy, ?WriteOptions $opts = null): ACLPolicyWriteResponse
+ public function PolicyCreate(ACLPolicy $policy, null|WriteOptions $opts = null): ACLPolicyWriteResponse
{
$ret = new ACLPolicyWriteResponse();
if ('' !== $policy->ID) {
@@ -153,7 +163,7 @@ public function PolicyCreate(ACLPolicy $policy, ?WriteOptions $opts = null): ACL
return $ret;
}
- public function PolicyUpdate(ACLPolicy $policy, ?WriteOptions $opts = null): ACLPolicyWriteResponse
+ public function PolicyUpdate(ACLPolicy $policy, null|WriteOptions $opts = null): ACLPolicyWriteResponse
{
$ret = new ACLPolicyWriteResponse();
if ('' === $policy->ID) {
@@ -165,12 +175,12 @@ public function PolicyUpdate(ACLPolicy $policy, ?WriteOptions $opts = null): ACL
return $ret;
}
- public function PolicyDelete(string $policyID, ?WriteOptions $opts = null): WriteResponse
+ public function PolicyDelete(string $policyID, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executeDelete(sprintf('/v1/acl/policy/%s', $policyID), $opts);
}
- public function PolicyRead(string $policyID, ?QueryOptions $opts = null): ACLPolicyQueryResponse
+ public function PolicyRead(string $policyID, null|QueryOptions $opts = null): ACLPolicyQueryResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/policy/%s', $policyID), $opts));
$ret = new ACLPolicyQueryResponse();
@@ -178,7 +188,7 @@ public function PolicyRead(string $policyID, ?QueryOptions $opts = null): ACLPol
return $ret;
}
- public function PolicyReadByName(string $policyName, ?QueryOptions $opts = null): ACLPolicyQueryResponse
+ public function PolicyReadByName(string $policyName, null|QueryOptions $opts = null): ACLPolicyQueryResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/policy/name/%s', $policyName), $opts));
$ret = new ACLPolicyQueryResponse();
@@ -186,7 +196,7 @@ public function PolicyReadByName(string $policyName, ?QueryOptions $opts = null)
return $ret;
}
- public function PolicyList(?QueryOptions $opts = null): ACLPolicyListEntryQueryResponse
+ public function PolicyList(null|QueryOptions $opts = null): ACLPolicyListEntryQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/policies', $opts));
$ret = new ACLPolicyListEntryQueryResponse();
@@ -194,7 +204,7 @@ public function PolicyList(?QueryOptions $opts = null): ACLPolicyListEntryQueryR
return $ret;
}
- public function RoleCreate(ACLRole $role, ?WriteOptions $opts = null): ACLRoleWriteResponse
+ public function RoleCreate(ACLRole $role, null|WriteOptions $opts = null): ACLRoleWriteResponse
{
$ret = new ACLRoleWriteResponse();
if ('' !== $role->ID) {
@@ -206,7 +216,7 @@ public function RoleCreate(ACLRole $role, ?WriteOptions $opts = null): ACLRoleWr
return $ret;
}
- public function RoleUpdate(ACLRole $role, ?WriteOptions $opts = null): ACLRoleWriteResponse
+ public function RoleUpdate(ACLRole $role, null|WriteOptions $opts = null): ACLRoleWriteResponse
{
$ret = new ACLRoleWriteResponse();
if ('' === $role->ID) {
@@ -218,12 +228,12 @@ public function RoleUpdate(ACLRole $role, ?WriteOptions $opts = null): ACLRoleWr
return $ret;
}
- public function RoleDelete(string $roleID, ?WriteOptions $opts = null): WriteResponse
+ public function RoleDelete(string $roleID, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executeDelete(sprintf('/v1/acl/role/%s', $roleID), $opts);
}
- public function RoleRead(string $roleID, ?QueryOptions $opts = null): ACLRoleQueryResponse
+ public function RoleRead(string $roleID, null|QueryOptions $opts = null): ACLRoleQueryResponse
{
$resp = $this->_requireNotFoundOrOK($this->_doGet(sprintf('/v1/acl/role/%s', $roleID), $opts));
$ret = new ACLRoleQueryResponse();
@@ -231,7 +241,7 @@ public function RoleRead(string $roleID, ?QueryOptions $opts = null): ACLRoleQue
return $ret;
}
- public function RoleReadByName(string $roleName, ?QueryOptions $opts = null): ACLRoleQueryResponse
+ public function RoleReadByName(string $roleName, null|QueryOptions $opts = null): ACLRoleQueryResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/role/name/%s', $roleName), $opts));
$ret = new ACLRoleQueryResponse();
@@ -239,7 +249,7 @@ public function RoleReadByName(string $roleName, ?QueryOptions $opts = null): AC
return $ret;
}
- public function RoleList(?QueryOptions $opts = null): ACLRolesQueryResponse
+ public function RoleList(null|QueryOptions $opts = null): ACLRolesQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/roles', $opts));
$ret = new ACLRolesQueryResponse();
@@ -247,7 +257,7 @@ public function RoleList(?QueryOptions $opts = null): ACLRolesQueryResponse
return $ret;
}
- public function AuthMethodCreate(ACLAuthMethod $authMethod, ?WriteOptions $opts = null): ACLAuthMethodWriteResponse
+ public function AuthMethodCreate(ACLAuthMethod $authMethod, null|WriteOptions $opts = null): ACLAuthMethodWriteResponse
{
$ret = new ACLAuthMethodWriteResponse();
if ('' !== $authMethod->Name) {
@@ -259,24 +269,24 @@ public function AuthMethodCreate(ACLAuthMethod $authMethod, ?WriteOptions $opts
return $ret;
}
- public function AuthMethodUpdate(ACLAuthMethod $authMethod, ?WriteOptions $opts = null): ACLAuthMethodWriteResponse
+ public function AuthMethodUpdate(ACLAuthMethod $authMethod, null|WriteOptions $opts = null): ACLAuthMethodWriteResponse
{
$ret = new ACLAuthMethodWriteResponse();
- if ('' === $authMethod->ID) {
- $ret->Err = new Error('must specify an ID in AuthMethod Update');
+ if ('' === $authMethod->Name) {
+ $ret->Err = new Error('must specify an Name in AuthMethod Update');
return $ret;
}
- $resp = $this->_requireOK($this->_doPut(sprintf('/v1/acl/auth-method/%s', $authMethod->ID), $authMethod, $opts));
+ $resp = $this->_requireOK($this->_doPut(sprintf('/v1/acl/auth-method/%s', $authMethod->Name), $authMethod, $opts));
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function AuthMethodDelete(string $authMethodID, ?WriteOptions $opts = null): WriteResponse
+ public function AuthMethodDelete(string $authMethodID, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executeDelete(sprintf('/v1/acl/authMethod/%s', $authMethodID), $opts);
}
- public function AuthMethodRead(string $authMethodID, ?QueryOptions $opts = null): ACLAuthMethodQueryResponse
+ public function AuthMethodRead(string $authMethodID, null|QueryOptions $opts = null): ACLAuthMethodQueryResponse
{
$resp = $this->_requireNotFoundOrOK($this->_doGet(sprintf('/v1/acl/authMethod/%s', $authMethodID), $opts));
$ret = new ACLAuthMethodQueryResponse();
@@ -284,7 +294,7 @@ public function AuthMethodRead(string $authMethodID, ?QueryOptions $opts = null)
return $ret;
}
- public function AuthMethodList(?QueryOptions $opts = null): ACLAuthMethodListEntryQueryResponse
+ public function AuthMethodList(null|QueryOptions $opts = null): ACLAuthMethodListEntryQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/auth-methods', $opts));
$ret = new ACLAuthMethodListEntryQueryResponse();
@@ -292,10 +302,8 @@ public function AuthMethodList(?QueryOptions $opts = null): ACLAuthMethodListEnt
return $ret;
}
- public function BindingRuleCreate(
- ACLBindingRule $bindingRule,
- ?WriteOptions $opts = null
- ): ACLBindingRuleWriteResponse {
+ public function BindingRuleCreate(ACLBindingRule $bindingRule, null|WriteOptions $opts = null): ACLBindingRuleWriteResponse
+ {
$ret = new ACLBindingRuleWriteResponse();
if ('' !== $bindingRule->ID) {
$ret->Err = new Error('cannot specify an id in BindingRule Create');
@@ -306,10 +314,8 @@ public function BindingRuleCreate(
return $ret;
}
- public function BindingRuleUpdate(
- ACLBindingRule $bindingRule,
- ?WriteOptions $opts = null
- ): ACLBindingRuleWriteResponse {
+ public function BindingRuleUpdate(ACLBindingRule $bindingRule, null|WriteOptions $opts = null): ACLBindingRuleWriteResponse
+ {
$ret = new ACLBindingRuleWriteResponse();
if ('' === $bindingRule->ID) {
$ret->Err = new Error('must specify an ID in BindingRule Update');
@@ -320,12 +326,12 @@ public function BindingRuleUpdate(
return $ret;
}
- public function BindingRuleDelete(string $bindingRuleID, ?WriteOptions $opts = null): WriteResponse
+ public function BindingRuleDelete(string $bindingRuleID, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executeDelete(sprintf('/v1/acl/binding-rule/%s', $bindingRuleID), $opts);
}
- public function BindingRuleRead(string $bindingRuleID, ?QueryOptions $opts = null): ACLBindingRuleQueryResponse
+ public function BindingRuleRead(string $bindingRuleID, null|QueryOptions $opts = null): ACLBindingRuleQueryResponse
{
$resp = $this->_requireNotFoundOrOK($this->_doGet(sprintf('/v1/acl/binding-rule/%s', $bindingRuleID), $opts));
$ret = new ACLBindingRuleQueryResponse();
@@ -333,7 +339,7 @@ public function BindingRuleRead(string $bindingRuleID, ?QueryOptions $opts = nul
return $ret;
}
- public function BindingRuleList(?QueryOptions $opts = null): ACLBindingRulesQueryResponse
+ public function BindingRuleList(null|QueryOptions $opts = null): ACLBindingRulesQueryResponse
{
$resp = $this->_requireOK($this->_doGet('/v1/acl/binding-rules', $opts));
$ret = new ACLBindingRulesQueryResponse();
@@ -341,7 +347,7 @@ public function BindingRuleList(?QueryOptions $opts = null): ACLBindingRulesQuer
return $ret;
}
- public function Login(ACLLoginParams $login, ?WriteOptions $opts = null): ACLTokenWriteResponse
+ public function Login(ACLLoginParams $login, null|WriteOptions $opts = null): ACLTokenWriteResponse
{
$resp = $this->_requireOK($this->_doPost('/v1/acl/login', $login, $opts));
$ret = new ACLTokenWriteResponse();
@@ -349,12 +355,12 @@ public function Login(ACLLoginParams $login, ?WriteOptions $opts = null): ACLTok
return $ret;
}
- public function Logout(?WriteOptions $opts = null): WriteResponse
+ public function Logout(null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePost('/v1/acl/logout', null, $opts);
}
- public function OIDCAuthURL(ACLOIDCAuthURLParams $auth, ?WriteOptions $opts = null): ValuedWriteStringResponse
+ public function OIDCAuthURL(ACLOIDCAuthURLParams $auth, null|WriteOptions $opts = null): ValuedWriteStringResponse
{
$ret = new ValuedWriteStringResponse();
if ('' === $auth->AuthMethod) {
@@ -366,7 +372,7 @@ public function OIDCAuthURL(ACLOIDCAuthURLParams $auth, ?WriteOptions $opts = nu
return $ret;
}
- public function OIDCCallback(ACLOIDCCallbackParams $auth, ?WriteOptions $opts = null): ACLTokenWriteResponse
+ public function OIDCCallback(ACLOIDCCallbackParams $auth, null|WriteOptions $opts = null): ACLTokenWriteResponse
{
$ret = new ACLTokenWriteResponse();
if ('' === $auth->AuthMethod) {
diff --git a/src/ACL/ACLEntriesResponse.php b/src/ACL/ACLEntriesResponse.php
index f9c4af8f..a686d375 100644
--- a/src/ACL/ACLEntriesResponse.php
+++ b/src/ACL/ACLEntriesResponse.php
@@ -20,22 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLEntry[] */
public array $ACLEntries = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLEntry[]
+ */
+ public function getValue(): array
{
return $this->ACLEntries;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- foreach ($decodedData as $entry) {
- $this->ACLEntries[] = new ACLEntry($entry);
+ $this->ACLEntries = [];
+ foreach ($decoded as $entry) {
+ $this->ACLEntries[] = ACLEntry::jsonUnserialize($entry);
}
}
}
diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php
index 4bc149f5..c90a7952 100644
--- a/src/ACL/ACLEntry.php
+++ b/src/ACL/ACLEntry.php
@@ -20,25 +20,41 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLEntry extends AbstractModel
+class ACLEntry extends AbstractType
{
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $ID = '';
- public string $Name = '';
- public string $Type = '';
- public string $Rules = '';
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $ID;
+ public string $Name;
+ public string $Type;
+ public string $Rules;
+
+ public function __construct(
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $ID = '',
+ string $Name = '',
+ string $Type = '',
+ string $Rules = '',
+ ) {
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Type = $Type;
+ $this->Rules = $Rules;
+ }
public function getCreateIndex(): int
{
return $this->CreateIndex;
}
- public function setCreateIndex(int $createIndex): self
+ public function setCreateIndex(int $CreateIndex): self
{
- $this->CreateIndex = $createIndex;
+ $this->CreateIndex = $CreateIndex;
return $this;
}
@@ -47,9 +63,9 @@ public function getModifyIndex(): int
return $this->ModifyIndex;
}
- public function setModifyIndex(int $modifyIndex): self
+ public function setModifyIndex(int $ModifyIndex): self
{
- $this->ModifyIndex = $modifyIndex;
+ $this->ModifyIndex = $ModifyIndex;
return $this;
}
@@ -58,9 +74,9 @@ public function getID(): string
return $this->ID;
}
- public function setID(string $id): self
+ public function setID(string $ID): self
{
- $this->ID = $id;
+ $this->ID = $ID;
return $this;
}
@@ -69,9 +85,9 @@ public function getName(): string
return $this->Name;
}
- public function setName(string $name): self
+ public function setName(string $Name): self
{
- $this->Name = $name;
+ $this->Name = $Name;
return $this;
}
@@ -80,9 +96,9 @@ public function getType(): string
return $this->Type;
}
- public function setType(string $type): self
+ public function setType(string $Type): self
{
- $this->Type = $type;
+ $this->Type = $Type;
return $this;
}
@@ -91,9 +107,30 @@ public function getRules(): string
return $this->Rules;
}
- public function setRules(string $rules): self
+ public function setRules(string $Rules): self
{
- $this->Rules = $rules;
+ $this->Rules = $Rules;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Type = $this->Type;
+ $out->Rules = $this->Rules;
+ return $out;
+ }
}
diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php
index 905e0a98..803ba203 100644
--- a/src/ACL/ACLLink.php
+++ b/src/ACL/ACLLink.php
@@ -20,20 +20,55 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLLink extends AbstractModel
+class ACLLink extends AbstractType
{
- public string $ID = '';
- public string $Name = '';
+ public string $ID;
+ public string $Name;
+
+ public function __construct(string $ID = '', string $Name = '')
+ {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ }
public function getID(): string
{
return $this->ID;
}
+ public function setID(string $ID): self
+ {
+ $this->ID = $ID;
+ return $this;
+ }
+
public function getName(): string
{
return $this->Name;
}
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ return $out;
+ }
}
diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php
index 19ce55aa..c546f1ba 100644
--- a/src/ACL/ACLLoginParams.php
+++ b/src/ACL/ACLLoginParams.php
@@ -20,21 +20,28 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
-class ACLLoginParams extends AbstractModel
+class ACLLoginParams extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_META => Transcoding::MAP_FIELD + [Transcoding::FIELD_OMITEMPTY => true],
- ];
-
- private const FIELD_META = 'Meta';
-
- public string $AuthMethod = '';
- public string $BearerToken = '';
- public ?FakeMap $Meta = null;
+ use MetaField;
+
+ public string $AuthMethod;
+ public string $BearerToken;
+
+ /**
+ * @param array $Meta
+ */
+ public function __construct(
+ string $AuthMethod = '',
+ string $BearerToken = '',
+ array $Meta = [],
+ ) {
+ $this->AuthMethod = $AuthMethod;
+ $this->BearerToken = $BearerToken;
+ $this->setMeta($Meta);
+ }
public function getAuthMethod(): string
{
@@ -58,14 +65,27 @@ public function setBearerToken(string $BearerToken): self
return $this;
}
- public function getMeta(): ?FakeMap
+ public static function jsonUnserialize(\stdClass $decoded): self
{
- return $this->Meta;
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
}
- public function setMeta(mixed $Meta): self
+ public function jsonSerialize(): \stdClass
{
- $this->Meta = FakeMap::parse($Meta);
- return $this;
+ $out = $this->_startJsonSerialize();
+ $out->AuthMethod = $this->AuthMethod;
+ $out->BearerToken = $this->BearerToken;
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ return $out;
}
}
diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php
index 400aca2d..45c63d2c 100644
--- a/src/ACL/ACLNodeIdentity.php
+++ b/src/ACL/ACLNodeIdentity.php
@@ -20,20 +20,55 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLNodeIdentity extends AbstractModel
+class ACLNodeIdentity extends AbstractType
{
- public string $NodeName = '';
- public string $Datacenter = '';
+ public string $NodeName;
+ public string $Datacenter;
+
+ public function __construct(string $NodeName = '', string $Datacenter = '')
+ {
+ $this->NodeName = $NodeName;
+ $this->Datacenter = $Datacenter;
+ }
public function getNodeName(): string
{
return $this->NodeName;
}
+ public function setNodeName(string $NodeName): self
+ {
+ $this->NodeName = $NodeName;
+ return $this;
+ }
+
public function getDatacenter(): string
{
return $this->Datacenter;
}
+
+ public function setDatacenter(string $Datacenter): self
+ {
+ $this->Datacenter = $Datacenter;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->NodeName = $this->NodeName;
+ $out->Datacenter = $this->Datacenter;
+ return $out;
+ }
}
diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php
index e5384cb7..84258ba3 100644
--- a/src/ACL/ACLOIDCAuthURLParams.php
+++ b/src/ACL/ACLOIDCAuthURLParams.php
@@ -20,22 +20,31 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
-class ACLOIDCAuthURLParams extends AbstractModel
+class ACLOIDCAuthURLParams extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_META => Transcoding::MAP_FIELD + [Transcoding::FIELD_OMITEMPTY => true],
- ];
-
- private const FIELD_META = 'Meta';
-
- public string $AuthMethod = '';
- public string $RedirectURI = '';
- public string $ClientNonce = '';
- public ?FakeMap $Meta = null;
+ use MetaField;
+
+ public string $AuthMethod;
+ public string $RedirectURI;
+ public string $ClientNonce;
+
+ /**
+ * @param array $Meta
+ */
+ public function __construct(
+ string $AuthMethod = '',
+ string $RedirectURI = '',
+ string $ClientNonce = '',
+ array $Meta = [],
+ ) {
+ $this->AuthMethod = $AuthMethod;
+ $this->RedirectURI = $RedirectURI;
+ $this->ClientNonce = $ClientNonce;
+ $this->setMeta($Meta);
+}
public function getAuthMethod(): string
{
@@ -70,14 +79,28 @@ public function setClientNonce(string $ClientNonce): self
return $this;
}
- public function getMeta(): ?FakeMap
+ public static function jsonUnserialize(\stdClass $decoded): self
{
- return $this->Meta;
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
}
- public function setMeta(mixed $Meta): self
+ public function jsonSerialize(): \stdClass
{
- $this->Meta = FakeMap::parse($Meta);
- return $this;
+ $out = $this->_startJsonSerialize();
+ $out->AuthMethod = $this->AuthMethod;
+ $out->RedirectURI = $this->RedirectURI;
+ $out->ClientNonce = $this->ClientNonce;
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ return $out;
}
}
diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php
index 1d7b196a..89d2b1a4 100644
--- a/src/ACL/ACLOIDCCallbackParams.php
+++ b/src/ACL/ACLOIDCCallbackParams.php
@@ -20,14 +20,26 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLOIDCCallbackParams extends AbstractModel
+class ACLOIDCCallbackParams extends AbstractType
{
- public string $AuthMethod = '';
- public string $State = '';
- public string $Code = '';
- public string $ClientNonce = '';
+ public string $AuthMethod;
+ public string $State;
+ public string $Code;
+ public string $ClientNonce;
+
+ public function __construct(
+ string $AuthMethod = '',
+ string $State = '',
+ string $Code = '',
+ string $ClientNonce = '',
+ ) {
+ $this->AuthMethod = $AuthMethod;
+ $this->State = $State;
+ $this->Code = $Code;
+ $this->ClientNonce = $ClientNonce;
+}
public function getAuthMethod(): string
{
@@ -72,4 +84,23 @@ public function setClientNonce(string $ClientNonce): self
$this->ClientNonce = $ClientNonce;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->AuthMethod = $this->AuthMethod;
+ $out->State = $this->State;
+ $out->Code = $this->Code;
+ $out->ClientNonce = $this->ClientNonce;
+ return $out;
+ }
}
diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php
index 88dd5d56..db60d8a7 100644
--- a/src/ACL/ACLPolicy.php
+++ b/src/ACL/ACLPolicy.php
@@ -20,26 +20,48 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLPolicy extends AbstractModel
+class ACLPolicy extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Name = '';
- public string $Description = '';
- public string $Rules = '';
- public array $Datacenters = [];
- public string $Hash = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public string $ID;
+ public string $Name;
+ public string $Description;
+ public string $Rules;
+ /** @var string[] */
+ public array $Datacenters;
+ public string $Hash;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array $Datacenters
+ */
+ public function __construct(
+ string $ID = '',
+ string $Name = '',
+ string $Description = '',
+ string $Rules = '',
+ array $Datacenters = [],
+ string $Hash = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Description = $Description;
+ $this->Rules = $Rules;
+ $this->setDatacenters(...$Datacenters);
+ $this->Hash = $Hash;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+}
public function getID(): string
{
@@ -85,12 +107,15 @@ public function setRules(string $Rules): self
return $this;
}
+ /**
+ * @return string[]
+ */
public function getDatacenters(): array
{
return $this->Datacenters;
}
- public function setDatacenters(array $Datacenters): self
+ public function setDatacenters(string ...$Datacenters): self
{
$this->Datacenters = $Datacenters;
return $this;
@@ -139,4 +164,48 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Datacenters' === $k) {
+ $n->setDatacenters(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Description = $this->Description;
+ $out->Rules = $this->Rules;
+ $out->Datacenters = $this->Datacenters;
+ $out->Hash = $this->Hash;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php
index 6cb4e67e..048fbfd4 100644
--- a/src/ACL/ACLPolicyListEntry.php
+++ b/src/ACL/ACLPolicyListEntry.php
@@ -20,25 +20,45 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLPolicyListEntry extends AbstractModel
+class ACLPolicyListEntry extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Name = '';
- public string $Description = '';
- public array $Datacenters = [];
- public string $Hash = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public string $ID;
+ public string $Name;
+ public string $Description;
+ /** @var array */
+ public array $Datacenters;
+ public string $Hash;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array $Datacenters
+ */
+ public function __construct(
+ string $ID = '',
+ string $Name = '',
+ string $Description = '',
+ array $Datacenters = [],
+ string $Hash = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Description = $Description;
+ $this->setDatacenters(...$Datacenters);
+ $this->Hash = $Hash;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+}
public function getID(): string
{
@@ -73,12 +93,15 @@ public function setDescription(string $Description): self
return $this;
}
+ /**
+ * @return array
+ */
public function getDatacenters(): array
{
return $this->Datacenters;
}
- public function setDatacenters(array $Datacenters): self
+ public function setDatacenters(string ...$Datacenters): self
{
$this->Datacenters = $Datacenters;
return $this;
@@ -127,4 +150,47 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Datacenters' === $k) {
+ $n->setDatacenters(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Description = $this->Description;
+ $out->Datacenters = $this->Datacenters;
+ $out->Hash = $this->Hash;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php
index 96f28700..41688af2 100644
--- a/src/ACL/ACLPolicyListEntryQueryResponse.php
+++ b/src/ACL/ACLPolicyListEntryQueryResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLPolicyListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ACLPolicyListEntries = [];
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLPolicyListEntry[] */
+ public array $ACLPolicyListEntries = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLPolicyListEntry[]
+ */
+ public function getValue(): array
{
return $this->ACLPolicyListEntries;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->ACLPolicyListEntries = [];
- foreach ($decodedData as $datum) {
- $this->ACLPolicyListEntries[] = new ACLPolicyListEntry($datum);
+ foreach ($decoded as $datum) {
+ $this->ACLPolicyListEntries[] = ACLPolicyListEntry::jsonUnserialize($datum);
}
}
}
diff --git a/src/ACL/ACLPolicyQueryResponse.php b/src/ACL/ACLPolicyQueryResponse.php
index e8aeb668..58ef1492 100644
--- a/src/ACL/ACLPolicyQueryResponse.php
+++ b/src/ACL/ACLPolicyQueryResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLPolicyQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLPolicy $ACLPolicy = null;
+ public null|ACLPolicy $ACLPolicy = null;
- public function getValue(): ?ACLPolicy
+ public function getValue(): null|ACLPolicy
{
return $this->ACLPolicy;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLPolicy = new ACLPolicy((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLPolicy = null;
+ return;
+ }
+ $this->ACLPolicy = ACLPolicy::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLPolicyWriteResponse.php b/src/ACL/ACLPolicyWriteResponse.php
index 1e9439d5..9cea121e 100644
--- a/src/ACL/ACLPolicyWriteResponse.php
+++ b/src/ACL/ACLPolicyWriteResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLPolicyWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?ACLPolicy $ACLPolicy = null;
+ public null|ACLPolicy $ACLPolicy = null;
- public function getValue(): ?ACLPolicy
+ public function getValue(): null|ACLPolicy
{
return $this->ACLPolicy;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLPolicy = new ACLPolicy((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLPolicy = null;
+ return;
+ }
+ $this->ACLPolicy = ACLPolicy::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php
index 479bc9c2..5c7a8794 100644
--- a/src/ACL/ACLReplicationStatus.php
+++ b/src/ACL/ACLReplicationStatus.php
@@ -21,80 +21,154 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use function DCarbone\PHPConsulAPI\PHPLib\parse_time;
-class ACLReplicationStatus extends AbstractModel
+class ACLReplicationStatus extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_LAST_SUCCESS => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_TIME,
- ],
- self::FIELD_LAST_ERROR => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_TIME,
- ],
- ];
-
- private const FIELD_LAST_SUCCESS = 'LastSuccess';
- private const FIELD_LAST_ERROR = 'LastError';
-
- public bool $Enabled = false;
- public bool $Running = false;
- public string $SourceDatacenter = '';
- public int $ReplicatedIndex = 0;
- public int $ReplicatedRoleIndex = 0;
- public int $ReplicatedTokenIndex = 0;
+ public bool $Enabled;
+ public bool $Running;
+ public string $SourceDatacenter;
+ public int $ReplicatedIndex;
+ public int $ReplicatedRoleIndex;
+ public int $ReplicatedTokenIndex;
public Time\Time $LastSuccess;
public Time\Time $LastError;
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->LastSuccess)) {
- $this->LastSuccess = Time::New();
- }
- if (!isset($this->LastError)) {
- $this->LastError = Time::New();
- }
- }
+ public function __construct(
+ bool $Enabled = false,
+ bool $Running = false,
+ string $SourceDatacenter = '',
+ int $ReplicatedIndex = 0,
+ int $ReplicatedRoleIndex = 0,
+ int $ReplicatedTokenIndex = 0,
+ null|Time\Time $LastSuccess = null,
+ null|Time\Time $LastError = null,
+ ) {
+ $this->Enabled = $Enabled;
+ $this->Running = $Running;
+ $this->SourceDatacenter = $SourceDatacenter;
+ $this->ReplicatedIndex = $ReplicatedIndex;
+ $this->ReplicatedRoleIndex = $ReplicatedRoleIndex;
+ $this->ReplicatedTokenIndex = $ReplicatedTokenIndex;
+ $this->LastSuccess = $LastSuccess ?? Time::New();
+ $this->LastError = $LastError ?? Time::New();
+}
public function isEnabled(): bool
{
return $this->Enabled;
}
+ public function setEnabled(bool $Enabled): self
+ {
+ $this->Enabled = $Enabled;
+ return $this;
+ }
+
public function isRunning(): bool
{
return $this->Running;
}
+ public function setRunning(bool $Running): self
+ {
+ $this->Running = $Running;
+ return $this;
+ }
+
public function getSourceDatacenter(): string
{
return $this->SourceDatacenter;
}
+ public function setSourceDatacenter(string $SourceDatacenter): self
+ {
+ $this->SourceDatacenter = $SourceDatacenter;
+ return $this;
+ }
+
public function getReplicatedIndex(): int
{
return $this->ReplicatedIndex;
}
+ public function setReplicatedIndex(int $ReplicatedIndex): self
+ {
+ $this->ReplicatedIndex = $ReplicatedIndex;
+ return $this;
+ }
+
public function getReplicatedRoleIndex(): int
{
return $this->ReplicatedRoleIndex;
}
+ public function setReplicatedRoleIndex(int $ReplicatedRoleIndex): self
+ {
+ $this->ReplicatedRoleIndex = $ReplicatedRoleIndex;
+ return $this;
+ }
+
public function getReplicatedTokenIndex(): int
{
return $this->ReplicatedTokenIndex;
}
+ public function setReplicatedTokenIndex(int $ReplicatedTokenIndex): self
+ {
+ $this->ReplicatedTokenIndex = $ReplicatedTokenIndex;
+ return $this;
+ }
+
public function getLastSuccess(): Time\Time
{
return $this->LastSuccess;
}
+ public function setLastSuccess(Time\Time $LastSuccess): self
+ {
+ $this->LastSuccess = $LastSuccess;
+ return $this;
+ }
+
public function getLastError(): Time\Time
{
return $this->LastError;
}
+
+ public function setLastError(Time\Time $LastError): self
+ {
+ $this->LastError = $LastError;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('LastSuccess' === $k) {
+ $n->LastSuccess = parse_time($v);
+ } elseif ('LastError' === $k) {
+ $n->LastError = parse_time($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Enabled = $this->Enabled;
+ $out->Running = $this->Running;
+ $out->SourceDatacenter = $this->SourceDatacenter;
+ $out->ReplicatedIndex = $this->ReplicatedIndex;
+ $out->ReplicatedRoleIndex = $this->ReplicatedRoleIndex;
+ $out->ReplicatedTokenIndex = $this->ReplicatedTokenIndex;
+ $out->LastSuccess = $this->LastSuccess->format(DATE_RFC3339);
+ $out->LastError = $this->LastError->format(DATE_RFC3339);
+ return $out;
+ }
}
diff --git a/src/ACL/ACLReplicationStatusResponse.php b/src/ACL/ACLReplicationStatusResponse.php
index df71f30f..61f12b9c 100644
--- a/src/ACL/ACLReplicationStatusResponse.php
+++ b/src/ACL/ACLReplicationStatusResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLReplicationStatusResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLReplicationStatus $ACLReplicationStatus = null;
+ public null|ACLReplicationStatus $ACLReplicationStatus = null;
- public function getValue(): ?ACLReplicationStatus
+ public function getValue(): null|ACLReplicationStatus
{
return $this->ACLReplicationStatus;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLReplicationStatus = new ACLReplicationStatus((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLReplicationStatus = null;
+ return;
+ }
+ $this->ACLReplicationStatus = ACLReplicationStatus::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php
index 1913ea18..c5f2f0f4 100644
--- a/src/ACL/ACLRole.php
+++ b/src/ACL/ACLRole.php
@@ -20,48 +20,60 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLRole extends AbstractModel
+class ACLRole extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_POLICIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLTokenPolicyLink::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_SERVICE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLServiceIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NODE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLNodeIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_POLICIES = 'Policies';
- private const FIELD_SERVICE_IDENTITIES = 'ServiceIdentities';
- private const FIELD_NODE_IDENTITIES = 'NodeIdentities';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Name = '';
- public string $Description = '';
- public array $Policies = [];
- public array $ServiceIdentities = [];
- public array $NodeIdentities = [];
- public string $Hash = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public string $ID;
+ public string $Name;
+ public string $Description;
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[] */
+ public array $Policies;
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[] */
+ public array $ServiceIdentities;
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] */
+ public array $NodeIdentities;
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[] */
+ public array $TemplatedPolicies;
+ public string $Hash;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink> $Policies
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> $ServiceIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> $NodeIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> $TemplatedPolicies
+ */
+ public function __construct(
+ string $ID = '',
+ string $Name = '',
+ string $Description = '',
+ array $Policies = [],
+ array $ServiceIdentities = [],
+ array $NodeIdentities = [],
+ array $TemplatedPolicies = [],
+ string $Hash = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Description = $Description;
+ $this->setPolicies(...$Policies);
+ $this->setServiceIdentities(...$ServiceIdentities);
+ $this->setNodeIdentities(...$NodeIdentities);
+ $this->setTemplatedPolicies(...$TemplatedPolicies);
+ $this->Hash = $Hash;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+}
public function getID(): string
{
@@ -96,39 +108,62 @@ public function setDescription(string $Description): self
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[]
+ */
public function getPolicies(): array
{
return $this->Policies;
}
- public function setPolicies(array $Policies): self
+ public function setPolicies(ACLRolePolicyLink ...$Policies): self
{
$this->Policies = $Policies;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[]
+ */
public function getServiceIdentities(): array
{
return $this->ServiceIdentities;
}
- public function setServiceIdentities(array $ServiceIdentities): self
+ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self
{
$this->ServiceIdentities = $ServiceIdentities;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[]
+ */
public function getNodeIdentities(): array
{
return $this->NodeIdentities;
}
- public function setNodeIdentities(array $NodeIdentities): self
+ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self
{
$this->NodeIdentities = $NodeIdentities;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[]
+ */
+ public function getTemplatedPolicies(): array
+ {
+ return $this->TemplatedPolicies;
+ }
+
+ public function setTemplatedPolicies(ACLTemplatedPolicy ...$TemplatedPolicies): self
+ {
+ $this->TemplatedPolicies = $TemplatedPolicies;
+ return $this;
+ }
+
public function getHash(): string
{
return $this->Hash;
@@ -172,4 +207,76 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Policies' === $k) {
+ $n->Policies = [];
+ foreach ($v as $vv) {
+ $n->Policies[] = ACLRolePolicyLink::jsonUnserialize($vv);
+ }
+ } elseif ('ServiceIdentities' === $k) {
+ $n->ServiceIdentities = [];
+ foreach ($v as $vv) {
+ $n->ServiceIdentities[] = ACLServiceIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('NodeIdentities' === $k) {
+ $n->NodeIdentities = [];
+ foreach ($v as $vv) {
+ $n->NodeIdentities[] = ACLNodeIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('TemplatedPolicies' === $k) {
+ $n->TemplatedPolicies = [];
+ foreach ($v as $vv) {
+ $n->TemplatedPolicies[] = ACLTemplatedPolicy::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Description = $this->Description;
+ $out->Hash = $this->Hash;
+ if ([] !== $this->Policies) {
+ $out->Policies = $this->Policies;
+ }
+ if ([] !== $this->ServiceIdentities) {
+ $out->ServiceIdentities = $this->ServiceIdentities;
+ }
+ if ([] !== $this->NodeIdentities) {
+ $out->NodeIdentities = $this->NodeIdentities;
+ }
+ if ([] !== $this->TemplatedPolicies) {
+ $out->TemplatedPolicies = $this->TemplatedPolicies;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLRolePolicyLink.php b/src/ACL/ACLRolePolicyLink.php
index 649dbc90..5dfd0ab2 100644
--- a/src/ACL/ACLRolePolicyLink.php
+++ b/src/ACL/ACLRolePolicyLink.php
@@ -22,4 +22,12 @@
class ACLRolePolicyLink extends ACLLink
{
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
}
diff --git a/src/ACL/ACLRoleQueryResponse.php b/src/ACL/ACLRoleQueryResponse.php
index 4ffbe236..814c6f5c 100644
--- a/src/ACL/ACLRoleQueryResponse.php
+++ b/src/ACL/ACLRoleQueryResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLRoleQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLRole $ACLRole = null;
+ public null|ACLRole $ACLRole = null;
- public function getValue(): ?ACLRole
+ public function getValue(): null|ACLRole
{
return $this->ACLRole;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLRole = new ACLRole((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLRole = null;
+ return;
+ }
+ $this->ACLRole = ACLRole::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLRoleWriteResponse.php b/src/ACL/ACLRoleWriteResponse.php
index cb94ff4e..3dcb49cf 100644
--- a/src/ACL/ACLRoleWriteResponse.php
+++ b/src/ACL/ACLRoleWriteResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLRoleWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?ACLRole $ACLRole = null;
+ public null|ACLRole $ACLRole = null;
- public function getValue(): ?ACLRole
+ public function getValue(): null|ACLRole
{
return $this->ACLRole;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLRole = new ACLRole((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLRole = null;
+ return;
+ }
+ $this->ACLRole = ACLRole::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php
index 37d58657..52ff3612 100644
--- a/src/ACL/ACLRolesQueryResponse.php
+++ b/src/ACL/ACLRolesQueryResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLRolesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ACLRoles = [];
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLRole[] */
+ public array $ACLRoles = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLRole[]
+ */
+ public function getValue(): array
{
return $this->ACLRoles;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->ACLRoles = [];
- foreach ($decodedData as $datum) {
- $this->ACLRoles[] = new ACLRole($datum);
+ foreach ($decoded as $datum) {
+ $this->ACLRoles[] = ACLRole::jsonUnserialize($datum);
}
}
}
diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php
index 99d7d938..52f80994 100644
--- a/src/ACL/ACLServiceIdentity.php
+++ b/src/ACL/ACLServiceIdentity.php
@@ -20,31 +20,68 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLServiceIdentity extends AbstractModel
+class ACLServiceIdentity extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_DATACENTERS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public string $ServiceName;
+ /** @var string[] */
+ public array $Datacenters;
- private const FIELD_DATACENTERS = 'Datacenters';
-
- public string $ServiceName = '';
- public array $Datacenters = [];
+ /**
+ * @param array $Datacenters
+ */
+ public function __construct(string $ServiceName = '', array $Datacenters = [])
+ {
+ $this->ServiceName = $ServiceName;
+ $this->setDatacenters(...$Datacenters);
+ }
public function getServiceName(): string
{
return $this->ServiceName;
}
+ public function setServiceName(string $ServiceName): self
+ {
+ $this->ServiceName = $ServiceName;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
public function getDatacenters(): array
{
return $this->Datacenters;
}
+
+ public function setDatacenters(string ...$Datacenters): self
+ {
+ $this->Datacenters = $Datacenters;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Datacenters' === $k) {
+ $n->setDatacenters(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ServiceName = $this->ServiceName;
+ if ([] !== $this->Datacenters) {
+ $out->Datacenters = $this->Datacenters;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php
new file mode 100644
index 00000000..87edf789
--- /dev/null
+++ b/src/ACL/ACLTemplatedPolicy.php
@@ -0,0 +1,108 @@
+ $Datacenters
+ */
+ public function __construct(
+ string $TemplateName = '',
+ null|ACLTemplatedPolicyVariables $TemplateVariables = null,
+ array $Datacenters = [],
+ ) {
+ $this->TemplateName = $TemplateName;
+ $this->TemplateVariables = $TemplateVariables;
+ $this->setDatacenters(...$Datacenters);
+ }
+
+ public function getTemplateName(): string
+ {
+ return $this->TemplateName;
+ }
+
+ public function setTemplateName(string $TemplateName): self
+ {
+ $this->TemplateName = $TemplateName;
+ return $this;
+ }
+
+ public function getTemplateVariables(): null|ACLTemplatedPolicyVariables
+ {
+ return $this->TemplateVariables;
+ }
+
+ public function setTemplateVariables(null|ACLTemplatedPolicyVariables $TemplateVariables): self
+ {
+ $this->TemplateVariables = $TemplateVariables;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getDatacenters(): array
+ {
+ return $this->Datacenters;
+ }
+
+ public function setDatacenters(string ...$Datacenters): self
+ {
+ $this->Datacenters = $Datacenters;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TemplateVariables' === $k) {
+ $n->setTemplateVariables($v);
+ } elseif ('Datacenters' === $k) {
+ $n->setDatacenters(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->TemplateName = $this->TemplateName;
+ if (null !== $this->TemplateVariables) {
+ $out->TemplateVariables = $this->TemplateVariables;
+ }
+ if ([] !== $this->Datacenters) {
+ $out->Datacenters = $this->Datacenters;
+ }
+ return $out;
+ }
+}
diff --git a/src/ACL/ACLTemplatedPolicyVariables.php b/src/ACL/ACLTemplatedPolicyVariables.php
new file mode 100644
index 00000000..8b56c6ec
--- /dev/null
+++ b/src/ACL/ACLTemplatedPolicyVariables.php
@@ -0,0 +1,60 @@
+Name = $Name;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php
index d417a98d..7da4165f 100644
--- a/src/ACL/ACLToken.php
+++ b/src/ACL/ACLToken.php
@@ -21,279 +21,78 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ACLToken extends AbstractModel
+class ACLToken extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_POLICIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLTokenPolicyLink::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_ROLES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLTokenRoleLink::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_SERVICE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLServiceIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NODE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLNodeIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_AUTH_METHOD => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_EXPIRATION_TTL => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_EXPIRATION_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_TIME,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CREATE_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_TIME,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_RULES => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_POLICIES = 'Policies';
- private const FIELD_ROLES = 'Roles';
- private const FIELD_SERVICE_IDENTITIES = 'ServiceIdentities';
- private const FIELD_NODE_IDENTITIES = 'NodeIdentities';
- private const FIELD_AUTH_METHOD = 'AuthMethod';
- private const FIELD_EXPIRATION_TTL = 'ExpirationTTL';
- private const FIELD_EXPIRATION_TIME = 'ExpirationTime';
- private const FIELD_CREATE_TIME = 'CreateTime';
- private const FIELD_RULES = 'Rules';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $AccessorID = '';
- public string $SecretID = '';
- public string $Description = '';
- public array $Policies = [];
- public array $Roles = [];
- public array $ServiceIdentities = [];
- public array $NodeIdentities = [];
- public bool $Local = false;
- public string $AuthMethod = '';
- public Time\Duration $ExpirationTTL;
- public ?Time\Time $ExpirationTime = null;
- public Time\Time $CreateTime;
- public string $Hash = '';
- public string $Namespace = '';
-
- public string $Rules = '';
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->ExpirationTTL)) {
- $this->ExpirationTTL = new Time\Duration();
- }
- if (!isset($this->CreateTime)) {
- $this->CreateTime = Time::New();
- }
- }
-
- public function getCreateIndex(): int
- {
- return $this->CreateIndex;
- }
-
- public function setCreateIndex(int $CreateIndex): self
- {
+ use ACLTokenFields;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> $Policies
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> $Roles
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> $ServiceIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> $NodeIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> $TemplatePolicies
+ */
+ public function __construct(
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $AccessorID = '',
+ string $SecretID = '',
+ string $Description = '',
+ array $Policies = [],
+ array $Roles = [],
+ array $ServiceIdentities = [],
+ array $NodeIdentities = [],
+ array $TemplatePolicies = [],
+ bool $Local = false,
+ string $AuthMethod = '',
+ null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL = null,
+ null|Time\Time $ExpirationTime = null,
+ null|Time\Time $CreateTime = null,
+ string $Hash = '',
+ string $Namespace = '',
+ string $Rules = '',
+ string $Partition = '',
+ string $AuthMethodNamespace = '',
+ ) {
$this->CreateIndex = $CreateIndex;
- return $this;
- }
-
- public function getModifyIndex(): int
- {
- return $this->ModifyIndex;
- }
-
- public function setModifyIndex(int $ModifyIndex): self
- {
$this->ModifyIndex = $ModifyIndex;
- return $this;
- }
-
- public function getAccessorID(): string
- {
- return $this->AccessorID;
- }
-
- public function setAccessorID(string $AccessorID): self
- {
$this->AccessorID = $AccessorID;
- return $this;
- }
-
- public function getSecretID(): string
- {
- return $this->SecretID;
- }
-
- public function setSecretID(string $SecretID): self
- {
$this->SecretID = $SecretID;
- return $this;
- }
-
- public function getDescription(): string
- {
- return $this->Description;
- }
-
- public function setDescription(string $Description): self
- {
$this->Description = $Description;
- return $this;
- }
-
- public function getPolicies(): array
- {
- return $this->Policies;
- }
-
- public function setPolicies(array $Policies): self
- {
- $this->Policies = $Policies;
- return $this;
- }
-
- public function getRoles(): array
- {
- return $this->Roles;
- }
-
- public function setRoles(array $Roles): self
- {
- $this->Roles = $Roles;
- return $this;
- }
-
- public function getServiceIdentities(): array
- {
- return $this->ServiceIdentities;
- }
-
- public function setServiceIdentities(array $ServiceIdentities): self
- {
- $this->ServiceIdentities = $ServiceIdentities;
- return $this;
- }
-
- public function getNodeIdentities(): array
- {
- return $this->NodeIdentities;
- }
-
- public function setNodeIdentities(array $NodeIdentities): self
- {
- $this->NodeIdentities = $NodeIdentities;
- return $this;
- }
-
- public function isLocal(): bool
- {
- return $this->Local;
- }
-
- public function setLocal(bool $Local): self
- {
+ $this->setPolicies(...$Policies);
+ $this->setRoles(...$Roles);
+ $this->setServiceIdentities(...$ServiceIdentities);
+ $this->setNodeIdentities(...$NodeIdentities);
+ $this->setTemplatePolicies(...$TemplatePolicies);
$this->Local = $Local;
- return $this;
- }
-
- public function getAuthMethod(): string
- {
- return $this->AuthMethod;
- }
-
- public function setAuthMethod(string $AuthMethod): self
- {
$this->AuthMethod = $AuthMethod;
- return $this;
- }
-
- public function getExpirationTTL(): Time\Duration
- {
- return $this->ExpirationTTL;
- }
-
- public function setExpirationTTL(Time\Duration $ExpirationTTL): self
- {
- $this->ExpirationTTL = $ExpirationTTL;
- return $this;
- }
-
- public function getExpirationTime(): ?Time\Time
- {
- return $this->ExpirationTime;
- }
-
- public function setExpirationTime(?Time\Time $ExpirationTime): self
- {
- $this->ExpirationTime = $ExpirationTime;
- return $this;
- }
-
- public function getCreateTime(): Time\Time
- {
- return $this->CreateTime;
- }
-
- public function setCreateTime(Time\Time $CreateTime): self
- {
- $this->CreateTime = $CreateTime;
- return $this;
- }
-
- public function getHash(): string
- {
- return $this->Hash;
- }
-
- public function setHash(string $Hash): self
- {
+ $this->setExpirationTTL($ExpirationTTL);
+ $this->setExpirationTime($ExpirationTime);
+ $this->CreateTime = $CreateTime ?? Time::New();
$this->Hash = $Hash;
- return $this;
- }
-
- public function getNamespace(): string
- {
- return $this->Namespace;
- }
-
- public function setNamespace(string $Namespace): self
- {
$this->Namespace = $Namespace;
- return $this;
- }
+ $this->Rules = $Rules;
+ $this->Partition = $Partition;
+ $this->AuthMethodNamespace = $AuthMethodNamespace;
+}
- public function getRules(): string
+ public static function jsonUnserialize(\stdClass $decoded): self
{
- return $this->Rules;
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if (!$n->_jsonUnserializeField($k, $v, $n)) {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
}
- public function setRules(string $Rules): self
+ public function jsonSerialize(): \stdClass
{
- $this->Rules = $Rules;
- return $this;
+ $out = $this->_startJsonSerialize();
+ $this->_jsonSerialize($out);
+ return $out;
}
}
diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php
new file mode 100644
index 00000000..070ae552
--- /dev/null
+++ b/src/ACL/ACLTokenExpanded.php
@@ -0,0 +1,240 @@
+ $ExpandedPolicies
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLRole> $ExpandedRoles
+ * @param array $NamespaceDefaultPolicyIDs
+ * @param array $NamespaceDefaultRoleIDs
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> $Policies
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> $Roles
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> $ServiceIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> $NodeIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> $TemplatePolicies
+ */
+ public function __construct(
+ array $ExpandedPolicies = [],
+ array $ExpandedRoles = [],
+ array $NamespaceDefaultPolicyIDs = [],
+ array $NamespaceDefaultRoleIDs = [],
+ string $AgentACLDefaultPolicy = '',
+ string $AgentACLDownPolicy = '',
+ string $ResolvedByAgent = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $AccessorID = '',
+ string $SecretID = '',
+ string $Description = '',
+ array $Policies = [],
+ array $Roles = [],
+ array $ServiceIdentities = [],
+ array $NodeIdentities = [],
+ array $TemplatePolicies = [],
+ bool $Local = false,
+ string $AuthMethod = '',
+ null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL = null,
+ null|Time\Time $ExpirationTime = null,
+ null|Time\Time $CreateTime = null,
+ string $Hash = '',
+ string $Namespace = '',
+ string $Rules = '',
+ string $Partition = '',
+ string $AuthMethodNamespace = ''
+ ) {
+ parent::__construct(
+ CreateIndex: $CreateIndex,
+ ModifyIndex: $ModifyIndex,
+ AccessorID: $AccessorID,
+ SecretID: $SecretID,
+ Description: $Description,
+ Policies: $Policies,
+ Roles: $Roles,
+ ServiceIdentities: $ServiceIdentities,
+ NodeIdentities: $NodeIdentities,
+ TemplatePolicies: $TemplatePolicies,
+ Local: $Local,
+ AuthMethod: $AuthMethod,
+ ExpirationTTL: $ExpirationTTL,
+ ExpirationTime: $ExpirationTime,
+ CreateTime: $CreateTime,
+ Hash: $Hash,
+ Namespace: $Namespace,
+ Rules: $Rules,
+ Partition: $Partition,
+ AuthMethodNamespace: $AuthMethodNamespace
+ );
+ $this->setExpandedPolicies(...$ExpandedPolicies);
+ $this->setExpandedRoles(...$ExpandedRoles);
+ $this->setNamespaceDefaultPolicyIDs(...$NamespaceDefaultPolicyIDs);
+ $this->setNamespaceDefaultRoleIDs(...$NamespaceDefaultRoleIDs);
+ $this->AgentACLDefaultPolicy = $AgentACLDefaultPolicy;
+ $this->AgentACLDownPolicy = $AgentACLDownPolicy;
+ $this->ResolvedByAgent = $ResolvedByAgent;
+}
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLPolicy[]
+ */
+ public function getExpandedPolicies(): array
+ {
+ return $this->ExpandedPolicies;
+ }
+
+ public function setExpandedPolicies(ACLPolicy ...$ExpandedPolicies): self
+ {
+ $this->ExpandedPolicies = $ExpandedPolicies;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ACL\ACLRole>
+ */
+ public function getExpandedRoles(): array
+ {
+ return $this->ExpandedRoles;
+ }
+
+ public function setExpandedRoles(ACLRole ...$ExpandedRoles): self
+ {
+ $this->ExpandedRoles = $ExpandedRoles;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getNamespaceDefaultPolicyIDs(): array
+ {
+ return $this->NamespaceDefaultPolicyIDs;
+ }
+
+ public function setNamespaceDefaultPolicyIDs(string ...$NamespaceDefaultPolicyIDs): self
+ {
+ $this->NamespaceDefaultPolicyIDs = $NamespaceDefaultPolicyIDs;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getNamespaceDefaultRoleIDs(): array
+ {
+ return $this->NamespaceDefaultRoleIDs;
+ }
+
+ public function setNamespaceDefaultRoleIDs(string ...$NamespaceDefaultRoleIDs): self
+ {
+ $this->NamespaceDefaultRoleIDs = $NamespaceDefaultRoleIDs;
+ return $this;
+ }
+
+ public function getAgentACLDefaultPolicy(): string
+ {
+ return $this->AgentACLDefaultPolicy;
+ }
+
+ public function setAgentACLDefaultPolicy(string $AgentACLDefaultPolicy): self
+ {
+ $this->AgentACLDefaultPolicy = $AgentACLDefaultPolicy;
+ return $this;
+ }
+
+ public function getAgentACLDownPolicy(): string
+ {
+ return $this->AgentACLDownPolicy;
+ }
+
+ public function setAgentACLDownPolicy(string $AgentACLDownPolicy): self
+ {
+ $this->AgentACLDownPolicy = $AgentACLDownPolicy;
+ return $this;
+ }
+
+ public function getResolvedByAgent(): string
+ {
+ return $this->ResolvedByAgent;
+ }
+
+ public function setResolvedByAgent(string $ResolvedByAgent): self
+ {
+ $this->ResolvedByAgent = $ResolvedByAgent;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ($n->_jsonUnserializeField($k, $v, $n)) {
+ continue;
+ }
+
+ if ('ExpandedPolicies' === $k) {
+ foreach ($v as $vv) {
+ $n->ExpandedPolicies[] = ACLPolicy::jsonUnserialize($vv);
+ }
+ } elseif ('ExpandedRoles' === $k) {
+ foreach ($v as $vv) {
+ $n->ExpandedRoles[] = ACLRole::jsonUnserialize($vv);
+ }
+ } elseif ('NamespaceDefaultPolicyIDs' === $k) {
+ $n->setNamespaceDefaultPolicyIDs(...$v);
+ } elseif ('NamespaceDefaultRoleIDs' === $k) {
+ $n->setNamespaceDefaultRoleIDs(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = parent::jsonSerialize();
+
+ $out->ExpandedPolicies = $this->ExpandedPolicies;
+ $out->ExpandedRoles = $this->ExpandedRoles;
+ $out->NamespaceDefaultPolicyIDs = $this->NamespaceDefaultPolicyIDs;
+ $out->NamespaceDefaultRoleIDs = $this->NamespaceDefaultRoleIDs;
+ $out->AgentACLDefaultPolicy = $this->AgentACLDefaultPolicy;
+ $out->AgentACLDownPolicy = $this->AgentACLDownPolicy;
+ $out->ResolvedByAgent = $this->ResolvedByAgent;
+
+ return $out;
+ }
+}
diff --git a/src/ACL/ACLTokenExpandedQueryResponse.php b/src/ACL/ACLTokenExpandedQueryResponse.php
new file mode 100644
index 00000000..953e6b51
--- /dev/null
+++ b/src/ACL/ACLTokenExpandedQueryResponse.php
@@ -0,0 +1,43 @@
+ACLTokenExpanded;
+ }
+
+ public function unmarshalValue(mixed $decoded): void
+ {
+ if (null === $decoded) {
+ $this->ACLTokenExpanded = null;
+ return;
+ }
+ $this->ACLTokenExpanded = ACLTokenExpanded::jsonUnserialize($decoded);
+ }
+}
diff --git a/src/ACL/ACLTokenFields.php b/src/ACL/ACLTokenFields.php
new file mode 100644
index 00000000..dc376d0e
--- /dev/null
+++ b/src/ACL/ACLTokenFields.php
@@ -0,0 +1,374 @@
+ */
+ public array $Policies;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> */
+ public array $Roles;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> */
+ public array $ServiceIdentities;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> */
+ public array $NodeIdentities;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> */
+ public array $TemplatePolicies;
+ public bool $Local;
+ public string $AuthMethod;
+ public Time\Duration $ExpirationTTL;
+ public null|Time\Time $ExpirationTime = null;
+ public null|Time\Time $CreateTime;
+ public string $Hash;
+ public string $Namespace;
+ public string $Partition;
+ public string $AuthMethodNamespace;
+
+ public string $Rules;
+
+ public function getCreateIndex(): int
+ {
+ return $this->CreateIndex;
+ }
+
+ public function setCreateIndex(int $CreateIndex): self
+ {
+ $this->CreateIndex = $CreateIndex;
+ return $this;
+ }
+
+ public function getModifyIndex(): int
+ {
+ return $this->ModifyIndex;
+ }
+
+ public function setModifyIndex(int $ModifyIndex): self
+ {
+ $this->ModifyIndex = $ModifyIndex;
+ return $this;
+ }
+
+ public function getAccessorID(): string
+ {
+ return $this->AccessorID;
+ }
+
+ public function setAccessorID(string $AccessorID): self
+ {
+ $this->AccessorID = $AccessorID;
+ return $this;
+ }
+
+ public function getSecretID(): string
+ {
+ return $this->SecretID;
+ }
+
+ public function setSecretID(string $SecretID): self
+ {
+ $this->SecretID = $SecretID;
+ return $this;
+ }
+
+ public function getDescription(): string
+ {
+ return $this->Description;
+ }
+
+ public function setDescription(string $Description): self
+ {
+ $this->Description = $Description;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[]
+ */
+ public function getPolicies(): array
+ {
+ return $this->Policies;
+ }
+
+ public function setPolicies(ACLTokenPolicyLink ...$Policies): self
+ {
+ $this->Policies = $Policies;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink[]
+ */
+ public function getRoles(): array
+ {
+ return $this->Roles;
+ }
+
+ public function setRoles(ACLTokenRoleLink ...$Roles): self
+ {
+ $this->Roles = $Roles;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[]
+ */
+ public function getServiceIdentities(): array
+ {
+ return $this->ServiceIdentities;
+ }
+
+ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self
+ {
+ $this->ServiceIdentities = $ServiceIdentities;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[]
+ */
+ public function getNodeIdentities(): array
+ {
+ return $this->NodeIdentities;
+ }
+
+ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self
+ {
+ $this->NodeIdentities = $NodeIdentities;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[]
+ */
+ public function getTemplatePolicies(): array
+ {
+ return $this->TemplatePolicies;
+ }
+
+ public function setTemplatePolicies(ACLTemplatedPolicy ...$TemplatePolicies): self
+ {
+ $this->TemplatePolicies = $TemplatePolicies;
+ return $this;
+ }
+
+ public function isLocal(): bool
+ {
+ return $this->Local;
+ }
+
+ public function setLocal(bool $Local): self
+ {
+ $this->Local = $Local;
+ return $this;
+ }
+
+ public function getAuthMethod(): string
+ {
+ return $this->AuthMethod;
+ }
+
+ public function setAuthMethod(string $AuthMethod): self
+ {
+ $this->AuthMethod = $AuthMethod;
+ return $this;
+ }
+
+ public function getExpirationTTL(): Time\Duration
+ {
+ return $this->ExpirationTTL;
+ }
+
+ public function setExpirationTTL(null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL): self
+ {
+ $this->ExpirationTTL = Time::Duration($ExpirationTTL);
+ return $this;
+ }
+
+ public function getExpirationTime(): null|Time\Time
+ {
+ return $this->ExpirationTime;
+ }
+
+ public function setExpirationTime(null|Time\Time $ExpirationTime): self
+ {
+ $this->ExpirationTime = $ExpirationTime;
+ return $this;
+ }
+
+ public function getCreateTime(): null|Time\Time
+ {
+ return $this->CreateTime;
+ }
+
+ public function setCreateTime(null|Time\Time $CreateTime): self
+ {
+ $this->CreateTime = $CreateTime;
+ return $this;
+ }
+
+ public function getHash(): string
+ {
+ return $this->Hash;
+ }
+
+ public function setHash(string $Hash): self
+ {
+ $this->Hash = $Hash;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getRules(): string
+ {
+ return $this->Rules;
+ }
+
+ public function setRules(string $Rules): self
+ {
+ $this->Rules = $Rules;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getAuthMethodNamespace(): string
+ {
+ return $this->AuthMethodNamespace;
+ }
+
+ public function setAuthMethodNamespace(string $AuthMethodNamespace): self
+ {
+ $this->AuthMethodNamespace = $AuthMethodNamespace;
+ return $this;
+ }
+
+ protected function _jsonUnserializeField(string $k, mixed $v, object $n): bool
+ {
+ if ('Policies' === $k) {
+ foreach ($v as $vv) {
+ $n->Policies[] = ACLTokenPolicyLink::jsonUnserialize($vv);
+ }
+ } elseif ('Roles' === $k) {
+ foreach ($v as $vv) {
+ $n->Roles[] = ACLTokenRoleLink::jsonUnserialize($vv);
+ }
+ } elseif ('ServiceIdentities' === $k) {
+ foreach ($v as $vv) {
+ $n->ServiceIdentities[] = ACLServiceIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('NodeIdentities' === $k) {
+ foreach ($v as $vv) {
+ $n->NodeIdentities[] = ACLNodeIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('TemplatePolicies' === $k) {
+ foreach ($v as $vv) {
+ $n->TemplatePolicies[] = ACLTemplatedPolicy::jsonUnserialize($vv);
+ }
+ } elseif ('ExpirationTTL' === $k) {
+ $n->setExpirationTTL($v);
+ } elseif ('ExpirationTime' === $k) {
+ $n->ExpirationTime = (null === $v ? $v : parse_time($v));
+ } elseif ('CreateTime' === $k) {
+ $n->CreateTime = parse_time($v);
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
+ protected function _jsonSerialize(\stdClass $out): void
+ {
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ $out->AccessorID = $this->AccessorID;
+ $out->SecretID = $this->SecretID;
+ $out->Description = $this->Description;
+ if ([] !== $this->Policies) {
+ $out->Policies = $this->Policies;
+ }
+ if ([] !== $this->Roles) {
+ $out->Roles = $this->Roles;
+ }
+ if ([] !== $this->ServiceIdentities) {
+ $out->ServiceIdentities = $this->ServiceIdentities;
+ }
+ if ([] !== $this->NodeIdentities) {
+ $out->NodeIdentities = $this->NodeIdentities;
+ }
+ if ([] !== $this->TemplatePolicies) {
+ $out->TemplatePolicies = $this->TemplatePolicies;
+ }
+ $out->Local = $this->Local;
+ if ('' !== $this->AuthMethod) {
+ $out->AuthMethod = $this->AuthMethod;
+ }
+ if (0 !== $this->ExpirationTTL->Nanoseconds()) {
+ $out->ExpirationTTL = $this->ExpirationTTL;
+ }
+ if (null !== $this->ExpirationTime) {
+ $out->ExpirationTime = $this->ExpirationTime->format(DATE_RFC3339);
+ }
+ if (null !== $this->CreateTime && !$this->CreateTime->isZero()) {
+ $out->CreateTime = $this->CreateTime->format(DATE_RFC3339);
+ }
+ $out->Hash = $this->Hash;
+ if ('' !== $this->Rules) {
+ $out->Rules = $this->Rules;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->AuthMethodNamespace) {
+ $out->AuthMethodNamespace = $this->AuthMethodNamespace;
+ }
+ }
+}
diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php
index eff21026..3ccedf64 100644
--- a/src/ACL/ACLTokenListEntry.php
+++ b/src/ACL/ACLTokenListEntry.php
@@ -21,80 +21,84 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use function DCarbone\PHPConsulAPI\PHPLib\parse_time;
-class ACLTokenListEntry extends AbstractModel
+class ACLTokenListEntry extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_POLICIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLTokenPolicyLink::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_ROLES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLTokenRoleLink::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_SERVICE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLServiceIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NODE_IDENTITIES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ACLNodeIdentity::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_AUTH_METHOD => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_EXPIRATION_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_TIME,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CREATE_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_TIME,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_POLICIES = 'Policies';
- private const FIELD_ROLES = 'Roles';
- private const FIELD_SERVICE_IDENTITIES = 'ServiceIdentities';
- private const FIELD_NODE_IDENTITIES = 'NodeIdentities';
- private const FIELD_AUTH_METHOD = 'AuthMethod';
- private const FIELD_EXPIRATION_TIME = 'ExpirationTime';
- private const FIELD_CREATE_TIME = 'CreateTime';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $AccessorID = '';
- public string $Description = '';
- public array $Policies = [];
- public array $Roles = [];
- public array $ServiceIdentities = [];
- public array $NodeIdentities = [];
- public bool $Local = false;
- public string $AuthMethod = '';
- public ?Time\Time $ExpirationTime = null;
- public Time\Time $CreateTime;
- public string $Hash = '';
- public bool $Legacy = false;
- public string $Namespace = '';
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->CreateTime)) {
- $this->CreateTime = Time::New();
- }
- }
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $AccessorID;
+ public string $SecretID;
+ public string $Description;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> */
+ public array $Policies;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> */
+ public array $Roles;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> */
+ public array $ServiceIdentities;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> */
+ public array $NodeIdentities;
+ /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> */
+ public array $TemplatedPolicies;
+ public bool $Local;
+ public string $AuthMethod;
+ public null|Time\Time $ExpirationTime = null;
+ public null|Time\Time $CreateTime;
+ public string $Hash;
+ public bool $Legacy;
+ public string $Namespace;
+ public string $Partition;
+ public string $AuthMethodNamespace;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> $Policies
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> $Roles
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> $ServiceIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> $NodeIdentities
+ * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> $TemplatedPolicies
+ */
+ public function __construct(
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $AccessorID = '',
+ string $SecretID = '',
+ string $Description = '',
+ array $Policies = [],
+ array $Roles = [],
+ array $ServiceIdentities = [],
+ array $NodeIdentities = [],
+ array $TemplatedPolicies = [],
+ bool $Local = false,
+ string $AuthMethod = '',
+ null|Time\Time $ExpirationTime = null,
+ null|Time\Time $CreateTime = null,
+ string $Hash = '',
+ bool $Legacy = false,
+ string $Namespace = '',
+ string $Partition = '',
+ string $AuthMethodNamespace = '',
+ ) {
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->AccessorID = $AccessorID;
+ $this->SecretID = $SecretID;
+ $this->Description = $Description;
+ $this->setPolicies(...$Policies);
+ $this->setRoles(...$Roles);
+ $this->setServiceIdentities(...$ServiceIdentities);
+ $this->setNodeIdentities(...$NodeIdentities);
+ $this->setTemplatedPolicies(...$TemplatedPolicies);
+ $this->Local = $Local;
+ $this->AuthMethod = $AuthMethod;
+ $this->setExpirationTime($ExpirationTime);
+ $this->CreateTime = $CreateTime ?? Time::New();
+ $this->Hash = $Hash;
+ $this->Legacy = $Legacy;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->AuthMethodNamespace = $AuthMethodNamespace;
+}
public function getCreateIndex(): int
{
@@ -129,6 +133,17 @@ public function setAccessorID(string $AccessorID): self
return $this;
}
+ public function getSecretID(): string
+ {
+ return $this->SecretID;
+ }
+
+ public function setSecretID(string $SecretID): self
+ {
+ $this->SecretID = $SecretID;
+ return $this;
+ }
+
public function getDescription(): string
{
return $this->Description;
@@ -140,50 +155,76 @@ public function setDescription(string $Description): self
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[]
+ */
public function getPolicies(): array
{
return $this->Policies;
}
- public function setPolicies(array $Policies): self
+ public function setPolicies(ACLTokenPolicyLink ...$Policies): self
{
$this->Policies = $Policies;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink[]
+ */
public function getRoles(): array
{
return $this->Roles;
}
- public function setRoles(array $Roles): self
+ public function setRoles(ACLTokenRoleLink ...$Roles): self
{
$this->Roles = $Roles;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[]
+ */
public function getServiceIdentities(): array
{
return $this->ServiceIdentities;
}
- public function setServiceIdentities(array $ServiceIdentities): self
+ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self
{
$this->ServiceIdentities = $ServiceIdentities;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[]
+ */
public function getNodeIdentities(): array
{
return $this->NodeIdentities;
}
- public function setNodeIdentities(array $NodeIdentities): self
+ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self
{
$this->NodeIdentities = $NodeIdentities;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[]
+ */
+ public function getTemplatedPolicies(): array
+ {
+ return $this->TemplatedPolicies;
+ }
+
+ public function setTemplatedPolicies(ACLTemplatedPolicy ...$TemplatedPolicies): self
+ {
+ $this->TemplatedPolicies = $TemplatedPolicies;
+ return $this;
+ }
+
public function isLocal(): bool
{
return $this->Local;
@@ -206,23 +247,23 @@ public function setAuthMethod(string $AuthMethod): self
return $this;
}
- public function getExpirationTime(): ?Time\Time
+ public function getExpirationTime(): null|Time\Time
{
return $this->ExpirationTime;
}
- public function setExpirationTime(?Time\Time $ExpirationTime): self
+ public function setExpirationTime(null|Time\Time $ExpirationTime): self
{
$this->ExpirationTime = $ExpirationTime;
return $this;
}
- public function getCreateTime(): Time\Time
+ public function getCreateTime(): null|Time\Time
{
return $this->CreateTime;
}
- public function setCreateTime(Time\Time $CreateTime): self
+ public function setCreateTime(null|Time\Time $CreateTime): self
{
$this->CreateTime = $CreateTime;
return $this;
@@ -260,4 +301,107 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getAuthMethodNamespace(): string
+ {
+ return $this->AuthMethodNamespace;
+ }
+
+ public function setAuthMethodNamespace(string $AuthMethodNamespace): self
+ {
+ $this->AuthMethodNamespace = $AuthMethodNamespace;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Policies' === $k) {
+ foreach ($v as $vv) {
+ $n->Policies[] = ACLTokenPolicyLink::jsonUnserialize($vv);
+ }
+ } elseif ('Roles' === $k) {
+ foreach ($v as $vv) {
+ $n->Roles[] = ACLTokenRoleLink::jsonUnserialize($vv);
+ }
+ } elseif ('ServiceIdentities' === $k) {
+ foreach ($v as $vv) {
+ $n->ServiceIdentities[] = ACLServiceIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('NodeIdentities' === $k) {
+ foreach ($v as $vv) {
+ $n->NodeIdentities[] = ACLNodeIdentity::jsonUnserialize($vv);
+ }
+ } elseif ('TemplatedPolicies' === $k) {
+ foreach ($v as $vv) {
+ $n->TemplatedPolicies[] = ACLTemplatedPolicy::jsonUnserialize($vv);
+ }
+ } elseif ('ExpirationTime' === $k) {
+ $n->ExpirationTime = (null === $v ? null : parse_time($v));
+ } elseif ('CreateTime' === $k) {
+ $n->CreateTime = parse_time($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ $out->AccessorID = $this->AccessorID;
+ $out->SecretID = $this->SecretID;
+ $out->Description = $this->Description;
+ if ([] !== $this->Policies) {
+ $out->Policies = $this->Policies;
+ }
+ if ([] !== $this->Roles) {
+ $out->Roles = $this->Roles;
+ }
+ if ([] !== $this->ServiceIdentities) {
+ $out->ServiceIdentities = $this->ServiceIdentities;
+ }
+ if ([] !== $this->NodeIdentities) {
+ $out->NodeIdentities = $this->NodeIdentities;
+ }
+ if ([] !== $this->TemplatedPolicies) {
+ $out->TemplatedPolicies = $this->TemplatedPolicies;
+ }
+ $out->Local = $this->Local;
+ if ('' !== $this->AuthMethod) {
+ $out->AuthMethod = $this->AuthMethod;
+ }
+ if (null !== $this->ExpirationTime) {
+ $out->ExpirationTime = $this->ExpirationTime->format(DATE_RFC3339);
+ }
+ if (null !== $this->CreateTime) {
+ $out->CreateTime = $this->CreateTime->format(DATE_RFC3339);
+ }
+ $out->Hash = $this->Hash;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->AuthMethodNamespace) {
+ $out->AuthMethodNamespace = $this->AuthMethodNamespace;
+ }
+ return $out;
+ }
}
diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php
index 529e314b..8ecebb6e 100644
--- a/src/ACL/ACLTokenListEntryQueryResponse.php
+++ b/src/ACL/ACLTokenListEntryQueryResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLTokenListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ACLTokenListEntries = [];
+ /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenListEntry[] */
+ public array $ACLTokenListEntries = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenListEntry[]
+ */
+ public function getValue(): array
{
return $this->ACLTokenListEntries;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->ACLTokenListEntries = [];
- foreach ($decodedData as $datum) {
- $this->ACLTokenListEntries[] = new ACLTokenListEntry($datum);
+ foreach ($decoded as $datum) {
+ $this->ACLTokenListEntries[] = ACLTokenListEntry::jsonUnserialize($datum);
}
}
}
diff --git a/src/ACL/ACLTokenPolicyLink.php b/src/ACL/ACLTokenPolicyLink.php
index 5cc163c0..f09beb3a 100644
--- a/src/ACL/ACLTokenPolicyLink.php
+++ b/src/ACL/ACLTokenPolicyLink.php
@@ -22,4 +22,12 @@
class ACLTokenPolicyLink extends ACLLink
{
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
}
diff --git a/src/ACL/ACLTokenQueryResponse.php b/src/ACL/ACLTokenQueryResponse.php
index 5092f215..1c72a9bc 100644
--- a/src/ACL/ACLTokenQueryResponse.php
+++ b/src/ACL/ACLTokenQueryResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLTokenQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?ACLToken $ACLToken = null;
+ public null|ACLToken $ACLToken = null;
- public function getValue(): ?ACLToken
+ public function getValue(): null|ACLToken
{
return $this->ACLToken;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLToken = new ACLToken((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLToken = null;
+ return;
+ }
+ $this->ACLToken = ACLToken::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/ACLTokenRoleLink.php b/src/ACL/ACLTokenRoleLink.php
index 22133f1d..f5b96b89 100644
--- a/src/ACL/ACLTokenRoleLink.php
+++ b/src/ACL/ACLTokenRoleLink.php
@@ -22,4 +22,12 @@
class ACLTokenRoleLink extends ACLLink
{
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
}
diff --git a/src/ACL/ACLTokenWriteResponse.php b/src/ACL/ACLTokenWriteResponse.php
index 1a1a4d91..55ad8ce2 100644
--- a/src/ACL/ACLTokenWriteResponse.php
+++ b/src/ACL/ACLTokenWriteResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ACLTokenWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?ACLToken $ACLToken = null;
+ public null|ACLToken $ACLToken = null;
- public function getValue(): ?ACLToken
+ public function getValue(): null|ACLToken
{
return $this->ACLToken;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->ACLToken = new ACLToken((array)$decodedData);
+ if (null === $decoded) {
+ $this->ACLToken = null;
+ return;
+ }
+ $this->ACLToken = ACLToken::jsonUnserialize($decoded);
}
}
diff --git a/src/ACL/BindingRuleBindType.php b/src/ACL/BindingRuleBindType.php
new file mode 100644
index 00000000..d42ece3c
--- /dev/null
+++ b/src/ACL/BindingRuleBindType.php
@@ -0,0 +1,32 @@
+ Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_CA_CERT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_ACCOUNT_JWT => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
+ public string $Host;
+ public string $CACert;
+ public string $ServiceAccountJWT;
- private const FIELD_HOST = 'Host';
- private const FIELD_CA_CERT = 'CACert';
- private const FIELD_SERVICE_ACCOUNT_JWT = 'ServiceAccountJWT';
-
- public string $Host = '';
- public string $CACert = '';
- public string $ServiceAccountJWT = '';
+ public function __construct(string $Host = '', string $CACert = '', string $ServiceAccountJWT = '')
+ {
+ $this->Host = $Host;
+ $this->CACert = $CACert;
+ $this->ServiceAccountJWT = $ServiceAccountJWT;
+ }
public function getHost(): string
{
@@ -77,16 +72,38 @@ public function setServiceAccountJWT(string $ServiceAccountJWT): self
* RenderToConfig converts this into a map[string]interface{} suitable for use
* in the ACLAuthMethod.Config field.
*
- * @return \DCarbone\PHPConsulAPI\FakeMap
+ * @return array
*/
- public function RenderToConfig(): FakeMap
+ public function RenderToConfig(): array
+ {
+ return [
+ 'Host' => $this->Host,
+ 'CACert' => $this->CACert,
+ 'ServiceAccountJWT' => $this->ServiceAccountJWT,
+ ];
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
{
- return new FakeMap(
- [
- self::FIELD_HOST => $this->Host,
- self::FIELD_CA_CERT => $this->CACert,
- self::FIELD_SERVICE_ACCOUNT_JWT => $this->ServiceAccountJWT,
- ]
- );
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Host) {
+ $out->Host = $this->Host;
+ }
+ if ('' !== $this->CACert) {
+ $out->CACert = $this->CACert;
+ }
+ if ('' !== $this->ServiceAccountJWT) {
+ $out->ServiceAccountJWT = $this->ServiceAccountJWT;
+ }
+ return $out;
}
}
diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php
index d8568659..a2ee0114 100644
--- a/src/ACL/OIDCAuthMethodConfig.php
+++ b/src/ACL/OIDCAuthMethodConfig.php
@@ -20,8 +20,448 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\Go\Time;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class OIDCAuthMethodConfig extends AbstractModel
+class OIDCAuthMethodConfig extends AbstractType
{
+ /** @var array */
+ public array $JWTSupportedAlgs;
+ /** @var array */
+ public array $BoundAudiences;
+ /** @var array */
+ public array $ClaimMappings;
+ /** @var array */
+ public array $ListClaimMappings;
+ public string $OIDCDiscoveryURL;
+ public string $OIDCDiscoveryCACert;
+ public string $OIDCClientID;
+ public string $OIDCClientSecret;
+ /** @var array */
+ public array $OIDCScopes;
+ /** @var array */
+ public array $OIDCACRValues;
+ /** @var array */
+ public array $AllowedRedirectURIs;
+ public bool $VerboseOIDCLogging;
+ public string $JWKSURL;
+ public string $JWKSCACert;
+ /** @var array */
+ public array $JWTValidationPubKeys;
+ public string $BoundIssuer;
+ public Time\Duration $ExpirationLeeway;
+ public Time\Duration $NotBeforeLeeway;
+ public Time\Duration $ClockSkewLeeway;
+
+ /**
+ * @param array $JWTSupportedAlgs
+ * @param array $BoundAudiences
+ * @param array $ClaimMappings
+ * @param array $ListClaimMappings
+ * @param array $OIDCScopes
+ * @param array $OIDCACRValues
+ * @param array $AllowedRedirectURIs
+ * @param array $JWTValidationPubKeys
+ */
+ public function __construct(
+ array $JWTSupportedAlgs = [],
+ array $BoundAudiences = [],
+ array $ClaimMappings = [],
+ array $ListClaimMappings = [],
+ string $OIDCDiscoveryURL = '',
+ string $OIDCDiscoveryCACert = '',
+ string $OIDCClientID = '',
+ string $OIDCClientSecret = '',
+ array $OIDCScopes = [],
+ array $OIDCACRValues = [],
+ array $AllowedRedirectURIs = [],
+ bool $VerboseOIDCLogging = false,
+ string $JWKSURL = '',
+ string $JWKSCACert = '',
+ array $JWTValidationPubKeys = [],
+ string $BoundIssuer = '',
+ null|int|float|string|\DateInterval|Time\Duration $ExpirationLeeway = null,
+ null|int|float|string|\DateInterval|Time\Duration $NotBeforeLeeway = null,
+ null|int|float|string|\DateInterval|Time\Duration $ClockSkewLeeway = null,
+ ) {
+ $this->setJWTSupportedAlgs(...$JWTSupportedAlgs);
+ $this->setBoundAudiences(...$BoundAudiences);
+ $this->setClaimMappings($ClaimMappings);
+ $this->setListClaimMappings($ListClaimMappings);
+ $this->OIDCDiscoveryURL = $OIDCDiscoveryURL;
+ $this->OIDCDiscoveryCACert = $OIDCDiscoveryCACert;
+ $this->OIDCClientID = $OIDCClientID;
+ $this->OIDCClientSecret = $OIDCClientSecret;
+ $this->setOIDCScopes(...$OIDCScopes);
+ $this->setOIDCACRValues(...$OIDCACRValues);
+ $this->setAllowedRedirectURIs(...$AllowedRedirectURIs);
+ $this->VerboseOIDCLogging = $VerboseOIDCLogging;
+ $this->JWKSURL = $JWKSURL;
+ $this->JWKSCACert = $JWKSCACert;
+ $this->setJWTValidationPubKeys(...$JWTValidationPubKeys);
+ $this->BoundIssuer = $BoundIssuer;
+ $this->setExpirationLeeway($ExpirationLeeway);
+ $this->setNotBeforeLeeway($NotBeforeLeeway);
+ $this->setClockSkewLeeway($ClockSkewLeeway);
+ }
+
+ /**
+ * @return array
+ */
+ public function getJWTSupportedAlgs(): array
+ {
+ return $this->JWTSupportedAlgs;
+ }
+
+ public function setJWTSupportedAlgs(string ...$JWTSupportedAlgs): self
+ {
+ $this->JWTSupportedAlgs = $JWTSupportedAlgs;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getBoundAudiences(): array
+ {
+ return $this->BoundAudiences;
+ }
+
+ public function setBoundAudiences(string ...$BoundAudiences): self
+ {
+ $this->BoundAudiences = $BoundAudiences;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getClaimMappings(): array
+ {
+ return $this->ClaimMappings;
+ }
+
+ public function setClaimMapping(string $k, string $v): self
+ {
+ $this->ClaimMappings[$k] = $v;
+ return $this;
+ }
+
+ /**
+ * @param array|\stdClass|null $ClaimMappings
+ */
+ public function setClaimMappings(null|array|\stdClass $ClaimMappings): self
+ {
+ $this->ClaimMappings = [];
+ if (null === $ClaimMappings) {
+ return $this;
+ }
+ foreach ($ClaimMappings as $k => $v) {
+ $this->setClaimMapping($k, $v);
+ }
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getListClaimMappings(): array
+ {
+ return $this->ListClaimMappings;
+ }
+
+ public function setListClaimMapping(string $k, string $v): self
+ {
+ $this->ListClaimMappings[$k] = $v;
+ return $this;
+ }
+
+ /**
+ * @param array|\stdClass|null $ListClaimMappings
+ */
+ public function setListClaimMappings(null|array|\stdClass $ListClaimMappings): self
+ {
+ $this->ListClaimMappings = [];
+ if (null === $ListClaimMappings) {
+ return $this;
+ }
+ foreach ($ListClaimMappings as $k => $v) {
+ $this->setListClaimMapping($k, $v);
+ }
+ return $this;
+ }
+
+ public function getOIDCDiscoveryURL(): string
+ {
+ return $this->OIDCDiscoveryURL;
+ }
+
+ public function setOIDCDiscoveryURL(string $OIDCDiscoveryURL): self
+ {
+ $this->OIDCDiscoveryURL = $OIDCDiscoveryURL;
+ return $this;
+ }
+
+ public function getOIDCDiscoveryCACert(): string
+ {
+ return $this->OIDCDiscoveryCACert;
+ }
+
+ public function setOIDCDiscoveryCACert(string $OIDCDiscoveryCACert): self
+ {
+ $this->OIDCDiscoveryCACert = $OIDCDiscoveryCACert;
+ return $this;
+ }
+
+ public function getOIDCClientID(): string
+ {
+ return $this->OIDCClientID;
+ }
+
+ public function setOIDCClientID(string $OIDCClientID): self
+ {
+ $this->OIDCClientID = $OIDCClientID;
+ return $this;
+ }
+
+ public function getOIDCClientSecret(): string
+ {
+ return $this->OIDCClientSecret;
+ }
+
+ public function setOIDCClientSecret(string $OIDCClientSecret): self
+ {
+ $this->OIDCClientSecret = $OIDCClientSecret;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getOIDCScopes(): array
+ {
+ return $this->OIDCScopes;
+ }
+
+ public function setOIDCScopes(string ...$OIDCScopes): self
+ {
+ $this->OIDCScopes = $OIDCScopes;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getOIDCACRValues(): array
+ {
+ return $this->OIDCACRValues;
+ }
+
+ public function setOIDCACRValues(string ...$OIDCACRValues): self
+ {
+ $this->OIDCACRValues = $OIDCACRValues;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getAllowedRedirectURIs(): array
+ {
+ return $this->AllowedRedirectURIs;
+ }
+
+ public function setAllowedRedirectURIs(string ...$AllowedRedirectURIs): self
+ {
+ $this->AllowedRedirectURIs = $AllowedRedirectURIs;
+ return $this;
+ }
+
+ public function isVerboseOIDCLogging(): bool
+ {
+ return $this->VerboseOIDCLogging;
+ }
+
+ public function setVerboseOIDCLogging(bool $VerboseOIDCLogging): self
+ {
+ $this->VerboseOIDCLogging = $VerboseOIDCLogging;
+ return $this;
+ }
+
+ public function getJWKSURL(): string
+ {
+ return $this->JWKSURL;
+ }
+
+ public function setJWKSURL(string $JWKSURL): self
+ {
+ $this->JWKSURL = $JWKSURL;
+ return $this;
+ }
+
+ public function getJWKSCACert(): string
+ {
+ return $this->JWKSCACert;
+ }
+
+ public function setJWKSCACert(string $JWKSCACert): self
+ {
+ $this->JWKSCACert = $JWKSCACert;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getJWTValidationPubKeys(): array
+ {
+ return $this->JWTValidationPubKeys;
+ }
+
+ public function setJWTValidationPubKeys(string ...$JWTValidationPubKeys): self
+ {
+ $this->JWTValidationPubKeys = $JWTValidationPubKeys;
+ return $this;
+ }
+
+ public function getBoundIssuer(): string
+ {
+ return $this->BoundIssuer;
+ }
+
+ public function setBoundIssuer(string $BoundIssuer): self
+ {
+ $this->BoundIssuer = $BoundIssuer;
+ return $this;
+ }
+
+ public function getExpirationLeeway(): Time\Duration
+ {
+ return $this->ExpirationLeeway;
+ }
+
+ public function setExpirationLeeway(null|int|float|string|\DateInterval|Time\Duration $ExpirationLeeway): self
+ {
+ $this->ExpirationLeeway = Time::Duration($ExpirationLeeway);
+ return $this;
+ }
+
+ public function getNotBeforeLeeway(): Time\Duration
+ {
+ return $this->NotBeforeLeeway;
+ }
+
+ public function setNotBeforeLeeway(null|int|float|string|\DateInterval|Time\Duration $NotBeforeLeeway): self
+ {
+ $this->NotBeforeLeeway = Time::Duration($NotBeforeLeeway);
+ return $this;
+ }
+
+ public function getClockSkewLeeway(): Time\Duration
+ {
+ return $this->ClockSkewLeeway;
+ }
+
+ public function setClockSkewLeeway(null|int|float|string|\DateInterval|Time\Duration $ClockSkewLeeway): self
+ {
+ $this->ClockSkewLeeway = Time::Duration($ClockSkewLeeway);
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('JWTSupportedAlgs' === $k) {
+ $n->setJWTSupportedAlgs(...$v);
+ } elseif ('BoundAudiences' === $k) {
+ $n->setBoundAudiences(...$v);
+ } elseif ('ClaimMappings' === $k) {
+ $n->setClaimMappings($v);
+ } elseif ('ListClaimMappings' === $k) {
+ $n->setListClaimMappings($v);
+ } elseif ('OIDCScopes' === $k) {
+ $n->setOIDCScopes(...$v);
+ } elseif ('OIDCACRValues' === $k) {
+ $n->setOIDCACRValues(...$v);
+ } elseif ('AllowedRedirectURIs' === $k) {
+ $n->setAllowedRedirectURIs(...$v);
+ } elseif ('JWTValidationPubKeys' === $k) {
+ $n->setJWTValidationPubKeys(...$v);
+ } elseif ('ExpirationLeeway' === $k) {
+ $n->setExpirationLeeway($v);
+ } elseif ('NotBeforeLeeway' === $k) {
+ $n->setNotBeforeLeeway($v);
+ } elseif ('ClockSkewLeeway' === $k) {
+ $n->setClockSkewLeeway($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+
+ if ([] !== $this->JWTSupportedAlgs) {
+ $out->JWTSupportedAlgs = $this->JWTSupportedAlgs;
+ }
+ if ([] !== $this->BoundAudiences) {
+ $out->BoundAudiences = $this->BoundAudiences;
+ }
+ if ([] !== $this->ClaimMappings) {
+ $out->ClaimMappings = $this->ClaimMappings;
+ }
+ if ([] !== $this->ListClaimMappings) {
+ $out->ListClaimMappings = $this->ListClaimMappings;
+ }
+ if ('' !== $this->OIDCDiscoveryURL) {
+ $out->OIDCDiscoveryURL = $this->OIDCDiscoveryURL;
+ }
+ if ('' !== $this->OIDCDiscoveryCACert) {
+ $out->OIDCDiscoveryCACert = $this->OIDCDiscoveryCACert;
+ }
+ if ('' !== $this->OIDCClientID) {
+ $out->OIDCClientID = $this->OIDCClientID;
+ }
+ if ('' !== $this->OIDCClientSecret) {
+ $out->OIDCClientSecret = $this->OIDCClientSecret;
+ }
+ if ([] !== $this->OIDCScopes) {
+ $out->OIDCScopes = $this->OIDCScopes;
+ }
+ if ([] !== $this->OIDCACRValues) {
+ $out->OIDCACRValues = $this->OIDCACRValues;
+ }
+ if ([] !== $this->AllowedRedirectURIs) {
+ $out->AllowedRedirectURIs = $this->AllowedRedirectURIs;
+ }
+ if ($this->VerboseOIDCLogging) {
+ $out->VerboseOIDCLogging = $this->VerboseOIDCLogging;
+ }
+ if ('' !== $this->JWKSURL) {
+ $out->JWKSURL = $this->JWKSURL;
+ }
+ if ('' !== $this->JWKSCACert) {
+ $out->JWKSCACert = $this->JWKSCACert;
+ }
+ if ([] !== $this->JWTValidationPubKeys) {
+ $out->JWTValidationPubKeys = $this->JWTValidationPubKeys;
+ }
+ if ('' !== $this->BoundIssuer) {
+ $out->BoundIssuer = $this->BoundIssuer;
+ }
+ if (0 !== $this->ExpirationLeeway->Nanoseconds()) {
+ $out->ExpirationLeeway = $this->ExpirationLeeway;
+ }
+ if (0 !== $this->NotBeforeLeeway->Nanoseconds()) {
+ $out->NotBeforeLeeway = $this->NotBeforeLeeway;
+ }
+ if (0 !== $this->ClockSkewLeeway->Nanoseconds()) {
+ $out->ClockSkewLeeway = $this->ClockSkewLeeway;
+ }
+ return $out;
+ }
}
diff --git a/src/AbstractModel.php b/src/AbstractModel.php
deleted file mode 100644
index d38bae8b..00000000
--- a/src/AbstractModel.php
+++ /dev/null
@@ -1,93 +0,0 @@
- $value) {
- $this->unmarshalField($field, $value);
- }
- }
-
- public function __set(string $field, $value): void
- {
- $this->_dyn[$field] = $value;
- }
-
- public function &__get(string $field)
- {
- if (!array_key_exists($field, $this->_dyn)) {
- $this->_dyn[$field] = null;
- }
- return $this->_dyn[$field];
- }
-
- /**
- * todo: this picks up non-public fields. externalize this at some point.
- *
- * @return array
- */
- public function jsonSerialize(): array
- {
- $out = [];
- // marshal fields
- foreach ((array)$this as $field => $value) {
- // marshal dynamically defined fields
- // todo: this is crap.
- if (substr($field, -4) === '_dyn') {
- if ([] !== $value) {
- foreach ($value as $k => $v) {
- $this->marshalField($out, $k, $v);
- }
- }
- } else {
- $this->marshalField($out, $field, $value);
- }
- }
- return $out;
- }
-
- public function __toString(): string
- {
- return static::class;
- }
-}
diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php
index 55235175..564cadac 100644
--- a/src/Agent/AgentCheck.php
+++ b/src/Agent/AgentCheck.php
@@ -20,42 +20,51 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Health\HealthCheckDefinition;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentCheck extends AbstractModel
+class AgentCheck extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_DEFINITION => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthCheckDefinition::class,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_DEFINITION = 'Definition';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Node = '';
- public string $CheckID = '';
- public string $Name = '';
- public string $Status = '';
- public string $Notes = '';
- public string $Output = '';
- public string $ServiceID = '';
- public string $ServiceName = '';
- public string $Type = '';
+ public string $Node;
+ public string $CheckID;
+ public string $Name;
+ public string $Status;
+ public string $Notes;
+ public string $Output;
+ public string $ServiceID;
+ public string $ServiceName;
+ public string $Type;
public HealthCheckDefinition $Definition;
- public string $Namespace = '';
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->Definition)) {
- $this->Definition = new HealthCheckDefinition(null);
- }
- }
+ public string $Namespace;
+ public string $Partition;
+
+ public function __construct(
+ string $Node = '',
+ string $CheckID = '',
+ string $Name = '',
+ string $Status = '',
+ string $Notes = '',
+ string $Output = '',
+ string $ServiceID = '',
+ string $ServiceName = '',
+ string $Type = '',
+ null|HealthCheckDefinition $Definition = null,
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->Node = $Node;
+ $this->CheckID = $CheckID;
+ $this->Name = $Name;
+ $this->Status = $Status;
+ $this->Notes = $Notes;
+ $this->Output = $Output;
+ $this->ServiceID = $ServiceID;
+ $this->ServiceName = $ServiceName;
+ $this->Type = $Type;
+ $this->Definition = $Definition ?? new HealthCheckDefinition();
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+}
public function getNode(): string
{
@@ -177,6 +186,42 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Definition' === $k) {
+ $n->Definition = HealthCheckDefinition::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ $out->CheckID = $this->CheckID;
+ $out->Name = $this->Name;
+ $out->Status = $this->Status;
+ $out->Notes = $this->Notes;
+ $out->Output = $this->Output;
+ $out->ServiceID = $this->ServiceID;
+ $out->ServiceName = $this->ServiceName;
+ $out->Type = $this->Type;
+ $out->Definition = $this->Definition;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
+
public function __toString(): string
{
return $this->CheckID;
diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php
index 0a2210f0..e4c8a0e5 100644
--- a/src/Agent/AgentCheckRegistration.php
+++ b/src/Agent/AgentCheckRegistration.php
@@ -20,23 +20,79 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\Values;
class AgentCheckRegistration extends AgentServiceCheck
{
- protected const FIELDS = [
- self::FIELD_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_ID = 'ID';
- private const FIELD_SERVICE_ID = 'ServiceID';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $ServiceID = '';
- public string $Namespace = '';
+ public string $ID;
+ public string $ServiceID;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array $Args
+ */
+ public function __construct(
+ string $ID = '',
+ string $ServiceID = '',
+ string $CheckID = '',
+ string $Name = '',
+ array $Args = [],
+ string $DockerContainerID = '',
+ string $Shell = '',
+ string $Interval = '',
+ string $Timeout = '',
+ string $TTL = '',
+ string $HTTP = '',
+ null|\stdClass|array|Values $Header = null,
+ string $Method = '',
+ string $TCP = '',
+ string $Status = '',
+ string $Notes = '',
+ bool $TLSSkipVerify = false,
+ string $GRPC = '',
+ bool $GRPCUseTLS = false,
+ string $H2PING = '',
+ bool $H2PingUseTLS = false,
+ string $AliasNode = '',
+ string $AliasService = '',
+ int $SuccessBeforePassing = 0,
+ int $FailuresBeforeCritical = 0,
+ string $DeregisterCriticalServiceAfter = '',
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ parent::__construct(
+ CheckID: $CheckID,
+ Name: $Name,
+ Args: $Args,
+ DockerContainerID: $DockerContainerID,
+ Shell: $Shell,
+ Interval: $Interval,
+ Timeout: $Timeout,
+ TTL: $TTL,
+ HTTP: $HTTP,
+ Header: $Header,
+ Method: $Method,
+ TCP: $TCP,
+ Status: $Status,
+ Notes: $Notes,
+ TLSSkipVerify: $TLSSkipVerify,
+ GRPC: $GRPC,
+ GRPCUseTLS: $GRPCUseTLS,
+ H2PING: $H2PING,
+ H2PINGUseTLS: $H2PingUseTLS,
+ AliasNode: $AliasNode,
+ AliasService: $AliasService,
+ SuccessBeforePassing: $SuccessBeforePassing,
+ FailuresBeforeCritical: $FailuresBeforeCritical,
+ DeregisterCriticalServiceAfter: $DeregisterCriticalServiceAfter,
+ );
+ $this->ID = $ID;
+ $this->ServiceID = $ServiceID;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ }
public function getID(): string
{
@@ -70,4 +126,39 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = parent::jsonSerialize();
+ if ('' !== $this->ID) {
+ $out->ID = $this->ID;
+ }
+ if ('' !== $this->ServiceID) {
+ $out->ServiceID = $this->ServiceID;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if (isset($out->Name) && $out->Name === '') {
+ unset($out->Name);
+ }
+ if (isset($out->Notes) && $out->Notes === '') {
+ unset($out->Notes);
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php
index aed5f53a..a5276315 100644
--- a/src/Agent/AgentCheckUpdate.php
+++ b/src/Agent/AgentCheckUpdate.php
@@ -20,21 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-final class AgentCheckUpdate extends AbstractModel
+class AgentCheckUpdate extends AbstractType
{
- public string $Status = '';
- public string $Output = '';
+ public string $Status;
+ public string $Output;
+
+ public function __construct(string $Status = '', string $Output = '')
+ {
+ $this->Status = $Status;
+ $this->Output = $Output;
+ }
public function getStatus(): string
{
return $this->Status;
}
- public function setStatus(string $status): self
+ public function setStatus(string $Status): self
{
- $this->Status = $status;
+ $this->Status = $Status;
return $this;
}
@@ -43,12 +49,29 @@ public function getOutput(): string
return $this->Output;
}
- public function setOutput(string $output): self
+ public function setOutput(string $Output): self
{
- $this->Output = $output;
+ $this->Output = $Output;
return $this;
}
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Status = $this->Status;
+ $out->Output = $this->Output;
+ return $out;
+ }
+
public function __toString(): string
{
return sprintf('%s: %s', $this->Status, $this->Output);
diff --git a/src/Agent/AgentChecksResponse.php b/src/Agent/AgentChecksResponse.php
index 4cf50761..99fbd7ee 100644
--- a/src/Agent/AgentChecksResponse.php
+++ b/src/Agent/AgentChecksResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class AgentChecksResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?array $Checks = null;
+ /** @var \DCarbone\PHPConsulAPI\Agent\AgentCheck[] */
+ public array $Checks = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\AgentCheck[]|null
+ */
+ public function getValue(): null|array
{
return $this->Checks;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->Checks = [];
- foreach ($decodedData as $k => $v) {
- $this->Checks[$k] = new AgentCheck($v);
+ foreach ($decoded as $k => $v) {
+ $this->Checks[$k] = AgentCheck::jsonUnserialize($v);
}
}
}
diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php
index 7e896ead..25aac427 100644
--- a/src/Agent/AgentClient.php
+++ b/src/Agent/AgentClient.php
@@ -21,21 +21,27 @@
*/
use DCarbone\Go\HTTP;
-use DCarbone\PHPConsulAPI\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
use DCarbone\PHPConsulAPI\Consul;
-use DCarbone\PHPConsulAPI\Error;
-use DCarbone\PHPConsulAPI\MapResponse;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\MapResponse;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedStringResponse;
use DCarbone\PHPConsulAPI\QueryOptions;
-use DCarbone\PHPConsulAPI\Request;
-use DCarbone\PHPConsulAPI\ValuedStringResponse;
+use DCarbone\PHPConsulAPI\PHPLib\Request;
class AgentClient extends AbstractClient
{
- private ?MapResponse $_self = null;
-
+ /** @var \DCarbone\PHPConsulAPI\PHPLib\MapResponse|null */
+ private null|MapResponse $_self = null;
+
+ /**
+ * @param bool $refresh
+ * @return \DCarbone\PHPConsulAPI\PHPLib\MapResponse
+ * @throws \Exception
+ */
public function Self(bool $refresh = false): MapResponse
{
- if (!$refresh && isset($this->_self)) {
+ if (!$refresh && null !== $this->_self) {
return $this->_self;
}
$resp = $this->_requireOK($this->_doGet('v1/agent/self', null));
@@ -47,6 +53,10 @@ public function Self(bool $refresh = false): MapResponse
return $ret;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\PHPLib\MapResponse
+ * @throws \Exception
+ */
public function Host(): MapResponse
{
$resp = $this->_requireOK($this->_doGet('v1/agent/host', null));
@@ -63,7 +73,7 @@ public function Metrics(): MetricsInfoResponse
return $ret;
}
- public function Reload(): ?Error
+ public function Reload(): null|Error
{
return $this->_executePut('v1/agent/reload', null, null)->Err;
}
@@ -76,8 +86,8 @@ public function NodeName(bool $refresh = false): ValuedStringResponse
if (null !== $self->Err) {
return $ret;
}
- if (isset($self->Map['Config'], $self->Map['Config']['NodeName'])) {
- $ret->Value = $self->Map['Config']['NodeName'];
+ if (isset($self->Map['Config']->NodeName)) {
+ $ret->Value = $self->Map['Config']->NodeName;
}
return $ret;
}
@@ -146,29 +156,28 @@ public function AgentHealthServiceByName(string $service): AgentHealthServicesRe
$resp = $this->_requireOK($this->_do($r));
if (null !== $resp->Err) {
- return new AgentHealthServicesResponse(Consul::HealthCritical, null, $resp->Err);
+ return new AgentHealthServicesResponse(Consul::HealthCritical, [], $resp->Err);
}
if (HTTP\StatusNotFound === $resp->Response->getStatusCode()) {
- return new AgentHealthServicesResponse(Consul::HealthCritical, null, null);
+ return new AgentHealthServicesResponse(Consul::HealthCritical, [], null);
}
$dec = $this->_decodeBody($resp->Response->getBody());
if (null !== $dec->Err) {
- return new AgentHealthServicesResponse(Consul::HealthCritical, null, $dec->Err);
+ return new AgentHealthServicesResponse(Consul::HealthCritical, [], $dec->Err);
}
$status = match ($resp->Response->getStatusCode()) {
HTTP\StatusOK => Consul::HealthPassing,
HTTP\StatusTooManyRequests => Consul::HealthWarning,
- HTTP\StatusServiceUnavailable => Consul::HealthCritical,
default => Consul::HealthCritical,
};
return new AgentHealthServicesResponse($status, $dec->Decoded, null);
}
- public function Service(string $serviceID, ?QueryOptions $opts = null): AgentServiceResponse
+ public function Service(string $serviceID, null|QueryOptions $opts = null): AgentServiceResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/agent/service/%s', $serviceID), $opts));
$ret = new AgentServiceResponse();
@@ -197,7 +206,7 @@ public function MemberOpts(MemberOpts $memberOpts): AgentMembersResponse
return $ret;
}
- public function ServiceRegisterOpts(AgentServiceRegistration $service, ServiceRegisterOpts $registerOpts): ?Error
+ public function ServiceRegisterOpts(AgentServiceRegistration $service, ServiceRegisterOpts $registerOpts): null|Error
{
$r = $this->_newPutRequest('v1/agent/service/register', $service, null);
if ($registerOpts->ReplaceExistingChecks) {
@@ -206,33 +215,33 @@ public function ServiceRegisterOpts(AgentServiceRegistration $service, ServiceRe
return $this->_requireOK($this->_do($r))->Err;
}
- public function ServiceRegister(AgentServiceRegistration $service): ?Error
+ public function ServiceRegister(AgentServiceRegistration $service): null|Error
{
- return $this->ServiceRegisterOpts($service, new ServiceRegisterOpts(['ReplaceExistingChecks' => false]));
+ return $this->ServiceRegisterOpts($service, new ServiceRegisterOpts(ReplaceExistingChecks: false));
}
- public function ServiceDeregister(string $serviceID): ?Error
+ public function ServiceDeregister(string $serviceID): null|Error
{
$r = new Request(HTTP\MethodPut, sprintf('v1/agent/service/deregister/%s', $serviceID), $this->_config, null);
return $this->_requireOK($this->_do($r))->Err;
}
- public function PassTTL(string $checkID, string $note): ?Error
+ public function PassTTL(string $checkID, string $note): null|Error
{
return $this->UpdateTTL($checkID, $note, 'pass');
}
- public function WarnTTL(string $checkID, string $note): ?Error
+ public function WarnTTL(string $checkID, string $note): null|Error
{
return $this->UpdateTTL($checkID, $note, 'warn');
}
- public function FailTTL(string $checkID, string $note): ?Error
+ public function FailTTL(string $checkID, string $note): null|Error
{
return $this->UpdateTTL($checkID, $note, 'fail');
}
- public function UpdateTTL(string $checkID, string $output, string $status): ?Error
+ public function UpdateTTL(string $checkID, string $output, string $status): null|Error
{
switch ($status) {
case Consul::HealthPassing:
@@ -256,23 +265,23 @@ public function UpdateTTL(string $checkID, string $output, string $status): ?Err
HTTP\MethodPut,
sprintf('v1/agent/check/update/%s', $checkID),
$this->_config,
- new AgentCheckUpdate(['Output' => $output, 'Status' => $status])
+ new AgentCheckUpdate(Status: $status, Output: $output)
);
return $this->_requireOK($this->_do($r))->Err;
}
- public function CheckRegister(AgentCheckRegistration $check): ?Error
+ public function CheckRegister(AgentCheckRegistration $check): null|Error
{
return $this->_executePut('v1/agent/check/register', $check, null)->Err;
}
- public function CheckDeregister(string $checkID): ?Error
+ public function CheckDeregister(string $checkID): null|Error
{
return $this->_executePut(sprintf('v1/agent/check/deregister/%s', $checkID), null, null)->Err;
}
- public function Join(string $addr, bool $wan = false): ?Error
+ public function Join(string $addr, bool $wan = false): null|Error
{
$r = $this->_newPutRequest(sprintf('v1/agent/join/%s', $addr), null, null);
if ($wan) {
@@ -281,24 +290,24 @@ public function Join(string $addr, bool $wan = false): ?Error
return $this->_requireOK($this->_do($r))->Err;
}
- public function Leave(): ?Error
+ public function Leave(): null|Error
{
return $this->_executePut('v1/agent/leave', null, null)->Err;
}
- public function ForceLeave(string $node): ?Error
+ public function ForceLeave(string $node): null|Error
{
return $this->_executePut(sprintf('v1/agent/force-leave/%s', $node), null, null)->Err;
}
- public function ForceLeavePrune(string $node): ?Error
+ public function ForceLeavePrune(string $node): null|Error
{
$r = $this->_newPutRequest(sprintf('v1/agent/force-leave/%s', $node), null, null);
$r->params->set('prune', '1');
return $this->_requireOK($this->_do($r))->Err;
}
- public function EnableServiceMaintenance(string $serviceID, string $reason = ''): ?Error
+ public function EnableServiceMaintenance(string $serviceID, string $reason = ''): null|Error
{
$r = $this->_newPutRequest(sprintf('v1/agent/service/maintenance/%s', $serviceID), null, null);
$r->params->set('enable', 'true');
@@ -306,14 +315,14 @@ public function EnableServiceMaintenance(string $serviceID, string $reason = '')
return $this->_requireOK($this->_do($r))->Err;
}
- public function DisableServiceMaintenance(string $serviceID): ?Error
+ public function DisableServiceMaintenance(string $serviceID): null|Error
{
$r = $this->_newPutRequest(sprintf('v1/agent/service/maintenance/%s', $serviceID), null, null);
$r->params->set('enable', 'false');
return $this->_requireOK($this->_do($r))->Err;
}
- public function EnableNodeMaintenance(string $reason = ''): ?Error
+ public function EnableNodeMaintenance(string $reason = ''): null|Error
{
$r = $this->_newPutRequest('v1/agent/maintenance', null, null);
$r->params->set('enable', 'true');
@@ -321,7 +330,7 @@ public function EnableNodeMaintenance(string $reason = ''): ?Error
return $this->_requireOK($this->_do($r))->Err;
}
- public function DisableNodeMaintenance(): ?Error
+ public function DisableNodeMaintenance(): null|Error
{
$r = $this->_newPutRequest('v1/agent/maintenance', null, null);
$r->params->set('enable', 'false');
diff --git a/src/Agent/AgentHealthServiceResponse.php b/src/Agent/AgentHealthServiceResponse.php
index 1da8b3c8..b7764403 100644
--- a/src/Agent/AgentHealthServiceResponse.php
+++ b/src/Agent/AgentHealthServiceResponse.php
@@ -20,23 +20,28 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractResponse;
-use DCarbone\PHPConsulAPI\Error;
-use DCarbone\PHPConsulAPI\ErrorContainer;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractResponse;
+/**
+ * @extends AbstractResponse
+ */
class AgentHealthServiceResponse extends AbstractResponse
{
- use ErrorContainer;
- public string $AggregatedStatus = '';
- public ?AgentServiceChecksInfo $AgentServiceChecksInfo = null;
+ public string $AggregatedStatus;
+ public null|AgentServiceChecksInfo $AgentServiceChecksInfo;
- public function __construct(string $aggregatedStatus, ?array $checkInfo, ?Error $err)
- {
+ public function __construct(
+ string $aggregatedStatus,
+ null|\stdClass $checksInfo,
+ null|Error $err
+ ) {
$this->AggregatedStatus = $aggregatedStatus;
- if (null !== $checkInfo) {
- $this->AgentServiceChecksInfo = new AgentServiceChecksInfo($checkInfo);
+ if (null !== $checksInfo) {
+ $checksInfo = AgentServiceChecksInfo::jsonUnserialize($checksInfo);
}
+ $this->AgentServiceChecksInfo = $checksInfo;
$this->Err = $err;
}
@@ -45,17 +50,17 @@ public function getAggregatedStatus(): string
return $this->AggregatedStatus;
}
- public function getAgentServiceChecksInfos(): ?AgentServiceChecksInfo
+ public function getAgentServiceChecksInfos(): null|AgentServiceChecksInfo
{
return $this->AgentServiceChecksInfo;
}
public function offsetExists(mixed $offset): bool
{
- return \is_int($offset) && 0 <= $offset && $offset < 3;
+ return is_int($offset) && 0 <= $offset && $offset < 3;
}
- public function offsetGet(mixed $offset): Error|string|null|AgentServiceChecksInfo
+ public function offsetGet(mixed $offset): string|AgentServiceChecksInfo|Error|null
{
if (0 === $offset) {
return $this->AggregatedStatus;
diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php
index d6d3a4c6..2cea87f8 100644
--- a/src/Agent/AgentHealthServicesResponse.php
+++ b/src/Agent/AgentHealthServicesResponse.php
@@ -20,25 +20,26 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractResponse;
-use DCarbone\PHPConsulAPI\Error;
-use DCarbone\PHPConsulAPI\ErrorContainer;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractResponse;
class AgentHealthServicesResponse extends AbstractResponse
{
- use ErrorContainer;
+ public string $AggregatedStatus;
+ /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[] */
+ public array $AgentServiceChecksInfos;
- public string $AggregatedStatus = '';
- public ?array $AgentServiceChecksInfos = null;
-
- public function __construct(string $aggregatedStatus, ?array $checkInfos, ?Error $err)
+ /**
+ * @param string $aggregatedStatus
+ * @param \stdClass[] $checkInfos
+ * @param \DCarbone\PHPConsulAPI\PHPLib\Error|null $err
+ */
+ public function __construct(string $aggregatedStatus, array $checkInfos, null|Error $err)
{
$this->AggregatedStatus = $aggregatedStatus;
- if (null !== $checkInfos) {
- $this->AgentServiceChecksInfos = [];
- foreach ($checkInfos as $checkInfo) {
- $this->AgentServiceChecksInfos[] = new AgentServiceChecksInfo($checkInfo);
- }
+ $this->AgentServiceChecksInfos = [];
+ foreach ($checkInfos as $checkInfo) {
+ $this->AgentServiceChecksInfos[] = AgentServiceChecksInfo::jsonUnserialize($checkInfo);
}
$this->Err = $err;
}
@@ -48,17 +49,24 @@ public function getAggregatedStatus(): string
return $this->AggregatedStatus;
}
- public function getAgentServiceChecksInfos(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[]
+ */
+ public function getAgentServiceChecksInfos(): array
{
return $this->AgentServiceChecksInfos;
}
public function offsetExists(mixed $offset): bool
{
- return \is_int($offset) && 0 <= $offset && $offset < 3;
+ return is_int($offset) && 0 <= $offset && $offset < 3;
}
- public function offsetGet(mixed $offset): mixed
+ /**
+ * @param mixed $offset
+ * @return string|\DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[]|\DCarbone\PHPConsulAPI\PHPLib\Error|null
+ */
+ public function offsetGet(mixed $offset): string|array|Error|null
{
if (0 === $offset) {
return $this->AggregatedStatus;
diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php
index 80167a8c..e3e84877 100644
--- a/src/Agent/AgentMember.php
+++ b/src/Agent/AgentMember.php
@@ -20,24 +20,67 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Consul;
-use DCarbone\PHPConsulAPI\HasStringTags;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentMember extends AbstractModel
+class AgentMember extends AbstractType
{
- use HasStringTags;
-
- public string $Name = '';
- public string $Addr = '';
- public int $Port = 0;
- public string $Status = '';
- public int $ProtocolMin = 0;
- public int $ProtocolMax = 0;
- public int $ProtocolCur = 0;
- public int $DelegateMin = 0;
- public int $DelegateMax = 0;
- public int $DelegateCur = 0;
+ public string $Name;
+ public string $Addr;
+ public int $Port;
+ /** @var array */
+ public array $Tags;
+ /**
+ * Status of the Member which corresponds to github.com/hashicorp/serf/serf.MemberStatus
+ * Value is one of:
+ * AgentMemberNone = 0
+ * AgentMemberAlive = 1
+ * AgentMemberLeaving = 2
+ * AgentMemberLeft = 3
+ * AgentMemberFailed = 4
+ * @var int
+ */
+ public int $Status;
+ public int $ProtocolMin;
+ public int $ProtocolMax;
+ public int $ProtocolCur;
+ public int $DelegateMin;
+ public int $DelegateMax;
+ public int $DelegateCur;
+
+ /**
+ * @param null|\stdClass|array $Tags
+ */
+ public function __construct(
+ string $Name = '',
+ string $Addr = '',
+ int $Port = 0,
+ null|\stdClass|array $Tags = null,
+ int $Status = 0,
+ int $ProtocolMin = 0,
+ int $ProtocolMax = 0,
+ int $ProtocolCur = 0,
+ int $DelegateMin = 0,
+ int $DelegateMax = 0,
+ int $DelegateCur = 0,
+ ) {
+ $this->Name = $Name;
+ $this->Addr = $Addr;
+ $this->Port = $Port;
+ $this->Tags = [];
+ if (null !== $Tags) {
+ foreach ($Tags as $k => $v) {
+ $this->Tags[$k] = $v;
+ }
+ }
+ $this->Status = $Status;
+ $this->ProtocolMin = $ProtocolMin;
+ $this->ProtocolMax = $ProtocolMax;
+ $this->ProtocolCur = $ProtocolCur;
+ $this->DelegateMin = $DelegateMin;
+ $this->DelegateMax = $DelegateMax;
+ $this->DelegateCur = $DelegateCur;
+ }
public function getName(): string
{
@@ -54,7 +97,7 @@ public function getPort(): int
return $this->Port;
}
- public function getStatus(): string
+ public function getStatus(): int
{
return $this->Status;
}
@@ -89,13 +132,13 @@ public function getDelegateCur(): int
return $this->DelegateCur;
}
- public function ACLMode(): string
+ public function ACLMode(): MemberACLMode
{
return match ($this->Tags[Consul::MemberTagKeyACLMode] ?? null) {
- Consul::ACLModeDisabled => Consul::ACLModeDisabled,
- Consul::ACLModeEnabled => Consul::ACLModeEnabled,
- Consul::ACLModeLegacy => Consul::ACLModeLegacy,
- default => Consul::ACLModeUnknown,
+ MemberACLMode::Disabled->value => MemberACLMode::Disabled,
+ MemberACLMode::Enabled->value => MemberACLMode::Enabled,
+ MemberACLMode::Legacy->value => MemberACLMode::Legacy,
+ default => MemberACLMode::Unknown,
};
}
@@ -105,6 +148,40 @@ public function IsConsulServer(): bool
Consul::MemberTagValueRoleServer === $this->Tags[Consul::MemberTagKeyACLMode];
}
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Tags' === $k) {
+ if (null !== $v) {
+ foreach ($v as $kk => $vv) {
+ $n->Tags[$kk] = $vv;
+ }
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Addr = $this->Addr;
+ $out->Port = $this->Port;
+ $out->Tags = $this->Tags;
+ $out->Status = $this->Status;
+ $out->ProtocolMin = $this->ProtocolMin;
+ $out->ProtocolMax = $this->ProtocolMax;
+ $out->ProtocolCur = $this->ProtocolCur;
+ $out->DelegateMin = $this->DelegateMin;
+ $out->DelegateMax = $this->DelegateMax;
+ $out->DelegateCur = $this->DelegateCur;
+ return $out;
+ }
+
public function __toString(): string
{
return $this->Name;
diff --git a/src/Agent/AgentMembersResponse.php b/src/Agent/AgentMembersResponse.php
index 816c924e..aea65ae6 100644
--- a/src/Agent/AgentMembersResponse.php
+++ b/src/Agent/AgentMembersResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class AgentMembersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?array $Members = null;
+ /** @var \DCarbone\PHPConsulAPI\Agent\AgentMember[] */
+ public array $Members = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\AgentMember[]
+ */
+ public function getValue(): array
{
return $this->Members;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->Members = [];
- foreach ($decodedData as $member) {
- $this->Members[] = new AgentMember($member);
+ foreach ($decoded as $member) {
+ $this->Members[] = AgentMember::jsonUnserialize($member);
}
}
}
diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php
index dd4de64e..6c254c4f 100644
--- a/src/Agent/AgentService.php
+++ b/src/Agent/AgentService.php
@@ -20,96 +20,96 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Catalog\ServiceAddress;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\HasStringTags;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Peering\Locality;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
-class AgentService extends AbstractModel
+class AgentService extends AbstractType
{
- use HasStringTags;
-
- protected const FIELDS = [
- self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_META => Transcoding::MAP_FIELD,
- self::FIELD_TAGGED_ADDRESSES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ServiceAddress::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_WEIGHTS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentWeights::class,
- ],
- self::FIELD_CREATE_INDEX => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_MODIFY_INDEX => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_CONTENT_HASH => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceConnectProxyConfig::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CONNECT => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceConnect::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DATACENTER => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_KIND = 'Kind';
- private const FIELD_META = 'Meta';
- private const FIELD_TAGGED_ADDRESSES = 'TaggedAddresses';
- private const FIELD_WEIGHTS = 'Weights';
- private const FIELD_CREATE_INDEX = 'CreateIndex';
- private const FIELD_MODIFY_INDEX = 'ModifyIndex';
- private const FIELD_CONTENT_HASH = 'ContentHash';
- private const FIELD_PROXY = 'Proxy';
- private const FIELD_CONNECT = 'Connect';
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_DATACENTER = 'Datacenter';
-
- public string $Kind = '';
- public string $ID = '';
- public string $Service = '';
- public FakeMap $Meta;
- public int $Port = 0;
- public string $Address = '';
- public array $TaggedAddresses = [];
+ use MetaField;
+
+ public ServiceKind $Kind;
+ public string $ID;
+ public string $Service;
+ /** @var array */
+ public array $Tags;
+ public int $Port;
+ public string $Address;
+ public string $SocketPath;
+ /** @var null|array */
+ public null|array $TaggedAddresses = null;
public AgentWeights $Weights;
- public bool $EnableTagOverride = false;
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public string $ContentHash = '';
- public ?AgentServiceConnectProxyConfig $Proxy = null;
- public ?AgentServiceConnect $Connect = null;
- public string $Namespace = '';
- public string $Datacenter = '';
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Weights)) {
- $this->Weights = new AgentWeights(null);
- }
- if (!isset($this->Meta)) {
- $this->Meta = new FakeMap(null);
- }
+ public bool $EnableTagOverride;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $ContentHash;
+ public null|AgentServiceConnectProxyConfig $Proxy;
+ public null|AgentServiceConnect $Connect;
+ public string $PeerName;
+ public string $Namespace;
+ public string $Partition;
+ public string $Datacenter;
+ public null|Locality $Locality;
+
+ /**
+ * @param array $Tags
+ * @param array $Meta
+ * @param array $TaggedAddresses
+ */
+ public function __construct(
+ string|ServiceKind $Kind = '',
+ string $ID = '',
+ string $Service = '',
+ string $SocketPath = '',
+ array $Tags = [],
+ array $Meta = [],
+ int $Port = 0,
+ string $Address = '',
+ array $TaggedAddresses = [],
+ null|AgentWeights $Weights = null,
+ bool $EnableTagOverride = false,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $ContentHash = '',
+ null|AgentServiceConnectProxyConfig $Proxy = null,
+ null|AgentServiceConnect $Connect = null,
+ string $PeerName = '',
+ string $Namespace = '',
+ string $Partition = '',
+ string $Datacenter = '',
+ null|Locality $Locality = null,
+ ) {
+ $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind;
+ $this->ID = $ID;
+ $this->Service = $Service;
+ $this->setMeta($Meta);
+ $this->Port = $Port;
+ $this->setTags(...$Tags);
+ $this->Address = $Address;
+ $this->SocketPath = $SocketPath;
+ $this->setTaggedAddresses($TaggedAddresses ?: null);
+ $this->Weights = $Weights ?? new AgentWeights();
+ $this->EnableTagOverride = $EnableTagOverride;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->ContentHash = $ContentHash;
+ $this->Proxy = $Proxy;
+ $this->Connect = $Connect;
+ $this->PeerName = $PeerName;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->Datacenter = $Datacenter;
+ $this->Locality = $Locality;
}
- public function getKind(): string
+ public function getKind(): ServiceKind
{
return $this->Kind;
}
- public function setKind(string $Kind): self
+ public function setKind(string|ServiceKind $Kind): self
{
- $this->Kind = $Kind;
+ $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind;
return $this;
}
@@ -135,14 +135,17 @@ public function setService(string $Service): self
return $this;
}
- public function getMeta(): FakeMap
+ /**
+ * @return array
+ */
+ public function getTags(): array
{
- return $this->Meta;
+ return $this->Tags;
}
- public function setMeta(FakeMap $Meta): self
+ public function setTags(string ...$Tags): self
{
- $this->Meta = $Meta;
+ $this->Tags = $Tags;
return $this;
}
@@ -168,14 +171,25 @@ public function setAddress(string $Address): self
return $this;
}
- public function getTaggedAddresses(): array
+ /**
+ * @return null|array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress>
+ */
+ public function getTaggedAddresses(): null|array
{
return $this->TaggedAddresses;
}
- public function setTaggedAddresses(array $TaggedAddresses): self
+ /**
+ * @param null|\stdClass|array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress> $TaggedAddresses
+ * @return $this
+ */
+ public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self
{
- $this->TaggedAddresses = $TaggedAddresses;
+ if (null === $TaggedAddresses || [] === $TaggedAddresses) {
+ $this->TaggedAddresses = null;
+ return $this;
+ }
+ $this->TaggedAddresses = (array)$TaggedAddresses;
return $this;
}
@@ -234,28 +248,39 @@ public function setContentHash(string $ContentHash): self
return $this;
}
- public function getProxy(): ?AgentServiceConnectProxyConfig
+ public function getProxy(): null|AgentServiceConnectProxyConfig
{
return $this->Proxy;
}
- public function setProxy(?AgentServiceConnectProxyConfig $Proxy): self
+ public function setProxy(null|AgentServiceConnectProxyConfig $Proxy): self
{
$this->Proxy = $Proxy;
return $this;
}
- public function getConnect(): ?AgentServiceConnect
+ public function getConnect(): null|AgentServiceConnect
{
return $this->Connect;
}
- public function setConnect(?AgentServiceConnect $Connect): self
+ public function setConnect(null|AgentServiceConnect $Connect): self
{
$this->Connect = $Connect;
return $this;
}
+ public function getPeerName(): string
+ {
+ return $this->PeerName;
+ }
+
+ public function setPeerName(string $PeerName): self
+ {
+ $this->PeerName = $PeerName;
+ return $this;
+ }
+
public function getNamespace(): string
{
return $this->Namespace;
@@ -267,6 +292,17 @@ public function setNamespace(string $Namespace): self
return $this;
}
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
public function getDatacenter(): string
{
return $this->Datacenter;
@@ -277,4 +313,95 @@ public function setDatacenter(string $Datacenter): self
$this->Datacenter = $Datacenter;
return $this;
}
+
+ public function getLocality(): null|Locality
+ {
+ return $this->Locality;
+ }
+
+ public function setLocality(null|Locality $Locality): self
+ {
+ $this->Locality = $Locality;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Kind' === $k) {
+ $n->Kind = ServiceKind::from($v);
+ } elseif ('Tags' === $k) {
+ $n->setTags(...$v);
+ } elseif ('Proxy' === $k) {
+ $n->Proxy = null === $v ? null : AgentServiceConnectProxyConfig::jsonUnserialize($v);
+ } elseif ('Weights' === $k) {
+ $n->Weights = AgentWeights::jsonUnserialize($v);
+ } elseif ('TaggedAddresses' === $k) {
+ $n->setTaggedAddresses($v);
+ } elseif ('Connect' === $k) {
+ $n->Connect = null === $v ? null : AgentServiceConnect::jsonUnserialize($v);
+ } elseif ('Locality' === $k) {
+ $n->Locality = null === $v ? null : Locality::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (ServiceKind::Typical !== $this->Kind) {
+ $out->Kind = $this->Kind;
+ }
+ $out->ID = $this->ID;
+ $out->Service = $this->Service;
+ $out->Tags = $this->Tags;
+ $out->Meta = $this->getMeta();
+ $out->Port = $this->Port;
+ $out->Address = $this->Address;
+ if ('' !== $this->SocketPath) {
+ $out->SocketPath = $this->SocketPath;
+ }
+ if (null !== $this->TaggedAddresses) {
+ $out->TaggedAddresses = $this->TaggedAddresses;
+ }
+ $out->Weights = $this->Weights;
+ $out->EnableTagOverride = $this->EnableTagOverride;
+ if (0 !== $this->CreateIndex) {
+ $out->CreateIndex = $this->CreateIndex;
+ }
+ if (0 !== $this->ModifyIndex) {
+ $out->ModifyIndex = $this->ModifyIndex;
+ }
+ if ('' !== $this->ContentHash) {
+ $out->ContentHash = $this->ContentHash;
+ }
+ if (null !== $this->Proxy) {
+ $out->Proxy = $this->Proxy;
+ }
+ if (null !== $this->Connect) {
+ $out->Connect = $this->Connect;
+ }
+ if ('' !== $this->PeerName) {
+ $out->PeerName = $this->PeerName;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Datacenter) {
+ $out->Datacenter = $this->Datacenter;
+ }
+ if (null !== $this->Locality) {
+ $out->Locality = $this->Locality;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php
index c31a3319..e9ae26ed 100644
--- a/src/Agent/AgentServiceCheck.php
+++ b/src/Agent/AgentServiceCheck.php
@@ -20,101 +20,102 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\Values;
-class AgentServiceCheck extends AbstractModel
+class AgentServiceCheck extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_CHECK_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SCRIPT_ARGS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_DOCKER_CONTAINER_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SHELL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_INTERVAL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TIMEOUT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TTL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_HTTP => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_HEADER => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::MIXED,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_METHOD => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_BODY => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TCP => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_STATUS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NOTES => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TLS_SKIP_VERIFY => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_GRPC => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_GRPC_USE_TLS => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_ALIAS_NODE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_ALIAS_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SUCCESS_BEFORE_PASSING => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_FAILURES_BEFORE_CRITICAL => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- ];
-
- private const FIELD_CHECK_ID = 'CheckID';
- private const FIELD_NAME = 'Name';
- private const FIELD_SCRIPT_ARGS = 'ScriptArgs';
- private const FIELD_DOCKER_CONTAINER_ID = 'DockerContainerID';
- private const FIELD_SHELL = 'Shell';
- private const FIELD_INTERVAL = 'Interval';
- private const FIELD_TIMEOUT = 'Timeout';
- private const FIELD_TTL = 'TTL';
- private const FIELD_HTTP = 'HTTP';
- private const FIELD_HEADER = 'Header';
- private const FIELD_METHOD = 'Method';
- private const FIELD_BODY = 'Body';
- private const FIELD_TCP = 'TCP';
- private const FIELD_STATUS = 'Status';
- private const FIELD_NOTES = 'Notes';
- private const FIELD_TLS_SKIP_VERIFY = 'TLSSkipVerify';
- private const FIELD_GRPC = 'GRPC';
- private const FIELD_GRPC_USE_TLS = 'GRPCUseTLS';
- private const FIELD_ALIAS_NODE = 'AliasNode';
- private const FIELD_ALIAS_SERVICE = 'AliasService';
- private const FIELD_SUCCESS_BEFORE_PASSING = 'SuccessBeforePassing';
- private const FIELD_FAILURES_BEFORE_CRITICAL = 'FailuresBeforeCritical';
- private const FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER = 'DeregisterCriticalServiceAfter';
-
- public string $CheckID = '';
- public string $Name = '';
- public array $ScriptArgs = [];
- public string $DockerContainerID = '';
- public string $Shell = '';
- public string $Interval = '';
- public string $Timeout = '';
- public string $TTL = '';
- public string $HTTP = '';
- public array $Header = [];
- public string $Method = '';
- public string $TCP = '';
- public string $Status = '';
- public string $Notes = '';
- public bool $TLSSkipVerify = false;
- public string $GRPC = '';
- public bool $GRPCUseTLS = false;
- public string $AliasNode = '';
- public string $AliasService = '';
- public int $SuccessBeforePassing = 0;
- public int $FailuresBeforeCritical = 0;
-
- public string $DeregisterCriticalServiceAfter = '';
+ public string $CheckID;
+ public string $Name;
+ /** @var string[] */
+ public array $Args;
+ public string $DockerContainerID;
+ public string $Shell;
+ public string $Interval;
+ public string $Timeout;
+ public string $TTL;
+ public string $HTTP;
+ public null|Values $Header = null;
+ public string $Method;
+ public string $TCP;
+ public string $Status;
+ public string $Notes;
+ public bool $TLSSkipVerify;
+ public string $GRPC;
+ public bool $GRPCUseTLS;
+ public string $H2PING;
+ public bool $H2PINGUseTLS;
+ public string $AliasNode;
+ public string $AliasService;
+ public int $SuccessBeforePassing;
+ public int $FailuresBeforeCritical;
+ public string $DeregisterCriticalServiceAfter;
+
+ /**
+ * @param array $Args
+ * @param null|array>|\DCarbone\PHPConsulAPI\PHPLib\Values $Header
+ */
+ public function __construct(
+ string $CheckID = '',
+ string $Name = '',
+ array $Args = [],
+ string $DockerContainerID = '',
+ string $Shell = '',
+ string $Interval = '',
+ string $Timeout = '',
+ string $TTL = '',
+ string $HTTP = '',
+ null|array|Values $Header = null,
+ string $Method = '',
+ string $TCP = '',
+ string $Status = '',
+ string $Notes = '',
+ bool $TLSSkipVerify = false,
+ string $GRPC = '',
+ bool $GRPCUseTLS = false,
+ string $H2PING = '',
+ bool $H2PINGUseTLS = false,
+ string $AliasNode = '',
+ string $AliasService = '',
+ int $SuccessBeforePassing = 0,
+ int $FailuresBeforeCritical = 0,
+ string $DeregisterCriticalServiceAfter = '',
+ ) {
+ $this->CheckID = $CheckID;
+ $this->Name = $Name;
+ $this->Args = [];
+ $this->setArgs(...$Args);
+ $this->DockerContainerID = $DockerContainerID;
+ $this->Shell = $Shell;
+ $this->Interval = $Interval;
+ $this->Timeout = $Timeout;
+ $this->TTL = $TTL;
+ $this->HTTP = $HTTP;
+ $this->setHeader($Header);
+ $this->Method = $Method;
+ $this->TCP = $TCP;
+ $this->Status = $Status;
+ $this->Notes = $Notes;
+ $this->TLSSkipVerify = $TLSSkipVerify;
+ $this->GRPC = $GRPC;
+ $this->GRPCUseTLS = $GRPCUseTLS;
+ $this->H2PING = $H2PING;
+ $this->H2PINGUseTLS = $H2PINGUseTLS;
+ $this->AliasNode = $AliasNode;
+ $this->AliasService = $AliasService;
+ $this->SuccessBeforePassing = $SuccessBeforePassing;
+ $this->FailuresBeforeCritical = $FailuresBeforeCritical;
+ $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter;
+ }
public function getCheckID(): string
{
return $this->CheckID;
}
- public function setCheckID(string $checkID): self
+ public function setCheckID(string $CheckID): self
{
- $this->CheckID = $checkID;
+ $this->CheckID = $CheckID;
return $this;
}
@@ -123,20 +124,23 @@ public function getName(): string
return $this->Name;
}
- public function setName(string $name): self
+ public function setName(string $Name): self
{
- $this->Name = $name;
+ $this->Name = $Name;
return $this;
}
- public function getScriptArgs(): array
+ /**
+ * @return array
+ */
+ public function getArgs(): array
{
- return $this->ScriptArgs;
+ return $this->Args;
}
- public function setScriptArgs(array $args): self
+ public function setArgs(string ...$Args): self
{
- $this->ScriptArgs = $args;
+ $this->Args = $Args;
return $this;
}
@@ -145,9 +149,9 @@ public function getDockerContainerID(): string
return $this->DockerContainerID;
}
- public function setDockerContainerID(string $dockerContainerID): self
+ public function setDockerContainerID(string $DockerContainerID): self
{
- $this->DockerContainerID = $dockerContainerID;
+ $this->DockerContainerID = $DockerContainerID;
return $this;
}
@@ -156,9 +160,9 @@ public function getShell(): string
return $this->Shell;
}
- public function setShell(string $shell): self
+ public function setShell(string $Shell): self
{
- $this->Shell = $shell;
+ $this->Shell = $Shell;
return $this;
}
@@ -167,9 +171,9 @@ public function getInterval(): string
return $this->Interval;
}
- public function setInterval(string $interval): self
+ public function setInterval(string $Interval): self
{
- $this->Interval = $interval;
+ $this->Interval = $Interval;
return $this;
}
@@ -178,9 +182,9 @@ public function getTimeout(): string
return $this->Timeout;
}
- public function setTimeout(string $timeout): self
+ public function setTimeout(string $Timeout): self
{
- $this->Timeout = $timeout;
+ $this->Timeout = $Timeout;
return $this;
}
@@ -189,9 +193,9 @@ public function getTTL(): string
return $this->TTL;
}
- public function setTTL(string $ttl): self
+ public function setTTL(string $TTL): self
{
- $this->TTL = $ttl;
+ $this->TTL = $TTL;
return $this;
}
@@ -200,20 +204,31 @@ public function getHTTP(): string
return $this->HTTP;
}
- public function setHTTP(string $http): self
+ public function setHTTP(string $HTTP): self
{
- $this->HTTP = $http;
+ $this->HTTP = $HTTP;
return $this;
}
- public function getHeader(): array
+ public function getHeader(): null|Values
{
return $this->Header;
}
- public function setHeader(array $header): self
- {
- $this->Header = $header;
+ /**
+ * @param \stdClass|array>|\DCarbone\PHPConsulAPI\PHPLib\Values|null $Header
+ * @return $this
+ */
+ public function setHeader(null|\stdClass|array|Values $Header): self
+ {
+ if (null === $Header) {
+ $this->Header = null;
+ return $this;
+ }
+ if (!$Header instanceof Values) {
+ $Header = Values::fromArray((array)$Header);
+ }
+ $this->Header = $Header;
return $this;
}
@@ -222,9 +237,9 @@ public function getMethod(): string
return $this->Method;
}
- public function setMethod(string $method): self
+ public function setMethod(string $Method): self
{
- $this->Method = $method;
+ $this->Method = $Method;
return $this;
}
@@ -233,9 +248,9 @@ public function getTCP(): string
return $this->TCP;
}
- public function setTCP(string $tcp): self
+ public function setTCP(string $TCP): self
{
- $this->TCP = $tcp;
+ $this->TCP = $TCP;
return $this;
}
@@ -244,9 +259,9 @@ public function getStatus(): string
return $this->Status;
}
- public function setStatus(string $status): self
+ public function setStatus(string $Status): self
{
- $this->Status = $status;
+ $this->Status = $Status;
return $this;
}
@@ -255,9 +270,9 @@ public function getNotes(): string
return $this->Notes;
}
- public function setNotes(string $notes): self
+ public function setNotes(string $Notes): self
{
- $this->Notes = $notes;
+ $this->Notes = $Notes;
return $this;
}
@@ -266,9 +281,9 @@ public function isTLSSkipVerify(): bool
return $this->TLSSkipVerify;
}
- public function setTLSSkipVerify(bool $tlsSkipVerify): self
+ public function setTLSSkipVerify(bool $TLSSkipVerify): self
{
- $this->TLSSkipVerify = $tlsSkipVerify;
+ $this->TLSSkipVerify = $TLSSkipVerify;
return $this;
}
@@ -288,6 +303,28 @@ public function isGRPCUseTLS(): bool
return $this->GRPCUseTLS;
}
+ public function getH2PING(): string
+ {
+ return $this->H2PING;
+ }
+
+ public function setH2PING(string $H2PING): self
+ {
+ $this->H2PING = $H2PING;
+ return $this;
+ }
+
+ public function isH2PINGUseTLS(): bool
+ {
+ return $this->H2PINGUseTLS;
+ }
+
+ public function setH2PINGUseTLS(bool $H2PINGUseTLS): self
+ {
+ $this->H2PINGUseTLS = $H2PINGUseTLS;
+ return $this;
+ }
+
public function setGRPCUseTLS(bool $GRPCUseTLS): self
{
$this->GRPCUseTLS = $GRPCUseTLS;
@@ -343,9 +380,102 @@ public function getDeregisterCriticalServiceAfter(): string
return $this->DeregisterCriticalServiceAfter;
}
- public function setDeregisterCriticalServiceAfter(string $deregisterCriticalServiceAfter): self
+ public function setDeregisterCriticalServiceAfter(string $DeregisterCriticalServiceAfter): self
{
- $this->DeregisterCriticalServiceAfter = $deregisterCriticalServiceAfter;
+ $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('ScriptArgs' === $k) {
+ $n->Args = $v;
+ } elseif ('Header' === $k) {
+ $n->setHeader($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->CheckID) {
+ $out->CheckID = $this->CheckID;
+ }
+ if ('' !== $this->Name) {
+ $out->Name = $this->Name;
+ }
+ if ([] !== $this->Args) {
+ $out->ScriptArgs = $this->Args;
+ }
+ if ('' !== $this->DockerContainerID) {
+ $out->DockerContainerID = $this->DockerContainerID;
+ }
+ if ('' !== $this->Shell) {
+ $out->Shell = $this->Shell;
+ }
+ if ('' !== $this->Interval) {
+ $out->Interval = $this->Interval;
+ }
+ if ('' !== $this->Timeout) {
+ $out->Timeout = $this->Timeout;
+ }
+ if ('' !== $this->TTL) {
+ $out->TTL = $this->TTL;
+ }
+ if ('' !== $this->HTTP) {
+ $out->HTTP = $this->HTTP;
+ }
+ if (null !== $this->Header) {
+ $out->Header = $this->Header;
+ }
+ if ('' !== $this->Method) {
+ $out->Method = $this->Method;
+ }
+ if ('' !== $this->TCP) {
+ $out->TCP = $this->TCP;
+ }
+ if ('' !== $this->Status) {
+ $out->Status = $this->Status;
+ }
+ if ('' !== $this->Notes) {
+ $out->Notes = $this->Notes;
+ }
+ if ($this->TLSSkipVerify) {
+ $out->TLSSkipVerify = $this->TLSSkipVerify;
+ }
+ if ('' !== $this->GRPC) {
+ $out->GRPC = $this->GRPC;
+ }
+ if ($this->GRPCUseTLS) {
+ $out->GRPCUseTLS = $this->GRPCUseTLS;
+ }
+ if ('' !== $this->H2PING) {
+ $out->H2PING = $this->H2PING;
+ }
+ if ($this->H2PINGUseTLS) {
+ $out->H2PINGUseTLS = $this->H2PINGUseTLS;
+ }
+ if ('' !== $this->AliasNode) {
+ $out->AliasNode = $this->AliasNode;
+ }
+ if ('' !== $this->AliasService) {
+ $out->AliasService = $this->AliasService;
+ }
+ if (0 !== $this->SuccessBeforePassing) {
+ $out->SuccessBeforePassing = $this->SuccessBeforePassing;
+ }
+ if (0 !== $this->FailuresBeforeCritical) {
+ $out->FailuresBeforeCritical = $this->FailuresBeforeCritical;
+ }
+ if ('' !== $this->DeregisterCriticalServiceAfter) {
+ $out->DeregisterCriticalServiceAfter = $this->DeregisterCriticalServiceAfter;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/AgentServiceChecks.php b/src/Agent/AgentServiceChecks.php
index 314f9339..78bbea05 100644
--- a/src/Agent/AgentServiceChecks.php
+++ b/src/Agent/AgentServiceChecks.php
@@ -20,15 +20,99 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeSlice;
-
-class AgentServiceChecks extends FakeSlice
+/**
+ * @implements \ArrayAccess
+ */
+class AgentServiceChecks implements \JsonSerializable, \Countable, \ArrayAccess
{
- protected string $containedClass = AgentServiceCheck::class;
+ /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck[] */
+ public array $Checks;
+
+ /**
+ * @param iterable $Checks
+ */
+ public function __construct(
+ iterable $Checks = [],
+ ) {
+ $this->setChecks(...$Checks);
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck[]
+ */
+ public function getChecks(): array
+ {
+ return $this->Checks;
+ }
+
+ public function setChecks(AgentServiceCheck ...$Checks): self
+ {
+ $this->Checks = $Checks;
+ return $this;
+ }
+
+ /**
+ * @return iterable
+ */
+ public function getIterator(): iterable
+ {
+ if ([] === $this->Checks) {
+ return new \EmptyIterator();
+ }
+ return new \ArrayIterator($this->Checks);
+ }
+
+ public function count(): int
+ {
+ return count($this->Checks);
+ }
+
+ public function offsetExists(mixed $offset): bool
+ {
+ return isset($this->Checks[$offset]);
+ }
+
+ public function offsetGet(mixed $offset): null|AgentServiceCheck
+ {
+ return $this->Checks[$offset] ?? null;
+ }
+
+ public function offsetSet(mixed $offset, mixed $value): void
+ {
+ if (is_int($offset) && $value instanceof AgentServiceCheck) {
+ $this->Checks[$offset] = $value;
+ } else {
+ throw new \InvalidArgumentException(sprintf(
+ 'Invalid offset %s or value %s, expected int and %s.',
+ var_export($offset, true),
+ var_export($value, true),
+ AgentServiceCheck::class
+ ));
+ }
+ }
+
+ public function offsetUnset(mixed $offset): void
+ {
+ unset($this->Checks[$offset]);
+ }
+
+ /**
+ * @param array<\stdClass> $decoded
+ */
+ public static function jsonUnserialize(array $decoded): self
+ {
+ $n = new self();
+ foreach ($decoded as $v) {
+ $n->Checks[] = AgentServiceCheck::jsonUnserialize($v);
+ }
+ return $n;
+ }
- protected function newChild(array $data): AbstractModel
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array
{
- return new AgentServiceCheck($data);
+ return $this->Checks;
}
}
diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php
index f2fb3dd6..b35aee11 100644
--- a/src/Agent/AgentServiceChecksInfo.php
+++ b/src/Agent/AgentServiceChecksInfo.php
@@ -20,38 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Health\HealthChecks;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentServiceChecksInfo extends AbstractModel
+class AgentServiceChecksInfo extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentService::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_CHECKS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthChecks::class,
- ],
- ];
-
- private const FIELD_SERVICE = 'Service';
- private const FIELD_CHECKS = 'Checks';
-
- public string $AggregatedStatus = '';
- public ?AgentService $Service = null;
+ public string $AggregatedStatus;
+ public null|AgentService $Service;
public HealthChecks $Checks;
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->Checks)) {
- $this->Checks = new HealthChecks();
- }
- }
+ public function __construct(
+ string $AggregatedStatus = '',
+ null|AgentService $Service = null,
+ null|HealthChecks $Checks = null,
+ ) {
+ $this->AggregatedStatus = $AggregatedStatus;
+ $this->Service = $Service;
+ $this->Checks = $Checks ?? new HealthChecks();
+}
public function getAggregatedStatus(): string
{
@@ -64,12 +50,12 @@ public function setAggregatedStatus(string $AggregatedStatus): self
return $this;
}
- public function getService(): ?AgentService
+ public function getService(): null|AgentService
{
return $this->Service;
}
- public function setService(?AgentService $Service): self
+ public function setService(null|AgentService $Service): self
{
$this->Service = $Service;
return $this;
@@ -85,6 +71,31 @@ public function setChecks(HealthChecks $Checks): self
$this->Checks = $Checks;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Checks' === $k) {
+ $n->Checks = HealthChecks::jsonUnserialize($v);
+ } elseif ('Service' === $k) {
+ $n->Service = null === $v ? null : AgentService::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->AggregatedStatus = $this->AggregatedStatus;
+ $out->Service = $this->Service;
+ $out->Checks = $this->Checks;
+ return $out;
+ }
+
public function __toString(): string
{
return $this->AggregatedStatus;
diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php
index 3f629e57..c98892dc 100644
--- a/src/Agent/AgentServiceConnect.php
+++ b/src/Agent/AgentServiceConnect.php
@@ -20,25 +20,20 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentServiceConnect extends AbstractModel
+class AgentServiceConnect extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NATIVE => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_SIDECAR_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AgentServiceRegistration::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public bool $Native;
+ public null|AgentServiceRegistration $SidecarService;
- private const FIELD_NATIVE = 'Native';
- private const FIELD_SIDECAR_SERVICE = 'SidecarService';
-
- public bool $Native = false;
- public array $SidecarService = [];
+ public function __construct(
+ bool $Native = false,
+ null|AgentServiceRegistration $SidecarService = null,
+ ) {
+ $this->Native = $Native;
+ $this->SidecarService = $SidecarService;
+}
public function isNative(): bool
{
@@ -51,14 +46,39 @@ public function setNative(bool $Native): self
return $this;
}
- public function getSidecarService(): array
+ public function getSidecarService(): null|AgentServiceRegistration
{
return $this->SidecarService;
}
- public function setSidecarService(array $SidecarService): self
+ public function setSidecarService(AgentServiceRegistration $SidecarService): self
{
$this->SidecarService = $SidecarService;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('SidecarService' === $k) {
+ $n->SidecarService = AgentServiceRegistration::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Native) {
+ $out->Native = $this->Native;
+ }
+ if (null !== $this->SidecarService) {
+ $out->SidecarService = $this->SidecarService;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php
index 0fc59582..f63016b1 100644
--- a/src/Agent/AgentServiceConnectProxyConfig.php
+++ b/src/Agent/AgentServiceConnectProxyConfig.php
@@ -20,77 +20,71 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\ConfigEntry\AccessLogsConfig;
+use DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension;
use DCarbone\PHPConsulAPI\ConfigEntry\ExposeConfig;
use DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\ConfigEntry\ProxyMode;
+use DCarbone\PHPConsulAPI\ConfigEntry\TransparentProxyConfig;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentServiceConnectProxyConfig extends AbstractModel
+class AgentServiceConnectProxyConfig extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_ENVOY_EXTENSIONS => [
- Transcoding::FIELD_CLASS => EnvoyExtension::class,
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_DESTINATION_SERVICE_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DESTINATION_SERVICE_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_LOCAL_SERVICE_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_LOCAL_SERVICE_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_CONFIG => Transcoding::OMITEMPTY_MAP_FIELD,
- self::FIELD_UPSTREAMS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => Upstream::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_MESH_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => MeshGatewayConfig::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_EXPOSE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ExposeConfig::class,
- ],
- ];
-
- private const FIELD_ENVOY_EXTENSIONS = 'EnvoyExtension';
- private const FIELD_DESTINATION_SERVICE_NAME = 'DestinationServiceName';
- private const FIELD_DESTINATION_SERVICE_ID = 'DestinationServiceID';
- private const FIELD_LOCAL_SERVICE_ADDRESS = 'LocalServiceAddress';
- private const FIELD_LOCAL_SERVICE_PORT = 'LocalServicePort';
- private const FIELD_CONFIG = 'Config';
- private const FIELD_UPSTREAMS = 'Upstreams';
- private const FIELD_MESH_GATEWAY = 'MeshGateway';
- private const FIELD_EXPOSE = 'Expose';
-
- public array $EnvoyExtensions = [];
- public string $DestinationServiceName = '';
- public string $DestinationServiceID = '';
- public string $LocalServiceAddress = '';
- public int $LocalServicePort = 0;
- public ?FakeMap $Config = null;
- public string $LocalServiceSocketPath = '';
- public string $Mode = '';
- public ?TransparentProxyConfig $TransparentProxy = null;
- public array $Upstreams = [];
- public MeshGatewayConfig $MeshGateway;
- public ExposeConfig $Expose;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->MeshGateway)) {
- $this->MeshGateway = new MeshGatewayConfig(null);
- }
- if (!isset($this->Expose)) {
- $this->Expose = new ExposeConfig(null);
- }
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */
+ public array $EnvoyExtensions;
+ public string $DestinationServiceName;
+ public string $DestinationServiceID;
+ public string $LocalServiceAddress;
+ public int $LocalServicePort;
+ public string $LocalServiceSocketPath;
+ public ProxyMode $Mode;
+ public null|TransparentProxyConfig $TransparentProxy;
+ /** @var null|array */
+ public null|array $Config = null;
+ /** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */
+ public array $Upstreams;
+ public null|MeshGatewayConfig $MeshGateway;
+ public null|ExposeConfig $Expose;
+ public null|AccessLogsConfig $AccessLogs;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions
+ * @param array $Config
+ * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams
+ */
+ public function __construct(
+ iterable $EnvoyExtensions = [],
+ string $DestinationServiceName = '',
+ string $DestinationServiceID = '',
+ string $LocalServiceAddress = '',
+ int $LocalServicePort = 0,
+ string $LocalServiceSocketPath = '',
+ string|ProxyMode $Mode = ProxyMode::Default,
+ null|TransparentProxyConfig $TransparentProxy = null,
+ array $Config = [],
+ iterable $Upstreams = [],
+ null|MeshGatewayConfig $MeshGateway = null,
+ null|ExposeConfig $Expose = null,
+ null|AccessLogsConfig $AccessLogs = null,
+ ) {
+ $this->setEnvoyExtensions(...$EnvoyExtensions);
+ $this->DestinationServiceName = $DestinationServiceName;
+ $this->DestinationServiceID = $DestinationServiceID;
+ $this->LocalServiceAddress = $LocalServiceAddress;
+ $this->LocalServicePort = $LocalServicePort;
+ $this->setConfig($Config);
+ $this->LocalServiceSocketPath = $LocalServiceSocketPath;
+ $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode);
+ $this->TransparentProxy = $TransparentProxy;
+ $this->setUpstreams(...$Upstreams);
+ $this->MeshGateway = $MeshGateway;
+ $this->Expose = $Expose;
+ $this->AccessLogs = $AccessLogs;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[]
+ */
public function getEnvoyExtensions(): array
{
return $this->EnvoyExtensions;
@@ -102,7 +96,7 @@ public function addEnvoyExtension(EnvoyExtension $envoyExtension): self
return $this;
}
- public function setEnvoyExtensions(array $EnvoyExtensions): self
+ public function setEnvoyExtensions(EnvoyExtension ...$EnvoyExtensions): self
{
$this->EnvoyExtensions = $EnvoyExtensions;
return $this;
@@ -163,69 +157,173 @@ public function setLocalServiceSocketPath(string $LocalServiceSocketPath): self
return $this;
}
- public function getMode(): string
+ public function getMode(): ProxyMode
{
return $this->Mode;
}
- public function setMode(string $Mode): self
+ public function setMode(string|ProxyMode $Mode): self
{
- $this->Mode = $Mode;
+ $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode);
return $this;
}
- public function getTransparentProxy(): ?TransparentProxyConfig
+ public function getTransparentProxy(): null|TransparentProxyConfig
{
return $this->TransparentProxy;
}
- public function setTransparentProxy(?TransparentProxyConfig $TransparentProxy): self
+ public function setTransparentProxy(null|TransparentProxyConfig $TransparentProxy): self
{
$this->TransparentProxy = $TransparentProxy;
return $this;
}
- public function getConfig(): ?FakeMap
+ /**
+ * @return array|null
+ */
+ public function getConfig(): null|array
{
return $this->Config;
}
- public function setConfig(array|FakeMap|\stdClass|null $Config): self
+ /**
+ * @param \stdClass|array|null $Config
+ * @return $this
+ */
+ public function setConfig(null|\stdClass|array $Config): self
{
- $this->Config = FakeMap::parse($Config);
+ if (null === $Config) {
+ $this->Config = null;
+ return $this;
+ }
+ $this->Config = [];
+ foreach ($Config as $k => $v) {
+ $this->Config[$k] = $v;
+ }
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\Upstream[]
+ */
public function getUpstreams(): array
{
return $this->Upstreams;
}
- public function setUpstreams(array $Upstreams): self
+ public function setUpstreams(Upstream ...$Upstreams): self
{
$this->Upstreams = $Upstreams;
return $this;
}
- public function getMeshGateway(): MeshGatewayConfig
+ public function getMeshGateway(): null|MeshGatewayConfig
{
return $this->MeshGateway;
}
- public function setMeshGateway(MeshGatewayConfig $MeshGateway): self
+ public function setMeshGateway(null|MeshGatewayConfig $MeshGateway): self
{
$this->MeshGateway = $MeshGateway;
return $this;
}
- public function getExpose(): ExposeConfig
+ public function getExpose(): null|ExposeConfig
{
return $this->Expose;
}
- public function setExpose(ExposeConfig $Expose): self
+ public function setExpose(null|ExposeConfig $Expose): self
{
$this->Expose = $Expose;
return $this;
}
+
+ public function getAccessLogs(): null|AccessLogsConfig
+ {
+ return $this->AccessLogs;
+ }
+
+ public function setAccessLogs(null|AccessLogsConfig $AccessLogs): self
+ {
+ $this->AccessLogs = $AccessLogs;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('EnvoyExtensions' === $k) {
+ foreach ($v as $vv) {
+ $n->EnvoyExtensions[] = EnvoyExtension::jsonUnserialize($vv);
+ }
+ } elseif ('Mode' === $k) {
+ $n->setMode($v);
+ } elseif ('TransparentProxy' === $k) {
+ $n->TransparentProxy = TransparentProxyConfig::jsonUnserialize($v);
+ } elseif ('Upstreams' === $k) {
+ foreach ($v as $vv) {
+ $n->Upstreams[] = Upstream::jsonUnserialize($vv);
+ }
+ } elseif ('MeshGateway' === $k) {
+ $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v);
+ } elseif ('Expose' === $k) {
+ $n->Expose = ExposeConfig::jsonUnserialize($v);
+ } elseif ('AccessLogs' === $k) {
+ $n->AccessLogs = null === $v ? null : AccessLogsConfig::jsonUnserialize($v);
+ } elseif ('Config' === $k) {
+ $n->setConfig($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ([] !== $this->EnvoyExtensions) {
+ $out->EnvoyExtensions = $this->EnvoyExtensions;
+ }
+ if ('' !== $this->DestinationServiceName) {
+ $out->DestinationServiceName = $this->DestinationServiceName;
+ }
+ if ('' !== $this->DestinationServiceID) {
+ $out->DestinationServiceID = $this->DestinationServiceID;
+ }
+ if ('' !== $this->LocalServiceAddress) {
+ $out->LocalServiceAddress = $this->LocalServiceAddress;
+ }
+ if (0 !== $this->LocalServicePort) {
+ $out->LocalServicePort = $this->LocalServicePort;
+ }
+ if (null !== $this->Config) {
+ $out->Config = $this->Config;
+ }
+ if ('' !== $this->LocalServiceSocketPath) {
+ $out->LocalServiceSocketPath = $this->LocalServiceSocketPath;
+ }
+ if (ProxyMode::Default !== $this->Mode) {
+ $out->Mode = $this->Mode->value;
+ }
+ if (null !== $this->TransparentProxy) {
+ $out->TransparentProxy = $this->TransparentProxy;
+ }
+ if ([] !== $this->Upstreams) {
+ $out->Upstreams = $this->Upstreams;
+ }
+ if (null !== $this->MeshGateway) {
+ $out->MeshGateway = $this->MeshGateway;
+ }
+ if (null !== $this->Expose) {
+ $out->Expose = $this->Expose;
+ }
+ if (null !== $this->AccessLogs) {
+ $out->AccessLogs = $this->AccessLogs;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php
index f565821b..0f09819e 100644
--- a/src/Agent/AgentServiceRegistration.php
+++ b/src/Agent/AgentServiceRegistration.php
@@ -20,112 +20,85 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Catalog\ServiceAddress;
-use DCarbone\PHPConsulAPI\HasSettableStringTags;
-use DCarbone\PHPConsulAPI\HasStringTags;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Peering\Locality;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
-class AgentServiceRegistration extends AbstractModel
+class AgentServiceRegistration extends AbstractType
{
- use HasSettableStringTags;
- use HasStringTags;
-
- protected const FIELDS = [
- self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_ID => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TAGGED_ADDRESSES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ServiceAddress::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_ENABLE_TAG_OVERRIDE => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_META => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::MIXED,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_WEIGHTS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentWeights::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CHECK => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceCheck::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_CHECKS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AgentServiceChecks::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceConnectProxyConfig::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CONNECT => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceConnect::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_KIND = 'Kind';
- private const FIELD_ID = 'ID';
- private const FIELD_NAME = 'Name';
- private const FIELD_PORT = 'Port';
- private const FIELD_ADDRESS = 'Address';
- private const FIELD_TAGGED_ADDRESSES = 'TaggedAddresses';
- private const FIELD_ENABLE_TAG_OVERRIDE = 'EnableTagOverride';
- private const FIELD_META = 'Meta';
- private const FIELD_WEIGHTS = 'Weights';
- private const FIELD_CHECK = 'Check';
- private const FIELD_CHECKS = 'Checks';
- private const FIELD_PROXY = 'Proxy';
- private const FIELD_CONNECT = 'Connect';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Kind = '';
- public string $ID = '';
- public string $Name = '';
- public int $Port = 0;
- public string $Address = '';
- public array $TaggedAddresses = [];
- public bool $EnableTagOverride = false;
- public array $Meta = [];
- public ?AgentWeights $Weights = null;
- public ?AgentServiceCheck $Check = null;
+ use MetaField;
+
+ public ServiceKind $Kind;
+ public string $ID;
+ public string $Name;
+ /** @var string[] */
+ public array $Tags;
+ public int $Port;
+ public string $Address;
+ /** @var null|array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress> */
+ public null|array $TaggedAddresses = null;
+ public bool $EnableTagOverride;
+ public null|AgentWeights $Weights;
+ public null|AgentServiceCheck $Check;
public AgentServiceChecks $Checks;
- public ?AgentServiceConnectProxyConfig $Proxy = null;
- public ?AgentServiceConnect $Connect = null;
- public string $Namespace = '';
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Checks)) {
- $this->Checks = new AgentServiceChecks(null);
- }
+ public null|AgentServiceConnectProxyConfig $Proxy;
+ public null|AgentServiceConnect $Connect;
+ public string $Namespace;
+ public string $Partition;
+ public null|Locality $Locality;
+
+ /**
+ * @param array $Tags
+ * @param array $TaggedAddresses
+ * @param array $Meta
+ */
+ public function __construct(
+ string|ServiceKind $Kind = ServiceKind::Typical,
+ string $ID = '',
+ string $Name = '',
+ array $Tags = [],
+ int $Port = 0,
+ string $Address = '',
+ array $TaggedAddresses = [],
+ bool $EnableTagOverride = false,
+ array $Meta = [],
+ null|AgentWeights $Weights = null,
+ null|AgentServiceCheck $Check = null,
+ null|AgentServiceChecks $Checks = null,
+ null|AgentServiceConnectProxyConfig $Proxy = null,
+ null|AgentServiceConnect $Connect = null,
+ string $Namespace = '',
+ string $Partition = '',
+ null|Locality $Locality = null,
+ ) {
+ $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind;
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->setTags(...$Tags);
+ $this->Port = $Port;
+ $this->Address = $Address;
+ $this->setTaggedAddresses($TaggedAddresses ?: null);
+ $this->EnableTagOverride = $EnableTagOverride;
+ $this->setMeta($Meta);
+ $this->Weights = $Weights;
+ $this->Check = $Check;
+ $this->Checks = $Checks ?? new AgentServiceChecks();
+ $this->Proxy = $Proxy;
+ $this->Connect = $Connect;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->Locality = $Locality;
}
- public function getKind(): string
+ public function getKind(): ServiceKind
{
return $this->Kind;
}
- public function setKind(string $Kind): self
+ public function setKind(string|ServiceKind $Kind): self
{
- $this->Kind = $Kind;
+ $this->Kind = $Kind instanceof ServiceKind ? $Kind : ServiceKind::from($Kind);
return $this;
}
@@ -151,6 +124,20 @@ public function setName(string $Name): self
return $this;
}
+ /**
+ * @return string[]
+ */
+ public function getTags(): array
+ {
+ return $this->Tags;
+ }
+
+ public function setTags(string ...$Tags): self
+ {
+ $this->Tags = $Tags;
+ return $this;
+ }
+
public function getPort(): int
{
return $this->Port;
@@ -173,56 +160,68 @@ public function setAddress(string $Address): self
return $this;
}
- public function getTaggedAddresses(): ?array
+ /**
+ * @return array|null
+ */
+ public function getTaggedAddresses(): null|array
{
return $this->TaggedAddresses;
}
- public function setTaggedAddresses(array $TaggedAddresses): self
+ public function setTaggedAddress(string $Tag, ServiceAddress $Address): self
{
- $this->TaggedAddresses = $TaggedAddresses;
+ if (null === $this->TaggedAddresses) {
+ $this->TaggedAddresses = [];
+ }
+ $this->TaggedAddresses[$Tag] = $Address;
return $this;
}
- public function isEnableTagOverride(): bool
- {
- return $this->EnableTagOverride;
- }
-
- public function setEnableTagOverride(bool $EnableTagOverride): self
+ /**
+ * @param array|null $TaggedAddresses
+ * @return $this
+ */
+ public function setTaggedAddresses(null|array $TaggedAddresses): self
{
- $this->EnableTagOverride = $EnableTagOverride;
+ if (null === $TaggedAddresses) {
+ $this->TaggedAddresses = null;
+ return $this;
+ }
+ $this->TaggedAddresses = [];
+ foreach ($TaggedAddresses as $k => $v) {
+ $this->setTaggedAddress($k, $v);
+ }
return $this;
}
- public function getMeta(): ?array
+ public function isEnableTagOverride(): bool
{
- return $this->Meta;
+ return $this->EnableTagOverride;
}
- public function setMeta(array $Meta): self
+ public function setEnableTagOverride(bool $EnableTagOverride): self
{
- $this->Meta = $Meta;
+ $this->EnableTagOverride = $EnableTagOverride;
return $this;
}
- public function getWeights(): ?AgentWeights
+ public function getWeights(): null|AgentWeights
{
return $this->Weights;
}
- public function setWeights(?AgentWeights $Weights): self
+ public function setWeights(null|AgentWeights $Weights): self
{
$this->Weights = $Weights;
return $this;
}
- public function getCheck(): ?AgentServiceCheck
+ public function getCheck(): null|AgentServiceCheck
{
return $this->Check;
}
- public function setCheck(?AgentServiceCheck $Check): self
+ public function setCheck(null|AgentServiceCheck $Check): self
{
$this->Check = $Check;
return $this;
@@ -239,23 +238,23 @@ public function setChecks(AgentServiceChecks $Checks): self
return $this;
}
- public function getProxy(): ?AgentServiceConnectProxyConfig
+ public function getProxy(): null|AgentServiceConnectProxyConfig
{
return $this->Proxy;
}
- public function setProxy(?AgentServiceConnectProxyConfig $Proxy): self
+ public function setProxy(null|AgentServiceConnectProxyConfig $Proxy): self
{
$this->Proxy = $Proxy;
return $this;
}
- public function getConnect(): ?AgentServiceConnect
+ public function getConnect(): null|AgentServiceConnect
{
return $this->Connect;
}
- public function setConnect(?AgentServiceConnect $Connect): self
+ public function setConnect(null|AgentServiceConnect $Connect): self
{
$this->Connect = $Connect;
return $this;
@@ -271,6 +270,116 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getLocality(): null|Locality
+ {
+ return $this->Locality;
+ }
+
+ public function setLocality(null|Locality $Locality): self
+ {
+ $this->Locality = $Locality;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Kind' === $k) {
+ $n->setKind($v);
+ } elseif ('Tags' === $k) {
+ $n->setTags(...$v);
+ } elseif ('TaggedAddresses' === $k) {
+ $n->TaggedAddresses = [];
+ foreach ($v as $kk => $vv) {
+ $n->TaggedAddresses[$kk] = ServiceAddress::jsonUnserialize($vv);
+ }
+ } elseif ('Weights' === $k) {
+ $n->Weights = AgentWeights::jsonUnserialize($v);
+ } elseif ('Check' === $k) {
+ $n->Check = AgentServiceCheck::jsonUnserialize($v);
+ } elseif ('Checks' === $k) {
+ $n->Checks = AgentServiceChecks::jsonUnserialize($v);
+ } elseif ('Proxy' === $k) {
+ $n->Proxy = AgentServiceConnectProxyConfig::jsonUnserialize($v);
+ } elseif ('Connect' === $k) {
+ $n->Connect = AgentServiceConnect::jsonUnserialize($v);
+ } elseif ('Locality' === $k) {
+ $n->Locality = Locality::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Kind !== ServiceKind::Typical) {
+ $out->Kind = $this->Kind;
+ }
+ if ('' !== $this->ID) {
+ $out->ID = $this->ID;
+ }
+ if ('' !== $this->Name) {
+ $out->Name = $this->Name;
+ }
+ if ([] !== $this->Tags) {
+ $out->Tags = $this->Tags;
+ }
+ if (0 !== $this->Port) {
+ $out->Port = $this->Port;
+ }
+ if ('' !== $this->Address) {
+ $out->Address = $this->Address;
+ }
+ if (null !== $this->TaggedAddresses && [] !== $this->TaggedAddresses) {
+ $out->TaggedAddresses = $this->TaggedAddresses;
+ }
+ if ($this->EnableTagOverride) {
+ $out->EnableTagOverride = $this->EnableTagOverride;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ if (null !== $this->Weights) {
+ $out->Weights = $this->Weights;
+ }
+ $out->Check = $this->Check;
+ $out->Checks = $this->Checks;
+ if (null !== $this->Proxy) {
+ $out->Proxy = $this->Proxy;
+ }
+ if (null !== $this->Connect) {
+ $out->Connect = $this->Connect;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if (null !== $this->Locality) {
+ $out->Locality = $this->Locality;
+ }
+ return $out;
+ }
+
public function __toString(): string
{
return $this->Name;
diff --git a/src/Agent/AgentServiceResponse.php b/src/Agent/AgentServiceResponse.php
index 35e871ad..1af541e7 100644
--- a/src/Agent/AgentServiceResponse.php
+++ b/src/Agent/AgentServiceResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class AgentServiceResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?AgentService $Service = null;
+ public null|AgentService $Service = null;
- public function getValue(): ?AgentService
+ public function getValue(): null|AgentService
{
return $this->Service;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->Service = new AgentService((array)$decodedData);
+ if (null === $decoded) {
+ $this->Service = null;
+ return;
+ }
+ $this->Service = AgentService::jsonUnserialize($decoded);
}
}
diff --git a/src/Agent/AgentServicesResponse.php b/src/Agent/AgentServicesResponse.php
index 2d559cbb..2f837091 100644
--- a/src/Agent/AgentServicesResponse.php
+++ b/src/Agent/AgentServicesResponse.php
@@ -20,23 +20,31 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class AgentServicesResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?array $Services = null;
+ /** @var null|array */
+ public null|array $Services = null;
- public function getValue(): ?array
+ /**
+ * @return array|null
+ */
+ public function getValue(): null|array
{
return $this->Services;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
+ if (null === $decoded) {
+ $this->Services = null;
+ return;
+ }
$this->Services = [];
- foreach ($decodedData as $k => $service) {
- $this->Services[$k] = new AgentService($service);
+ foreach ($decoded as $k => $v) {
+ $this->Services[$k] = AgentService::jsonUnserialize($v);
}
}
}
diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php
index 4f95dba6..5b84ad07 100644
--- a/src/Agent/AgentToken.php
+++ b/src/Agent/AgentToken.php
@@ -20,11 +20,17 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentToken extends AbstractModel
+class AgentToken extends AbstractType
{
- public string $Token = '';
+ public string $Token;
+
+ public function __construct(
+ string $Token = '',
+ ) {
+ $this->Token = $Token;
+}
public function getToken(): string
{
@@ -36,4 +42,20 @@ public function setToken(string $Token): self
$this->Token = $Token;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Token = $this->Token;
+ return $out;
+ }
}
diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php
index 19dcb0b4..1fb248d9 100644
--- a/src/Agent/AgentWeights.php
+++ b/src/Agent/AgentWeights.php
@@ -20,20 +20,57 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AgentWeights extends AbstractModel
+class AgentWeights extends AbstractType
{
- public int $Passing = 0;
- public int $Warning = 0;
+ public int $Passing;
+ public int $Warning;
+
+ public function __construct(
+ int $Passing = 0,
+ int $Warning = 0,
+ ) {
+ $this->Passing = $Passing;
+ $this->Warning = $Warning;
+}
public function getPassing(): int
{
return $this->Passing;
}
+ public function setPassing(int $Passing): self
+ {
+ $this->Passing = $Passing;
+ return $this;
+ }
+
public function getWarning(): int
{
return $this->Warning;
}
+
+ public function setWarning(int $Warning): self
+ {
+ $this->Warning = $Warning;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Passing = $this->Passing;
+ $out->Warning = $this->Warning;
+ return $out;
+ }
}
diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php
new file mode 100644
index 00000000..7341d8de
--- /dev/null
+++ b/src/Agent/ConnectProxyConfig.php
@@ -0,0 +1,168 @@
+ */
+ public null|array $Config = null;
+ /** @var array<\DCarbone\PHPConsulAPI\Agent\Upstream> */
+ public array $Upstreams;
+
+ /**
+ * @param array $Config
+ * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams
+ */
+ public function __construct(
+ string $ProxyServiceID = '',
+ string $TargetServiceID = '',
+ string $TargetServiceName = '',
+ string $ContentHash = '',
+ array $Config = [],
+ array $Upstreams = [],
+ ) {
+ $this->ProxyServiceID = $ProxyServiceID;
+ $this->TargetServiceID = $TargetServiceID;
+ $this->TargetServiceName = $TargetServiceName;
+ $this->ContentHash = $ContentHash;
+ $this->setConfig($Config);
+ $this->setUpstreams(...$Upstreams);
+}
+
+ public function getProxyServiceID(): string
+ {
+ return $this->ProxyServiceID;
+ }
+
+ public function setProxyServiceID(string $ProxyServiceID): self
+ {
+ $this->ProxyServiceID = $ProxyServiceID;
+ return $this;
+ }
+
+ public function getTargetServiceID(): string
+ {
+ return $this->TargetServiceID;
+ }
+
+ public function setTargetServiceID(string $TargetServiceID): self
+ {
+ $this->TargetServiceID = $TargetServiceID;
+ return $this;
+ }
+
+ public function getTargetServiceName(): string
+ {
+ return $this->TargetServiceName;
+ }
+
+ public function setTargetServiceName(string $TargetServiceName): self
+ {
+ $this->TargetServiceName = $TargetServiceName;
+ return $this;
+ }
+
+ public function getContentHash(): string
+ {
+ return $this->ContentHash;
+ }
+
+ public function setContentHash(string $ContentHash): self
+ {
+ $this->ContentHash = $ContentHash;
+ return $this;
+ }
+
+ /**
+ * @return null|array
+ */
+ public function getConfig(): null|array
+ {
+ return $this->Config;
+ }
+
+ /**
+ * @param \stdClass|array|null $Config
+ * @return $this
+ */
+ public function setConfig(null|\stdClass|array $Config): self
+ {
+ if (null === $Config) {
+ $this->Config = null;
+ return $this;
+ }
+ $this->Config = [];
+ foreach ($Config as $k => $v) {
+ $this->Config[$k] = $v;
+ }
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\Upstream[]
+ */
+ public function getUpstreams(): array
+ {
+ return $this->Upstreams;
+ }
+
+ public function setUpstreams(Upstream ...$Upstreams): self
+ {
+ $this->Upstreams = $Upstreams;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Upstreams' === $k) {
+ $n->Upstreams = [];
+ foreach ($v as $vv) {
+ $n->Upstreams[] = Upstream::jsonUnserialize($vv);
+ }
+ } elseif ('Config' === $k) {
+ $n->setConfig($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ProxyServiceID = $this->ProxyServiceID;
+ $out->TargetServiceID = $this->TargetServiceID;
+ $out->TargetServiceName = $this->TargetServiceName;
+ $out->ContentHash = $this->ContentHash;
+ $out->Config = $this->getConfig();
+ $out->Upstreams = $this->Upstreams;
+ return $out;
+ }
+}
diff --git a/src/Agent/EnvoyExtension.php b/src/Agent/EnvoyExtension.php
deleted file mode 100644
index e433e843..00000000
--- a/src/Agent/EnvoyExtension.php
+++ /dev/null
@@ -1,103 +0,0 @@
- Transcoding::MAP_FIELD,
- ];
-
- private const FIELD_ARGUMENTS = 'Arguments';
-
- public string $Name = '';
- public bool $Required = false;
- public FakeMap $Arguments;
- public string $ConsulVersion = '';
- public string $EnvoyVersion = '';
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Arguments)) {
- $this->Arguments = new FakeMap(null);
- }
- }
-
- public function getName(): string
- {
- return $this->Name;
- }
-
- public function setName(string $Name): self
- {
- $this->Name = $Name;
- return $this;
- }
-
- public function isRequired(): bool
- {
- return $this->Required;
- }
-
- public function setRequired(bool $Required): self
- {
- $this->Required = $Required;
- return $this;
- }
-
- public function getArguments(): ?FakeMap
- {
- return $this->Arguments;
- }
-
- public function setArguments(array|FakeMap|\stdClass|null $Arguments): self
- {
- $this->Arguments = FakeMap::parse($Arguments);
- return $this;
- }
-
- public function getConsulVersion(): string
- {
- return $this->ConsulVersion;
- }
-
- public function setConsulVersion(string $ConsulVersion): self
- {
- $this->ConsulVersion = $ConsulVersion;
- return $this;
- }
-
- public function getEnvoyVersion(): string
- {
- return $this->EnvoyVersion;
- }
-
- public function setEnvoyVersion(string $EnvoyVersion): self
- {
- $this->EnvoyVersion = $EnvoyVersion;
- return $this;
- }
-}
diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php
index e1ec1a6b..f7c954cf 100644
--- a/src/Agent/GaugeValue.php
+++ b/src/Agent/GaugeValue.php
@@ -20,22 +20,36 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class GaugeValue extends AbstractModel
+class GaugeValue extends AbstractType
{
- public string $Name = '';
- public float $Value = 0.0;
- public array $Labels = [];
+ public string $Name;
+ public float $Value;
+ /** @var null|array */
+ public null|array $Labels = null;
+
+ /**
+ * @param array $Labels
+ */
+ public function __construct(
+ string $Name = '',
+ float $Value = 0.0,
+ array $Labels = [],
+ ) {
+ $this->Name = $Name;
+ $this->Value = $Value;
+ $this->setLabels($Labels);
+ }
public function getName(): string
{
return $this->Name;
}
- public function setName(string $name): self
+ public function setName(string $Name): self
{
- $this->Name = $name;
+ $this->Name = $Name;
return $this;
}
@@ -44,20 +58,56 @@ public function getValue(): float
return $this->Value;
}
- public function setValue(float $value): self
+ public function setValue(float $Value): self
{
- $this->Value = $value;
+ $this->Value = $Value;
return $this;
}
- public function getLabels(): array
+ /**
+ * @return null|array
+ */
+ public function getLabels(): null|array
{
return $this->Labels;
}
- public function setLabels(array $labels): self
+ /**
+ * @param \stdClass|array|null $Labels
+ * @return $this
+ */
+ public function setLabels(null|\stdClass|array $Labels): self
{
- $this->Labels = $labels;
+ if (null === $Labels) {
+ $this->Labels = null;
+ return $this;
+ }
+ $this->Labels = [];
+ foreach ($Labels as $k => $v) {
+ $this->Labels[$k] = $v;
+ }
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Labels' === $k) {
+ $n->setLabels($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Value = $this->Value;
+ $out->Labels = $this->getLabels();
+ return $out;
+ }
}
diff --git a/src/Agent/MemberACLMode.php b/src/Agent/MemberACLMode.php
new file mode 100644
index 00000000..0d0e9607
--- /dev/null
+++ b/src/Agent/MemberACLMode.php
@@ -0,0 +1,47 @@
+WAN = $WAN;
+ $this->Segment = $Segment;
+ $this->Filter = $Filter;
+ }
public function isWAN(): bool
{
return $this->WAN;
}
- public function setWAN(bool $wan): self
+ public function setWAN(bool $WAN): self
{
- $this->WAN = $wan;
+ $this->WAN = $WAN;
return $this;
}
@@ -43,9 +54,44 @@ public function getSegment(): string
return $this->Segment;
}
- public function setSegment(string $segment): self
+ public function setSegment(string $Segment): self
{
- $this->Segment = $segment;
+ $this->Segment = $Segment;
return $this;
}
+
+ public function getFilter(): string
+ {
+ return $this->Filter;
+ }
+
+ public function setFilter(string $Filter): self
+ {
+ $this->Filter = $Filter;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->WAN) {
+ $out->WAN = $this->WAN;
+ }
+ if ('' !== $this->Segment) {
+ $out->Segment = $this->Segment;
+ }
+ if ('' !== $this->Filter) {
+ $out->Filter = $this->Filter;
+ }
+ return $out;
+ }
}
diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php
index d580ab99..09cfe40b 100644
--- a/src/Agent/MetricsInfo.php
+++ b/src/Agent/MetricsInfo.php
@@ -20,97 +20,146 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class MetricsInfo extends AbstractModel
+class MetricsInfo extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_GAUGES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => GaugeValue::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_POINTS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => PointValue::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_COUNTERS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => SampledValue::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_SAMPLES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => SampledValue::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- ];
-
- private const FIELD_GAUGES = 'Gauges';
- private const FIELD_POINTS = 'Points';
- private const FIELD_COUNTERS = 'Counters';
- private const FIELD_SAMPLES = 'Samples';
-
- public string $Timestamp = '';
- public array $Gauges = [];
- public array $Points = [];
- public array $Counters = [];
- public array $Samples = [];
+ public string $Timestamp;
+ /** @var \DCarbone\PHPConsulAPI\Agent\GaugeValue[] */
+ public array $Gauges;
+ /** @var \DCarbone\PHPConsulAPI\Agent\PointValue[] */
+ public array $Points;
+ /** @var \DCarbone\PHPConsulAPI\Agent\SampledValue[] */
+ public array $Counters;
+ /** @var \DCarbone\PHPConsulAPI\Agent\SampledValue[] */
+ public array $Samples;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\Agent\GaugeValue> $Gauges
+ * @param array<\DCarbone\PHPConsulAPI\Agent\PointValue> $Points
+ * @param array<\DCarbone\PHPConsulAPI\Agent\SampledValue> $Counters
+ * @param array<\DCarbone\PHPConsulAPI\Agent\SampledValue> $Samples
+ */
+ public function __construct(
+ string $Timestamp = '',
+ array $Gauges = [],
+ array $Points = [],
+ array $Counters = [],
+ array $Samples = [],
+ ) {
+ $this->Timestamp = $Timestamp;
+ $this->setGauges(...$Gauges);
+ $this->setPoints(...$Points);
+ $this->setCounters(...$Counters);
+ $this->setSamples(...$Samples);
+ }
public function getTimestamp(): string
{
return $this->Timestamp;
}
- public function setTimestamp(string $timestamp): self
+ public function setTimestamp(string $Timestamp): self
{
- $this->Timestamp = $timestamp;
+ $this->Timestamp = $Timestamp;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\GaugeValue[]
+ */
public function getGauges(): array
{
return $this->Gauges;
}
- public function setGauges(array $gauges): self
+ public function setGauges(GaugeValue ...$gauges): self
{
$this->Gauges = $gauges;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\PointValue[]
+ */
public function getPoints(): array
{
return $this->Points;
}
- public function setPoints(array $points): self
+ public function setPoints(PointValue ...$points): self
{
$this->Points = $points;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\SampledValue[]
+ */
public function getCounters(): array
{
return $this->Counters;
}
- public function setCounters(array $counters): self
+ public function setCounters(SampledValue ...$counters): self
{
$this->Counters = $counters;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\Agent\SampledValue[]
+ */
public function getSamples(): array
{
return $this->Samples;
}
- public function setSamples(array $samples): self
+ public function setSamples(SampledValue ...$samples): self
{
$this->Samples = $samples;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Gauges' === $k) {
+ $n->Gauges = [];
+ foreach ($v as $vv) {
+ $n->Gauges[] = GaugeValue::jsonUnserialize($vv);
+ }
+ } elseif ('Points' === $k) {
+ $n->Points = [];
+ foreach ($v as $vv) {
+ $n->Points[] = PointValue::jsonUnserialize($vv);
+ }
+ } elseif ('Counters' === $k) {
+ $n->Counters = [];
+ foreach ($v as $vv) {
+ $n->Counters[] = SampledValue::jsonUnserialize($vv);
+ }
+ } elseif ('Samples' === $k) {
+ $n->Samples = [];
+ foreach ($v as $vv) {
+ $n->Samples[] = SampledValue::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Timestamp = $this->Timestamp;
+ $out->Gauges = $this->Gauges;
+ $out->Points = $this->Points;
+ $out->Counters = $this->Counters;
+ $out->Samples = $this->Samples;
+ return $out;
+ }
}
diff --git a/src/Agent/MetricsInfoResponse.php b/src/Agent/MetricsInfoResponse.php
index da7e1ed9..1cb65e7f 100644
--- a/src/Agent/MetricsInfoResponse.php
+++ b/src/Agent/MetricsInfoResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class MetricsInfoResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?MetricsInfo $MetricsInfo = null;
+ public null|MetricsInfo $MetricsInfo = null;
- public function getValue(): ?MetricsInfo
+ public function getValue(): null|MetricsInfo
{
return $this->MetricsInfo;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->MetricsInfo = new MetricsInfo((array)$decodedData);
+ if (null === $decoded) {
+ $this->MetricsInfo = null;
+ return;
+ }
+ $this->MetricsInfo = MetricsInfo::jsonUnserialize($decoded);
}
}
diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php
index 00cd83fa..870679aa 100644
--- a/src/Agent/PointValue.php
+++ b/src/Agent/PointValue.php
@@ -20,32 +20,64 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class PointValue extends AbstractModel
+class PointValue extends AbstractType
{
- public string $Name = '';
- public array $Points = [];
+ public string $Name;
+ /** @var float[] */
+ public array $Points;
+
+ /**
+ * @param iterable $Points
+ */
+ public function __construct(
+ string $Name = '',
+ iterable $Points = [],
+ ) {
+ $this->Name = $Name;
+ $this->setPoints(...$Points);
+}
public function getName(): string
{
return $this->Name;
}
- public function setName(string $name): self
+ public function setName(string $Name): self
{
- $this->Name = $name;
+ $this->Name = $Name;
return $this;
}
+ /**
+ * @return float[]
+ */
public function getPoints(): array
{
return $this->Points;
}
- public function setPoints(array $points): self
+ public function setPoints(float ...$points): self
{
$this->Points = $points;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Points = $this->Points;
+ return $out;
+ }
}
diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php
index 9c177c95..15b5ef6b 100644
--- a/src/Agent/SampledValue.php
+++ b/src/Agent/SampledValue.php
@@ -20,27 +20,51 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class SampledValue extends AbstractModel
+class SampledValue extends AbstractType
{
- public string $Name = '';
- public int $Count = 0;
- public float $Sum = 0.0;
- public float $Min = 0.0;
- public float $Max = 0.0;
- public float $Mean = 0.0;
- public float $Stddev = 0.0;
- public array $Labels = [];
+ public string $Name;
+ public int $Count;
+ public float $Sum;
+ public float $Min;
+ public float $Max;
+ public float $Mean;
+ public float $Stddev;
+ /** @var null|array */
+ public null|array $Labels = null;
+
+ /**
+ * @param array $Labels
+ */
+ public function __construct(
+ string $Name = '',
+ int $Count = 0,
+ float $Sum = 0.0,
+ float $Min = 0.0,
+ float $Max = 0.0,
+ float $Mean = 0.0,
+ float $Stddev = 0.0,
+ array $Labels = [],
+ ) {
+ $this->Name = $Name;
+ $this->Count = $Count;
+ $this->Sum = $Sum;
+ $this->Min = $Min;
+ $this->Max = $Max;
+ $this->Mean = $Mean;
+ $this->Stddev = $Stddev;
+ $this->setLabels($Labels);
+ }
public function getName(): string
{
return $this->Name;
}
- public function setName(string $name): self
+ public function setName(string $Name): self
{
- $this->Name = $name;
+ $this->Name = $Name;
return $this;
}
@@ -49,9 +73,9 @@ public function getCount(): int
return $this->Count;
}
- public function setCount(int $count): self
+ public function setCount(int $Count): self
{
- $this->Count = $count;
+ $this->Count = $Count;
return $this;
}
@@ -60,9 +84,9 @@ public function getSum(): float
return $this->Sum;
}
- public function setSum(float $sum): self
+ public function setSum(float $Sum): self
{
- $this->Sum = $sum;
+ $this->Sum = $Sum;
return $this;
}
@@ -71,9 +95,9 @@ public function getMin(): float
return $this->Min;
}
- public function setMin(float $min): self
+ public function setMin(float $Min): self
{
- $this->Min = $min;
+ $this->Min = $Min;
return $this;
}
@@ -82,9 +106,9 @@ public function getMax(): float
return $this->Max;
}
- public function setMax(float $max): self
+ public function setMax(float $Max): self
{
- $this->Max = $max;
+ $this->Max = $Max;
return $this;
}
@@ -93,9 +117,9 @@ public function getMean(): float
return $this->Mean;
}
- public function setMean(float $mean): self
+ public function setMean(float $Mean): self
{
- $this->Mean = $mean;
+ $this->Mean = $Mean;
return $this;
}
@@ -110,14 +134,55 @@ public function setStddev(float $Stddev): self
return $this;
}
- public function getLabels(): array
+ /**
+ * @return array|null
+ */
+ public function getLabels(): null|array
{
return $this->Labels;
}
- public function setLabels(array $labels): self
- {
- $this->Labels = $labels;
+ /**
+ * @param \stdClass|array|null $Labels
+ * @return $this
+ */
+ public function setLabels(null|\stdClass|array $Labels): self
+ {
+ if (null === $Labels) {
+ $this->Labels = null;
+ return $this;
+ }
+ $this->Labels = [];
+ foreach ($Labels as $k => $v) {
+ $this->Labels[$k] = $v;
+ }
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Labels' === $k) {
+ $n->setLabels($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Count = $this->Count;
+ $out->Sum = $this->Sum;
+ $out->Min = $this->Min;
+ $out->Max = $this->Max;
+ $out->Mean = $this->Mean;
+ $out->Stddev = $this->Stddev;
+ $out->Labels = $this->getLabels();
+ return $out;
+ }
}
diff --git a/src/Agent/ServiceKind.php b/src/Agent/ServiceKind.php
new file mode 100644
index 00000000..08c57c6c
--- /dev/null
+++ b/src/Agent/ServiceKind.php
@@ -0,0 +1,66 @@
+ReplaceExistingChecks = $ReplaceExistingChecks;
+ $this->Token = $Token;
+}
public function isReplaceExistingChecks(): bool
{
return $this->ReplaceExistingChecks;
}
- public function setReplaceExistingChecks(bool $replaceExistingChecks): self
+ public function setReplaceExistingChecks(bool $ReplaceExistingChecks): self
{
- $this->ReplaceExistingChecks = $replaceExistingChecks;
+ $this->ReplaceExistingChecks = $ReplaceExistingChecks;
return $this;
}
+
+ public function getToken(): string
+ {
+ return $this->Token;
+ }
+
+ public function setToken(string $Token): self
+ {
+ $this->Token = $Token;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ReplaceExistingChecks = $this->ReplaceExistingChecks;
+ $out->Token = $this->Token;
+ return $out;
+ }
}
diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php
index 96672596..2bc7e7c0 100644
--- a/src/Agent/Upstream.php
+++ b/src/Agent/Upstream.php
@@ -20,63 +20,78 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class Upstream extends AbstractModel
+class Upstream extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_DESTINATION_TYPE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DESTINATION_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DATACENTER => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_LOCAL_BIND_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_LOCAL_BIND_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_CONFIG => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::MIXED,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_MESH_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => MeshGatewayConfig::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
-
- private const FIELD_DESTINATION_TYPE = 'DestinationType';
- private const FIELD_DESTINATION_NAMESPACE = 'DestinationNamespace';
- private const FIELD_DATACENTER = 'Datacenter';
- private const FIELD_LOCAL_BIND_ADDRESS = 'LocalBindAddress';
- private const FIELD_LOCAL_BIND_PORT = 'LocalBindPort';
- private const FIELD_CONFIG = 'Config';
- private const FIELD_MESH_GATEWAY = 'MeshGateway';
-
- public string $DestinationType = '';
- public string $DestinationNamespace = '';
- public string $DestinationName = '';
- public string $Datacenter = '';
- public string $LocalBindAddress = '';
- public int $LocalBindPort = 0;
- public array $Config = [];
- public MeshGatewayConfig $MeshGatewayConfig;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->MeshGatewayConfig)) {
- $this->MeshGatewayConfig = new MeshGatewayConfig(null);
- }
+ public UpstreamDestType $DestinationType;
+ public string $DestinationPartition;
+ public string $DestinationNamespace;
+ public string $DestinationPeer;
+ public string $DestinationName;
+ public string $Datacenter;
+ public string $LocalBindAddress;
+ public int $LocalBindPort;
+ public string $LocalBindSocketPath;
+ public string $LocalBindSocketMode;
+ /** @var array */
+ public null|array $Config;
+ public null|MeshGatewayConfig $MeshGateway;
+ public bool $CentrallyConfigured;
+
+ /**
+ * @param array $Config
+ */
+ public function __construct(
+ string|UpstreamDestType $DestinationType = UpstreamDestType::UNDEFINED,
+ string $DestinationPartition = '',
+ string $DestinationNamespace = '',
+ string $DestinationPeer = '',
+ string $DestinationName = '',
+ string $Datacenter = '',
+ string $LocalBindAddress = '',
+ int $LocalBindPort = 0,
+ string $LocalBindSocketPath = '',
+ string $LocalBindSocketMode = '',
+ array $Config = [],
+ null|MeshGatewayConfig $MeshGateway = null,
+ bool $CentrallyConfigured = false,
+ ) {
+ $this->setDestinationType($DestinationType);
+ $this->DestinationPartition = $DestinationPartition;
+ $this->DestinationNamespace = $DestinationNamespace;
+ $this->DestinationPeer = $DestinationPeer;
+ $this->DestinationName = $DestinationName;
+ $this->Datacenter = $Datacenter;
+ $this->LocalBindAddress = $LocalBindAddress;
+ $this->LocalBindPort = $LocalBindPort;
+ $this->LocalBindSocketPath = $LocalBindSocketPath;
+ $this->LocalBindSocketMode = $LocalBindSocketMode;
+ $this->setConfig($Config);
+ $this->MeshGateway = $MeshGateway;
+ $this->CentrallyConfigured = $CentrallyConfigured;
}
- public function getDestinationType(): string
+ public function getDestinationType(): UpstreamDestType
{
return $this->DestinationType;
}
- public function setDestinationType(string $DestinationType): self
+ public function setDestinationType(string|UpstreamDestType $DestinationType): self
+ {
+ $this->DestinationType = $DestinationType instanceof UpstreamDestType ? $DestinationType : UpstreamDestType::from($DestinationType);
+ return $this;
+ }
+
+ public function getDestinationPartition(): string
+ {
+ return $this->DestinationPartition;
+ }
+
+ public function setDestinationPartition(string $DestinationPartition): self
{
- $this->DestinationType = $DestinationType;
+ $this->DestinationPartition = $DestinationPartition;
return $this;
}
@@ -91,6 +106,17 @@ public function setDestinationNamespace(string $DestinationNamespace): self
return $this;
}
+ public function getDestinationPeer(): string
+ {
+ return $this->DestinationPeer;
+ }
+
+ public function setDestinationPeer(string $DestinationPeer): self
+ {
+ $this->DestinationPeer = $DestinationPeer;
+ return $this;
+ }
+
public function getDestinationName(): string
{
return $this->DestinationName;
@@ -135,25 +161,132 @@ public function setLocalBindPort(int $LocalBindPort): self
return $this;
}
- public function getConfig(): array
+ public function getLocalBindSocketPath(): string
+ {
+ return $this->LocalBindSocketPath;
+ }
+
+ public function setLocalBindSocketPath(string $LocalBindSocketPath): self
+ {
+ $this->LocalBindSocketPath = $LocalBindSocketPath;
+ return $this;
+ }
+
+ public function getLocalBindSocketMode(): string
+ {
+ return $this->LocalBindSocketMode;
+ }
+
+ public function setLocalBindSocketMode(string $LocalBindSocketMode): self
+ {
+ $this->LocalBindSocketMode = $LocalBindSocketMode;
+ return $this;
+ }
+
+ /**
+ * @return null|array
+ */
+ public function getConfig(): null|array
{
return $this->Config;
}
- public function setConfig(array $Config): self
+ /**
+ * @param \stdClass|array|null $Config
+ * @return $this
+ */
+ public function setConfig(null|\stdClass|array $Config): self
+ {
+ if (null == $Config) {
+ $this->Config = null;
+ return $this;
+ }
+ $this->Config = [];
+ foreach ($Config as $k => $v) {
+ $this->Config[$k] = $v;
+ }
+ return $this;
+ }
+
+ public function getMeshGateway(): null|MeshGatewayConfig
+ {
+ return $this->MeshGateway;
+ }
+
+ public function setMeshGateway(null|MeshGatewayConfig $MeshGateway): self
{
- $this->Config = $Config;
+ $this->MeshGateway = $MeshGateway;
return $this;
}
- public function getMeshGatewayConfig(): MeshGatewayConfig
+ public function isCentrallyConfigured(): bool
{
- return $this->MeshGatewayConfig;
+ return $this->CentrallyConfigured;
}
- public function setMeshGatewayConfig(MeshGatewayConfig $MeshGatewayConfig): self
+ public function setCentrallyConfigured(bool $CentrallyConfigured): self
{
- $this->MeshGatewayConfig = $MeshGatewayConfig;
+ $this->CentrallyConfigured = $CentrallyConfigured;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('DestinationType' === $k) {
+ $n->setDestinationType($v);
+ } elseif ('MeshGateway' === $k) {
+ $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v);
+ } elseif ('Config' === $k) {
+ $n->setConfig($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->DestinationType !== UpstreamDestType::UNDEFINED) {
+ $out->DestinationType = $this->DestinationType;
+ }
+ if ('' !== $this->DestinationPartition) {
+ $out->DestinationPartition = $this->DestinationPartition;
+ }
+ if ('' !== $this->DestinationNamespace) {
+ $out->DestinationNamespace = $this->DestinationNamespace;
+ }
+ if ('' !== $this->DestinationPeer) {
+ $out->DestinationPeer = $this->DestinationPeer;
+ }
+ $out->DestinationName = $this->DestinationName;
+ if ('' !== $this->Datacenter) {
+ $out->Datacenter = $this->Datacenter;
+ }
+ if ('' !== $this->LocalBindAddress) {
+ $out->LocalBindAddress = $this->LocalBindAddress;
+ }
+ if (0 !== $this->LocalBindPort) {
+ $out->LocalBindPort = $this->LocalBindPort;
+ }
+ if ('' !== $this->LocalBindSocketPath) {
+ $out->LocalBindSocketPath = $this->LocalBindSocketPath;
+ }
+ if ('' !== $this->LocalBindSocketMode) {
+ $out->LocalBindSocketMode = $this->LocalBindSocketMode;
+ }
+ if (null !== $this->Config) {
+ $out->Config = $this->Config;
+ }
+ if (null !== $this->MeshGateway) {
+ $out->MeshGateway = $this->MeshGateway;
+ }
+ if ($this->CentrallyConfigured) {
+ $out->CentrallyConfigured = $this->CentrallyConfigured;
+ }
+ return $out;
+ }
}
diff --git a/src/KV/KVTxnOps.php b/src/Agent/UpstreamDestType.php
similarity index 65%
rename from src/KV/KVTxnOps.php
rename to src/Agent/UpstreamDestType.php
index a1c1ac8f..856ccef2 100644
--- a/src/KV/KVTxnOps.php
+++ b/src/Agent/UpstreamDestType.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace DCarbone\PHPConsulAPI\KV;
+namespace DCarbone\PHPConsulAPI\Agent;
/*
Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
@@ -20,15 +20,15 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeSlice;
-
-class KVTxnOps extends FakeSlice
+enum UpstreamDestType: string
{
- protected string $containedClass = KVTxnOp::class;
+ // Service discovers instances via healthy service lookup.
+ case Service = 'service';
+
+ // PreparedQuery discovers instances via prepared query
+ // execution.
+ case PreparedQuery = 'prepared_query';
- protected function newChild(array $data): AbstractModel
- {
- return new KVTxnOp($data);
- }
+ // Default case for when value is not set.
+ case UNDEFINED = '';
}
diff --git a/src/Catalog/CatalogClient.php b/src/Catalog/CatalogClient.php
index c778c499..a5dc6966 100644
--- a/src/Catalog/CatalogClient.php
+++ b/src/Catalog/CatalogClient.php
@@ -20,21 +20,21 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedQueryStringsResponse;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedStringsResponse;
+use DCarbone\PHPConsulAPI\PHPLib\WriteResponse;
use DCarbone\PHPConsulAPI\QueryOptions;
-use DCarbone\PHPConsulAPI\ValuedQueryStringsResponse;
-use DCarbone\PHPConsulAPI\ValuedStringsResponse;
use DCarbone\PHPConsulAPI\WriteOptions;
-use DCarbone\PHPConsulAPI\WriteResponse;
class CatalogClient extends AbstractClient
{
- public function Register(CatalogRegistration $catalogRegistration, ?WriteOptions $opts = null): WriteResponse
+ public function Register(CatalogRegistration $catalogRegistration, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePut('v1/catalog/register', $catalogRegistration, $opts);
}
- public function Deregister(CatalogDeregistration $catalogDeregistration, ?WriteOptions $opts = null): WriteResponse
+ public function Deregister(CatalogDeregistration $catalogDeregistration, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePut('v1/catalog/deregister', $catalogDeregistration, $opts);
}
@@ -47,7 +47,7 @@ public function Datacenters(): ValuedStringsResponse
return $ret;
}
- public function Nodes(?QueryOptions $opts = null): NodesResponse
+ public function Nodes(null|QueryOptions $opts = null): NodesResponse
{
$resp = $this->_requireOK($this->_doGet('v1/catalog/nodes', $opts));
$ret = new NodesResponse();
@@ -55,7 +55,7 @@ public function Nodes(?QueryOptions $opts = null): NodesResponse
return $ret;
}
- public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
+ public function Services(null|QueryOptions $opts = null): ValuedQueryStringsResponse
{
$resp = $this->_requireOK($this->_doGet('v1/catalog/services', $opts));
$ret = new ValuedQueryStringsResponse();
@@ -63,7 +63,7 @@ public function Services(?QueryOptions $opts = null): ValuedQueryStringsResponse
return $ret;
}
- public function NodeServicesList(string $node, ?QueryOptions $opts = null): CatalogNodeServicesListResponse
+ public function NodeServicesList(string $node, null|QueryOptions $opts = null): CatalogNodeServicesListResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/catalog/node-services/%s', urlencode($node)), $opts));
$ret = new CatalogNodeServicesListResponse();
@@ -71,10 +71,13 @@ public function NodeServicesList(string $node, ?QueryOptions $opts = null): Cata
return $ret;
}
+ /**
+ * @param array $tags
+ */
public function ServiceMultipleTags(
string $service,
array $tags,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): CatalogServicesResponse {
$r = $this->_newGetRequest(sprintf('v1/catalog/service/%s', $service), $opts);
if ([] !== $tags) {
@@ -86,12 +89,12 @@ public function ServiceMultipleTags(
return $ret;
}
- public function Service(string $service, string $tag = '', ?QueryOptions $opts = null): CatalogServicesResponse
+ public function Service(string $service, string $tag = '', null|QueryOptions $opts = null): CatalogServicesResponse
{
return $this->ServiceMultipleTags($service, '' !== $tag ? [$tag] : [], $opts);
}
- public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeResponse
+ public function Node(string $node, null|QueryOptions $opts = null): CatalogNodeResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/catalog/node/%s', $node), $opts));
$ret = new CatalogNodeResponse();
@@ -99,7 +102,7 @@ public function Node(string $node, ?QueryOptions $opts = null): CatalogNodeRespo
return $ret;
}
- public function GatewayServices(string $gateway, ?QueryOptions $opts = null): GatewayServicesResponse
+ public function GatewayServices(string $gateway, null|QueryOptions $opts = null): GatewayServicesResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/catalog/gateway-services/%s', urlencode($gateway)), $opts));
$ret = new GatewayServicesResponse();
diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php
index 139008fc..cc91c9a3 100644
--- a/src/Catalog/CatalogDeregistration.php
+++ b/src/Catalog/CatalogDeregistration.php
@@ -20,33 +20,44 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CatalogDeregistration extends AbstractModel
+class CatalogDeregistration extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_ADDRESS = 'Address';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Node = '';
- public string $Address = '';
- public string $Datacenter = '';
- public string $ServiceID = '';
- public string $CheckID = '';
+ public string $Node;
+ public string $Address;
+ public string $Datacenter;
+ public string $ServiceID;
+ public string $CheckID;
+ public string $Namespace;
+ public string $Partition;
+
+ public function __construct(
+ string $Node = '',
+ string $Address = '',
+ string $Datacenter = '',
+ string $ServiceID = '',
+ string $CheckID = '',
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->Node = $Node;
+ $this->Address = $Address;
+ $this->Datacenter = $Datacenter;
+ $this->ServiceID = $ServiceID;
+ $this->CheckID = $CheckID;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ }
public function getNode(): string
{
return $this->Node;
}
- public function setNode(string $node): self
+ public function setNode(string $Node): self
{
- $this->Node = $node;
+ $this->Node = $Node;
return $this;
}
@@ -55,9 +66,9 @@ public function getAddress(): string
return $this->Address;
}
- public function setAddress(string $address): self
+ public function setAddress(string $Address): self
{
- $this->Address = $address;
+ $this->Address = $Address;
return $this;
}
@@ -66,9 +77,9 @@ public function getDatacenter(): string
return $this->Datacenter;
}
- public function setDatacenter(string $datacenter): self
+ public function setDatacenter(string $Datacenter): self
{
- $this->Datacenter = $datacenter;
+ $this->Datacenter = $Datacenter;
return $this;
}
@@ -77,9 +88,9 @@ public function getServiceID(): string
return $this->ServiceID;
}
- public function setServiceID(string $serviceID): self
+ public function setServiceID(string $ServiceID): self
{
- $this->ServiceID = $serviceID;
+ $this->ServiceID = $ServiceID;
return $this;
}
@@ -88,9 +99,59 @@ public function getCheckID(): string
return $this->CheckID;
}
- public function setCheckID(string $checkID): self
+ public function setCheckID(string $CheckID): self
+ {
+ $this->CheckID = $CheckID;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
{
- $this->CheckID = $checkID;
+ $this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ if ('' !== $this->Address) {
+ $out->Address = $this->Address;
+ }
+ $out->Datacenter = $this->Datacenter;
+ $out->ServiceID = $this->ServiceID;
+ $out->CheckID = $this->CheckID;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php
index 1f947d62..49de4aca 100644
--- a/src/Catalog/CatalogNode.php
+++ b/src/Catalog/CatalogNode.php
@@ -20,49 +20,77 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Agent\AgentService;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CatalogNode extends AbstractModel
+class CatalogNode extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NODE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Node::class,
- ],
- self::FIELD_SERVICES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AgentService::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- ];
+ public null|Node $Node;
+ /** @var array */
+ public array $Services;
- private const FIELD_NODE = 'Node';
- private const FIELD_SERVICES = 'Services';
-
- public ?Node $Node = null;
- public array $Services = [];
+ /**
+ * @param array $Services
+ */
+ public function __construct(
+ null|Node $Node = null,
+ array $Services = [],
+ ) {
+ $this->Node = $Node;
+ $this->Services = $Services;
+ }
- public function getNode(): ?Node
+ public function getNode(): null|Node
{
return $this->Node;
}
- public function setNode(?Node $Node): self
+ public function setNode(null|Node $Node): self
{
$this->Node = $Node;
return $this;
}
+ /**
+ * @return array
+ */
public function getServices(): array
{
return $this->Services;
}
+ /**
+ * @param array $Services
+ */
public function setServices(array $Services): self
{
$this->Services = $Services;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Node' === $k) {
+ $n->Node = null === $v ? null : Node::jsonUnserialize($v);
+ } elseif ('Services' === $k) {
+ $n->Services = [];
+ foreach ($v as $kk => $vv) {
+ $n->Services[$kk] = AgentService::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->getNode();
+ $out->Services = $this->getServices();
+ return $out;
+ }
}
diff --git a/src/Catalog/CatalogNodeResponse.php b/src/Catalog/CatalogNodeResponse.php
index b3095658..29f998cc 100644
--- a/src/Catalog/CatalogNodeResponse.php
+++ b/src/Catalog/CatalogNodeResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class CatalogNodeResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?CatalogNode $Node = null;
+ public null|CatalogNode $Node = null;
- public function getValue(): ?CatalogNode
+ public function getValue(): null|CatalogNode
{
return $this->Node;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->Node = new CatalogNode((array)$decodedData);
+ if (null === $decoded) {
+ $this->Node = null;
+ return;
+ }
+ $this->Node = CatalogNode::jsonUnserialize($decoded);
}
}
diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php
index abae0f3a..b0e9579a 100644
--- a/src/Catalog/CatalogNodeServiceList.php
+++ b/src/Catalog/CatalogNodeServiceList.php
@@ -20,49 +20,75 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Agent\AgentService;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CatalogNodeServiceList extends AbstractModel
+class CatalogNodeServiceList extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NODE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Node::class,
- ],
- self::FIELD_SERVICES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AgentService::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- ];
+ public null|Node $Node;
+ /** @var array<\DCarbone\PHPConsulAPI\Agent\AgentService> */
+ public array $Services;
- private const FIELD_NODE = 'Node';
- private const FIELD_SERVICES = 'Services';
-
- public ?Node $Node = null;
- public array $Services = [];
+ /**
+ * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node
+ * @param array<\DCarbone\PHPConsulAPI\Agent\AgentService> $Services
+ */
+ public function __construct(
+ null|Node $Node = null,
+ array $Services = [],
+ ) {
+ $this->Node = $Node;
+ $this->setServices(...$Services);
+ }
- public function getNode(): ?Node
+ public function getNode(): null|Node
{
return $this->Node;
}
- public function setNode(?Node $Node): self
+ public function setNode(null|Node $Node): self
{
$this->Node = $Node;
return $this;
}
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\Agent\AgentService>
+ */
public function getServices(): array
{
return $this->Services;
}
- public function setServices(array $Services): self
+ public function setServices(AgentService ...$Services): self
{
$this->Services = $Services;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Node' === $k) {
+ $n->Node = null === $v ? null : Node::jsonUnserialize($v);
+ } elseif ('Services' === $k) {
+ $n->Services = [];
+ foreach ($v as $vv) {
+ $n->Services[] = AgentService::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ $out->Services = $this->Services;
+ return $out;
+ }
}
diff --git a/src/Catalog/CatalogNodeServicesListResponse.php b/src/Catalog/CatalogNodeServicesListResponse.php
index d7f712fd..e3917927 100644
--- a/src/Catalog/CatalogNodeServicesListResponse.php
+++ b/src/Catalog/CatalogNodeServicesListResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class CatalogNodeServicesListResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?CatalogNodeServiceList $CatalogNodeServiceList = null;
+ public null|CatalogNodeServiceList $CatalogNodeServiceList = null;
- public function getValue(): ?CatalogNodeServiceList
+ public function getValue(): null|CatalogNodeServiceList
{
return $this->CatalogNodeServiceList;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->CatalogNodeServiceList = new CatalogNodeServiceList((array)$decodedData);
+ if (null === $decoded) {
+ $this->CatalogNodeServiceList = null;
+ return;
+ }
+ $this->CatalogNodeServiceList = CatalogNodeServiceList::jsonUnserialize($decoded);
}
}
diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php
index 5175edc2..63bfbb50 100644
--- a/src/Catalog/CatalogRegistration.php
+++ b/src/Catalog/CatalogRegistration.php
@@ -20,61 +20,60 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Agent\AgentCheck;
use DCarbone\PHPConsulAPI\Agent\AgentService;
-use DCarbone\PHPConsulAPI\FakeMap;
use DCarbone\PHPConsulAPI\Health\HealthChecks;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Peering\Locality;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\NodeMetaField;
+use DCarbone\PHPConsulAPI\PHPLib\TaggedAddressField;
-class CatalogRegistration extends AbstractModel
+class CatalogRegistration extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD,
- self::FIELD_NODE_META => Transcoding::MAP_FIELD,
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentService::class,
- ],
- self::FIELD_CHECK => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentCheck::class,
- ],
- self::FIELD_CHECKS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthChecks::class,
- ],
- ];
-
- private const FIELD_TAGGED_ADDRESSES = 'TaggedAddresses';
- private const FIELD_NODE_META = 'NodeMeta';
- private const FIELD_SERVICE = 'Service';
- private const FIELD_CHECK = 'Check';
- private const FIELD_CHECKS = 'Checks';
-
- public string $ID = '';
- public string $Node = '';
- public string $Address = '';
- public FakeMap $TaggedAddresses;
- public FakeMap $NodeMeta;
- public string $Datacenter = '';
- public ?AgentService $Service = null;
- public ?AgentCheck $Check = null;
- public HealthChecks $Checks;
- public bool $SkipNodeUpdate = false;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Checks)) {
- $this->Checks = new HealthChecks(null);
- }
- if (!isset($this->TaggedAddresses)) {
- $this->TaggedAddresses = new FakeMap(null);
- }
- if (!isset($this->NodeMeta)) {
- $this->NodeMeta = new FakeMap(null);
- }
+ use TaggedAddressField;
+ use NodeMetaField;
+
+ public string $ID;
+ public string $Node;
+ public string $Address;
+ public string $Datacenter;
+ public null|AgentService $Service;
+ public null|AgentCheck $Check;
+ public null|HealthChecks $Checks;
+ public bool $SkipNodeUpdate;
+ public string $Partition;
+ public null|Locality $Locality;
+
+ /**
+ * @param array $TaggedAddresses
+ * @param array $NodeMeta
+ */
+ public function __construct(
+ string $ID = '',
+ string $Node = '',
+ string $Address = '',
+ array $TaggedAddresses = [],
+ array $NodeMeta = [],
+ string $Datacenter = '',
+ null|AgentService $Service = null,
+ null|AgentCheck $Check = null,
+ null|HealthChecks $Checks = null,
+ bool $SkipNodeUpdate = false,
+ string $Partition = '',
+ null|Locality $Locality = null,
+ ) {
+ $this->ID = $ID;
+ $this->Node = $Node;
+ $this->Address = $Address;
+ $this->setTaggedAddresses($TaggedAddresses);
+ $this->setNodeMeta($NodeMeta);
+ $this->Datacenter = $Datacenter;
+ $this->Service = $Service;
+ $this->Check = $Check;
+ $this->Checks = $Checks;
+ $this->SkipNodeUpdate = $SkipNodeUpdate;
+ $this->Partition = $Partition;
+ $this->Locality = $Locality;
}
public function getID(): string
@@ -110,28 +109,6 @@ public function setAddress(string $Address): self
return $this;
}
- public function getTaggedAddresses(): FakeMap
- {
- return $this->TaggedAddresses;
- }
-
- public function setTaggedAddresses(FakeMap $TaggedAddresses): self
- {
- $this->TaggedAddresses = $TaggedAddresses;
- return $this;
- }
-
- public function getNodeMeta(): FakeMap
- {
- return $this->NodeMeta;
- }
-
- public function setNodeMeta(FakeMap $NodeMeta): self
- {
- $this->NodeMeta = $NodeMeta;
- return $this;
- }
-
public function getDatacenter(): string
{
return $this->Datacenter;
@@ -143,23 +120,23 @@ public function setDatacenter(string $Datacenter): self
return $this;
}
- public function getService(): ?AgentService
+ public function getService(): null|AgentService
{
return $this->Service;
}
- public function setService(?AgentService $Service): self
+ public function setService(null|AgentService $Service): self
{
$this->Service = $Service;
return $this;
}
- public function getCheck(): ?AgentCheck
+ public function getCheck(): null|AgentCheck
{
return $this->Check;
}
- public function setCheck(?AgentCheck $Check): self
+ public function setCheck(null|AgentCheck $Check): self
{
$this->Check = $Check;
return $this;
@@ -170,9 +147,9 @@ public function getChecks(): HealthChecks
return $this->Checks;
}
- public function setChecks(HealthChecks $checks): self
+ public function setChecks(HealthChecks $Checks): self
{
- $this->Checks = $checks;
+ $this->Checks = $Checks;
return $this;
}
@@ -186,4 +163,71 @@ public function setSkipNodeUpdate(bool $SkipNodeUpdate): self
$this->SkipNodeUpdate = $SkipNodeUpdate;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getLocality(): null|Locality
+ {
+ return $this->Locality;
+ }
+
+ public function setLocality(null|Locality $Locality): self
+ {
+ $this->Locality = $Locality;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TaggedAddresses' === $k) {
+ $n->setTaggedAddresses($v);
+ } elseif ('NodeMeta' === $k) {
+ $n->setNodeMeta($v);
+ } elseif ('Service' === $k) {
+ $n->Service = null === $v ? null : AgentService::jsonUnserialize($v);
+ } elseif ('Check' === $k) {
+ $n->Check = null === $v ? null : AgentCheck::jsonUnserialize($v);
+ } elseif ('Checks' === $k) {
+ $n->Checks = null === $v ? null : HealthChecks::jsonUnserialize($v);
+ } elseif ('Locality' === $k) {
+ $n->Locality = null === $v ? null : Locality::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Node = $this->Node;
+ $out->Address = $this->Address;
+ $out->TaggedAddresses = $this->getTaggedAddresses();
+ $out->NodeMeta = $this->getNodeMeta();
+ $out->Datacenter = $this->Datacenter;
+ $out->Service = $this->Service;
+ $out->Check = $this->Check;
+ $out->Checks = $this->Checks;
+ $out->SkipNodeUpdate = $this->SkipNodeUpdate;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if (null !== $this->Locality) {
+ $out->Locality = $this->Locality;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php
index deb51345..ae86217d 100644
--- a/src/Catalog/CatalogService.php
+++ b/src/Catalog/CatalogService.php
@@ -20,60 +20,96 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig;
use DCarbone\PHPConsulAPI\Health\HealthChecks;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Peering\Locality;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\NodeMetaField;
+use DCarbone\PHPConsulAPI\PHPLib\ServiceMetaField;
+use DCarbone\PHPConsulAPI\PHPLib\TaggedAddressField;
-class CatalogService extends AbstractModel
+class CatalogService extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE_TAGGED_ADDRESSES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ServiceAddress::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_SERVICE_WEIGHTS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Weights::class,
- ],
- self::FIELD_SERVICE_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentServiceConnectProxyConfig::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_HEALTH_CHECKS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthChecks::class,
- ],
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_SERVICE_TAGGED_ADDRESSES = 'ServiceTaggedAddresses';
- private const FIELD_SERVICE_WEIGHTS = 'ServiceWeights';
- private const FIELD_SERVICE_PROXY = 'ServiceProxy';
- private const FIELD_HEALTH_CHECKS = 'HealthChecks';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $ID = '';
- public string $Node = '';
- public string $Address = '';
- public string $Datacenter = '';
- public array $TaggedAddresses = [];
- public array $NodeMeta = [];
- public string $ServiceID = '';
- public string $ServiceName = '';
- public string $ServiceAddress = '';
- public array $ServiceTaggedAddresses = [];
- public array $ServiceTags = [];
- public array $ServiceMeta = [];
- public int $ServicePort = 0;
+ use TaggedAddressField;
+ use NodeMetaField;
+ use ServiceMetaField;
+
+ public string $ID;
+ public string $Node;
+ public string $Address;
+ public string $Datacenter;
+ public string $ServiceID;
+ public string $ServiceName;
+ public string $ServiceAddress;
+ /** @var null|array */
+ public null|array $ServiceTaggedAddresses = null;
+ /** @var array */
+ public array $ServiceTags;
+ public int $ServicePort;
public Weights $ServiceWeights;
- public bool $ServiceEnableTagOverride = false;
- public int $CreateIndex = 0;
- public ?AgentServiceConnectProxyConfig $ServiceProxy = null;
- public int $ModifyIndex = 0;
- public string $Namespace = '';
+ public bool $ServiceEnableTagOverride;
+ public null|AgentServiceConnectProxyConfig $ServiceProxy;
+ public null|Locality $ServiceLocality;
+ public int $CreateIndex;
+ public HealthChecks $Checks;
+ public int $ModifyIndex;
+ public string $Namespace;
+ public string $Partition;
+
+ /**
+ * @param array $TaggedAddresses
+ * @param array $NodeMeta
+ * @param array $ServiceTaggedAddresses
+ * @param array $ServiceTags
+ * @param array $ServiceMeta
+ */
+ public function __construct(
+ string $ID = '',
+ string $Node = '',
+ string $Address = '',
+ string $Datacenter = '',
+ array $TaggedAddresses = [],
+ array $NodeMeta = [],
+ string $ServiceID = '',
+ string $ServiceName = '',
+ string $ServiceAddress = '',
+ array $ServiceTaggedAddresses = [],
+ array $ServiceTags = [],
+ array $ServiceMeta = [],
+ int $ServicePort = 0,
+ null|Weights $ServiceWeights = null,
+ bool $ServiceEnableTagOverride = false,
+ null|AgentServiceConnectProxyConfig $ServiceProxy = null,
+ null|Locality $ServiceLocality = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ null|HealthChecks $Checks = null,
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->ID = $ID;
+ $this->Node = $Node;
+ $this->Address = $Address;
+ $this->Datacenter = $Datacenter;
+ $this->setTaggedAddresses($TaggedAddresses);
+ $this->setNodeMeta($NodeMeta);
+ $this->ServiceID = $ServiceID;
+ $this->ServiceName = $ServiceName;
+ $this->ServiceAddress = $ServiceAddress;
+ $this->setServiceTags(...$ServiceTags);
+ $this->setServiceTaggedAddresses($ServiceTaggedAddresses);
+ $this->setServiceMeta($ServiceMeta);
+ $this->ServicePort = $ServicePort;
+ $this->ServiceWeights = $ServiceWeights ?? new Weights();
+ $this->ServiceEnableTagOverride = $ServiceEnableTagOverride;
+ $this->ServiceProxy = $ServiceProxy;
+ $this->ServiceLocality = $ServiceLocality;
+ $this->CreateIndex = $CreateIndex;
+ $this->Checks = $Checks ?? new HealthChecks();
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ }
public function getID(): string
{
@@ -119,28 +155,6 @@ public function setDatacenter(string $Datacenter): self
return $this;
}
- public function getTaggedAddresses(): array
- {
- return $this->TaggedAddresses;
- }
-
- public function setTaggedAddresses(array $TaggedAddresses): self
- {
- $this->TaggedAddresses = $TaggedAddresses;
- return $this;
- }
-
- public function getNodeMeta(): array
- {
- return $this->NodeMeta;
- }
-
- public function setNodeMeta(array $NodeMeta): self
- {
- $this->NodeMeta = $NodeMeta;
- return $this;
- }
-
public function getServiceID(): string
{
return $this->ServiceID;
@@ -174,36 +188,50 @@ public function setServiceAddress(string $ServiceAddress): self
return $this;
}
- public function getServiceTaggedAddresses(): array
+ /**
+ * @return array|null
+ */
+ public function getServiceTaggedAddresses(): null|array
{
return $this->ServiceTaggedAddresses;
}
- public function setServiceTaggedAddresses(array $ServiceTaggedAddresses): self
+ public function setServiceTaggedAddress(string $Tag, ServiceAddress $ServiceAddress): self
{
- $this->ServiceTaggedAddresses = $ServiceTaggedAddresses;
+ if (null === $this->ServiceTaggedAddresses) {
+ $this->ServiceTaggedAddresses = [];
+ }
+ $this->ServiceTaggedAddresses[$Tag] = $ServiceAddress;
return $this;
}
- public function getServiceTags(): array
- {
- return $this->ServiceTags;
- }
-
- public function setServiceTags(array $ServiceTags): self
+ /**
+ * @param array|null $ServiceTaggedAddresses
+ */
+ public function setServiceTaggedAddresses(null|array $ServiceTaggedAddresses): self
{
- $this->ServiceTags = $ServiceTags;
+ if (null === $ServiceTaggedAddresses) {
+ $this->TaggedAddresses = null;
+ return $this;
+ }
+ $this->TaggedAddresses = null;
+ foreach ($ServiceTaggedAddresses as $k => $v) {
+ $this->setServiceTaggedAddress($k, $v);
+ }
return $this;
}
- public function getServiceMeta(): array
+ /**
+ * @return array
+ */
+ public function getServiceTags(): array
{
- return $this->ServiceMeta;
+ return $this->ServiceTags;
}
- public function setServiceMeta(array $ServiceMeta): self
+ public function setServiceTags(string ...$ServiceTags): self
{
- $this->ServiceMeta = $ServiceMeta;
+ $this->ServiceTags = $ServiceTags;
return $this;
}
@@ -240,6 +268,28 @@ public function setServiceEnableTagOverride(bool $ServiceEnableTagOverride): sel
return $this;
}
+ public function getServiceProxy(): null|AgentServiceConnectProxyConfig
+ {
+ return $this->ServiceProxy;
+ }
+
+ public function setServiceProxy(null|AgentServiceConnectProxyConfig $ServiceProxy): self
+ {
+ $this->ServiceProxy = $ServiceProxy;
+ return $this;
+ }
+
+ public function getServiceLocality(): null|Locality
+ {
+ return $this->ServiceLocality;
+ }
+
+ public function setServiceLocality(null|Locality $ServiceLocality): self
+ {
+ $this->ServiceLocality = $ServiceLocality;
+ return $this;
+ }
+
public function getCreateIndex(): int
{
return $this->CreateIndex;
@@ -251,14 +301,14 @@ public function setCreateIndex(int $CreateIndex): self
return $this;
}
- public function getServiceProxy(): ?AgentServiceConnectProxyConfig
+ public function getChecks(): HealthChecks
{
- return $this->ServiceProxy;
+ return $this->Checks;
}
- public function setServiceProxy(?AgentServiceConnectProxyConfig $ServiceProxy): self
+ public function setChecks(HealthChecks $Checks): self
{
- $this->ServiceProxy = $ServiceProxy;
+ $this->Checks = $Checks;
return $this;
}
@@ -273,14 +323,94 @@ public function setModifyIndex(int $ModifyIndex): self
return $this;
}
- public function getNamespace(): ?string
+ public function getNamespace(): string
{
return $this->Namespace;
}
- public function setNamespace(?string $Namespace): self
+ public function setNamespace(string $Namespace): self
{
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TaggedAddresses' === $k) {
+ $n->setTaggedAddresses($v);
+ } elseif ('NodeMeta' === $k) {
+ $n->setNodeMeta($v);
+ } elseif ('ServiceTaggedAddresses' === $k) {
+ foreach ($v as $kk => $vv) {
+ $n->setServiceTaggedAddress($kk, ServiceAddress::jsonUnserialize($vv));
+ }
+ } elseif ('Weights' === $k || 'ServiceWeights' === $k) {
+ $n->ServiceWeights = Weights::jsonUnserialize($v);
+ } elseif ('ServiceProxy' === $k) {
+ if (null !== $v) {
+ $n->ServiceProxy = AgentServiceConnectProxyConfig::jsonUnserialize($v);
+ }
+ } elseif ('ServiceLocality' === $k) {
+ if (null !== $v) {
+ $n->ServiceLocality = Locality::jsonUnserialize($v);
+ }
+ } elseif ('Checks' === $k) {
+ if (null !== $v) {
+ $n->Checks = HealthChecks::jsonUnserialize($v);
+ }
+ } elseif ('ServiceMeta' === $k) {
+ $n->setServiceMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Node = $this->Node;
+ $out->Address = $this->Address;
+ $out->Datacenter = $this->Datacenter;
+ $out->TaggedAddresses = $this->getTaggedAddresses();
+ $out->NodeMeta = $this->getNodeMeta();
+ $out->ServiceID = $this->ServiceID;
+ $out->ServiceName = $this->ServiceName;
+ $out->ServiceAddress = $this->ServiceAddress;
+ $out->ServiceTaggedAddresses = $this->getServiceTaggedAddresses();
+ $out->ServiceTags = $this->ServiceTags;
+ $out->ServiceMeta = $this->getServiceMeta();
+ $out->ServicePort = $this->ServicePort;
+ $out->ServiceWeights = $this->ServiceWeights;
+ $out->ServiceEnableTagOverride = $this->ServiceEnableTagOverride;
+ $out->ServiceProxy = $this->ServiceProxy;
+ if (null !== $this->ServiceLocality) {
+ $out->ServiceLocality = $this->ServiceLocality;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->Checks = $this->Checks;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/CatalogServicesResponse.php b/src/Catalog/CatalogServicesResponse.php
index 6cbbc8f1..2fbb2162 100644
--- a/src/Catalog/CatalogServicesResponse.php
+++ b/src/Catalog/CatalogServicesResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class CatalogServicesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $Services = null;
+ /** @var array<\DCarbone\PHPConsulAPI\Catalog\CatalogService> */
+ public array $Services = [];
- public function getValue(): ?array
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\Catalog\CatalogService>
+ */
+ public function getValue(): array
{
return $this->Services;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->Services = [];
- foreach ($decodedData as $node) {
- $this->Services[] = new CatalogService($node);
+ foreach ($decoded as $node) {
+ $this->Services[] = CatalogService::jsonUnserialize($node);
}
}
}
diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php
index 31d32162..41852136 100644
--- a/src/Catalog/CompoundServiceName.php
+++ b/src/Catalog/CompoundServiceName.php
@@ -20,19 +20,23 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CompoundServiceName extends AbstractModel
+class CompoundServiceName extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
+ public string $Name;
+ public string $Namespace;
+ public string $Partition;
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Name = '';
- public string $Namespace = '';
+ public function __construct(
+ string $Name = '',
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->Name = $Name;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ }
public function getName(): string
{
@@ -55,4 +59,37 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php
index 2a47bee2..b277beec 100644
--- a/src/Catalog/GatewayService.php
+++ b/src/Catalog/GatewayService.php
@@ -20,66 +20,51 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Agent\ServiceKind;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class GatewayService extends AbstractModel
+class GatewayService extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => CompoundServiceName::class,
- ],
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => CompoundServiceName::class,
- ],
- self::FIELD_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_HOSTS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_CA_FILE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_CERT_FILE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_KEY_FILE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SNI => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_FROM_WILDCARD => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- ];
-
- private const FIELD_GATEWAY = 'Gateway';
- private const FIELD_SERVICE = 'Service';
- private const FIELD_PORT = 'Port';
- private const FIELD_PROTOCOL = 'Protocol';
- private const FIELD_HOSTS = 'Hosts';
- private const FIELD_CA_FILE = 'CAFile';
- private const FIELD_CERT_FILE = 'CertFile';
- private const FIELD_KEY_FILE = 'KeyFile';
- private const FIELD_SNI = 'SNI';
- private const FIELD_FROM_WILDCARD = 'FromWildcard';
-
public CompoundServiceName $Gateway;
public CompoundServiceName $Service;
- public string $GatewayKind = '';
- public int $Port = 0;
- public string $Protocol = '';
- public array $Hosts = [];
- public string $CAFile = '';
- public string $CertFile = '';
- public string $KeyFile = '';
- public string $SNI = '';
- public string $FromWildCard = '';
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Gateway)) {
- $this->Gateway = new CompoundServiceName();
- }
- if (!isset($this->Service)) {
- $this->Service = new CompoundServiceName();
- }
+ public ServiceKind $GatewayKind;
+ public int $Port;
+ public string $Protocol;
+ /** @var array */
+ public array $Hosts;
+ public string $CAFile;
+ public string $CertFile;
+ public string $KeyFile;
+ public string $SNI;
+ public string $FromWildCard;
+
+ /**
+ * @param array $Hosts
+ */
+ public function __construct(
+ null|CompoundServiceName $Gateway = null,
+ null|CompoundServiceName $Service = null,
+ string|ServiceKind $GatewayKind = '',
+ int $Port = 0,
+ string $Protocol = '',
+ array $Hosts = [],
+ string $CAFile = '',
+ string $CertFile = '',
+ string $KeyFile = '',
+ string $SNI = '',
+ string $FromWildCard = '',
+ ) {
+ $this->Gateway = $Gateway ?? new CompoundServiceName();
+ $this->Service = $Service ?? new CompoundServiceName();
+ $this->GatewayKind = $GatewayKind instanceof ServiceKind ? $GatewayKind : ServiceKind::from($GatewayKind);
+ $this->Port = $Port;
+ $this->Protocol = $Protocol;
+ $this->setHosts(...$Hosts);
+ $this->CAFile = $CAFile;
+ $this->CertFile = $CertFile;
+ $this->KeyFile = $KeyFile;
+ $this->SNI = $SNI;
+ $this->FromWildCard = $FromWildCard;
}
public function getGateway(): CompoundServiceName
@@ -104,12 +89,12 @@ public function setService(CompoundServiceName $Service): self
return $this;
}
- public function getGatewayKind(): string
+ public function getGatewayKind(): ServiceKind
{
return $this->GatewayKind;
}
- public function setGatewayKind(string $GatewayKind): self
+ public function setGatewayKind(ServiceKind $GatewayKind): self
{
$this->GatewayKind = $GatewayKind;
return $this;
@@ -137,12 +122,15 @@ public function setProtocol(string $Protocol): self
return $this;
}
+ /**
+ * @return array
+ */
public function getHosts(): array
{
return $this->Hosts;
}
- public function setHosts(array $Hosts): self
+ public function setHosts(string ...$Hosts): self
{
$this->Hosts = $Hosts;
return $this;
@@ -202,4 +190,57 @@ public function setFromWildCard(string $FromWildCard): self
$this->FromWildCard = $FromWildCard;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Gateway' === $k) {
+ $n->Gateway = CompoundServiceName::jsonUnserialize($v);
+ } elseif ('Service' === $k) {
+ $n->Service = CompoundServiceName::jsonUnserialize($v);
+ } elseif ('GatewayKind' === $k) {
+ $n->GatewayKind = ServiceKind::from($v);
+ } elseif ('Hosts' === $k) {
+ $n->setHosts(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Gateway = $this->Gateway;
+ $out->Service = $this->Service;
+ $out->GatewayKind = $this->GatewayKind->value;
+ if (0 !== $this->Port) {
+ $out->Port = $this->Port;
+ }
+ if ('' !== $this->Protocol) {
+ $out->Protocol = $this->Protocol;
+ }
+ if ([] !== $this->Hosts) {
+ $out->Hosts = $this->Hosts;
+ }
+ if ('' !== $this->CAFile) {
+ $out->CAFile = $this->CAFile;
+ }
+ if ('' !== $this->CertFile) {
+ $out->CertFile = $this->CertFile;
+ }
+ if ('' !== $this->KeyFile) {
+ $out->KeyFile = $this->KeyFile;
+ }
+ if ('' !== $this->SNI) {
+ $out->SNI = $this->SNI;
+ }
+ if ('' !== $this->FromWildCard) {
+ $out->FromWildCard = $this->FromWildCard;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/GatewayServicesResponse.php b/src/Catalog/GatewayServicesResponse.php
index cbf9d620..933dd34d 100644
--- a/src/Catalog/GatewayServicesResponse.php
+++ b/src/Catalog/GatewayServicesResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class GatewayServicesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $GatewayServices = null;
+ /** @var \DCarbone\PHPConsulAPI\Catalog\GatewayService[] */
+ public array $GatewayServices = [];
- public function getValue(): mixed
+ /**
+ * @return \DCarbone\PHPConsulAPI\Catalog\GatewayService[]
+ */
+ public function getValue(): array
{
return $this->GatewayServices;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->GatewayServices = [];
- foreach ($decodedData as $service) {
- $this->GatewayServices[] = new GatewayService($service);
+ foreach ($decoded as $service) {
+ $this->GatewayServices[] = GatewayService::jsonUnserialize($service);
}
}
}
diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php
index 2a6d19fa..39a9c54f 100644
--- a/src/Catalog/Node.php
+++ b/src/Catalog/Node.php
@@ -20,35 +20,54 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Peering\Locality;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
+use DCarbone\PHPConsulAPI\PHPLib\TaggedAddressField;
-class Node extends AbstractModel
+class Node extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD,
- self::FIELD_META => Transcoding::MAP_FIELD,
- ];
-
- private const FIELD_TAGGED_ADDRESSES = 'TaggedAddresses';
- private const FIELD_META = 'Meta';
-
- public string $ID = '';
- public string $Node = '';
- public string $Address = '';
- public string $Datacenter = '';
- public FakeMap $TaggedAddresses;
- public FakeMap $Meta;
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Meta)) {
- $this->Meta = new FakeMap(null);
- }
+ use MetaField;
+ use TaggedAddressField;
+
+ public string $ID;
+ public string $Node;
+ public string $Address;
+ public string $Datacenter;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public string $Partition;
+ public string $PeerName;
+ public null|Locality $Locality;
+
+ /**
+ * @param array $TaggedAddresses
+ * @param array $Meta
+ */
+ public function __construct(
+ string $ID = '',
+ string $Node = '',
+ string $Address = '',
+ string $Datacenter = '',
+ array $TaggedAddresses = [],
+ array $Meta = [],
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Partition = '',
+ string $PeerName = '',
+ null|Locality $Locality = null,
+ ) {
+ $this->ID = $ID;
+ $this->Node = $Node;
+ $this->Address = $Address;
+ $this->Datacenter = $Datacenter;
+ $this->setTaggedAddresses($TaggedAddresses);
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Partition = $Partition;
+ $this->PeerName = $PeerName;
+ $this->Locality = $Locality;
}
public function getID(): string
@@ -95,47 +114,98 @@ public function setDatacenter(string $Datacenter): self
return $this;
}
- public function getTaggedAddresses(): FakeMap
+ public function getCreateIndex(): int
{
- return $this->TaggedAddresses;
+ return $this->CreateIndex;
}
- public function setTaggedAddresses(FakeMap $TaggedAddresses): self
+ public function setCreateIndex(int $CreateIndex): self
{
- $this->TaggedAddresses = $TaggedAddresses;
+ $this->CreateIndex = $CreateIndex;
return $this;
}
- public function getMeta(): FakeMap
+ public function getModifyIndex(): int
{
- return $this->Meta;
+ return $this->ModifyIndex;
}
- public function setMeta(FakeMap $Meta): self
+ public function setModifyIndex(int $ModifyIndex): self
{
- $this->Meta = $Meta;
+ $this->ModifyIndex = $ModifyIndex;
return $this;
}
- public function getCreateIndex(): int
+ public function getPartition(): string
{
- return $this->CreateIndex;
+ return $this->Partition;
}
- public function setCreateIndex(int $CreateIndex): self
+ public function setPartition(string $Partition): self
{
- $this->CreateIndex = $CreateIndex;
+ $this->Partition = $Partition;
return $this;
}
- public function getModifyIndex(): int
+ public function getPeerName(): string
{
- return $this->ModifyIndex;
+ return $this->PeerName;
}
- public function setModifyIndex(int $ModifyIndex): self
+ public function setPeerName(string $PeerName): self
{
- $this->ModifyIndex = $ModifyIndex;
+ $this->PeerName = $PeerName;
+ return $this;
+ }
+
+ public function getLocality(): null|Locality
+ {
+ return $this->Locality;
+ }
+
+ public function setLocality(null|Locality $Locality): self
+ {
+ $this->Locality = $Locality;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Locality' === $k) {
+ $n->Locality = Locality::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } elseif ('TaggedAddresses' === $k) {
+ $n->setTaggedAddresses($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Node = $this->Node;
+ $out->Address = $this->Address;
+ $out->Datacenter = $this->Datacenter;
+ $out->TaggedAddresses = $this->getTaggedAddresses();
+ $out->Meta = $this->getMeta();
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->PeerName) {
+ $out->PeerName = $this->PeerName;
+ }
+ if (null !== $this->Locality) {
+ $out->Locality = $this->Locality;
+ }
+ return $out;
+ }
}
diff --git a/src/Catalog/NodesResponse.php b/src/Catalog/NodesResponse.php
index f38cddd9..06db580c 100644
--- a/src/Catalog/NodesResponse.php
+++ b/src/Catalog/NodesResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class NodesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $Nodes = null;
+ /** @var \DCarbone\PHPConsulAPI\Catalog\Node[] */
+ public array $Nodes = [];
- public function getValue(): mixed
+ /**
+ * @return \DCarbone\PHPConsulAPI\Catalog\Node[]
+ */
+ public function getValue(): array
{
return $this->Nodes;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->Nodes = [];
- foreach ($decodedData as $node) {
- $this->Nodes[] = new Node($node);
+ foreach ($decoded as $node) {
+ $this->Nodes[] = Node::jsonUnserialize($node);
}
}
}
diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php
index 27d1fb6b..6fa62893 100644
--- a/src/Catalog/ServiceAddress.php
+++ b/src/Catalog/ServiceAddress.php
@@ -20,21 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceAddress extends AbstractModel
+class ServiceAddress extends AbstractType
{
- public string $Address = '';
- public int $Port = 0;
+ public string $Address;
+ public int $Port;
+
+ public function __construct(string $Address = '', int $Port = 0)
+ {
+ $this->Address = $Address;
+ $this->Port = $Port;
+ }
public function getAddress(): string
{
return $this->Address;
}
- public function setAddress(string $address): self
+ public function setAddress(string $Address): self
{
- $this->Address = $address;
+ $this->Address = $Address;
return $this;
}
@@ -43,9 +49,26 @@ public function getPort(): int
return $this->Port;
}
- public function setPort(int $port): self
+ public function setPort(int $Port): self
{
- $this->Port = $port;
+ $this->Port = $Port;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Address = $this->Address;
+ $out->Port = $this->Port;
+ return $out;
+ }
}
diff --git a/src/Catalog/Weights.php b/src/Catalog/Weights.php
index 08021e75..f4940d5e 100644
--- a/src/Catalog/Weights.php
+++ b/src/Catalog/Weights.php
@@ -20,12 +20,18 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class Weights extends AbstractModel
+class Weights extends AbstractType
{
- public int $Passing = 0;
- public int $Warning = 0;
+ public int $Passing;
+ public int $Warning;
+
+ public function __construct(int $Passing = 0, int $Warning = 0)
+ {
+ $this->Passing = $Passing;
+ $this->Warning = $Warning;
+ }
public function getPassing(): int
{
@@ -48,4 +54,21 @@ public function setWarning(int $Warning): self
$this->Warning = $Warning;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Passing = $this->Passing;
+ $out->Warning = $this->Warning;
+ return $out;
+ }
}
diff --git a/src/Config.php b/src/Config.php
index 7f652148..010cf8ea 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -27,63 +27,38 @@
class Config
{
- use Unmarshaller;
-
public const DEFAULT_REQUEST_OPTIONS = [
RequestOptions::HTTP_ERRORS => false,
RequestOptions::DECODE_CONTENT => false,
];
- protected const FIELDS = [
- self::FIELD_HTTP_AUTH => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => 'setHttpAuth',
- ],
- self::FIELD_WAIT_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION,
- ],
- ];
+ public const DEFAULT_ADDRESS = '127.0.0.1:8500';
+ public const DEFAULT_SCHEME = 'http';
- private const FIELD_HTTP_AUTH = 'HttpAuth';
- private const FIELD_WAIT_TIME = 'WaitTime';
- private const FIELD_ADDRESS = 'Address';
- private const FIELD_SCHEME = 'Scheme';
- private const FIELD_JSON_ENCODE_OPTS = 'JSONEncodeOpts';
- private const FIELD_TOKEN = 'Token';
- private const FIELD_TOKEN_FILE = 'TokenFile';
- private const FIELD_CA_FILE = 'CAFile';
- private const FIELD_CERT_FILE = 'CertFile';
- private const FIELD_KEY_FILE = 'KeyFile';
- private const FIELD_INSECURE_SKIP_VERIFY = 'InsecureSkipVerify';
-
- private const DEFAULT_CONFIG = [
- self::FIELD_ADDRESS => '127.0.0.1:8500',
- self::FIELD_SCHEME => 'http',
- self::FIELD_JSON_ENCODE_OPTS => \JSON_UNESCAPED_SLASHES,
- ];
/**
* The address, including port, of your Consul Agent
*
* @var string
*/
- public string $Address = '';
+ public string $Address;
- public string $Scheme = '';
+ public string $Scheme;
- public string $Datacenter = '';
+ public string $Datacenter;
- public string $Namespace = '';
+ public string $Namespace;
/**
* HTTP authentication, if used
*
* @var \DCarbone\PHPConsulAPI\HttpAuth|null
*/
- public ?HttpAuth $HttpAuth = null;
+ public null|HttpAuth $HttpAuth;
- public ?Time\Duration $WaitTime = null;
+ public null|Time\Duration $WaitTime;
- public string $Token = '';
+ public string $Token;
/**
* File containing the current token to use for this client.
@@ -92,35 +67,63 @@ class Config
*
* @var string
*/
- public string $TokenFile = '';
+ public string $TokenFile;
- public string $CAFile = '';
+ public string $CAFile;
/**
* Optional path to certificate. If set, KeyFile must also be set
*
* @var string
*/
- public string $CertFile = '';
+ public string $CertFile;
/**
* Optional path to private key. If set, CertFile must also be set
*
* @var string
*/
- public string $KeyFile = '';
+ public string $KeyFile;
- public bool $InsecureSkipVerify = false;
+ public bool $InsecureSkipVerify;
public ClientInterface $HttpClient;
- public int $JSONEncodeOpts = 0;
-
- public function __construct(array $config = [])
- {
- foreach ($config + self::_getDefaultConfig() as $k => $v) {
- $this->unmarshalField($k, $v);
- }
+ public int $JSONEncodeOpts;
+ public int $JSONDecodeMaxDepth;
+ public int $JSONDecodeOpts;
+
+ public function __construct(
+ string $Address = self::DEFAULT_ADDRESS,
+ string $Scheme = self::DEFAULT_SCHEME,
+ string $Datacenter = '',
+ string $Namespace = '',
+ null|string|HttpAuth $HttpAuth = null,
+ null|string|int|float|\DateInterval|Time\Duration $WaitTime = null,
+ string $Token = '',
+ string $TokenFile = '',
+ string $CAFile = '',
+ string $CertFile = '',
+ string $KeyFile = '',
+ bool $InsecureSkipVerify = false,
+ null|ClientInterface $HttpClient = null,
+ int $JSONEncodeOpts = JSON_UNESCAPED_SLASHES,
+ int $JSONDecodeMaxDepth = 512,
+ int $JSONDecodeOpts = 0,
+ ) {
+ $this->Address = self::_resolveValue($Address, Consul::HTTPAddrEnvName, self::DEFAULT_ADDRESS);
+ $this->setScheme(self::_resolveValue($Scheme, Consul::HTTPSSLEnvName, self::DEFAULT_SCHEME));
+ $this->Datacenter = $Datacenter;
+ $this->Namespace = $Namespace;
+ $this->setHttpAuth(self::_resolveValue($HttpAuth, Consul::HTTPAuthEnvName, null));
+ $this->setWaitTime($WaitTime);
+ $this->Token = self::_resolveValue($Token, Consul::HTTPTokenEnvName, '');
+ $this->TokenFile = self::_resolveValue($TokenFile, Consul::HTTPTokenFileEnvName, '');
+ $this->CAFile = self::_resolveValue($CAFile, Consul::HTTPCAFileEnvName, '');
+ $this->CertFile = self::_resolveValue($CertFile, Consul::HTTPClientCertEnvName, '');
+ $this->KeyFile = self::_resolveValue($KeyFile, Consul::HTTPClientKeyEnvName, '');
+ $skipVerify = self::_resolveValue($InsecureSkipVerify, Consul::HTTPSSLVerifyEnvName, false);
+ $this->InsecureSkipVerify = is_string($skipVerify) ? strtolower($skipVerify) === 'true' : $skipVerify;
// quick validation on key/cert combo
$c = $this->CertFile;
@@ -136,13 +139,14 @@ public function __construct(array $config = [])
);
}
- // if client hasn't been constructed, construct.
- if (!isset($this->HttpClient)) {
- $this->HttpClient = new Client();
- }
+ $this->HttpClient = $HttpClient ?? new Client();
+
+ $this->JSONEncodeOpts = $JSONEncodeOpts;
+ $this->JSONDecodeMaxDepth = $JSONDecodeMaxDepth;
+ $this->JSONDecodeOpts = $JSONDecodeOpts;
}
- public static function merge(?self $inc): self
+ public static function merge(null|Config $inc): Config
{
$actual = static::newDefaultConfig();
if (null === $inc) {
@@ -184,18 +188,22 @@ public static function merge(?self $inc): self
if ($inc->InsecureSkipVerify) {
$actual->InsecureSkipVerify = true;
}
- if (null !== $inc->HttpClient) {
+ if (isset($inc->HttpClient)) {
$actual->HttpClient = $inc->HttpClient;
}
if (0 !== $inc->JSONEncodeOpts) {
$actual->JSONEncodeOpts = $inc->JSONEncodeOpts;
}
+ if (0 !== $inc->JSONDecodeMaxDepth) {
+ $actual->JSONDecodeMaxDepth = $inc->JSONDecodeMaxDepth;
+ }
+ $actual->JSONDecodeOpts = self::_resolveValue($inc->JSONDecodeOpts, '', $actual->JSONDecodeOpts);
return $actual;
}
public static function newDefaultConfig(): self
{
- return new static(self::_getDefaultConfig());
+ return new self();
}
public function getAddress(): string
@@ -214,9 +222,13 @@ public function getScheme(): string
return $this->Scheme;
}
- public function setScheme(string $scheme): self
+ public function setScheme(bool|string $scheme): self
{
- $this->Scheme = $scheme;
+ $this->Scheme = match (is_string($scheme) ? strtolower($scheme) : $scheme) {
+ true, 'true', '1' => 'https',
+ false, 'false', '0' => 'http',
+ default => $scheme,
+ };
return $this;
}
@@ -236,9 +248,10 @@ public function getNamespace(): string
return $this->Namespace;
}
- public function setNamespace(string $namespace): void
+ public function setNamespace(string $namespace): self
{
$this->Namespace = $namespace;
+ return $this;
}
public function getWaitTime(): Time\Duration
@@ -246,7 +259,7 @@ public function getWaitTime(): Time\Duration
return $this->WaitTime;
}
- public function setWaitTime(mixed $waitTime): self
+ public function setWaitTime(null|string|int|float|\DateInterval|Time\Duration $waitTime): self
{
$this->WaitTime = Time::Duration($waitTime);
return $this;
@@ -290,9 +303,14 @@ public function getHttpAuth(): HttpAuth
return $this->HttpAuth;
}
- public function setHttpAuth(HttpAuth|string $httpAuth): self
+ public function setHttpAuth(null|string|HttpAuth $httpAuth): self
{
- if (\is_string($httpAuth)) {
+ if (null === $httpAuth) {
+ $this->HttpAuth = null;
+ return $this;
+ }
+
+ if (is_string($httpAuth)) {
$colon = strpos($httpAuth, ':');
if (false === $colon) {
$username = $httpAuth;
@@ -304,18 +322,8 @@ public function setHttpAuth(HttpAuth|string $httpAuth): self
$httpAuth = new HttpAuth($username, $password);
}
- if ($httpAuth instanceof HttpAuth) {
- $this->HttpAuth = $httpAuth;
- return $this;
- }
-
- throw new \InvalidArgumentException(
- sprintf(
- '%s::setHttpAuth - Value is expected to be string of "username:password" or instance of "\\DCarbone\\PHPConsulApi\\HttpAuth", %s seen.',
- static::class,
- \is_string($httpAuth) ? $httpAuth : \gettype($httpAuth)
- )
- );
+ $this->HttpAuth = $httpAuth;
+ return $this;
}
public function getCAFile(): string
@@ -373,77 +381,44 @@ public function setJSONEncodeOpts(int $jsonEncodeOpts): self
return $this;
}
- public static function getEnvironmentConfig(): array
- {
- $ret = [];
- foreach (
- [
- Consul::HTTPAddrEnvName => static::_tryGetEnvParam(Consul::HTTPAddrEnvName),
- Consul::HTTPTokenEnvName => static::_tryGetEnvParam(Consul::HTTPTokenEnvName),
- Consul::HTTPTokenFileEnvName => static::_tryGetEnvParam(Consul::HTTPTokenFileEnvName),
- Consul::HTTPAuthEnvName => static::_tryGetEnvParam(Consul::HTTPAuthEnvName),
- Consul::HTTPCAFileEnvName => static::_tryGetEnvParam(Consul::HTTPCAFileEnvName),
- Consul::HTTPClientCertEnvName => static::_tryGetEnvParam(Consul::HTTPClientCertEnvName),
- Consul::HTTPClientKeyEnvName => static::_tryGetEnvParam(Consul::HTTPClientKeyEnvName),
- Consul::HTTPSSLEnvName => static::_tryGetEnvParam(Consul::HTTPSSLEnvName),
- Consul::HTTPSSLVerifyEnvName => static::_tryGetEnvParam(Consul::HTTPSSLVerifyEnvName),
- ] as $k => $v
- ) {
- if (null !== $v) {
- $ret[$k] = $v;
- }
- }
- return $ret;
+ public function getJSONDecodeMaxDepth(): int
+ {
+ return $this->JSONDecodeMaxDepth;
}
- protected static function _tryGetEnvParam(string $param): ?string
+ public function setJSONDecodeMaxDepth(int $JSONDecodeMaxDepth): self
{
- if (isset($_ENV[$param])) {
- return $_ENV[$param];
- }
+ $this->JSONDecodeMaxDepth = $JSONDecodeMaxDepth;
+ return $this;
+ }
- if (false !== ($value = getenv($param))) {
- return $value;
- }
+ public function getJSONDecodeOpts(): int
+ {
+ return $this->JSONDecodeOpts;
+ }
- if (isset($_SERVER[$param])) {
- return $_SERVER[$param];
+ public function setJSONDecodeOpts(int $JSONDecodeOpts): self
+ {
+ $this->JSONDecodeOpts = $JSONDecodeOpts;
+ return $this;
+ }
+
+ protected static function _resolveValue(mixed $explicit, string $env, mixed $default): mixed
+ {
+ if ($explicit !== $default) {
+ return $explicit;
}
- return null;
- }
-
- private static function _getDefaultConfig(): array
- {
- $conf = self::DEFAULT_CONFIG;
-
- // parse env vars
- foreach (static::getEnvironmentConfig() as $k => $v) {
- if (Consul::HTTPAddrEnvName === $k) {
- $conf[self::FIELD_ADDRESS] = $v;
- } elseif (Consul::HTTPTokenEnvName === $k) {
- $conf[self::FIELD_TOKEN] = $v;
- } elseif (Consul::HTTPTokenFileEnvName === $k) {
- $conf[self::FIELD_TOKEN_FILE] = $v;
- } elseif (Consul::HTTPAuthEnvName === $k) {
- $conf[self::FIELD_HTTP_AUTH] = $v;
- } elseif (Consul::HTTPCAFileEnvName === $k) {
- $conf[self::FIELD_CA_FILE] = $v;
- } elseif (Consul::HTTPClientCertEnvName === $k) {
- $conf[self::FIELD_CERT_FILE] = $v;
- } elseif (Consul::HTTPClientKeyEnvName === $k) {
- $conf[self::FIELD_KEY_FILE] = $v;
- } elseif (Consul::HTTPSSLEnvName === $k) {
- if ((bool)$v) {
- $conf[self::FIELD_SCHEME] = 'https';
- }
- } elseif (Consul::HTTPSSLVerifyEnvName === $k) {
- if ((bool)$v) {
- $conf[self::FIELD_INSECURE_SKIP_VERIFY] = true;
- }
+ if ($env !== '') {
+ if (isset($_ENV[$env])) {
+ return $_ENV[$env];
+ } elseif (false !== ($value = getenv($env))) {
+ return $value;
+ } elseif (isset($_SERVER[$env])) {
+ return $_SERVER[$env];
}
}
- return $conf;
+ return $default;
}
}
diff --git a/src/ConfigEntry/AccessLogsConfig.php b/src/ConfigEntry/AccessLogsConfig.php
new file mode 100644
index 00000000..7fec5ec0
--- /dev/null
+++ b/src/ConfigEntry/AccessLogsConfig.php
@@ -0,0 +1,152 @@
+Enabled = $Enabled;
+ $this->DisableListenerLogs = $DisableListenerLogs;
+ $this->Type = $Type instanceof LogSinkType ? $Type : LogSinkType::from($Type);
+ $this->Path = $Path;
+ $this->JSONFormat = $JSONFormat;
+ $this->TextFormat = $TextFormat;
+ }
+
+ public function isEnabled(): bool
+ {
+ return $this->Enabled;
+ }
+
+ public function setEnabled(bool $Enabled): self
+ {
+ $this->Enabled = $Enabled;
+ return $this;
+ }
+
+ public function isDisableListenerLogs(): bool
+ {
+ return $this->DisableListenerLogs;
+ }
+
+ public function setDisableListenerLogs(bool $DisableListenerLogs): self
+ {
+ $this->DisableListenerLogs = $DisableListenerLogs;
+ return $this;
+ }
+
+ public function getType(): LogSinkType
+ {
+ return $this->Type;
+ }
+
+ public function setType(string|LogSinkType $Type): self
+ {
+ $this->Type = $Type instanceof LogSinkType ? $Type : LogSinkType::from($Type);
+ return $this;
+ }
+
+ public function getPath(): string
+ {
+ return $this->Path;
+ }
+
+ public function setPath(string $Path): self
+ {
+ $this->Path = $Path;
+ return $this;
+ }
+
+ public function getJSONFormat(): string
+ {
+ return $this->JSONFormat;
+ }
+
+ public function setJSONFormat(string $JSONFormat): self
+ {
+ $this->JSONFormat = $JSONFormat;
+ return $this;
+ }
+
+ public function getTextFormat(): string
+ {
+ return $this->TextFormat;
+ }
+
+ public function setTextFormat(string $TextFormat): self
+ {
+ $this->TextFormat = $TextFormat;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Type' === $k) {
+ $n->setType($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Enabled) {
+ $out->Enabled = $this->Enabled;
+ }
+ if ($this->DisableListenerLogs) {
+ $out->DisableListenerLogs = $this->DisableListenerLogs;
+ }
+ if ($this->Type !== LogSinkType::Default) {
+ $out->Type = $this->Type->value;
+ }
+ if ('' !== $this->Path) {
+ $out->Path = $this->Path;
+ }
+ if ('' !== $this->JSONFormat) {
+ $out->JSONFormat = $this->JSONFormat;
+ }
+ if ('' !== $this->TextFormat) {
+ $out->TextFormat = $this->TextFormat;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/ConfigEntry.php b/src/ConfigEntry/ConfigEntry.php
index 23789581..e90438a5 100644
--- a/src/ConfigEntry/ConfigEntry.php
+++ b/src/ConfigEntry/ConfigEntry.php
@@ -20,9 +20,6 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
-
/**
* Interface ConfigEntry
*
@@ -31,21 +28,16 @@
*/
interface ConfigEntry
{
- public const INTERFACE_FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_META => Transcoding::MAP_FIELD,
- ];
-
- public const FIELD_NAMESPACE = 'Namespace';
- public const FIELD_META = 'Meta';
-
public function GetKind(): string;
public function GetName(): string;
public function GetNamespace(): string;
- public function GetMeta(): ?FakeMap;
+ /**
+ * @return array|null
+ */
+ public function GetMeta(): null|array;
public function GetCreateIndex(): int;
diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php
index 3a302dc1..38d9bb86 100644
--- a/src/ConfigEntry/ConfigEntryTrait.php
+++ b/src/ConfigEntry/ConfigEntryTrait.php
@@ -20,67 +20,33 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\FakeMap;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
trait ConfigEntryTrait
{
- public string $Kind = '';
- public string $Name = '';
- public string $Namespace = '';
- public ?FakeMap $Meta = null;
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
+ use MetaField;
- public function getKind(): string
- {
- return $this->Kind;
- }
-
- public function setKind(string $Kind): ConfigEntry
- {
- $this->Kind = $Kind;
- return $this;
- }
-
- public function getName(): string
- {
- return $this->Name;
- }
-
- public function setName(string $Name): ConfigEntry
- {
- $this->Name = $Name;
- return $this;
- }
+ public string $Namespace;
+ public int $CreateIndex;
+ public int $ModifyIndex;
public function getNamespace(): string
{
return $this->Namespace;
}
- public function setNamespace(string $Namespace): ConfigEntry
+ public function setNamespace(string $Namespace): self
{
$this->Namespace = $Namespace;
return $this;
}
- public function getMeta(): ?FakeMap
- {
- return $this->Meta;
- }
-
- public function setMeta(mixed $Meta): ProxyConfigEntry
- {
- $this->Meta = FakeMap::parse($Meta);
- return $this;
- }
-
public function getCreateIndex(): int
{
return $this->CreateIndex;
}
- public function setCreateIndex(int $CreateIndex): ProxyConfigEntry
+ public function setCreateIndex(int $CreateIndex): self
{
$this->CreateIndex = $CreateIndex;
return $this;
@@ -91,7 +57,7 @@ public function getModifyIndex(): int
return $this->ModifyIndex;
}
- public function setModifyIndex(int $ModifyIndex): ProxyConfigEntry
+ public function setModifyIndex(int $ModifyIndex): self
{
$this->ModifyIndex = $ModifyIndex;
return $this;
diff --git a/src/ConfigEntry/CookieConfig.php b/src/ConfigEntry/CookieConfig.php
new file mode 100644
index 00000000..a0ff4caa
--- /dev/null
+++ b/src/ConfigEntry/CookieConfig.php
@@ -0,0 +1,103 @@
+Session = $Session;
+ $this->TTL = Time::Duration($TTL);
+ $this->Path = $Path;
+ }
+
+ public function getSession(): bool
+ {
+ return $this->Session;
+ }
+
+ public function setSession(bool $Session): self
+ {
+ $this->Session = $Session;
+ return $this;
+ }
+
+ public function getTTL(): Time\Duration
+ {
+ return $this->TTL;
+ }
+
+ public function setTTL(Time\Duration $TTL): self
+ {
+ $this->TTL = $TTL;
+ return $this;
+ }
+
+ public function getPath(): string
+ {
+ return $this->Path;
+ }
+
+ public function setPath(string $Path): self
+ {
+ $this->Path = $Path;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TTL' === $k) {
+ $n->TTL = Time::Duration($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Session) {
+ $out->Session = $this->Session;
+ }
+ $ns = $this->TTL->Nanoseconds();
+ if ((0 !== $ns)) {
+ $out->TTL = $ns;
+ }
+ if ('' !== $this->Path) {
+ $out->Path = $this->Path;
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/DestinationConfig.php b/src/ConfigEntry/DestinationConfig.php
new file mode 100644
index 00000000..0c32524e
--- /dev/null
+++ b/src/ConfigEntry/DestinationConfig.php
@@ -0,0 +1,85 @@
+ */
+ public array $Addresses;
+ public int $Port;
+
+ /**
+ * @param array $Addresses
+ */
+ public function __construct(array $Addresses = [], int $Port = 0)
+ {
+ $this->setAddresses(...$Addresses);
+ $this->Port = $Port;
+ }
+
+ /**
+ * @return array
+ */
+ public function getAddresses(): array
+ {
+ return $this->Addresses;
+ }
+
+ public function setAddresses(string ...$Addresses): self
+ {
+ $this->Addresses = $Addresses;
+ return $this;
+ }
+
+ public function getPort(): int
+ {
+ return $this->Port;
+ }
+
+ public function setPort(int $Port): self
+ {
+ $this->Port = $Port;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ([] !== $this->Addresses) {
+ $out->Addresses = $this->Addresses;
+ }
+ if (0 !== $this->Port) {
+ $out->Port = $this->Port;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php
new file mode 100644
index 00000000..fbfb67c6
--- /dev/null
+++ b/src/ConfigEntry/EnvoyExtension.php
@@ -0,0 +1,151 @@
+ */
+ public null|array $Arguments = null;
+ public string $ConsulVersion;
+ public string $EnvoyVersion;
+
+ /**
+ * @param array $Arguments
+ */
+ public function __construct(
+ string $Name = '',
+ bool $Required = false,
+ array $Arguments = [],
+ string $ConsulVersion = '',
+ string $EnvoyVersion = '',
+ ) {
+ $this->Name = $Name;
+ $this->Required = $Required;
+ $this->setArguments($Arguments);
+ $this->ConsulVersion = $ConsulVersion;
+ $this->EnvoyVersion = $EnvoyVersion;
+}
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function isRequired(): bool
+ {
+ return $this->Required;
+ }
+
+ public function setRequired(bool $Required): self
+ {
+ $this->Required = $Required;
+ return $this;
+ }
+
+ /**
+ * @return null|array
+ */
+ public function getArguments(): null|array
+ {
+ return $this->Arguments;
+ }
+
+ public function setArgument(string $k, mixed $v): self
+ {
+ if (null === $this->Arguments) {
+ $this->Arguments = [];
+ }
+ $this->Arguments[$k] = $v;
+ return $this;
+ }
+
+ /**
+ * @param \stdClass|array|null $Arguments
+ */
+ public function setArguments(null|\stdClass|array $Arguments): self
+ {
+ if (null === $Arguments) {
+ $this->Arguments = null;
+ return $this;
+ }
+ $this->Arguments = [];
+ foreach ($Arguments as $k => $v) {
+ $this->setArgument($k, $v);
+ }
+ return $this;
+ }
+
+ public function getConsulVersion(): string
+ {
+ return $this->ConsulVersion;
+ }
+
+ public function setConsulVersion(string $ConsulVersion): self
+ {
+ $this->ConsulVersion = $ConsulVersion;
+ return $this;
+ }
+
+ public function getEnvoyVersion(): string
+ {
+ return $this->EnvoyVersion;
+ }
+
+ public function setEnvoyVersion(string $EnvoyVersion): self
+ {
+ $this->EnvoyVersion = $EnvoyVersion;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Arguments' === $k) {
+ $n->setArguments($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Required = $this->Required;
+ $out->Arguments = $this->getArguments();
+ $out->ConsulVersion = $this->ConsulVersion;
+ $out->EnvoyVersion = $this->EnvoyVersion;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php
index de9d7867..abda7143 100644
--- a/src/ConfigEntry/ExposeConfig.php
+++ b/src/ConfigEntry/ExposeConfig.php
@@ -20,26 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ExposeConfig extends AbstractModel
+class ExposeConfig extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_CHECKS => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PATHS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ExposePath::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public bool $Checks;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> */
+ public array $Paths;
- private const FIELD_CHECKS = 'Checks';
- private const FIELD_PATHS = 'Paths';
-
- public bool $Checks = false;
- public array $Paths = [];
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> $Paths
+ */
+ public function __construct(
+ bool $Checks = false,
+ array $Paths = [],
+ ) {
+ $this->Checks = $Checks;
+ $this->setPaths(...$Paths);
+}
public function isChecks(): bool
{
@@ -52,14 +50,44 @@ public function setChecks(bool $Checks): self
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ConfigEntry\ExposePath[]
+ */
public function getPaths(): array
{
return $this->Paths;
}
- public function setPaths(array $Paths): self
+ public function setPaths(ExposePath ...$Paths): self
{
$this->Paths = $Paths;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): self
+ {
+ $n = $n ?? new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Paths' === $k) {
+ foreach ($v as $vv) {
+ $n->Paths[] = ExposePath::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Checks) {
+ $out->Checks = true;
+ }
+ if ([] !== $this->Paths) {
+ $out->Paths = $this->Paths;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php
index 78d0ddb4..258b2f7e 100644
--- a/src/ConfigEntry/ExposePath.php
+++ b/src/ConfigEntry/ExposePath.php
@@ -20,28 +20,29 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ExposePath extends AbstractModel
+class ExposePath extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_LISTENER_PORT => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_PATH => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_LOCAL_PORT_PATH => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_LISTENER_PORT = 'ListenerPort';
- private const FIELD_PATH = 'Path';
- private const FIELD_LOCAL_PORT_PATH = 'LocalPortPath';
- private const FIELD_PROTOCOL = 'Protocol';
-
- public int $ListenerPort = 0;
- public string $Path = '';
- public int $LocalPathPort = 0;
- public string $Protocol = '';
- public bool $ParsedFromCheck = false;
+ public int $ListenerPort;
+ public string $Path;
+ public int $LocalPathPort;
+ public string $Protocol;
+ public bool $ParsedFromCheck;
+
+ public function __construct(
+ int $ListenerPort = 0,
+ string $Path = '',
+ int $LocalPathPort = 0,
+ string $Protocol = '',
+ bool $ParsedFromCheck = false
+ ) {
+ $this->ListenerPort = $ListenerPort;
+ $this->Path = $Path;
+ $this->LocalPathPort = $LocalPathPort;
+ $this->Protocol = $Protocol;
+ $this->ParsedFromCheck = $ParsedFromCheck;
+}
public function getListenerPort(): int
{
@@ -97,4 +98,40 @@ public function setParsedFromCheck(bool $ParsedFromCheck): self
$this->ParsedFromCheck = $ParsedFromCheck;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): self
+ {
+ $n = $n ?? new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('listener_port' === $k) {
+ $n->ListenerPort = $v;
+ } elseif ('local_path_port' === $k) {
+ $n->LocalPathPort = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (0 !== $this->ListenerPort) {
+ $out->ListenerPort = $this->ListenerPort;
+ }
+ if ('' !== $this->Path) {
+ $out->Path = $this->Path;
+ }
+ if (0 !== $this->LocalPathPort) {
+ $out->LocalPathPort = $this->LocalPathPort;
+ }
+ if ('' !== $this->Protocol) {
+ $out->Protocol = $this->Protocol;
+ }
+ if ($this->ParsedFromCheck) {
+ $out->ParsedFromCheck = true;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/GatewayServiceTLSConfig.php b/src/ConfigEntry/GatewayServiceTLSConfig.php
new file mode 100644
index 00000000..46e423a4
--- /dev/null
+++ b/src/ConfigEntry/GatewayServiceTLSConfig.php
@@ -0,0 +1,66 @@
+SDS = $SDS;
+ }
+
+ public function getSDS(): null|GatewayTLSSDSConfig
+ {
+ return $this->SDS;
+ }
+
+ public function setSDS(null|GatewayTLSSDSConfig $SDS): self
+ {
+ $this->SDS = $SDS;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach((array)$decoded as $k => $v) {
+ if ('SDS' === $k) {
+ $n->SDS = GatewayTLSSDSConfig::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (null !== $this->SDS) {
+ $out->SDS = $this->SDS->jsonSerialize();
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/GatewayTLSConfig.php b/src/ConfigEntry/GatewayTLSConfig.php
new file mode 100644
index 00000000..fdcc3b05
--- /dev/null
+++ b/src/ConfigEntry/GatewayTLSConfig.php
@@ -0,0 +1,146 @@
+ */
+ public array $CipherSuites;
+
+ /**
+ * @param array $CipherSuites
+ */
+ public function __construct(
+ bool $Enabled = false,
+ null|GatewayTLSSDSConfig $SDS = null,
+ string $TLSMinVersion = '',
+ string $TLSMaxVersion = '',
+ array $CipherSuites = []
+ ) {
+ $this->Enabled = $Enabled;
+ $this->SDS = $SDS;
+ $this->TLSMinVersion = $TLSMinVersion;
+ $this->TLSMaxVersion = $TLSMaxVersion;
+ $this->setCipherSuites(...$CipherSuites);
+ }
+
+ public function isEnabled(): bool
+ {
+ return $this->Enabled;
+ }
+
+ public function setEnabled(bool $Enabled): self
+ {
+ $this->Enabled = $Enabled;
+ return $this;
+ }
+
+ public function getSDS(): null|GatewayTLSSDSConfig
+ {
+ return $this->SDS;
+ }
+
+ public function setSDS(null|GatewayTLSSDSConfig $SDS): self
+ {
+ $this->SDS = $SDS;
+ return $this;
+ }
+
+ public function getTLSMinVersion(): string
+ {
+ return $this->TLSMinVersion;
+ }
+
+ public function setTLSMinVersion(string $TLSMinVersion): self
+ {
+ $this->TLSMinVersion = $TLSMinVersion;
+ return $this;
+ }
+
+ public function getTLSMaxVersion(): string
+ {
+ return $this->TLSMaxVersion;
+ }
+
+ public function setTLSMaxVersion(string $TLSMaxVersion): self
+ {
+ $this->TLSMaxVersion = $TLSMaxVersion;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getCipherSuites(): array
+ {
+ return $this->CipherSuites;
+ }
+
+ public function setCipherSuites(string ...$CipherSuites): self
+ {
+ $this->CipherSuites = $CipherSuites;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('tls_min_version' === $k) {
+ $n->TLSMinVersion = (string)$v;
+ } elseif ('tls_max_version' === $k) {
+ $n->TLSMaxVersion = (string)$v;
+ } elseif ('CipherSuites' === $k || 'cipher_suites' === $k) {
+ $n->setcipherSuites(...$v);
+ } elseif ('SDS' === $k) {
+ $n->SDS = GatewayTLSSDSConfig::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Enabled = $this->Enabled;
+ if (null !== $this->SDS) {
+ $out->SDS = $this->SDS->jsonSerialize();
+ }
+ if ('' !== $this->TLSMinVersion) {
+ $out->TLSMinVersion = $this->TLSMinVersion;
+ }
+ if ('' !== $this->TLSMaxVersion) {
+ $out->TLSMaxVersion = $this->TLSMaxVersion;
+ }
+ if ([] !== $this->CipherSuites) {
+ $out->CipherSuites = $this->CipherSuites;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/GatewayTLSSDSConfig.php b/src/ConfigEntry/GatewayTLSSDSConfig.php
new file mode 100644
index 00000000..51c6991f
--- /dev/null
+++ b/src/ConfigEntry/GatewayTLSSDSConfig.php
@@ -0,0 +1,86 @@
+ClusterName = $ClusterName;
+ $this->CertResource = $CertResource;
+ }
+
+ public function getClusterName(): string
+ {
+ return $this->ClusterName;
+ }
+
+ public function setClusterName(string $ClusterName): self
+ {
+ $this->ClusterName = $ClusterName;
+ return $this;
+ }
+
+ public function getCertResource(): string
+ {
+ return $this->CertResource;
+ }
+
+ public function setCertResource(string $CertResource): self
+ {
+ $this->CertResource = $CertResource;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('cluster_name' === $k) {
+ $n->ClusterName = (string)$v;
+ } elseif ('cert_resource' === $k) {
+ $n->CertResource = (string)$v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->ClusterName) {
+ $out->ClusterName = $this->ClusterName;
+ }
+ if ('' !== $this->CertResource) {
+ $out->CertResource = $this->CertResource;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php
new file mode 100644
index 00000000..50243fb4
--- /dev/null
+++ b/src/ConfigEntry/HTTPHeaderModifiers.php
@@ -0,0 +1,156 @@
+ */
+ public array $Add = [];
+ /** @var array */
+ public array $Set = [];
+ /** @var array */
+ public array $Remove = [];
+
+ /**
+ * @param null|array $Add
+ * @param null|array $Set
+ * @param null|array $Remove
+ */
+ public function __construct(
+ null|array $Add = null,
+ null|array $Set = null,
+ null|array $Remove = null,
+ ) {
+ $this->setAdd($Add);
+ $this->setSet($Set);
+ if (null !== $Remove) {
+ $this->setRemove(...$Remove);
+ }
+ }
+
+ /**
+ * @return array
+ */
+ public function getAdd(): array
+ {
+ return $this->Add;
+ }
+
+ public function setAddKey(string $k, string $v): self
+ {
+ $this->Add[$k] = $v;
+ return $this;
+ }
+
+ /**
+ * @param null|\stdClass|array $Add
+ */
+ public function setAdd(null|\stdClass|array $Add): self
+ {
+ $this->Add = [];
+ if (null === $Add) {
+ return $this;
+ }
+ foreach ($Add as $k => $v) {
+ $this->Add[$k] = $v;
+ }
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getSet(): array
+ {
+ return $this->Set;
+ }
+
+ public function setSetKey(string $k, string $v): self
+ {
+ $this->Set[$k] = $v;
+ return $this;
+ }
+
+ /**
+ * @param null|\stdClass|array $Set
+ */
+ public function setSet(null|\stdClass|array $Set): self
+ {
+ $this->Set = [];
+ if (null === $Set) {
+ return $this;
+ }
+ foreach ($Set as $k => $v) {
+ $this->Set[$k] = $v;
+ }
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getRemove(): array
+ {
+ return $this->Remove;
+ }
+
+ public function setRemove(string ...$Remove): self
+ {
+ $this->Remove = $Remove;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Set' === $k) {
+ $n->setSet($v);
+ } elseif ('Add' === $k) {
+ $n->setAdd($v);
+ } elseif ('Remove' === $k) {
+ if (null !== $v) {
+ $n->setRemove(...$v);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ([] !== $this->Add) {
+ $out->Add = $this->Add;
+ }
+ if ([] !== $this->Set) {
+ $out->Set = $this->Set;
+ }
+ if ([] !== $this->Remove) {
+ $out->Remove = $this->Remove;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/HashPolicy.php b/src/ConfigEntry/HashPolicy.php
new file mode 100644
index 00000000..575bf597
--- /dev/null
+++ b/src/ConfigEntry/HashPolicy.php
@@ -0,0 +1,139 @@
+Field = $Field;
+ $this->FieldValue = $FieldValue;
+ $this->CookieConfig = $CookieConfig;
+ $this->SourceIP = $SourceIP;
+ $this->Terminal = $Terminal;
+ }
+
+ public function getField(): string
+ {
+ return $this->Field;
+ }
+
+ public function setField(string $Field): self
+ {
+ $this->Field = $Field;
+ return $this;
+ }
+
+ public function getFieldValue(): string
+ {
+ return $this->FieldValue;
+ }
+
+ public function setFieldValue(string $FieldValue): self
+ {
+ $this->FieldValue = $FieldValue;
+ return $this;
+ }
+
+ public function getCookieConfig(): null|CookieConfig
+ {
+ return $this->CookieConfig;
+ }
+
+ public function setCookieConfig(null|CookieConfig $CookieConfig): self
+ {
+ $this->CookieConfig = $CookieConfig;
+ return $this;
+ }
+
+ public function isSourceIP(): bool
+ {
+ return $this->SourceIP;
+ }
+
+ public function setSourceIP(bool $SourceIP): self
+ {
+ $this->SourceIP = $SourceIP;
+ return $this;
+ }
+
+ public function isTerminal(): bool
+ {
+ return $this->Terminal;
+ }
+
+ public function setTerminal(bool $Terminal): self
+ {
+ $this->Terminal = $Terminal;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('field_value' === $k) {
+ $n->FieldValue = $v;
+ } elseif ('CookieConfig' === $k || 'cookie_config' === $k) {
+ $n->CookieConfig = CookieConfig::jsonUnserialize($v);
+ } elseif ('source_ip' === $k) {
+ $n->SourceIP = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Field) {
+ $out->Field = $this->Field;
+ }
+ if ('' !== $this->FieldValue) {
+ $out->FieldValue = $this->FieldValue;
+ }
+ if (null !== $this->CookieConfig) {
+ $out->CookieConfig = $this->CookieConfig;
+ }
+ if ($this->SourceIP) {
+ $out->SourceIP = $this->SourceIP;
+ }
+ if ($this->Terminal) {
+ $out->Terminal = $this->Terminal;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php
new file mode 100644
index 00000000..adc6b8ee
--- /dev/null
+++ b/src/ConfigEntry/IngressGatewayConfigEntry.php
@@ -0,0 +1,182 @@
+ */
+ public array $Listeners;
+ public null|IngressServiceConfig $Defaults;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener> $Listeners
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ null|GatewayTLSConfig $TLS = null,
+ array $Listeners = [],
+ array $Meta = [],
+ null|IngressServiceConfig $Defaults = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->TLS = $TLS ?? new GatewayTLSConfig();
+ $this->setListeners(...$Listeners);
+ $this->setMeta($Meta);
+ $this->Defaults = $Defaults;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getTLS(): GatewayTLSConfig
+ {
+ return $this->TLS;
+ }
+
+ public function setTLS(GatewayTLSConfig $TLS): self
+ {
+ $this->TLS = $TLS;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener>
+ */
+ public function getListeners(): array
+ {
+ return $this->Listeners;
+ }
+
+ /**
+ * @param \DCarbone\PHPConsulAPI\ConfigEntry\IngressListener ...$Listeners
+ */
+ public function setListeners(IngressListener ...$Listeners): self
+ {
+ $this->Listeners = $Listeners;
+ return $this;
+ }
+
+ public function getDefaults(): null|IngressServiceConfig
+ {
+ return $this->Defaults;
+ }
+
+ public function setDefaults(null|IngressServiceConfig $Defaults): self
+ {
+ $this->Defaults = $Defaults;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TLS' === $k) {
+ $n->TLS = GatewayTLSConfig::jsonUnserialize($v);
+ } elseif ('Listeners' === $k) {
+ $n->Listeners = [];
+ foreach ($v as $vv) {
+ $n->Listeners[] = IngressListener::jsonUnserialize($vv);
+ }
+ } elseif ('Defaults' === $k) {
+ $n->Defaults = null === $v ? null : IngressServiceConfig::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ $out->TLS = $this->TLS;
+ $out->Listeners = $this->Listeners;
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ if (null !== $this->Defaults) {
+ $out->Defaults = $this->Defaults;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IngressListener.php b/src/ConfigEntry/IngressListener.php
new file mode 100644
index 00000000..158262db
--- /dev/null
+++ b/src/ConfigEntry/IngressListener.php
@@ -0,0 +1,125 @@
+ */
+ public array $Services;
+ public null|GatewayTLSConfig $TLS;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressService> $Services
+ */
+ public function __construct(
+ int $Port = 0,
+ string $Protocol = '',
+ array $Services = [],
+ null|GatewayTLSConfig $TLS = null
+ ) {
+ $this->Port = $Port;
+ $this->Protocol = $Protocol;
+ $this->setServices(...$Services);
+ $this->TLS = $TLS;
+ }
+
+ public function getPort(): int
+ {
+ return $this->Port;
+ }
+
+ public function setPort(int $Port): self
+ {
+ $this->Port = $Port;
+ return $this;
+ }
+
+ public function getProtocol(): string
+ {
+ return $this->Protocol;
+ }
+
+ public function setProtocol(string $Protocol): self
+ {
+ $this->Protocol = $Protocol;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressService>
+ */
+ public function getServices(): array
+ {
+ return $this->Services;
+ }
+
+ public function setServices(IngressService ...$Services): self
+ {
+ $this->Services = $Services;
+ return $this;
+ }
+
+ public function getTLS(): null|GatewayTLSConfig
+ {
+ return $this->TLS;
+ }
+
+ public function setTLS(null|GatewayTLSConfig $TLS): self
+ {
+ $this->TLS = $TLS;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Services' === $k) {
+ $n->Services = [];
+ foreach ($v as $vv) {
+ $n->Services[] = IngressService::jsonUnserialize($vv);
+ }
+ } elseif ('TLS' === $k) {
+ $n->TLS = null === $v ? null : GatewayTLSConfig::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Port = $this->Port;
+ $out->Protocol = $this->Protocol;
+ $out->Services = $this->Services;
+ if (null !== $this->TLS) {
+ $out->TLS = $this->TLS;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IngressService.php b/src/ConfigEntry/IngressService.php
new file mode 100644
index 00000000..51454e98
--- /dev/null
+++ b/src/ConfigEntry/IngressService.php
@@ -0,0 +1,247 @@
+ */
+ public array $Hosts;
+ public string $Namespace;
+ public string $Partition;
+ public null|GatewayServiceTLSConfig $TLS;
+ public null|HTTPHeaderModifiers $RequestHeaders;
+ public null|HTTPHeaderModifiers $ResponseHeaders;
+
+ public null|int $MaxConnections;
+ public null|int $MaxPendingRequests;
+ public null|int $MaxConcurrentRequests;
+ public null|PassiveHealthCheck $PassiveHealthCheck;
+
+ /**
+ * @param array $Hosts
+ */
+ public function __construct(
+ string $Name = '',
+ array $Hosts = [],
+ string $Namespace = '',
+ string $Partition = '',
+ null|GatewayServiceTLSConfig $TLS = null,
+ null|HTTPHeaderModifiers $RequestHeaders = null,
+ null|HTTPHeaderModifiers $ResponseHeaders = null,
+ null|int $MaxConnections = null,
+ null|int $MaxPendingRequests = null,
+ null|int $MaxConcurrentRequests = null,
+ null|PassiveHealthCheck $PassiveHealthCheck = null
+ ) {
+ $this->Name = $Name;
+ $this->setHosts(...$Hosts);
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->TLS = $TLS;
+ $this->RequestHeaders = $RequestHeaders;
+ $this->ResponseHeaders = $ResponseHeaders;
+ $this->MaxConnections = $MaxConnections;
+ $this->MaxPendingRequests = $MaxPendingRequests;
+ $this->MaxConcurrentRequests = $MaxConcurrentRequests;
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getHosts(): array
+ {
+ return $this->Hosts;
+ }
+
+ public function setHosts(string ...$Hosts): self
+ {
+ $this->Hosts = $Hosts;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getTLS(): null|GatewayServiceTLSConfig
+ {
+ return $this->TLS;
+ }
+
+ public function setTLS(null|GatewayServiceTLSConfig $TLS): self
+ {
+ $this->TLS = $TLS;
+ return $this;
+ }
+
+ public function getRequestHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->RequestHeaders;
+ }
+
+ public function setRequestHeaders(null|HTTPHeaderModifiers $RequestHeaders): self
+ {
+ $this->RequestHeaders = $RequestHeaders;
+ return $this;
+ }
+
+ public function getResponseHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->ResponseHeaders;
+ }
+
+ public function setResponseHeaders(null|HTTPHeaderModifiers $ResponseHeaders): self
+ {
+ $this->ResponseHeaders = $ResponseHeaders;
+ return $this;
+ }
+
+ public function getMaxConnections(): null|int
+ {
+ return $this->MaxConnections;
+ }
+
+ public function setMaxConnections(null|int $MaxConnections): self
+ {
+ $this->MaxConnections = $MaxConnections;
+ return $this;
+ }
+
+ public function getMaxPendingRequests(): null|int
+ {
+ return $this->MaxPendingRequests;
+ }
+
+ public function setMaxPendingRequests(null|int $MaxPendingRequests): self
+ {
+ $this->MaxPendingRequests = $MaxPendingRequests;
+ return $this;
+ }
+
+ public function getMaxConcurrentRequests(): null|int
+ {
+ return $this->MaxConcurrentRequests;
+ }
+
+ public function setMaxConcurrentRequests(null|int $MaxConcurrentRequests): self
+ {
+ $this->MaxConcurrentRequests = $MaxConcurrentRequests;
+ return $this;
+ }
+
+ public function getPassiveHealthCheck(): null|PassiveHealthCheck
+ {
+ return $this->PassiveHealthCheck;
+ }
+
+ public function setPassiveHealthCheck(null|PassiveHealthCheck $PassiveHealthCheck): self
+ {
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach((array)$decoded as $k => $v) {
+ if ('RequestHeaders' === $k || 'request_headers' === $k) {
+ $n->RequestHeaders = HTTPHeaderModifiers::jsonUnserialize($v);
+ } elseif ('ResponseHeaders' === $k || 'response_headers' === $k) {
+ $n->ResponseHeaders = HTTPHeaderModifiers::jsonUnserialize($v);
+ } elseif ('TLS' === $k) {
+ $n->TLS = GatewayServiceTLSConfig::jsonUnserialize($v);
+ } elseif ('PassiveHealthCheck' === $k || 'passive_health_check' === $k) {
+ $n->PassiveHealthCheck = PassiveHealthCheck::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Hosts = $this->Hosts;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if (null !== $this->TLS) {
+ $out->TLS = $this->TLS;
+ }
+ if (null !== $this->RequestHeaders) {
+ $out->RequestHeaders = $this->RequestHeaders;
+ }
+ if (null !== $this->ResponseHeaders) {
+ $out->ResponseHeaders = $this->ResponseHeaders;
+ }
+ if (null !== $this->MaxConnections) {
+ $out->MaxConnections = $this->MaxConnections;
+ }
+ if (null !== $this->MaxPendingRequests) {
+ $out->MaxPendingRequests = $this->MaxPendingRequests;
+ }
+ if (null !== $this->MaxConcurrentRequests) {
+ $out->MaxConcurrentRequests = $this->MaxConcurrentRequests;
+ }
+ if (null !== $this->PassiveHealthCheck) {
+ $out->PassiveHealthCheck = $this->PassiveHealthCheck;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IngressServiceConfig.php b/src/ConfigEntry/IngressServiceConfig.php
new file mode 100644
index 00000000..b3c1dcde
--- /dev/null
+++ b/src/ConfigEntry/IngressServiceConfig.php
@@ -0,0 +1,112 @@
+MaxConnections = $MaxConnections;
+ $this->MaxPendingRequests = $MaxPendingRequests;
+ $this->MaxConcurrentRequests = $MaxConcurrentRequests;
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ }
+
+ public function getMaxConnections(): null|int
+ {
+ return $this->MaxConnections;
+ }
+
+ public function setMaxConnections(null|int $MaxConnections): self
+ {
+ $this->MaxConnections = $MaxConnections;
+ return $this;
+ }
+
+ public function getMaxPendingRequests(): null|int
+ {
+ return $this->MaxPendingRequests;
+ }
+
+ public function setMaxPendingRequests(null|int $MaxPendingRequests): self
+ {
+ $this->MaxPendingRequests = $MaxPendingRequests;
+ return $this;
+ }
+
+ public function getMaxConcurrentRequests(): null|int
+ {
+ return $this->MaxConcurrentRequests;
+ }
+
+ public function setMaxConcurrentRequests(null|int $MaxConcurrentRequests): self
+ {
+ $this->MaxConcurrentRequests = $MaxConcurrentRequests;
+ return $this;
+ }
+
+ public function getPassiveHealthCheck(): null|PassiveHealthCheck
+ {
+ return $this->PassiveHealthCheck;
+ }
+
+ public function setPassiveHealthCheck(null|PassiveHealthCheck $PassiveHealthCheck): self
+ {
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('PassiveHealthCheck' === $k || 'passive_health_check' === $k) {
+ $n->PassiveHealthCheck = null === $v ? null : PassiveHealthCheck::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->MaxConnections = $this->MaxConnections;
+ $out->MaxPendingRequests = $this->MaxPendingRequests;
+ $out->MaxConcurrentRequests = $this->MaxConcurrentRequests;
+ if (null !== $this->PassiveHealthCheck) {
+ $out->PassiveHealthCheck = $this->PassiveHealthCheck->jsonSerialize();
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/InstanceLevelRateLimits.php b/src/ConfigEntry/InstanceLevelRateLimits.php
new file mode 100644
index 00000000..40a5b20d
--- /dev/null
+++ b/src/ConfigEntry/InstanceLevelRateLimits.php
@@ -0,0 +1,109 @@
+ */
+ public array $Routes;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\InstanceLevelRouteRateLimits> $Routes
+ */
+ public function __construct(
+ int $RequestsPerSecond = 0,
+ int $RequestsMaxBurst = 0,
+ array $Routes = []
+ ) {
+ $this->RequestsPerSecond = $RequestsPerSecond;
+ $this->RequestsMaxBurst = $RequestsMaxBurst;
+ $this->SetRoutes(...$Routes);
+ }
+
+ public function getRequestsPerSecond(): int
+ {
+ return $this->RequestsPerSecond;
+ }
+
+ public function setRequestsPerSecond(int $RequestsPerSecond): self
+ {
+ $this->RequestsPerSecond = $RequestsPerSecond;
+ return $this;
+ }
+
+ public function getRequestsMaxBurst(): int
+ {
+ return $this->RequestsMaxBurst;
+ }
+
+ public function setRequestsMaxBurst(int $RequestsMaxBurst): self
+ {
+ $this->RequestsMaxBurst = $RequestsMaxBurst;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\InstanceLevelRouteRateLimits>
+ */
+ public function getRoutes(): array
+ {
+ return $this->Routes;
+ }
+
+ public function setRoutes(InstanceLevelRouteRateLimits ...$Routes): self
+ {
+ $this->Routes = $Routes;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('requests_per_second' === $k) {
+ $n->RequestsPerSecond = $v;
+ } elseif ('requests_max_burst' === $k) {
+ $n->RequestsMaxBurst = $v;
+ } elseif ('Routes' === $k) {
+ $n->Routes = [];
+ foreach ($v as $rv) {
+ $n->Routes[] = InstanceLevelRouteRateLimits::jsonUnserialize($rv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->RequestsPerSecond = $this->RequestsPerSecond;
+ $out->RequestsMaxBurst = $this->RequestsMaxBurst;
+ $out->Routes = $this->Routes;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/InstanceLevelRouteRateLimits.php b/src/ConfigEntry/InstanceLevelRouteRateLimits.php
new file mode 100644
index 00000000..831e8eee
--- /dev/null
+++ b/src/ConfigEntry/InstanceLevelRouteRateLimits.php
@@ -0,0 +1,133 @@
+PathExact = $PathExact;
+ $this->PathPrefix = $PathPrefix;
+ $this->PathRegex = $PathRegex;
+ $this->RequestsPerSecond = $RequestsPerSecond;
+ $this->RequestsMaxBurst = $RequestsMaxBurst;
+ }
+
+ public function getPathExact(): string
+ {
+ return $this->PathExact;
+ }
+
+ public function setPathExact(string $PathExact): self
+ {
+ $this->PathExact = $PathExact;
+ return $this;
+ }
+
+ public function getPathPrefix(): string
+ {
+ return $this->PathPrefix;
+ }
+
+ public function setPathPrefix(string $PathPrefix): self
+ {
+ $this->PathPrefix = $PathPrefix;
+ return $this;
+ }
+
+ public function getPathRegex(): string
+ {
+ return $this->PathRegex;
+ }
+
+ public function setPathRegex(string $PathRegex): self
+ {
+ $this->PathRegex = $PathRegex;
+ return $this;
+ }
+
+ public function getRequestsPerSecond(): int
+ {
+ return $this->RequestsPerSecond;
+ }
+
+ public function setRequestsPerSecond(int $RequestsPerSecond): self
+ {
+ $this->RequestsPerSecond = $RequestsPerSecond;
+ return $this;
+ }
+
+ public function getRequestsMaxBurst(): int
+ {
+ return $this->RequestsMaxBurst;
+ }
+
+ public function setRequestsMaxBurst(int $RequestsMaxBurst): self
+ {
+ $this->RequestsMaxBurst = $RequestsMaxBurst;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('path_exact' === $k) {
+ $n->PathExact = $v;
+ } elseif ('path_prefix' === $k) {
+ $n->PathPrefix = $v;
+ } elseif ('path_regex' === $k) {
+ $n->PathRegex = $v;
+ } elseif ('requests_per_second' === $k) {
+ $n->RequestsPerSecond = (int)$v;
+ } elseif ('requests_max_burst' === $k) {
+ $n->RequestsMaxBurst = (int)$v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->PathExact = $this->PathExact;
+ $out->PathPrefix = $this->PathPrefix;
+ $out->PathRegex = $this->PathRegex;
+ $out->RequestsPerSecond = $this->RequestsPerSecond;
+ $out->RequestsMaxBurst = $this->RequestsMaxBurst;
+ return $out;
+ }
+}
diff --git a/src/WriteMetaContainer.php b/src/ConfigEntry/IntentionAction.php
similarity index 77%
rename from src/WriteMetaContainer.php
rename to src/ConfigEntry/IntentionAction.php
index 76c5d857..e97f19d8 100644
--- a/src/WriteMetaContainer.php
+++ b/src/ConfigEntry/IntentionAction.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace DCarbone\PHPConsulAPI;
+namespace DCarbone\PHPConsulAPI\ConfigEntry;
/*
Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
@@ -20,12 +20,11 @@
limitations under the License.
*/
-trait WriteMetaContainer
+enum IntentionAction: string
{
- public ?WriteMeta $WriteMeta = null;
+ case Allow = 'allow';
+ case Deny = 'deny';
- public function getWriteMeta(): ?WriteMeta
- {
- return $this->WriteMeta;
- }
-}
+ // Default case for when value is not set.
+ case UNDEFINED = '';
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/IntentionHTTPHeaderPermission.php b/src/ConfigEntry/IntentionHTTPHeaderPermission.php
new file mode 100644
index 00000000..404f9f63
--- /dev/null
+++ b/src/ConfigEntry/IntentionHTTPHeaderPermission.php
@@ -0,0 +1,157 @@
+Name = $Name;
+ $this->Present = $Present;
+ $this->Exact = $Exact;
+ $this->Prefix = $Prefix;
+ $this->Suffix = $Suffix;
+ $this->Regex = $Regex;
+ $this->Invert = $Invert;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function isPresent(): bool
+ {
+ return $this->Present;
+ }
+
+ public function setPresent(bool $Present): self
+ {
+ $this->Present = $Present;
+ return $this;
+ }
+
+ public function getExact(): string
+ {
+ return $this->Exact;
+ }
+
+ public function setExact(string $Exact): self
+ {
+ $this->Exact = $Exact;
+ return $this;
+ }
+
+ public function getPrefix(): string
+ {
+ return $this->Prefix;
+ }
+
+ public function setPrefix(string $Prefix): self
+ {
+ $this->Prefix = $Prefix;
+ return $this;
+ }
+
+ public function getSuffix(): string
+ {
+ return $this->Suffix;
+ }
+
+ public function setSuffix(string $Suffix): self
+ {
+ $this->Suffix = $Suffix;
+ return $this;
+ }
+
+ public function getRegex(): string
+ {
+ return $this->Regex;
+ }
+
+ public function setRegex(string $Regex): self
+ {
+ $this->Regex = $Regex;
+ return $this;
+ }
+
+ public function isInvert(): bool
+ {
+ return $this->Invert;
+ }
+
+ public function setInvert(bool $Invert): self
+ {
+ $this->Invert = $Invert;
+ return $this;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ($this->Present) {
+ $out->Present = $this->Present;
+ }
+ if ('' !== $this->Exact) {
+ $out->Exact = $this->Exact;
+ }
+ if ('' !== $this->Prefix) {
+ $out->Prefix = $this->Prefix;
+ }
+ if ('' !== $this->Suffix) {
+ $out->Suffix = $this->Suffix;
+ }
+ if ('' !== $this->Regex) {
+ $out->Regex = $this->Regex;
+ }
+ if ($this->Invert) {
+ $out->Invert = $this->Invert;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IntentionHTTPPermission.php b/src/ConfigEntry/IntentionHTTPPermission.php
new file mode 100644
index 00000000..b83ca3ff
--- /dev/null
+++ b/src/ConfigEntry/IntentionHTTPPermission.php
@@ -0,0 +1,156 @@
+ */
+ public array $Header;
+ /** @var array */
+ public array $Methods;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IntentionHTTPHeaderPermission> $Header
+ * @param array $Methods
+ */
+ public function __construct(
+ string $PathExact = '',
+ string $PathPrefix = '',
+ string $PathRegex = '',
+ array $Header = [],
+ array $Methods = []
+ ) {
+ $this->PathExact = $PathExact;
+ $this->PathPrefix = $PathPrefix;
+ $this->PathRegex = $PathRegex;
+ $this->setHeader(...$Header);
+ $this->setMethods(...$Methods);
+ }
+
+ public function getPathExact(): string
+ {
+ return $this->PathExact;
+ }
+
+ public function setPathExact(string $PathExact): self
+ {
+ $this->PathExact = $PathExact;
+ return $this;
+ }
+
+ public function getPathPrefix(): string
+ {
+ return $this->PathPrefix;
+ }
+
+ public function setPathPrefix(string $PathPrefix): self
+ {
+ $this->PathPrefix = $PathPrefix;
+ return $this;
+ }
+
+ public function getPathRegex(): string
+ {
+ return $this->PathRegex;
+ }
+
+ public function setPathRegex(string $PathRegex): self
+ {
+ $this->PathRegex = $PathRegex;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\IntentionHTTPHeaderPermission>
+ */
+ public function getHeader(): array
+ {
+ return $this->Header;
+ }
+
+ public function setHeader(IntentionHTTPHeaderPermission ...$Header): self
+ {
+ $this->Header = $Header;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getMethods(): array
+ {
+ return $this->Methods;
+ }
+
+ public function setMethods(string ...$Methods): self
+ {
+ $this->Methods = $Methods;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('path_exact' === $k) {
+ $n->PathExact = $v;
+ } elseif ('path_prefix' === $k) {
+ $n->PathPrefix = $v;
+ } elseif ('path_regex' === $k) {
+ $n->PathRegex = $v;
+ } elseif ('Header' === $k) {
+ $n->Header = [];
+ foreach ($v as $vv) {
+ $n->Header[] = IntentionHTTPHeaderPermission::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->PathExact) {
+ $out->PathExact = $this->PathExact;
+ }
+ if ('' !== $this->PathPrefix) {
+ $out->PathPrefix = $this->PathPrefix;
+ }
+ if ('' !== $this->PathRegex) {
+ $out->PathRegex = $this->PathRegex;
+ }
+ if ([] === $this->Header) {
+ $out->Header = $this->Header;
+ }
+ if ([] !== $this->Methods) {
+ $out->Methods = $this->Methods;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IntentionJWTClaimVerification.php b/src/ConfigEntry/IntentionJWTClaimVerification.php
new file mode 100644
index 00000000..307d7a4d
--- /dev/null
+++ b/src/ConfigEntry/IntentionJWTClaimVerification.php
@@ -0,0 +1,79 @@
+ */
+ public array $Path;
+ public string $Value;
+
+ /**
+ * @param array $Path
+ */
+ public function __construct(array $Path = [], string $Value = '')
+ {
+ $this->setPath(...$Path);
+ $this->Value = $Value;
+ }
+
+ /**
+ * @return array
+ */
+ public function getPath(): array
+ {
+ return $this->Path;
+ }
+
+ public function setPath(string ...$Path): self
+ {
+ $this->Path = $Path;
+ return $this;
+ }
+
+ public function getValue(): string
+ {
+ return $this->Value;
+ }
+
+ public function setValue(string $Value): self
+ {
+ $this->Value = $Value;
+ return $this;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ([] !== $this->Path) {
+ $out->Path = $this->Path;
+ }
+ if ('' !== $this->Value) {
+ $out->Value = $this->Value;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IntentionJWTRequirement.php b/src/ConfigEntry/IntentionJWTRequirement.php
new file mode 100644
index 00000000..328ce644
--- /dev/null
+++ b/src/ConfigEntry/IntentionJWTRequirement.php
@@ -0,0 +1,92 @@
+ */
+ public array $VerifyClaims;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IntentionJWTClaimVerification> $VerifyClaims
+ */
+ public function __construct(string $Name = '', array $VerifyClaims = [])
+ {
+ $this->Name = $Name;
+ $this->setVerifyClaims(...$VerifyClaims);
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\IntentionJWTClaimVerification>
+ */
+ public function getVerifyClaims(): array
+ {
+ return $this->VerifyClaims;
+ }
+
+ public function setVerifyClaims(IntentionJWTClaimVerification ...$VerifyClaims): self
+ {
+ $this->VerifyClaims = $VerifyClaims;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('VerifyClaims' === $k || 'verify_claims' === $k) {
+ $n->VerifyClaims = [];
+ foreach ($v as $vv) {
+ $n->VerifyClaims[] = IntentionJWTClaimVerification::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Name) {
+ $out->Name = $this->Name;
+ }
+ if ([] !== $this->VerifyClaims) {
+ $out->VerifyClaims = $this->VerifyClaims;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/IntentionMatchType.php b/src/ConfigEntry/IntentionMatchType.php
new file mode 100644
index 00000000..704b76d1
--- /dev/null
+++ b/src/ConfigEntry/IntentionMatchType.php
@@ -0,0 +1,30 @@
+Action = $Action instanceof IntentionAction ? $Action : IntentionAction::from($Action);
+ $this->HTTP = $HTTP;
+ $this->JWT = $JWT;
+ }
+
+ public function getAction(): IntentionAction
+ {
+ return $this->Action;
+ }
+
+ public function setAction(IntentionAction $Action): self
+ {
+ $this->Action = $Action;
+ return $this;
+ }
+
+ public function getHTTP(): null|IntentionHTTPPermission
+ {
+ return $this->HTTP;
+ }
+
+ public function setHTTP(null|IntentionHTTPPermission $HTTP): self
+ {
+ $this->HTTP = $HTTP;
+ return $this;
+ }
+
+ public function getJWT(): null|IntentionJWTRequirement
+ {
+ return $this->JWT;
+ }
+
+ public function setJWT(null|IntentionJWTRequirement $JWT): self
+ {
+ $this->JWT = $JWT;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ($k === 'Action') {
+ $n->{$k} = IntentionAction::from($v);
+ } elseif ($k === 'HTTP') {
+ $n->{$k} = null === $v ? null : IntentionHTTPPermission::jsonUnserialize($v);
+ } elseif ($k === 'JWT') {
+ $n->{$k} = null === $v ? null : IntentionJWTRequirement::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Action = $this->Action->value;
+ if (null !== $this->HTTP) {
+ $out->HTTP = $this->HTTP;
+ }
+ if (null !== $this->JWT) {
+ $out->JWT = $this->JWT;
+ }
+ return $out;
+ }
+}
diff --git a/src/HasStringTags.php b/src/ConfigEntry/IntentionSourceType.php
similarity index 78%
rename from src/HasStringTags.php
rename to src/ConfigEntry/IntentionSourceType.php
index 9546a477..69dca2a1 100644
--- a/src/HasStringTags.php
+++ b/src/ConfigEntry/IntentionSourceType.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace DCarbone\PHPConsulAPI;
+namespace DCarbone\PHPConsulAPI\ConfigEntry;
/*
Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
@@ -20,12 +20,10 @@
limitations under the License.
*/
-trait HasStringTags
+enum IntentionSourceType: string
{
- public array $Tags = [];
+ case Consul = 'consul';
- public function getTags(): array
- {
- return $this->Tags;
- }
-}
+ // Default case for when value is not set.
+ case UNDEFINED = '';
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/LeastRequestConfig.php b/src/ConfigEntry/LeastRequestConfig.php
new file mode 100644
index 00000000..a606e854
--- /dev/null
+++ b/src/ConfigEntry/LeastRequestConfig.php
@@ -0,0 +1,66 @@
+ChoiceCount = $ChoiceCount;
+ }
+
+ public function getChoiceCount(): int
+ {
+ return $this->ChoiceCount;
+ }
+
+ public function setChoiceCount(int $ChoiceCount): self
+ {
+ $this->ChoiceCount = $ChoiceCount;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('choice_count' === $k) {
+ $n->ChoiceCount = $v;
+ } else {
+ $n->{$k}= $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (0 !== $this->ChoiceCount) {
+ $out->ChoiceCount = $this->ChoiceCount;
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/LinkedService.php b/src/ConfigEntry/LinkedService.php
new file mode 100644
index 00000000..a994e256
--- /dev/null
+++ b/src/ConfigEntry/LinkedService.php
@@ -0,0 +1,156 @@
+Namespace = $Namespace;
+ $this->Name = $Name;
+ $this->CAFile = $CAFile;
+ $this->CertFile = $CertFile;
+ $this->KeyFile = $KeyFile;
+ $this->SNI = $SNI;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getCAFile(): string
+ {
+ return $this->CAFile;
+ }
+
+ public function setCAFile(string $CAFile): self
+ {
+ $this->CAFile = $CAFile;
+ return $this;
+ }
+
+ public function getCertFile(): string
+ {
+ return $this->CertFile;
+ }
+
+ public function setCertFile(string $CertFile): self
+ {
+ $this->CertFile = $CertFile;
+ return $this;
+ }
+
+ public function getKeyFile(): string
+ {
+ return $this->KeyFile;
+ }
+
+ public function setKeyFile(string $KeyFile): self
+ {
+ $this->KeyFile = $KeyFile;
+ return $this;
+ }
+
+ public function getSNI(): string
+ {
+ return $this->SNI;
+ }
+
+ public function setSNI(string $SNI): self
+ {
+ $this->SNI = $SNI;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('ca_file' === $k) {
+ $n->CAFile = $v;
+ } elseif ('cert_file' === $k) {
+ $n->CertFile = $v;
+ } elseif ('key_file' === $k) {
+ $n->KeyFile = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Name) {
+ $out->Name = $this->Name;
+ }
+ if ('' !== $this->CAFile) {
+ $out->CAFile = $this->CAFile;
+ }
+ if ('' !== $this->CertFile) {
+ $out->CertFile = $this->CertFile;
+ }
+ if ('' !== $this->KeyFile) {
+ $out->KeyFile = $this->KeyFile;
+ }
+ if ('' !== $this->SNI) {
+ $out->SNI = $this->SNI;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/LoadBalancer.php b/src/ConfigEntry/LoadBalancer.php
new file mode 100644
index 00000000..0e53ee8c
--- /dev/null
+++ b/src/ConfigEntry/LoadBalancer.php
@@ -0,0 +1,138 @@
+ */
+ public null|array $HashPolicies = null;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\HashPolicy> $HashPolicies
+ */
+ public function __construct(
+ string $Policy = '',
+ null|RingHashConfig $RingHashConfig = null,
+ null|LeastRequestConfig $LeastRequestConfig = null,
+ null|array $HashPolicies = null
+ ) {
+ $this->Policy = $Policy;
+ $this->RingHashConfig = $RingHashConfig;
+ $this->LeastRequestConfig = $LeastRequestConfig;
+ if (null !== $HashPolicies) {
+ $this->setHashPolicies(...$HashPolicies);
+ }
+ }
+
+ public function getPolicy(): string
+ {
+ return $this->Policy;
+ }
+
+ public function setPolicy(string $Policy): self
+ {
+ $this->Policy = $Policy;
+ return $this;
+ }
+
+ public function getRingHashConfig(): null|RingHashConfig
+ {
+ return $this->RingHashConfig;
+ }
+
+ public function setRingHashConfig(null|RingHashConfig $RingHashConfig): self
+ {
+ $this->RingHashConfig = $RingHashConfig;
+ return $this;
+ }
+
+ public function getLeastRequestConfig(): null|LeastRequestConfig
+ {
+ return $this->LeastRequestConfig;
+ }
+
+ public function setLeastRequestConfig(null|LeastRequestConfig $LeastRequestConfig): self
+ {
+ $this->LeastRequestConfig = $LeastRequestConfig;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\HashPolicy>
+ */
+ public function getHashPolicies(): array
+ {
+ return $this->HashPolicies;
+ }
+
+ /**
+ * @param \DCarbone\PHPConsulAPI\ConfigEntry\HashPolicy ...$HashPolicies
+ */
+ public function setHashPolicies(HashPolicy ...$HashPolicies): self
+ {
+ $this->HashPolicies = $HashPolicies;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('RingHashConfig' === $k || 'ring_hash_config' === $k) {
+ $n->RingHashConfig = RingHashConfig::jsonUnserialize($v);
+ } elseif ('LeastRequestConfig' === $k || 'least_request_config' === $k) {
+ $n->LeastRequestConfig = LeastRequestConfig::jsonUnserialize($v);
+ } elseif ('HashPolicies' === $k || 'hash_policies' === $k) {
+ if (null !== $v) {
+ foreach ($v as $hp) {
+ $n->HashPolicies[] = HashPolicy::jsonUnserialize($hp);
+ }
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Policy) {
+ $out->Policy = $this->Policy;
+ }
+ if (null !== $this->RingHashConfig) {
+ $out->RingHashConfig = $this->RingHashConfig;
+ }
+ if (null !== $this->LeastRequestConfig) {
+ $out->LeastRequestConfig = $this->LeastRequestConfig;
+ }
+ if (null !== $this->HashPolicies) {
+ $out->HashPolicies = $this->HashPolicies;
+ }
+ return $out;
+ }
+}
diff --git a/src/ErrorContainer.php b/src/ConfigEntry/LogSinkType.php
similarity index 79%
rename from src/ErrorContainer.php
rename to src/ConfigEntry/LogSinkType.php
index 0eb20750..099d032a 100644
--- a/src/ErrorContainer.php
+++ b/src/ConfigEntry/LogSinkType.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace DCarbone\PHPConsulAPI;
+namespace DCarbone\PHPConsulAPI\ConfigEntry;
/*
Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com)
@@ -20,12 +20,10 @@
limitations under the License.
*/
-trait ErrorContainer
+enum LogSinkType: string
{
- public ?Error $Err = null;
-
- public function getErr(): ?Error
- {
- return $this->Err;
- }
-}
+ case Default = '';
+ case File = 'file';
+ case StdErr = 'stderr';
+ case StdOut = 'stdout';
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php
index 27414433..b436bae1 100644
--- a/src/ConfigEntry/MeshConfigEntry.php
+++ b/src/ConfigEntry/MeshConfigEntry.php
@@ -20,34 +20,160 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Consul;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class MeshConfigEntry extends AbstractModel implements ConfigEntry
+class MeshConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- protected const FIELDS = COnfigEntry::INTERFACE_FIELDS + [
- self::FIELD_TRANSPARENT_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TransparentProxyConfig::class,
- Transcoding::FIELD_NULLABLE => false,
- Transcoding::FIELD_OMITEMPTY => false,
- ],
- ];
+ public string $Partition;
+ public TransparentProxyMeshConfig $TransparentProxy;
+ public bool $AllowEnablingPermissiveMutualTLS;
+ public null|MeshTLSConfig $TLS;
+ public null|MeshHTTPConfig $HTTP;
+ public null|PeeringMeshConfig $Peering;
- private const FIELD_TRANSPARENT_PROXY = 'TransparentProxy';
+ /**
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Partition = '',
+ string $Namespace = '',
+ null|TransparentProxyMeshConfig $TransparentProxy = null,
+ bool $AllowEnablingPermissiveMutualTLS = false,
+ null|MeshTLSConfig $TLS = null,
+ null|MeshHTTPConfig $HTTP = null,
+ null|PeeringMeshConfig $Peering = null,
+ array $Meta = [],
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0
+ ) {
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->TransparentProxy = $TransparentProxy ?? new TransparentProxyMeshConfig();
+ $this->AllowEnablingPermissiveMutualTLS = $AllowEnablingPermissiveMutualTLS;
+ $this->TLS = $TLS;
+ $this->HTTP = $HTTP;
+ $this->Peering = $Peering;
+}
- public TransparentProxyConfig $TransparentProxy;
+ public function getKind(): string
+ {
+ return Consul::MeshConfig;
+ }
+
+ public function getName(): string
+ {
+ return Consul::MeshConfigMesh;
+ }
- public function getTransparentProxy(): TransparentProxyConfig
+ public function getTransparentProxy(): TransparentProxyMeshConfig
{
return $this->TransparentProxy;
}
- public function setTransparentProxy(TransparentProxyConfig $TransparentProxy): self
+ public function setTransparentProxy(TransparentProxyMeshConfig $TransparentProxy): self
{
$this->TransparentProxy = $TransparentProxy;
return $this;
}
+
+ public function isAllowEnablingPermissiveMutualTLS(): bool
+ {
+ return $this->AllowEnablingPermissiveMutualTLS;
+ }
+
+ public function setAllowEnablingPermissiveMutualTLS(bool $AllowEnablingPermissiveMutualTLS): self
+ {
+ $this->AllowEnablingPermissiveMutualTLS = $AllowEnablingPermissiveMutualTLS;
+ return $this;
+ }
+
+ public function getTLS(): null|MeshTLSConfig
+ {
+ return $this->TLS;
+ }
+
+ public function setTLS(null|MeshTLSConfig $TLS): self
+ {
+ $this->TLS = $TLS;
+ return $this;
+ }
+
+ public function getHTTP(): null|MeshHTTPConfig
+ {
+ return $this->HTTP;
+ }
+
+ public function setHTTP(null|MeshHTTPConfig $HTTP): self
+ {
+ $this->HTTP = $HTTP;
+ return $this;
+ }
+
+ public function getPeering(): null|PeeringMeshConfig
+ {
+ return $this->Peering;
+ }
+
+ public function setPeering(null|PeeringMeshConfig $Peering): self
+ {
+ $this->Peering = $Peering;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): self
+ {
+ $n = $n ?? new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('TransparentProxy' === $k || 'transparent_proxy' === $k) {
+ $n->TransparentProxy = null === $v ? new TransparentProxyMeshConfig() : TransparentProxyMeshConfig::jsonUnserialize($v);
+ } elseif ('TLS' === $k) {
+ $n->TLS = null === $v ? null : MeshTLSConfig::jsonUnserialize($v);
+ } elseif ('HTTP' === $k) {
+ $n->HTTP = null === $v ? null : MeshHTTPConfig::jsonUnserialize($v);
+ } elseif ('Peering' === $k) {
+ $n->Peering = null === $v ? null : PeeringMeshConfig::jsonUnserialize($v);
+ } elseif ('allow_enabling_permissive_mutual_tls' === $k) {
+ $n->AllowEnablingPermissiveMutualTLS = $v;
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = Consul::MeshConfigMesh;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ $out->TransparentProxy = $this->TransparentProxy;
+ if ($this->AllowEnablingPermissiveMutualTLS) {
+ $out->AllowEnablingPermissiveMutualTLS = true;
+ }
+ if (null !== $this->TLS) {
+ $out->TLS = $this->TLS;
+ }
+ if (null !== $this->HTTP) {
+ $out->HTTP = $this->HTTP;
+ }
+ if (null !== $this->Peering) {
+ $out->Peering = $this->Peering;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/MeshDirectionalTLSConfig.php b/src/ConfigEntry/MeshDirectionalTLSConfig.php
new file mode 100644
index 00000000..8c609797
--- /dev/null
+++ b/src/ConfigEntry/MeshDirectionalTLSConfig.php
@@ -0,0 +1,112 @@
+ */
+ public array $CipherSuites;
+
+ /**
+ * @param array $CipherSuites
+ */
+ public function __construct(
+ string $TLSMinVersion = '',
+ string $TLSMaxVersion = '',
+ array $CipherSuites = [],
+ ) {
+ $this->TLSMinVersion = $TLSMinVersion;
+ $this->TLSMaxVersion = $TLSMaxVersion;
+ $this->setCipherSuites(...$CipherSuites);
+ }
+
+ public function getTLSMinVersion(): string
+ {
+ return $this->TLSMinVersion;
+ }
+
+ public function setTLSMinVersion(string $TLSMinVersion): self
+ {
+ $this->TLSMinVersion = $TLSMinVersion;
+ return $this;
+ }
+
+ public function getTLSMaxVersion(): string
+ {
+ return $this->TLSMaxVersion;
+ }
+
+ public function setTLSMaxVersion(string $TLSMaxVersion): self
+ {
+ $this->TLSMaxVersion = $TLSMaxVersion;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getCipherSuites(): array
+ {
+ return $this->CipherSuites;
+ }
+
+ public function setCipherSuites(string ...$CipherSuites): self
+ {
+ $this->CipherSuites = $CipherSuites;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('CipherSuites' === $k || 'cipher_suites' === $k) {
+ $n->setCipherSuites(...$v);
+ } elseif ('tls_min_version' === $k) {
+ $n->TLSMinVersion = $v;
+ } elseif ('tls_max_version' === $k) {
+ $n->TLSMaxVersion = $v;
+ } else {
+ $n->{$k} = (string)$v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->TLSMinVersion) {
+ $out->TLSMinVersion = $this->TLSMinVersion;
+ }
+ if ('' !== $this->TLSMaxVersion) {
+ $out->TLSMaxVersion = $this->TLSMaxVersion;
+ }
+ if ([] !== $this->CipherSuites) {
+ $out->CipherSuites = $this->CipherSuites;
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php
index 68074e57..850da89c 100644
--- a/src/ConfigEntry/MeshGatewayConfig.php
+++ b/src/ConfigEntry/MeshGatewayConfig.php
@@ -20,27 +20,45 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class MeshGatewayConfig extends AbstractModel
+class MeshGatewayConfig extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
+ public MeshGatewayMode $Mode;
- private const FIELD_MODE = 'Mode';
-
- public string $Mode = '';
+ public function __construct(
+ string|MeshGatewayMode $mode = MeshGatewayMode::Default,
+ ) {
+ $this->setMode($mode);
+}
- public function getMode(): string
+ public function getMode(): MeshGatewayMode
{
return $this->Mode;
}
- public function setMode(string $mode): self
+ public function setMode(string|MeshGatewayMode $Mode): self
{
- $this->Mode = $mode;
+ $this->Mode = $Mode instanceof MeshGatewayMode ? $Mode : MeshGatewayMode::from($Mode);
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Mode' === $k) {
+ $n->setMode($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/MeshGatewayMode.php b/src/ConfigEntry/MeshGatewayMode.php
new file mode 100644
index 00000000..0f2f2311
--- /dev/null
+++ b/src/ConfigEntry/MeshGatewayMode.php
@@ -0,0 +1,46 @@
+SanitizeXForwardClientCert = $SanitizeXForwardClientCert;
+ }
+
+ public function isSanitizeXForwardClientCert(): bool
+ {
+ return $this->SanitizeXForwardClientCert;
+ }
+
+ public function setSanitizeXForwardClientCert(bool $SanitizeXForwardClientCert): self
+ {
+ $this->SanitizeXForwardClientCert = $SanitizeXForwardClientCert;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->SanitizeXForwardClientCert = $this->SanitizeXForwardClientCert;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/MeshTLSConfig.php b/src/ConfigEntry/MeshTLSConfig.php
new file mode 100644
index 00000000..c3310099
--- /dev/null
+++ b/src/ConfigEntry/MeshTLSConfig.php
@@ -0,0 +1,85 @@
+Incoming = $Incoming;
+ $this->Outgoing = $Outgoing;
+ }
+
+ public function getIncoming(): null|MeshDirectionalTLSConfig
+ {
+ return $this->Incoming;
+ }
+ public function setIncoming(null|MeshDirectionalTLSConfig $Incoming): self
+ {
+ $this->Incoming = $Incoming;
+ return $this;
+ }
+
+ public function getOutgoing(): null|MeshDirectionalTLSConfig
+ {
+ return $this->Outgoing;
+ }
+
+ public function setOutgoing(null|MeshDirectionalTLSConfig $Outgoing): self
+ {
+ $this->Outgoing = $Outgoing;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $V) {
+ if ('Incoming' === $k) {
+ $n->Incoming = null === $V ? null : MeshDirectionalTLSConfig::jsonUnserialize($V);
+ } elseif ('Outgoing' === $k) {
+ $n->Outgoing = null === $V ? null : MeshDirectionalTLSConfig::jsonUnserialize($V);
+ } else {
+ $n->{$k} = $V;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (null !== $this->Incoming) {
+ $out->Incoming = $this->Incoming;
+ }
+ if (null !== $this->Outgoing) {
+ $out->Outgoing = $this->Outgoing;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/MutualTLSMode.php b/src/ConfigEntry/MutualTLSMode.php
new file mode 100644
index 00000000..c12604ca
--- /dev/null
+++ b/src/ConfigEntry/MutualTLSMode.php
@@ -0,0 +1,39 @@
+ [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public Time\Duration $Interval;
+ public int $MaxFailures;
- private const FIELD_INTERVAL = 'Interval';
+ public null|int $EnforcingConsecutive5xx;
+ public null|int $MaxEjectionPercent;
- public Time\Duration $Interval;
- public int $MaxFailures = 0;
+ public null|Time\Duration $BaseEjectionTime;
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Interval)) {
- $this->Interval = new Time\Duration();
- }
- }
+ public function __construct(
+ null|string|int|float|\DateInterval|Time\Duration $Interval = null,
+ int $MaxFailures = 0,
+ null|int $EnforcingConsecutive5xx = null,
+ null|int $MaxEjectionPercent = null,
+ null|string|int|float|\DateInterval|Time\Duration $BaseEjectionTime = null,
+ ) {
+ $this->Interval = Time::Duration($Interval);
+ $this->MaxFailures = $MaxFailures;
+ $this->EnforcingConsecutive5xx = $EnforcingConsecutive5xx;
+ $this->MaxEjectionPercent = $MaxEjectionPercent;
+ $this->BaseEjectionTime = null !== $BaseEjectionTime ? Time::Duration($BaseEjectionTime) : null;
+}
public function getInterval(): Time\Duration
{
return $this->Interval;
}
- public function setInterval(Time\Duration $Interval): self
+ public function setInterval(null|string|int|float|\DateInterval|Time\Duration $Interval): self
{
- $this->Interval = $Interval;
+ $this->Interval = Time::Duration($Interval);
return $this;
}
@@ -67,4 +68,77 @@ public function setMaxFailures(int $MaxFailures): self
$this->MaxFailures = $MaxFailures;
return $this;
}
+
+ public function getEnforcingConsecutive5xx(): null|int
+ {
+ return $this->EnforcingConsecutive5xx;
+ }
+
+ public function setEnforcingConsecutive5xx(null|int $EnforcingConsecutive5xx): self
+ {
+ $this->EnforcingConsecutive5xx = $EnforcingConsecutive5xx;
+ return $this;
+ }
+
+ public function getMaxEjectionPercent(): null|int
+ {
+ return $this->MaxEjectionPercent;
+ }
+
+ public function setMaxEjectionPercent(null|int $MaxEjectionPercent): self
+ {
+ $this->MaxEjectionPercent = $MaxEjectionPercent;
+ return $this;
+ }
+
+ public function getBaseEjectionTime(): null|Time\Duration
+ {
+ return $this->BaseEjectionTime;
+ }
+
+ public function setBaseEjectionTime(null|Time\Duration $BaseEjectionTime): self
+ {
+ $this->BaseEjectionTime = $BaseEjectionTime;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Interval' === $k) {
+ $n->Interval = Time::ParseDuration($v);
+ } elseif ('max_failures' === $k) {
+ $n->MaxFailures = $v;
+ } elseif ('enforcing_consecutive_5xx' === $k) {
+ $n->EnforcingConsecutive5xx = $v;
+ } elseif ('max_ejection_percent' === $k) {
+ $n->MaxEjectionPercent = $v;
+ } elseif ('base_ejection_time' === $k) {
+ $n->BaseEjectionTime = Time::ParseDuration($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ($this->Interval->Nanoseconds() !== 0) {
+ $out->Interval = $this->Interval;
+ }
+ $out->MaxFailures = $this->MaxFailures;
+ if (null !== $this->EnforcingConsecutive5xx) {
+ $out->EnforcingConsecutive5xx = $this->EnforcingConsecutive5xx;
+ }
+ if (null !== $this->MaxEjectionPercent) {
+ $out->MaxEjectionPercent = $this->MaxEjectionPercent;
+ }
+ if (null !== $this->BaseEjectionTime) {
+ $out->BaseEjectionTime = $this->BaseEjectionTime;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/PeeringMeshConfig.php b/src/ConfigEntry/PeeringMeshConfig.php
new file mode 100644
index 00000000..f024460b
--- /dev/null
+++ b/src/ConfigEntry/PeeringMeshConfig.php
@@ -0,0 +1,60 @@
+PeerThroughMeshGateways = $PeerThroughMeshGateways;
+ }
+
+ public function isPeerThroughMeshGateways(): bool
+ {
+ return $this->PeerThroughMeshGateways;
+ }
+
+ public function setPeerThroughMeshGateways(bool $PeerThroughMeshGateways): self
+ {
+ $this->PeerThroughMeshGateways = $PeerThroughMeshGateways;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->PeerThroughMeshGateways = $this->PeerThroughMeshGateways;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php
index d8896dd8..65dc3138 100644
--- a/src/ConfigEntry/ProxyConfigEntry.php
+++ b/src/ConfigEntry/ProxyConfigEntry.php
@@ -20,77 +20,162 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeMap;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\Consul;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued;
-class ProxyConfigEntry extends AbstractModel implements ConfigEntry
+class ProxyConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [
- self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_CONFIG => Transcoding::MAP_FIELD,
- self::FIELD_TRANSPARENT_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TransparentProxyConfig::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_MESH_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => MeshGatewayConfig::class,
- Transcoding::FIELD_OMITEMPTY => true, // todo: does nothing as field is not nullable..
- ],
- self::FIELD_EXPOSE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ExposeConfig::class,
- Transcoding::FIELD_OMITEMPTY => true, // todo: does nothing as field is not nullable,
- ],
- ];
-
- private const FIELD_MODE = 'Mode';
- private const FIELD_TRANSPARENT_PROXY = 'TransparentProxy';
- private const FIELD_CONFIG = 'Config';
- private const FIELD_MESH_GATEWAY = 'MeshGateway';
- private const FIELD_EXPOSE = 'Expose';
-
- public string $Mode = '';
- public ?TransparentProxyConfig $TransparentProxy = null;
- public ?FakeMap $Config = null;
+ public string $Kind;
+ public string $Name;
+ public string $Partition;
+ public null|ProxyMode $Mode;
+ public null|TransparentProxyConfig $TransparentProxy;
+ public MutualTLSMode $MutualTLSMode;
+ /** @var array */
+ public array $Config;
+
public MeshGatewayConfig $MeshGateway;
public ExposeConfig $Expose;
+ public null|AccessLogsConfig $AccessLogs;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */
+ public array $EnvoyExtensions;
+ public null|ServiceResolverFailoverPolicy $FailoverPolicy;
+ public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality;
- public function getMode(): string
+ /**
+ * @param array $Config
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string|ProxyMode $Mode = ProxyMode::Default,
+ null|TransparentProxyConfig $TransparentProxy = null,
+ string|MutualTLSMode $MutualTLSMode = MutualTLSMode::Default,
+ array $Config = [],
+ null|MeshGatewayConfig $MeshGateway = null,
+ null|ExposeConfig $Expose = null,
+ null|AccessLogsConfig $AccessLogs = null,
+ array $EnvoyExtensions = [],
+ null|ServiceResolverFailoverPolicy $FailoverPolicy = null,
+ null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null,
+ string $Namespace = '',
+ array $Meta = [],
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode);
+ $this->TransparentProxy = $TransparentProxy;
+ $this->MutualTLSMode = $MutualTLSMode instanceof MutualTLSMode ? $MutualTLSMode : MutualTLSMode::from($MutualTLSMode);
+ $this->setConfig($Config);
+ $this->MeshGateway = $MeshGateway ?? new MeshGatewayConfig();
+ $this->Expose = $Expose ?? new ExposeConfig();
+ $this->AccessLogs = $AccessLogs;
+ $this->setEnvoyExtensions(...$EnvoyExtensions);
+ $this->FailoverPolicy = $FailoverPolicy;
+ $this->PrioritizeByLocality = $PrioritizeByLocality;
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+}
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return Consul::ProxyConfigGlobal;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getMode(): ProxyMode
{
return $this->Mode;
}
- public function setMode(string $Mode): self
+ public function setMode(ProxyMode $Mode): self
{
$this->Mode = $Mode;
return $this;
}
- public function getTransparentProxy(): ?TransparentProxyConfig
+ public function getTransparentProxy(): null|TransparentProxyConfig
{
return $this->TransparentProxy;
}
- public function setTransparentProxy(?TransparentProxyConfig $TransparentProxy): self
+ public function setTransparentProxy(null|TransparentProxyConfig $TransparentProxy): self
{
$this->TransparentProxy = $TransparentProxy;
return $this;
}
- public function getConfig(): ?FakeMap
+ public function getMutualTLSMode(): MutualTLSMode
+ {
+ return $this->MutualTLSMode;
+ }
+
+ public function setMutualTLSMode(MutualTLSMode $MutualTLSMode): self
+ {
+ $this->MutualTLSMode = $MutualTLSMode;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getConfig(): array
{
return $this->Config;
}
- public function setConfig(mixed $Config): self
+ /**
+ * @param null|\stdClass|array $Config
+ * @return $this
+ */
+ public function setConfig(null|\stdClass|array $Config): self
{
- $this->Config = FakeMap::parse($Config);
+ $this->Config = [];
+ if (null !== $Config) {
+ foreach ($Config as $k => $v) {
+ $this->Config[$k] = $v;
+ }
+ }
return $this;
}
@@ -115,4 +200,133 @@ public function setExpose(ExposeConfig $Expose): self
$this->Expose = $Expose;
return $this;
}
+
+ public function getAccessLogs(): null|AccessLogsConfig
+ {
+ return $this->AccessLogs;
+ }
+
+ public function setAccessLogs(null|AccessLogsConfig $AccessLogs): self
+ {
+ $this->AccessLogs = $AccessLogs;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension>
+ */
+ public function getEnvoyExtensions(): array
+ {
+ return $this->EnvoyExtensions;
+ }
+
+ /**
+ * @param \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension ...$EnvoyExtensions
+ */
+ public function setEnvoyExtensions(EnvoyExtension ...$EnvoyExtensions): self
+ {
+ $this->EnvoyExtensions = $EnvoyExtensions;
+ return $this;
+ }
+
+ public function getFailoverPolicy(): null|ServiceResolverFailoverPolicy
+ {
+ return $this->FailoverPolicy;
+ }
+
+ public function setFailoverPolicy(null|ServiceResolverFailoverPolicy $FailoverPolicy): self
+ {
+ $this->FailoverPolicy = $FailoverPolicy;
+ return $this;
+ }
+
+ public function getPrioritizeByLocality(): null|ServiceResolverPrioritizeByLocality
+ {
+ return $this->PrioritizeByLocality;
+ }
+
+ public function setPrioritizeByLocality(null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality): self
+ {
+ $this->PrioritizeByLocality = $PrioritizeByLocality;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('ProxyMode' === $k) {
+ $n->Mode = ProxyMode::from($v);
+ } elseif ('TransparentProxy' === $k || 'transparent_proxy' === $k) {
+ $n->TransparentProxy = TransparentProxyConfig::jsonUnserialize($v);
+ } elseif ('MutualTLSMode' === $k || 'mutual_tls_mode' === $k) {
+ $n->MutualTLSMode = MutualTLSMode::from($v);
+ } elseif ('MeshGateway' === $k || 'mesh_gateway' === $k) {
+ $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v);
+ } elseif ('Expose' === $k) {
+ $n->Expose = ExposeConfig::jsonUnserialize($v);
+ } elseif ('AccessLogs' === $k || 'access_logs' === $k) {
+ $n->AccessLogs = AccessLogsConfig::jsonUnserialize($v);
+ } elseif ('EnvoyExtensions' === $k || 'envoy_extensions' === $k) {
+ foreach ($v as $ext) {
+ $n->EnvoyExtensions[] = EnvoyExtension::jsonUnserialize($ext);
+ }
+ } elseif ('FailoverPolicy' === $k || 'failover_policy' === $k) {
+ $n->FailoverPolicy = ServiceResolverFailoverPolicy::jsonUnserialize($v);
+ } elseif ('PrioritizeByLocality' === $k || 'prioritize_by_locality' === $k) {
+ $n->PrioritizeByLocality = ServiceResolverPrioritizeByLocality::jsonUnserialize($v);
+ } elseif ('Config' === $k) {
+ $n->setConfig($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if (ProxyMode::Default !== $this->Mode) {
+ $out->ProxyMode = $this->Mode->value;
+ }
+ if (null !== $this->TransparentProxy) {
+ $out->TransparentProxy = $this->TransparentProxy;
+ }
+ if (MutualTLSMode::Default !== $this->MutualTLSMode) {
+ $out->MutualTLSMode = $this->MutualTLSMode->value;
+ }
+ if ([] !== $this->Config) {
+ $out->Config = $this->Config;
+ }
+ _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway);
+ _enc_obj_if_valued($out, 'Expose', $this->Expose);
+ if (null !== $this->AccessLogs) {
+ $out->AccessLogs = $this->AccessLogs;
+ } if ([] !== $this->EnvoyExtensions) {
+ $out->EnvoyExtensions = $this->EnvoyExtensions;
+ }
+ if (null !== $this->FailoverPolicy) {
+ $out->FailoverPolicy = $this->FailoverPolicy;
+ }
+ if (null !== $this->PrioritizeByLocality) {
+ $out->PrioritizeByLocality = $this->PrioritizeByLocality;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ([] !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ProxyMode.php b/src/ConfigEntry/ProxyMode.php
new file mode 100644
index 00000000..c416a423
--- /dev/null
+++ b/src/ConfigEntry/ProxyMode.php
@@ -0,0 +1,43 @@
+InstanceLevel = $instanceLevel ?? new InstanceLevelRateLimits();
+ }
+
+ public function getInstanceLevel(): InstanceLevelRateLimits
+ {
+ return $this->InstanceLevel;
+ }
+
+ public function setInstanceLevel(InstanceLevelRateLimits $InstanceLevel): self
+ {
+ $this->InstanceLevel = $InstanceLevel;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('InstanceLevel' === $k || 'instance_level' === $k) {
+ $n->InstanceLevel = InstanceLevelRateLimits::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->InstanceLevel = $this->InstanceLevel;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php
index 6b7fad97..7c763742 100644
--- a/src/ConfigEntry/RingHashConfig.php
+++ b/src/ConfigEntry/RingHashConfig.php
@@ -20,16 +20,65 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class RingHashConfig extends AbstractModel
+class RingHashConfig extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_MINIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_MAXIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD,
- ];
+ public int $MinimumRingSize = 0;
+ public int $MaximumRingSize = 0;
- private const FIELD_MINIMUM_RING_SIZE = 'MinimumRingSize';
- private const FIELD_MAXIMUM_RING_SIZE = 'MaximumRingSize';
+ public function __construct(int $MinimumRingSize = 0, int $MaximumRingSize = 0)
+ {
+ $this->MinimumRingSize = $MinimumRingSize;
+ $this->MaximumRingSize = $MaximumRingSize;
+ }
+
+ public function getMinimumRingSize(): int
+ {
+ return $this->MinimumRingSize;
+ }
+
+ public function setMinimumRingSize(int $MinimumRingSize): self
+ {
+ $this->MinimumRingSize = $MinimumRingSize;
+ return $this;
+ }
+
+ public function getMaximumRingSize(): int
+ {
+ return $this->MaximumRingSize;
+ }
+
+ public function setMaximumRingSize(int $MaximumRingSize): self
+ {
+ $this->MaximumRingSize = $MaximumRingSize;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('minimum_ring_size' === $k) {
+ $n->MinimumRingSize = $v;
+ } elseif ('maximum_ring_size' === $k) {
+ $n->MaximumRingSize = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (0 !== $this->MinimumRingSize) {
+ $out->MinimumRingSize = $this->MinimumRingSize;
+ }
+ if (0 !== $this->MaximumRingSize) {
+ $out->MaximumRingSize = $this->MaximumRingSize;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php
index 750fe4ce..d1c2770c 100644
--- a/src/ConfigEntry/ServiceConfigEntry.php
+++ b/src/ConfigEntry/ServiceConfigEntry.php
@@ -20,56 +20,118 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued;
-class ServiceConfigEntry extends AbstractModel implements ConfigEntry
+class ServiceConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [
- self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TRANSPARENT_PROXY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TransparentProxyConfig::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_MESH_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => MeshGatewayConfig::class,
- Transcoding::FIELD_OMITEMPTY => true, // todo: does nothing as it isn't nullable...
- ],
- self::FIELD_EXPOSE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ExposeConfig::class,
- Transcoding::FIELD_OMITEMPTY => true, // todo: does nothing as isn't nullable..
- ],
- self::FIELD_EXTERNAL_SNI => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_UPSTREAM_CONFIG => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => UpstreamConfiguration::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
-
- private const FIELD_PROTOCOL = 'Protocol';
- private const FIELD_MODE = 'Mode';
- private const FIELD_TRANSPARENT_PROXY = 'TransparentProxy';
- private const FIELD_MESH_GATEWAY = 'MeshGateway';
- private const FIELD_EXPOSE = 'Expose';
- private const FIELD_EXTERNAL_SNI = 'ExternalSNI';
- private const FIELD_UPSTREAM_CONFIG = 'UpstreamConfig';
-
- public string $Protocol = '';
- public string $Mode = '';
- public ?TransparentProxyConfig $TransparentProxy = null;
+ public string $Kind;
+ public string $Name;
+ public string $Partition;
+ public string $Protocol;
+ public ProxyMode $Mode;
+ public null|TransparentProxyConfig $TransparentProxy;
+
+ public MutualTLSMode $MutualTLSMode;
public MeshGatewayConfig $MeshGateway;
public ExposeConfig $Expose;
- public string $ExternalSNI = '';
- public ?UpstreamConfiguration $UpstreamConfig = null;
+ public string $ExternalSNI;
+ public null|UpstreamConfiguration $UpstreamConfig;
+ public null|DestinationConfig $Destination;
+ public int $MaxInboundConnections;
+ public int $LocalConnectTimeoutMs;
+ public int $LocalRequestTimeoutMs;
+ public string $BalanceInboundConnections;
+ public null|RateLimits $RateLimits;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */
+ public array $EnvoyExtensions;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ string $Protocol = '',
+ string|ProxyMode $Mode = ProxyMode::Default,
+ null|TransparentProxyConfig $TransparentProxy = null,
+ string|MutualTLSMode $MutualTLSMode = MutualTLSMode::Default,
+ null|MeshGatewayConfig $MeshGateway = null,
+ null|ExposeConfig $Expose = null,
+ string $ExternalSNI = '',
+ null|UpstreamConfiguration $UpstreamConfig = null,
+ null|DestinationConfig $Destination = null,
+ int $MaxInboundConnections = 0,
+ int $LocalConnectTimeoutMs = 0,
+ int $LocalRequestTimeoutMs = 0,
+ string $BalanceInboundConnections = '',
+ null|RateLimits $RateLimits = null,
+ array $EnvoyExtensions = [],
+ array $Meta = [],
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->Protocol = $Protocol;
+ $this->Mode = is_string($Mode) ? ProxyMode::from($Mode) : $Mode;
+ $this->TransparentProxy = $TransparentProxy;
+ $this->MutualTLSMode = is_string($MutualTLSMode) ? MutualTLSMode::from($MutualTLSMode) : $MutualTLSMode;
+ $this->MeshGateway = $MeshGateway ?? new MeshGatewayConfig();
+ $this->Expose = $Expose ?? new ExposeConfig();
+ $this->ExternalSNI = $ExternalSNI;
+ $this->UpstreamConfig = $UpstreamConfig;
+ $this->Destination = $Destination;
+ $this->MaxInboundConnections = $MaxInboundConnections;
+ $this->LocalConnectTimeoutMs = $LocalConnectTimeoutMs;
+ $this->LocalRequestTimeoutMs = $LocalRequestTimeoutMs;
+ $this->BalanceInboundConnections = $BalanceInboundConnections;
+ $this->RateLimits = $RateLimits;
+ $this->setEnvoyExtensions(...$EnvoyExtensions);
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
public function getProtocol(): string
{
@@ -82,28 +144,39 @@ public function setProtocol(string $Protocol): self
return $this;
}
- public function getMode(): string
+ public function getMode(): ProxyMode
{
return $this->Mode;
}
- public function setMode(string $Mode): self
+ public function setMode(ProxyMode $Mode): self
{
$this->Mode = $Mode;
return $this;
}
- public function getTransparentProxy(): ?TransparentProxyConfig
+ public function getTransparentProxy(): null|TransparentProxyConfig
{
return $this->TransparentProxy;
}
- public function setTransparentProxy(?TransparentProxyConfig $TransparentProxy): self
+ public function setTransparentProxy(null|TransparentProxyConfig $TransparentProxy): self
{
$this->TransparentProxy = $TransparentProxy;
return $this;
}
+ public function getMutualTLSMode(): MutualTLSMode
+ {
+ return $this->MutualTLSMode;
+ }
+
+ public function setMutualTLSMode(MutualTLSMode $MutualTLSMode): self
+ {
+ $this->MutualTLSMode = $MutualTLSMode;
+ return $this;
+ }
+
public function getMeshGateway(): MeshGatewayConfig
{
return $this->MeshGateway;
@@ -137,14 +210,197 @@ public function setExternalSNI(string $ExternalSNI): self
return $this;
}
- public function getUpstreamConfig(): ?UpstreamConfiguration
+ public function getUpstreamConfig(): null|UpstreamConfiguration
{
return $this->UpstreamConfig;
}
- public function setUpstreamConfig(?UpstreamConfiguration $UpstreamConfig): self
+ public function setUpstreamConfig(null|UpstreamConfiguration $UpstreamConfig): self
{
$this->UpstreamConfig = $UpstreamConfig;
return $this;
}
+
+ public function getDestination(): null|DestinationConfig
+ {
+ return $this->Destination;
+ }
+
+ public function setDestination(null|DestinationConfig $Destination): self
+ {
+ $this->Destination = $Destination;
+ return $this;
+ }
+
+ public function getMaxInboundConnections(): int
+ {
+ return $this->MaxInboundConnections;
+ }
+
+ public function setMaxInboundConnections(int $MaxInboundConnections): self
+ {
+ $this->MaxInboundConnections = $MaxInboundConnections;
+ return $this;
+ }
+
+ public function getLocalConnectTimeoutMs(): int
+ {
+ return $this->LocalConnectTimeoutMs;
+ }
+
+ public function setLocalConnectTimeoutMs(int $LocalConnectTimeoutMs): self
+ {
+ $this->LocalConnectTimeoutMs = $LocalConnectTimeoutMs;
+ return $this;
+ }
+
+ public function getLocalRequestTimeoutMs(): int
+ {
+ return $this->LocalRequestTimeoutMs;
+ }
+
+ public function setLocalRequestTimeoutMs(int $LocalRequestTimeoutMs): self
+ {
+ $this->LocalRequestTimeoutMs = $LocalRequestTimeoutMs;
+ return $this;
+ }
+
+ public function getBalanceInboundConnections(): string
+ {
+ return $this->BalanceInboundConnections;
+ }
+
+ public function setBalanceInboundConnections(string $BalanceInboundConnections): self
+ {
+ $this->BalanceInboundConnections = $BalanceInboundConnections;
+ return $this;
+ }
+
+ public function getRateLimits(): null|RateLimits
+ {
+ return $this->RateLimits;
+ }
+
+ public function setRateLimits(null|RateLimits $RateLimits): self
+ {
+ $this->RateLimits = $RateLimits;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension>
+ */
+ public function getEnvoyExtensions(): array
+ {
+ return $this->EnvoyExtensions;
+ }
+
+ public function setEnvoyExtensions(EnvoyExtension ...$EnvoyExtensions): self
+ {
+ $this->EnvoyExtensions = $EnvoyExtensions;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Mode' === $k) {
+ $n->Mode = ProxyMode::from($v);
+ } elseif ('TransparentProxy' === $k || 'transparent_proxy' === $k) {
+ $n->TransparentProxy = null === $v ? null : TransparentProxyConfig::jsonUnserialize($v);
+ } elseif ('MutualTLSMode' === $k || 'mutual_tls_mode' === $k) {
+ $n->MutualTLSMode = MutualTLSMode::from($v);
+ } elseif ('MeshGateway' === $k || 'mesh_gateway' === $k) {
+ $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v);
+ } elseif ('Expose' === $k) {
+ $n->Expose = ExposeConfig::jsonUnserialize($v);
+ } elseif ('external_sni' === $k) {
+ $n->ExternalSNI = $v;
+ } elseif ('UpstreamConfig' === $k || 'upstream_config' === $k) {
+ $n->UpstreamConfig = null === $v ? null : UpstreamConfiguration::jsonUnserialize($v);
+ } elseif ('Destination' === $k) {
+ $n->Destination = null === $v ? null : DestinationConfig::jsonUnserialize($v);
+ } elseif ('max_inbound_connections' === $k) {
+ $n->MaxInboundConnections = $v;
+ } elseif ('local_connect_timeout_ms' === $k) {
+ $n->LocalConnectTimeoutMs = $v;
+ } elseif ('local_request_timeout_ms' === $k) {
+ $n->LocalRequestTimeoutMs = $v;
+ } elseif ('balance_inbound_connections' === $k) {
+ $n->BalanceInboundConnections = $v;
+ } elseif ('RateLimits' === $k || 'rate_limits' === $k) {
+ $n->RateLimits = null === $v ? null : RateLimits::jsonUnserialize($v);
+ } elseif ('EnvoyExtensions' === $k || 'envoy_extensions' === $k) {
+ foreach ($v as $ext) {
+ $n->EnvoyExtensions[] = EnvoyExtension::jsonUnserialize($ext);
+ }
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Protocol) {
+ $out->Protocol = $this->Protocol;
+ }
+ if (ProxyMode::Default !== $this->Mode) {
+ $out->Mode = $this->Mode->value;
+ }
+ if (null !== $this->TransparentProxy) {
+ $out->TransparentProxy = $this->TransparentProxy;
+ }
+ if (MutualTLSMode::Default !== $this->MutualTLSMode) {
+ $out->MutualTLSMode = $this->MutualTLSMode->value;
+ }
+ _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway);
+ _enc_obj_if_valued($out, 'Expose', $this->Expose);
+ if ('' !== $this->ExternalSNI) {
+ $out->ExternalSNI = $this->ExternalSNI;
+ }
+ if (null !== $this->UpstreamConfig) {
+ $out->UpstreamConfig = $this->UpstreamConfig;
+ }
+ if (null !== $this->Destination) {
+ $out->Destination = $this->Destination;
+ }
+ if (0 !== $this->MaxInboundConnections) {
+ $out->MaxInboundConnections = $this->MaxInboundConnections;
+ }
+ if (0 !== $this->LocalConnectTimeoutMs) {
+ $out->LocalConnectTimeoutMs = $this->LocalConnectTimeoutMs;
+ }
+ if (0 !== $this->LocalRequestTimeoutMs) {
+ $out->LocalRequestTimeoutMs = $this->LocalRequestTimeoutMs;
+ }
+ if ('' !== $this->BalanceInboundConnections) {
+ $out->BalanceInboundConnections = $this->BalanceInboundConnections;
+ }
+ if (null !== $this->RateLimits) {
+ $out->RateLimits = $this->RateLimits;
+ }
+ if ([] !== $this->EnvoyExtensions) {
+ $out->EnvoyExtensions = $this->EnvoyExtensions;
+ }
+ if ([] !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php
new file mode 100644
index 00000000..741086f4
--- /dev/null
+++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php
@@ -0,0 +1,176 @@
+ */
+ public array $Sources;
+ public null|IntentionJWTRequirement $JWT;
+
+ /**
+ * @param array $Sources
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ array $Sources = [],
+ null|IntentionJWTRequirement $JWT = null,
+ array $Meta = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->name = $name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->setSources(...$Sources);
+ $this->JWT = $JWT;
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->name;
+ }
+
+ public function setName(string $name): self
+ {
+ $this->name = $name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getSources(): array
+ {
+ return $this->Sources;
+ }
+
+ public function setSources(null|SourceIntention ...$Sources): self
+ {
+ $this->Sources = $Sources;
+ return $this;
+ }
+
+ public function getJWT(): null|IntentionJWTRequirement
+ {
+ return $this->JWT;
+ }
+
+ public function setJWT(null|IntentionJWTRequirement $JWT): self
+ {
+ $this->JWT = $JWT;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Sources' === $k) {
+ $n->Sources = [];
+ foreach ($v as $vv) {
+ $n->Sources[] = null === $vv ? null : SourceIntention::jsonUnserialize($vv);
+ }
+ } elseif ('JWT' === $k) {
+ $n->JWT = null === $v ? null : IntentionJWTRequirement::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ([] !== $this->Sources) {
+ $out->Sources = $this->Sources;
+ }
+ if (null !== $this->JWT) {
+ $out->JWT = $this->JWT;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php
index 7766fbd2..0d35b3e6 100644
--- a/src/ConfigEntry/ServiceResolverConfigEntry.php
+++ b/src/ConfigEntry/ServiceResolverConfigEntry.php
@@ -20,16 +20,303 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\Go\Time;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry
+class ServiceResolverConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- private const FIELD_DEFAULT_SUBSET = 'DefaultSubset';
- private const FIELD_SUBSETS = 'Subsets';
- private const FIELD_REDIRECT = 'Redirect';
- private const FIELD_FAILOVER = 'Failover';
- private const FIELD_CONNECT_TIMEOUT = 'ConnectTimeout';
- private const FIELD_LOAD_BALANCER = 'LoadBalancer';
+ public string $Kind;
+ public string $Name;
+ public string $Partition;
+ public string $DefaultSubset;
+ /** @var null|array */
+ public null|array $Subsets = null;
+ public null|ServiceResolverRedirect $Redirect;
+ /** @var null|array */
+ public null|array $Failover = null;
+ public Time\Duration $ConnectTimeout;
+ public Time\Duration $RequestTimeout;
+ public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality;
+ public null|LoadBalancer $LoadBalancer;
+
+ /**
+ * @param null|array $Subsets
+ * @param null|array $Failover
+ * @param null|array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ string $DefaultSubnet = '',
+ null|array $Subsets = null,
+ null|ServiceResolverRedirect $Redirect = null,
+ null|array $Failover = null,
+ null|string|int|float|\DateInterval|Time\Duration $ConnectTimeout = null,
+ null|string|int|float|\DateInterval|Time\Duration $RequestTimeout = null,
+ null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null,
+ null|LoadBalancer $LoadBalancer = null,
+ null|array $Meta = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->DefaultSubset = $DefaultSubnet;
+ $this->setSubsets($Subsets);
+ $this->Redirect = $Redirect;
+ $this->setFailover($Failover);
+ $this->ConnectTimeout = Time::Duration($ConnectTimeout);
+ $this->RequestTimeout = Time::Duration($RequestTimeout);
+ $this->PrioritizeByLocality = $PrioritizeByLocality;
+ $this->LoadBalancer = $LoadBalancer;
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getDefaultSubset(): string
+ {
+ return $this->DefaultSubset;
+ }
+
+ public function setDefaultSubset(string $DefaultSubset): self
+ {
+ $this->DefaultSubset = $DefaultSubset;
+ return $this;
+ }
+
+ /**
+ * @return null|array
+ */
+ public function getSubsets(): null|array
+ {
+ return $this->Subsets;
+ }
+
+ public function setSubsetKey(string $key, ServiceResolverSubset $subset): self
+ {
+ if (null === $this->Subsets) {
+ $this->Subsets = [];
+ }
+ $this->Subsets[$key] = $subset;
+ return $this;
+ }
+
+ /**
+ * @param null|array $Subsets
+ */
+ public function setSubsets(null|array $Subsets): self
+ {
+ $this->Subsets = null;
+ if (null === $Subsets) {
+ return $this;
+ }
+ foreach ($Subsets as $k => $v) {
+ $this->setSubsetKey($k, $v);
+ }
+ return $this;
+ }
+
+ public function getRedirect(): null|ServiceResolverRedirect
+ {
+ return $this->Redirect;
+ }
+
+ public function setRedirect(null|ServiceResolverRedirect $Redirect): self
+ {
+ $this->Redirect = $Redirect;
+ return $this;
+ }
+
+ /**
+ * @return null|array
+ */
+ public function getFailover(): null|array
+ {
+ return $this->Failover;
+ }
+
+ public function setFailoverKey(string $key, ServiceResolverFailover $failover): self
+ {
+ if (null === $this->Failover) {
+ $this->Failover = [];
+ }
+ $this->Failover[$key] = $failover;
+ return $this;
+ }
+
+ /**
+ * @param null|array $Failover
+ */
+ public function setFailover(null|array $Failover): self
+ {
+ $this->Failover = null;
+ if (null === $Failover) {
+ return $this;
+ }
+ foreach ($Failover as $k => $v) {
+ $this->setFailoverKey($k, $v);
+ }
+ return $this;
+ }
+
+ public function getConnectTimeout(): Time\Duration
+ {
+ return $this->ConnectTimeout;
+ }
+
+ public function setConnectTimeout(Time\Duration $ConnectTimeout): self
+ {
+ $this->ConnectTimeout = $ConnectTimeout;
+ return $this;
+ }
+
+ public function getRequestTimeout(): Time\Duration
+ {
+ return $this->RequestTimeout;
+ }
+
+ public function setRequestTimeout(Time\Duration $RequestTimeout): self
+ {
+ $this->RequestTimeout = $RequestTimeout;
+ return $this;
+ }
+
+ public function getPrioritizeByLocality(): null|ServiceResolverPrioritizeByLocality
+ {
+ return $this->PrioritizeByLocality;
+ }
+
+ public function setPrioritizeByLocality(null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality): self
+ {
+ $this->PrioritizeByLocality = $PrioritizeByLocality;
+ return $this;
+ }
+
+ public function getLoadBalancer(): null|LoadBalancer
+ {
+ return $this->LoadBalancer;
+ }
+
+ public function setLoadBalancer(null|LoadBalancer $LoadBalancer): self
+ {
+ $this->LoadBalancer = $LoadBalancer;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('default_subset' === $k) {
+ $n->DefaultSubset = $v;
+ } elseif ('Subsets' === $k) {
+ foreach ($v as $kk => $vv) {
+ $n->setSubsetKey($kk, ServiceResolverSubset::jsonUnserialize($vv));
+ }
+ } elseif ('Redirect' === $k) {
+ $n->Redirect = ServiceResolverRedirect::jsonUnserialize($v);
+ } elseif ('Failover' === $k) {
+ foreach ($v as $kk => $vv) {
+ $n->setFailoverKey($kk, ServiceResolverFailover::jsonUnserialize($vv));
+ }
+ } elseif ('ConnectTimeout' === $k || 'connect_timeout' === $k) {
+ $n->ConnectTimeout = Time::ParseDuration($v);
+ } elseif ('RequestTimeout' === $k || 'request_timeout' === $k) {
+ $n->RequestTimeout = Time::ParseDuration($v);
+ } elseif ('PrioritizeByLocality' === $k || 'prioritize_by_locality' === $k) {
+ $n->PrioritizeByLocality = ServiceResolverPrioritizeByLocality::jsonUnserialize($v);
+ } elseif ('LoadBalancer' === $k || 'load_balancer' === $k) {
+ $n->LoadBalancer = LoadBalancer::jsonUnserialize($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->DefaultSubset) {
+ $out->DefaultSubset = $this->DefaultSubset;
+ }
+ if (null !== $this->Subsets) {
+ $out->Subsets = $this->Subsets;
+ }
+ if (null !== $this->Redirect) {
+ $out->Redirect = $this->Redirect;
+ }
+ if (null !== $this->Failover) {
+ $out->Failover = $this->Failover;
+ }
+ if (0 !== $this->ConnectTimeout->Nanoseconds()) {
+ $out->ConnectTimeout = (string)$this->ConnectTimeout;
+ }
+ if (0 !== $this->RequestTimeout->Nanoseconds()) {
+ $out->RequestTimeout = (string)$this->RequestTimeout;
+ }
+ if (null !== $this->PrioritizeByLocality) {
+ $out->PrioritizeByLocality = $this->PrioritizeByLocality;
+ }
+ if (null !== $this->LoadBalancer) {
+ $out->LoadBalancer = $this->LoadBalancer;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php
index 54fad4ca..f8ba23c7 100644
--- a/src/ConfigEntry/ServiceResolverFailover.php
+++ b/src/ConfigEntry/ServiceResolverFailover.php
@@ -20,27 +20,41 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceResolverFailover extends AbstractModel
+class ServiceResolverFailover extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DATACENTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- ];
-
- private const FIELD_SERVICE = 'Service';
- private const FIELD_SERVICE_SUBSET = 'ServiceSubset';
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_DATACENTERS = 'Datacenters';
-
- public string $Service = '';
- public string $ServiceSubset = '';
- public string $Namespace = '';
- public array $Datacenters = [];
+ public string $Service;
+ public string $ServiceSubset;
+ public string $Namespace;
+ /** @var array */
+ public array $Datacenters;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceResolverFailoverTarget> */
+ public array $Targets;
+ public null|ServiceResolverFailoverPolicy $Policy;
+ public string $SamenessGroup;
+
+ /**
+ * @param array $Datacenters
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceResolverFailoverTarget> $Targets
+ */
+ public function __construct(
+ string $Service = '',
+ string $ServiceSubset = '',
+ string $Namespace = '',
+ array $Datacenters = [],
+ array $Targets = [],
+ null|ServiceResolverFailoverPolicy $Policy = null,
+ string $SamenessGroup = ''
+ ) {
+ $this->Service = $Service;
+ $this->ServiceSubset = $ServiceSubset;
+ $this->Namespace = $Namespace;
+ $this->setDatacenters(...$Datacenters);
+ $this->setTargets(...$Targets);
+ $this->Policy = $Policy;
+ $this->SamenessGroup = $SamenessGroup;
+ }
public function getService(): string
{
@@ -75,14 +89,100 @@ public function setNamespace(string $Namespace): self
return $this;
}
+ /**
+ * @return array
+ */
public function getDatacenters(): array
{
return $this->Datacenters;
}
- public function setDatacenters(array $Datacenters): self
+ public function setDatacenters(string ...$Datacenters): self
{
$this->Datacenters = $Datacenters;
return $this;
}
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceResolverFailoverTarget>
+ */
+ public function getTargets(): array
+ {
+ return $this->Targets;
+ }
+
+ public function setTargets(ServiceResolverFailoverTarget ...$Targets): self
+ {
+ $this->Targets = $Targets;
+ return $this;
+ }
+
+ public function getPolicy(): null|ServiceResolverFailoverPolicy
+ {
+ return $this->Policy;
+ }
+
+ public function setPolicy(null|ServiceResolverFailoverPolicy $Policy): self
+ {
+ $this->Policy = $Policy;
+ return $this;
+ }
+
+ public function getSamenessGroup(): string
+ {
+ return $this->SamenessGroup;
+ }
+
+ public function setSamenessGroup(string $SamenessGroup): self
+ {
+ $this->SamenessGroup = $SamenessGroup;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Targtes' === $k) {
+ $n->Targets = [];
+ foreach ($v as $vv) {
+ $n->Targets[] = ServiceResolverFailoverTarget::jsonUnserialize($vv);
+ }
+ } elseif ('service_subset' === $k) {
+ $n->ServiceSubset = $v;
+ } elseif ('sameness_group' === $k) {
+ $n->SamenessGroup = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Service) {
+ $out->Service = $this->Service;
+ }
+ if ('' !== $this->ServiceSubset) {
+ $out->ServiceSubset = $this->ServiceSubset;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ([] !== $this->Datacenters) {
+ $out->Datacenters = $this->Datacenters;
+ }
+ if ([] !== $this->Targets) {
+ $out->Targets = $this->Targets;
+ }
+ if (null !== $this->Policy) {
+ $out->Policy = $this->Policy;
+ }
+ if ('' !== $this->SamenessGroup) {
+ $out->SamenessGroup = $this->SamenessGroup;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceResolverFailoverPolicy.php b/src/ConfigEntry/ServiceResolverFailoverPolicy.php
new file mode 100644
index 00000000..f74e52fb
--- /dev/null
+++ b/src/ConfigEntry/ServiceResolverFailoverPolicy.php
@@ -0,0 +1,85 @@
+ */
+ public array $Regions;
+
+ /**
+ * @param array $Regions
+ */
+ public function __construct(string $Mode = '', array $Regions = [])
+ {
+ $this->Mode = $Mode;
+ $this->Regions = $Regions;
+ }
+
+ public function getMode(): string
+ {
+ return $this->Mode;
+ }
+
+ public function setMode(string $Mode): self
+ {
+ $this->Mode = $Mode;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getRegions(): array
+ {
+ return $this->Regions;
+ }
+
+ public function setRegions(string ...$Regions): self
+ {
+ $this->Regions = $Regions;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Mode) {
+ $out->Mode = $this->Mode;
+ }
+ if ([] !== $this->Regions) {
+ $out->Regions = $this->Regions;
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/ServiceResolverFailoverTarget.php b/src/ConfigEntry/ServiceResolverFailoverTarget.php
new file mode 100644
index 00000000..25c58710
--- /dev/null
+++ b/src/ConfigEntry/ServiceResolverFailoverTarget.php
@@ -0,0 +1,140 @@
+Service = $Service;
+ $this->ServiceSubset = $ServiceSubset;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->Datacenter = $Datacenter;
+ $this->Peer = $Peer;
+ }
+
+ public function getService(): string
+ {
+ return $this->Service;
+ }
+
+ public function setService(string $Service): self
+ {
+ $this->Service = $Service;
+ return $this;
+ }
+
+ public function getServiceSubset(): string
+ {
+ return $this->ServiceSubset;
+ }
+
+ public function setServiceSubset(string $ServiceSubset): self
+ {
+ $this->ServiceSubset = $ServiceSubset;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getDatacenter(): string
+ {
+ return $this->Datacenter;
+ }
+
+ public function setDatacenter(string $Datacenter): self
+ {
+ $this->Datacenter = $Datacenter;
+ return $this;
+ }
+
+ public function getPeer(): string
+ {
+ return $this->Peer;
+ }
+
+ public function setPeer(string $Peer): self
+ {
+ $this->Peer = $Peer;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('service_subset' === $k) {
+ $n->ServiceSubset = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Service = $this->Service;
+ $out->ServiceSubset = $this->ServiceSubset;
+ $out->Partition = $this->Partition;
+ $out->Namespace = $this->Namespace;
+ $out->Datacenter = $this->Datacenter;
+ $out->Peer = $this->Peer;
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php
new file mode 100644
index 00000000..b22a4bce
--- /dev/null
+++ b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php
@@ -0,0 +1,62 @@
+Mode = $Mode;
+ }
+
+ public function getMode(): string
+ {
+ return $this->Mode;
+ }
+
+ public function setMode(string $Mode): self
+ {
+ $this->Mode = $Mode;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Mode) {
+ $out->Mode = $this->Mode;
+ }
+ return $out;
+ }
+}
\ No newline at end of file
diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php
index a8410274..103f38e7 100644
--- a/src/ConfigEntry/ServiceResolverRedirect.php
+++ b/src/ConfigEntry/ServiceResolverRedirect.php
@@ -20,27 +20,35 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceResolverRedirect extends AbstractModel
+class ServiceResolverRedirect extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DATACENTER => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_SERVICE = 'Service';
- private const FIELD_SERVICE_SUBSET = 'ServiceSubset';
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_DATACENTER = 'Datacenter';
-
- public string $Service = '';
- public string $ServiceSubset = '';
- public string $Namespace = '';
- public string $Datacenter = '';
+ public string $Service;
+ public string $ServiceSubset;
+ public string $Namespace;
+ public string $Partition;
+ public string $Datacenter;
+ public string $Peer;
+ public string $SamenessGroup;
+
+ public function __construct(
+ string $Service = '',
+ string $ServiceSubset = '',
+ string $Namespace = '',
+ string $Partition = '',
+ string $Datacenter = '',
+ string $Peer = '',
+ string $SamenessGroup = ''
+ ) {
+ $this->Service = $Service;
+ $this->ServiceSubset = $ServiceSubset;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->Datacenter = $Datacenter;
+ $this->Peer = $Peer;
+ $this->SamenessGroup = $SamenessGroup;
+ }
public function getService(): string
{
@@ -75,6 +83,17 @@ public function setNamespace(string $Namespace): self
return $this;
}
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
public function getDatacenter(): string
{
return $this->Datacenter;
@@ -85,4 +104,68 @@ public function setDatacenter(string $Datacenter): self
$this->Datacenter = $Datacenter;
return $this;
}
+
+ public function getPeer(): string
+ {
+ return $this->Peer;
+ }
+
+ public function setPeer(string $Peer): self
+ {
+ $this->Peer = $Peer;
+ return $this;
+ }
+
+ public function getSamenessGroup(): string
+ {
+ return $this->SamenessGroup;
+ }
+
+ public function setSamenessGroup(string $SamenessGroup): self
+ {
+ $this->SamenessGroup = $SamenessGroup;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('service_subset' === $k) {
+ $n->ServiceSubset = $v;
+ } elseif ('sameness_group' === $k) {
+ $n->SamenessGroup = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Service) {
+ $out->Service = $this->Service;
+ }
+ if ('' !== $this->ServiceSubset) {
+ $out->service_subset = $this->ServiceSubset;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Datacenter) {
+ $out->Datacenter = $this->Datacenter;
+ }
+ if ('' !== $this->Peer) {
+ $out->Peer = $this->Peer;
+ }
+ if ('' !== $this->SamenessGroup) {
+ $out->sameness_group = $this->SamenessGroup;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceResolverSubset.php b/src/ConfigEntry/ServiceResolverSubset.php
index 7a1f8909..04347677 100644
--- a/src/ConfigEntry/ServiceResolverSubset.php
+++ b/src/ConfigEntry/ServiceResolverSubset.php
@@ -20,21 +20,18 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceResolverSubset extends AbstractModel
+class ServiceResolverSubset extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_FILTER => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_ONLY_PASSING => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- ];
+ public string $Filter;
+ public bool $OnlyPassing;
- private const FIELD_FILTER = 'Filter';
- private const FIELD_ONLY_PASSING = 'OnlyPassing';
-
- public string $Filter = '';
- public bool $OnlyPassing = false;
+ public function __construct(string $Filter = '', bool $OnlyPassing = false)
+ {
+ $this->Filter = $Filter;
+ $this->OnlyPassing = $OnlyPassing;
+ }
public function getFilter(): string
{
@@ -57,4 +54,29 @@ public function setOnlyPassing(bool $OnlyPassing): self
$this->OnlyPassing = $OnlyPassing;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('only_passing' === $k) {
+ $n->OnlyPassing = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Filter) {
+ $out->Filter = $this->Filter;
+ }
+ if ($this->OnlyPassing) {
+ $out->OnlyPassing = $this->OnlyPassing;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php
index c8c60400..f5df8c1d 100644
--- a/src/ConfigEntry/ServiceRoute.php
+++ b/src/ConfigEntry/ServiceRoute.php
@@ -20,12 +20,67 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRoute extends AbstractModel
+class ServiceRoute extends AbstractType
{
- protected const FIELDS = [];
+ public null|ServiceRouteMatch $Match;
+ public null|ServiceRouteDestination $Destination;
- private const FIELD_MATCH = 'Match';
- private const FIELD_DESTINATION = 'Destination';
+ public function __construct(
+ null|ServiceRouteMatch $Match = null,
+ null|ServiceRouteDestination $Destination = null,
+ ) {
+ $this->Match = $Match;
+ $this->Destination = $Destination;
+ }
+
+ public function getMatch(): null|ServiceRouteMatch
+ {
+ return $this->Match;
+ }
+
+ public function setMatch(null|ServiceRouteMatch $Match): self
+ {
+ $this->Match = $Match;
+ return $this;
+ }
+
+ public function getDestination(): null|ServiceRouteDestination
+ {
+ return $this->Destination;
+ }
+
+ public function setDestination(null|ServiceRouteDestination $Destination): self
+ {
+ $this->Destination = $Destination;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Match' === $k) {
+ $n->Match = null === $v ? null : ServiceRouteMatch::jsonUnserialize($v);
+ } elseif ('Destination' === $k) {
+ $n->Destination = null === $v ? null : ServiceRouteDestination::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (null !== $this->Match) {
+ $out->Match = $this->Match;
+ }
+ if (null !== $this->Destination) {
+ $out->Destination = $this->Destination;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php
index 22db2b68..f2d45a37 100644
--- a/src/ConfigEntry/ServiceRouteDestination.php
+++ b/src/ConfigEntry/ServiceRouteDestination.php
@@ -21,42 +21,59 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouteDestination extends AbstractModel
+class ServiceRouteDestination extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PREFIX_REWRITE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_REQUEST_TIMEOUT => Transcoding::DURATION_FIELD + [
- Transcoding::FIELD_UNMARSHAL_AS => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_NUM_RETRIES => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_RETRY_ON_CONNECT_FAILURE => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_RETRY_ON_STATUS_CODES => Transcoding::OMITEMPTY_INTEGER_ARRAY_FIELD,
- ];
-
- private const FIELD_SERVICE = 'Service';
- private const FIELD_SERVICE_SUBSET = 'ServiceSubset';
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_PREFIX_REWRITE = 'PrefixRewrite';
- private const FIELD_REQUEST_TIMEOUT = 'RequestTimeout';
- private const FIELD_NUM_RETRIES = 'NumRetries';
- private const FIELD_RETRY_ON_CONNECT_FAILURE = 'RetryOnConnectFailure';
- private const FIELD_RETRY_ON_STATUS_CODES = 'RetryOnStatusCodes';
-
- public string $Service = '';
- public string $ServiceSubset = '';
- public string $Namespace = '';
- public string $PrefixRewrite = '';
+ public string $Service;
+ public string $ServiceSubset;
+ public string $Namespace;
+ public string $Partition;
+ public string $PrefixRewrite;
public Time\Duration $RequestTimeout;
- public int $NumRetries = 0;
- public bool $RetryOnConnectFailure = false;
- public array $RetryOnStatusCodes = [];
+ public Time\Duration $IdleTimeout;
+ public int $NumRetries;
+ public bool $RetryOnConnectFailure;
+ /** @var array */
+ public array $RetryOnStatusCodes;
+ /** @var array */
+ public array $RetryOn;
+ public null|HTTPHeaderModifiers $RequestHeaders;
+ public null|HTTPHeaderModifiers $ResponseHeaders;
+
+ /**
+ * @param array $RetryOnStatusCodes
+ * @param array $RetryOn
+ */
+ public function __construct(
+ string $Service = '',
+ string $ServiceSubset = '',
+ string $Namespace = '',
+ string $Partition = '',
+ string $PrefixRewrite = '',
+ null|string|int|float|\DateInterval|Time\Duration $RequestTimeout = null,
+ null|string|int|float|\DateInterval|Time\Duration $IdleTimeout = null,
+ int $NumRetries = 0,
+ bool $RetryOnConnectFailure = false,
+ array $RetryOnStatusCodes = [],
+ array $RetryOn = [],
+ null|HTTPHeaderModifiers $RequestHeaders = null,
+ null|HTTPHeaderModifiers $ResponseHeaders = null,
+ ) {
+ $this->Service = $Service;
+ $this->ServiceSubset = $ServiceSubset;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->PrefixRewrite = $PrefixRewrite;
+ $this->RequestTimeout = Time::Duration($RequestTimeout);
+ $this->IdleTimeout = Time::Duration($IdleTimeout);
+ $this->NumRetries = $NumRetries;
+ $this->RetryOnConnectFailure = $RetryOnConnectFailure;
+ $this->setRetryOnStatusCodes(...$RetryOnStatusCodes);
+ $this->setRetryOn(...$RetryOn);
+ $this->RequestHeaders = $RequestHeaders;
+ $this->ResponseHeaders = $ResponseHeaders;
+ }
public function getService(): string
{
@@ -91,6 +108,17 @@ public function setNamespace(string $Namespace): self
return $this;
}
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
public function getPrefixRewrite(): string
{
return $this->PrefixRewrite;
@@ -107,9 +135,20 @@ public function getRequestTimeout(): Time\Duration
return $this->RequestTimeout;
}
- public function setRequestTimeout(Time\Duration $RequestTimeout): self
+ public function setRequestTimeout(null|string|int|float|\DateInterval|Time\Duration $RequestTimeout): self
+ {
+ $this->RequestTimeout = Time::Duration($RequestTimeout);
+ return $this;
+ }
+
+ public function getIdleTimeout(): Time\Duration
{
- $this->RequestTimeout = $RequestTimeout;
+ return $this->IdleTimeout;
+ }
+
+ public function setIdleTimeout(null|string|int|float|\DateInterval|Time\Duration $IdleTimeout): self
+ {
+ $this->IdleTimeout = Time::Duration($IdleTimeout);
return $this;
}
@@ -135,14 +174,129 @@ public function setRetryOnConnectFailure(bool $RetryOnConnectFailure): self
return $this;
}
+ /**
+ * @return array
+ */
public function getRetryOnStatusCodes(): array
{
return $this->RetryOnStatusCodes;
}
- public function setRetryOnStatusCodes(array $RetryOnStatusCodes): self
+ public function setRetryOnStatusCodes(int ...$RetryOnStatusCodes): self
{
$this->RetryOnStatusCodes = $RetryOnStatusCodes;
return $this;
}
+
+ /**
+ * @return array
+ */
+ public function getRetryOn(): array
+ {
+ return $this->RetryOn;
+ }
+
+ public function setRetryOn(string ...$RetryOn): self
+ {
+ $this->RetryOn = $RetryOn;
+ return $this;
+ }
+
+ public function getRequestHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->RequestHeaders;
+ }
+
+ public function setRequestHeaders(null|HTTPHeaderModifiers $RequestHeaders): self
+ {
+ $this->RequestHeaders = $RequestHeaders;
+ return $this;
+ }
+
+ public function getResponseHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->ResponseHeaders;
+ }
+
+ public function setResponseHeaders(null|HTTPHeaderModifiers $ResponseHeaders): self
+ {
+ $this->ResponseHeaders = $ResponseHeaders;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('service_subset' === $k) {
+ $n->ServiceSubset = $v;
+ } elseif ('prefix_rewrite' === $k) {
+ $n->PrefixRewrite = $v;
+ } elseif ('RequestTimeout' === $k || 'request_timeout' === $k) {
+ $n->RequestTimeout = Time::Duration($v);
+ } elseif ('IdleTimeout' === $k || 'idle_timeout' === $k) {
+ $n->IdleTimeout = Time::Duration($v);
+ } elseif ('num_retries' === $k) {
+ $n->NumRetries = $v;
+ } elseif ('retry_on_connect_failure' === $k) {
+ $n->RetryOnConnectFailure = $v;
+ } elseif ('retry_on_status_codes' === $k) {
+ $n->RetryOnStatusCodes = $v;
+ } elseif ('retry_on' === $k) {
+ $n->RetryOn = $v;
+ } elseif ('RequestHeaders' === $k || 'request_headers' === $k) {
+ $n->RequestHeaders = null === $v ? null : HTTPHeaderModifiers::jsonUnserialize($v);
+ } elseif ('ResponseHeaders' === $k || 'response_headers' === $k) {
+ $n->ResponseHeaders = null === $v ? null : HTTPHeaderModifiers::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Service) {
+ $out->Service = $this->Service;
+ }
+ if ('' !== $this->ServiceSubset) {
+ $out->ServiceSubset = $this->ServiceSubset;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->PrefixRewrite) {
+ $out->PrefixRewrite = $this->PrefixRewrite;
+ }
+ if (0 !== $this->RequestTimeout->Nanoseconds()) {
+ $out->RequestTimeout = (string)$this->RequestTimeout;
+ }
+ if (0 !== $this->IdleTimeout->Nanoseconds()) {
+ $out->IdleTimeout = (string)$this->IdleTimeout;
+ }
+ if (0 !== $this->NumRetries) {
+ $out->NumRetries = $this->NumRetries;
+ }
+ if ($this->RetryOnConnectFailure) {
+ $out->RetryOnConnectFailure = $this->RetryOnConnectFailure;
+ }
+ if ([] !== $this->RetryOnStatusCodes) {
+ $out->RetryOnStatusCodes = $this->RetryOnStatusCodes;
+ }
+ if ([] !== $this->RetryOn) {
+ $out->RetryOn = $this->RetryOn;
+ }
+ if (null !== $this->RequestHeaders) {
+ $out->RequestHeaders = $this->RequestHeaders;
+ }
+ if (null !== $this->ResponseHeaders) {
+ $out->ResponseHeaders = $this->ResponseHeaders;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php
index 6e0e4211..105637e3 100644
--- a/src/ConfigEntry/ServiceRouteHTTPMatch.php
+++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php
@@ -20,43 +20,43 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouteHTTPMatch extends AbstractModel
+class ServiceRouteHTTPMatch extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_PATH_EXACT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PATH_PREFIX => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PATH_REGEX => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_HEADER => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => self::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_QUERY_PARAM => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => ServiceRouteHTTPMatchQueryParam::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_METHODS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- ];
-
- private const FIELD_PATH_EXACT = 'PathExact';
- private const FIELD_PATH_PREFIX = 'PathPrefix';
- private const FIELD_PATH_REGEX = 'PathRegex';
- private const FIELD_HEADER = 'Header';
- private const FIELD_QUERY_PARAM = 'QueryParam';
- private const FIELD_METHODS = 'Methods';
-
- public string $PathExact = '';
- public string $PathPrefix = '';
- public string $PathRegex = '';
- public array $Header = [];
- public array $QueryParam = [];
- public array $Methods = [];
+ public string $PathExact;
+ public string $PathPrefix;
+ public string $PathRegex;
+ public bool $CaseInsensitive;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchHeader> */
+ public array $Header;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchQueryParam> */
+ public array $QueryParam;
+ /** @var array */
+ public array $Methods;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchHeader> $Header
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchQueryParam> $QueryParam
+ * @param array $Methods
+ */
+ public function __construct(
+ string $PathExact = '',
+ string $PathPrefix = '',
+ string $PathRegex = '',
+ bool $CaseInsensitive = false,
+ array $Header = [],
+ array $QueryParam = [],
+ array $Methods = [],
+ ) {
+ $this->PathExact = $PathExact;
+ $this->PathPrefix = $PathPrefix;
+ $this->PathRegex = $PathRegex;
+ $this->CaseInsensitive = $CaseInsensitive;
+ $this->setHeader(...$Header);
+ $this->setQueryParam(...$QueryParam);
+ $this->setMethods(...$Methods);
+ }
public function getPathExact(): string
{
@@ -91,36 +91,101 @@ public function setPathRegex(string $PathRegex): self
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchHeader[]
+ */
public function getHeader(): array
{
return $this->Header;
}
- public function setHeader(array $Header): self
+ public function setHeader(ServiceRouteHTTPMatchHeader ...$Header): self
{
$this->Header = $Header;
return $this;
}
+ /**
+ * @return \DCarbone\PHPConsulAPI\ConfigEntry\ServiceRouteHTTPMatchQueryParam[]
+ */
public function getQueryParam(): array
{
return $this->QueryParam;
}
- public function setQueryParam(array $QueryParam): self
+ public function setQueryParam(ServiceRouteHTTPMatchQueryParam ...$QueryParam): self
{
$this->QueryParam = $QueryParam;
return $this;
}
+ /**
+ * @return string[]
+ */
public function getMethods(): array
{
return $this->Methods;
}
- public function setMethods(array $Methods): self
+ public function setMethods(string ...$Methods): self
{
$this->Methods = $Methods;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('path_exact' === $k) {
+ $n->PathExact = $v;
+ } elseif ('path_prefix' === $k) {
+ $n->PathPrefix = $v;
+ } elseif ('path_regex' === $k) {
+ $n->PathRegex = $v;
+ } elseif ('case_insensitive' === $k) {
+ $n->CaseInsensitive = $v;
+ } elseif ('Header' === $k) {
+ $n->Header = [];
+ foreach ($v as $vv) {
+ $n->Header[] = ServiceRouteHTTPMatchHeader::jsonUnserialize($vv);
+ }
+ } elseif ('QueryParam' === $k || 'query_param' === $k) {
+ $n->QueryParam = [];
+ foreach ($v as $vv) {
+ $n->QueryParam[] = ServiceRouteHTTPMatchQueryParam::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->PathExact) {
+ $out->PathExact = $this->PathExact;
+ }
+ if ('' !== $this->PathPrefix) {
+ $out->PathPrefix = $this->PathPrefix;
+ }
+ if ('' !== $this->PathRegex) {
+ $out->PathRegex = $this->PathRegex;
+ }
+ if ($this->CaseInsensitive) {
+ $out->CaseInsensitive = $this->CaseInsensitive;
+ }
+ if ([] !== $this->Header) {
+ $out->Header = $this->Header;
+ }
+ if ([] !== $this->QueryParam) {
+ $out->QueryParam = $this->QueryParam;
+ }
+ if ([] !== $this->Methods) {
+ $out->Methods = $this->Methods;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php
index b7181eea..1ae3c979 100644
--- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php
+++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php
@@ -20,34 +20,35 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouteHTTPMatchHeader extends AbstractModel
+class ServiceRouteHTTPMatchHeader extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PREFIX => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SUFFIX => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_REGEX => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_INVERT => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- ];
-
- private const FIELD_PRESENT = 'Present';
- private const FIELD_EXACT = 'Exact';
- private const FIELD_PREFIX = 'Prefix';
- private const FIELD_SUFFIX = 'Suffix';
- private const FIELD_REGEX = 'Regex';
- private const FIELD_INVERT = 'Invert';
-
- public string $Name = '';
- public bool $Present = false;
- public string $Exact = '';
- public string $Prefix = '';
- public string $Suffix = '';
- public string $Regex = '';
- public bool $Invert = false;
+ public string $Name;
+ public bool $Present;
+ public string $Exact;
+ public string $Prefix;
+ public string $Suffix;
+ public string $Regex;
+ public bool $Invert;
+
+ public function __construct(
+ string $Name = '',
+ bool $Present = false,
+ string $Exact = '',
+ string $Prefix = '',
+ string $Suffix = '',
+ string $Regex = '',
+ bool $Invert = false,
+ ) {
+ $this->Name = $Name;
+ $this->Present = $Present;
+ $this->Exact = $Exact;
+ $this->Prefix = $Prefix;
+ $this->Suffix = $Suffix;
+ $this->Regex = $Regex;
+ $this->Invert = $Invert;
+ }
public function getName(): string
{
@@ -115,14 +116,48 @@ public function setRegex(string $Regex): self
return $this;
}
- public function getInvert(): bool|string
+ public function getInvert(): bool
{
return $this->Invert;
}
- public function setInvert(bool|string $Invert): static
+ public function setInvert(bool $Invert): self
{
$this->Invert = $Invert;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ($this->Present) {
+ $out->Present = $this->Present;
+ }
+ if ('' !== $this->Exact) {
+ $out->Exact = $this->Exact;
+ }
+ if ('' !== $this->Prefix) {
+ $out->Prefix = $this->Prefix;
+ }
+ if ('' !== $this->Suffix) {
+ $out->Suffix = $this->Suffix;
+ }
+ if ('' !== $this->Regex) {
+ $out->Regex = $this->Regex;
+ }
+ if ($this->Invert) {
+ $out->Invert = $this->Invert;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php
index 0063f23b..f407f349 100644
--- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php
+++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php
@@ -20,25 +20,26 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouteHTTPMatchQueryParam extends AbstractModel
+class ServiceRouteHTTPMatchQueryParam extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_REGEX => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_PRESENT = 'Present';
- private const FIELD_EXACT = 'Exact';
- private const FIELD_REGEX = 'Regex';
-
- public string $Name = '';
- public bool $Present = false;
- public string $Exact = '';
- public string $Regex = '';
+ public string $Name;
+ public bool $Present;
+ public string $Exact;
+ public string $Regex;
+
+ public function __construct(
+ string $Name = '',
+ bool $Present = false,
+ string $Exact = '',
+ string $Regex = '',
+ ) {
+ $this->Name = $Name;
+ $this->Present = $Present;
+ $this->Exact = $Exact;
+ $this->Regex = $Regex;
+ }
public function getName(): string
{
@@ -83,4 +84,29 @@ public function setRegex(string $Regex): self
$this->Regex = $Regex;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ($this->Present) {
+ $out->Present = $this->Present;
+ }
+ if ('' !== $this->Exact) {
+ $out->Exact = $this->Exact;
+ }
+ if ('' !== $this->Regex) {
+ $out->Regex = $this->Regex;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php
index dfb7f5d6..c3d5877e 100644
--- a/src/ConfigEntry/ServiceRouteMatch.php
+++ b/src/ConfigEntry/ServiceRouteMatch.php
@@ -20,32 +20,47 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouteMatch extends AbstractModel
+class ServiceRouteMatch extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_HTTP => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ServiceRouteHTTPMatch::class,
- Transcoding::FIELD_NULLABLE => true,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public null|ServiceRouteHTTPMatch $HTTP = null;
- private const FIELD_HTTP = 'HTTP';
-
- public ?ServiceRouteHTTPMatch $HTTP = null;
+ public function __construct(null|ServiceRouteHTTPMatch $HTTP = null)
+ {
+ $this->HTTP = $HTTP;
+ }
- public function getHTTP(): ?ServiceRouteHTTPMatch
+ public function getHTTP(): null|ServiceRouteHTTPMatch
{
return $this->HTTP;
}
- public function setHTTP(?ServiceRouteHTTPMatch $HTTP): self
+ public function setHTTP(null|ServiceRouteHTTPMatch $HTTP): self
{
$this->HTTP = $HTTP;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('HTTP' === $k) {
+ $n->HTTP = ServiceRouteHTTPMatch::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (null !== $this->HTTP) {
+ $out->HTTP = $this->HTTP;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php
index 5ae2d93c..1afa0746 100644
--- a/src/ConfigEntry/ServiceRouterConfigEntry.php
+++ b/src/ConfigEntry/ServiceRouterConfigEntry.php
@@ -20,34 +20,126 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry
+class ServiceRouterConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [
- self::FIELD_ROUTES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ServiceRoute::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public string $Kind;
+ public string $Name;
+ public string $Partition;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRoute> */
+ public array $Routes;
- private const FIELD_ROUTES = 'Routes';
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRoute> $Routes
+ * @param null|array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ array $Routes = [],
+ null|array $Meta = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->setRoutes(...$Routes);
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
- public array $Routes = [];
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRoute>
+ */
public function getRoutes(): array
{
return $this->Routes;
}
- public function setRoutes(array $Routes): self
+ public function setRoutes(ServiceRoute ...$Routes): self
{
$this->Routes = $Routes;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Routes' === $k) {
+ $n->Routes = [];
+ foreach ($v as $vv) {
+ $n->Routes[] = ServiceRoute::jsonUnserialize($vv);
+ }
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ([] !== $this->Routes) {
+ $out->Routes = $this->Routes;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php
index 96319b07..df44a514 100644
--- a/src/ConfigEntry/ServiceSplit.php
+++ b/src/ConfigEntry/ServiceSplit.php
@@ -20,25 +20,35 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceSplit extends AbstractModel
+class ServiceSplit extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_SERVICE = 'Service';
- private const FIELD_SERVICE_SUBSET = 'ServiceSubset';
- private const FIELD_NAMESPACE = 'Namespace';
-
- public float $Weight = 0.0;
- public string $Service = '';
- public string $ServiceSubset = '';
- public string $Namespace = '';
+ public float $Weight;
+ public string $Service;
+ public string $ServiceSubset;
+ public string $Namespace;
+ public string $Partition;
+ public null|HTTPHeaderModifiers $RequestHeaders;
+ public null|HTTPHeaderModifiers $ResponseHeaders;
+
+ public function __construct(
+ float $Weight = 0.0,
+ string $Service = '',
+ string $ServiceSubset = '',
+ string $Namespace = '',
+ string $Partition = '',
+ null|HTTPHeaderModifiers $RequestHeaders = null,
+ null|HTTPHeaderModifiers $ResponseHeaders = null
+ ) {
+ $this->Weight = $Weight;
+ $this->Service = $Service;
+ $this->ServiceSubset = $ServiceSubset;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->RequestHeaders = $RequestHeaders;
+ $this->ResponseHeaders = $ResponseHeaders;
+ }
public function getWeight(): float
{
@@ -83,4 +93,79 @@ public function setNamespace(string $Namespace): self
$this->Namespace = $Namespace;
return $this;
}
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getRequestHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->RequestHeaders;
+ }
+
+ public function setRequestHeaders(null|HTTPHeaderModifiers $RequestHeaders): self
+ {
+ $this->RequestHeaders = $RequestHeaders;
+ return $this;
+ }
+
+ public function getResponseHeaders(): null|HTTPHeaderModifiers
+ {
+ return $this->ResponseHeaders;
+ }
+
+ public function setResponseHeaders(null|HTTPHeaderModifiers $ResponseHeaders): self
+ {
+ $this->ResponseHeaders = $ResponseHeaders;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('service_subset' === $k) {
+ $n->ServiceSubset = $v;
+ } elseif ('RequestHeaders' === $k || 'request_headers' === $k) {
+ $n->RequestHeaders = HTTPHeaderModifiers::jsonUnserialize($v);
+ } elseif ('ResponseHeaders' === $k || 'response_headers' === $k) {
+ $n->ResponseHeaders = HTTPHeaderModifiers::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Weight = $this->Weight;
+ if ('' !== $this->Service) {
+ $out->Service = $this->Service;
+ }
+ if ('' !== $this->ServiceSubset) {
+ $out->ServiceSubset = $this->ServiceSubset;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if (null !== $this->RequestHeaders) {
+ $out->RequestHeaders = $this->RequestHeaders;
+ }
+ if (null !== $this->ResponseHeaders) {
+ $out->ResponseHeaders = $this->ResponseHeaders;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php
index b821f2cb..f063f6f3 100644
--- a/src/ConfigEntry/ServiceSplitterConfigEntry.php
+++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php
@@ -20,34 +20,126 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry
+class ServiceSplitterConfigEntry extends AbstractType implements ConfigEntry
{
use ConfigEntryTrait;
- protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [
- self::FIELD_SPLITS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ServiceSplit::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
+ public string $Kind;
+ public string $Name;
+ public string $Partition;
+ /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceSplit> */
+ public array $Splits;
- private const FIELD_SPLITS = 'Splits';
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceSplit> $Splits
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ string $Partition = '',
+ string $Namespace = '',
+ array $Splits = [],
+ null|\stdClass|array $Meta = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->setSplits(...$Splits);
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
- public array $Splits = [];
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceSplit>
+ */
public function getSplits(): array
{
return $this->Splits;
}
- public function setSplits(array $Splits): self
+ public function setSplits(ServiceSplit ...$Splits): self
{
$this->Splits = $Splits;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Splits' === $k) {
+ $n->Splits = [];
+ foreach ($v as $vv) {
+ $n->Splits[] = ServiceSplit::jsonUnserialize($vv);
+ }
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ([] !== $this->Splits) {
+ $out->Splits = $this->Splits;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/SourceIntention.php b/src/ConfigEntry/SourceIntention.php
new file mode 100644
index 00000000..45a6a358
--- /dev/null
+++ b/src/ConfigEntry/SourceIntention.php
@@ -0,0 +1,308 @@
+ */
+ public array $Permissions;
+ public int $Precedence;
+ public IntentionSourceType $Type;
+ public string $Description;
+ public string $LegacyID;
+ public null|\stdClass $LegacyMeta;
+ public null|Time\Time $LegacyCreateTime;
+ public null|Time\Time $LegacyUpdateTime;
+
+ /**
+ * @param array $Permissions
+ */
+ public function __construct(
+ string $Name = '',
+ string $Peer = '',
+ string $Partition = '',
+ string $Namespace = '',
+ string $SamenessGroup = '',
+ string|IntentionAction $Action = IntentionAction::UNDEFINED,
+ array $Permissions = [],
+ int $Precedence = 0,
+ string|IntentionSourceType $Type = IntentionSourceType::UNDEFINED,
+ string $Description = '',
+ string $LegacyID = '',
+ null|\stdClass $LegacyMeta = null,
+ null|Time\Time $LegacyCreateTime = null,
+ null|Time\Time $LegacyUpdateTime = null,
+ ) {
+ $this->Name = $Name;
+ $this->Peer = $Peer;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->SamenessGroup = $SamenessGroup;
+ $this->Action = $Action instanceof IntentionAction ? $Action : IntentionAction::from($Action);
+ $this->setPermissions(...$Permissions);
+ $this->Precedence = $Precedence;
+ $this->Type = $Type instanceof IntentionSourceType ? $Type : IntentionSourceType::from($Type);
+ $this->Description = $Description;
+ $this->LegacyID = $LegacyID;
+ $this->LegacyMeta = $LegacyMeta;
+ $this->LegacyCreateTime = $LegacyCreateTime;
+ $this->LegacyUpdateTime = $LegacyUpdateTime;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPeer(): string
+ {
+ return $this->Peer;
+ }
+
+ public function setPeer(string $Peer): self
+ {
+ $this->Peer = $Peer;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getSamenessGroup(): string
+ {
+ return $this->SamenessGroup;
+ }
+
+ public function setSamenessGroup(string $SamenessGroup): self
+ {
+ $this->SamenessGroup = $SamenessGroup;
+ return $this;
+ }
+
+ public function getAction(): IntentionAction
+ {
+ return $this->Action;
+ }
+
+ public function setAction(IntentionAction $Action): self
+ {
+ $this->Action = $Action;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getPermissions(): array
+ {
+ return $this->Permissions;
+ }
+
+ public function setPermissions(null|IntentionPermission ...$Permissions): self
+ {
+ $this->Permissions = $Permissions;
+ return $this;
+ }
+
+ public function getPrecedence(): int
+ {
+ return $this->Precedence;
+ }
+
+ public function setPrecedence(int $Precedence): self
+ {
+ $this->Precedence = $Precedence;
+ return $this;
+ }
+
+ public function getType(): IntentionSourceType
+ {
+ return $this->Type;
+ }
+
+ public function setType(IntentionSourceType $Type): self
+ {
+ $this->Type = $Type;
+ return $this;
+ }
+
+ public function getDescription(): string
+ {
+ return $this->Description;
+ }
+
+ public function setDescription(string $Description): self
+ {
+ $this->Description = $Description;
+ return $this;
+ }
+
+ public function getLegacyID(): string
+ {
+ return $this->LegacyID;
+ }
+
+ public function setLegacyID(string $LegacyID): self
+ {
+ $this->LegacyID = $LegacyID;
+ return $this;
+ }
+
+ public function getLegacyMeta(): null|\stdClass
+ {
+ return $this->LegacyMeta;
+ }
+
+ public function setLegacyMeta(null|\stdClass $LegacyMeta): self
+ {
+ $this->LegacyMeta = $LegacyMeta;
+ return $this;
+ }
+
+ public function getLegacyCreateTime(): null|Time\Time
+ {
+ return $this->LegacyCreateTime;
+ }
+
+ public function setLegacyCreateTime(null|Time\Time $LegacyCreateTime): self
+ {
+ $this->LegacyCreateTime = $LegacyCreateTime;
+ return $this;
+ }
+
+ public function getLegacyUpdateTime(): null|Time\Time
+ {
+ return $this->LegacyUpdateTime;
+ }
+
+ public function setLegacyUpdateTime(null|Time\Time $LegacyUpdateTime): self
+ {
+ $this->LegacyUpdateTime = $LegacyUpdateTime;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('sameness_group' === $k) {
+ $n->SamenessGroup = $v;
+ } elseif ('Action' === $k) {
+ $n->Action = IntentionAction::from($v);
+ } elseif ('Permissions' === $k) {
+ $n->Permissions = [];
+ foreach ($v as $vv) {
+ $n->Permissions[] = null === $vv ? null : IntentionPermission::jsonUnserialize($vv);
+ }
+ } elseif ('Type' === $k) {
+ $n->Type = IntentionSourceType::from($v);
+ } elseif ('legacy_id' === $k) {
+ $n->LegacyID = $v;
+ } elseif ('legacy_meta' === $k) {
+ $n->LegacyMeta = $v;
+ } elseif ('legacy_create_time' === $k) {
+ $n->LegacyCreateTime = null === $v ? null : parse_time($v);
+ } elseif ('legacy_update_time' === $k) {
+ $n->LegacyUpdateTime = null === $v ? null : parse_time($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ if ('' !== $this->Peer) {
+ $out->Peer = $this->Peer;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->SamenessGroup) {
+ $out->SamenessGroup = $this->SamenessGroup;
+ }
+ if (IntentionAction::UNDEFINED !== $this->Action) {
+ $out->Action = $this->Action->value;
+ }
+ if ([] !== $this->Permissions) {
+ $out->Permissions = $this->Permissions;
+ }
+ $out->Precedence = $this->Precedence;
+ $out->Type = $this->Type;
+ if ('' !== $this->Description) {
+ $out->Description = $this->Description;
+ }
+ if ('' !== $this->LegacyID) {
+ $out->LegacyID = $this->LegacyID;
+ }
+ if (null !== $this->LegacyMeta) {
+ $out->LegacyMeta = $this->LegacyMeta;
+ }
+ if (null !== $this->LegacyCreateTime) {
+ $out->LegacyCreateTime = $this->LegacyCreateTime->format(DATE_RFC3339);
+ }
+ if (null !== $this->LegacyUpdateTime) {
+ $out->LegacyUpdateTime = $this->LegacyUpdateTime->format(DATE_RFC3339);
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php
new file mode 100644
index 00000000..b59f0afb
--- /dev/null
+++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php
@@ -0,0 +1,159 @@
+ */
+ public array $Services;
+ public string $Partition;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\LinkedService> $Services
+ * @param array $Meta
+ */
+ public function __construct(
+ string $Kind = '',
+ string $Name = '',
+ array $Services = [],
+ null|\stdClass|array $Meta = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ string $Partition = '',
+ string $Namespace = '',
+ ) {
+ $this->Kind = $Kind;
+ $this->Name = $Name;
+ $this->setServices(...$Services);
+ $this->setMeta($Meta);
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ }
+
+ public function getKind(): string
+ {
+ return $this->Kind;
+ }
+
+ public function setKind(string $Kind): self
+ {
+ $this->Kind = $Kind;
+ return $this;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\ConfigEntry\LinkedService>
+ */
+ public function getServices(): array
+ {
+ return $this->Services;
+ }
+
+ /**
+ * @param \DCarbone\PHPConsulAPI\ConfigEntry\LinkedService ...$Services
+ */
+ public function setServices(LinkedService ...$Services): self
+ {
+ $this->Services = $Services;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Services' === $k) {
+ $n->Services = [];
+ foreach ($v as $vv) {
+ $n->Services[] = LinkedService::jsonUnserialize($vv);
+ }
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Kind = $this->Kind;
+ $out->Name = $this->Name;
+ if ([] !== $this->Services) {
+ $out->Services = $this->Services;
+ }
+ if (null !== $this->Meta) {
+ $out->Meta = $this->Meta;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php
index 0f6d5b30..a25892d2 100644
--- a/src/ConfigEntry/TransparentProxyConfig.php
+++ b/src/ConfigEntry/TransparentProxyConfig.php
@@ -20,21 +20,20 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class TransparentProxyConfig extends AbstractModel
+class TransparentProxyConfig extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_OUTBOUND_LISTENER_PORT => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DIALED_DIRECTLY => Transcoding::OMITEMPTY_BOOLEAN_FIELD,
- ];
+ public int $OutboundListenerPort;
+ public bool $DialedDirectly;
- private const FIELD_OUTBOUND_LISTENER_PORT = 'OutboundListenerPort';
- private const FIELD_DIALED_DIRECTLY = 'DialedDirectly';
-
- public int $OutboundListenerPort = 0;
- public bool $DialedDirectly = false;
+ public function __construct(
+ int $OutboundListenerPort = 0,
+ bool $DialedDirectly = false
+ ) {
+ $this->OutboundListenerPort = $OutboundListenerPort;
+ $this->DialedDirectly = $DialedDirectly;
+}
public function getOutboundListenerPort(): int
{
@@ -57,4 +56,25 @@ public function setDialedDirectly(bool $DialedDirectly): self
$this->DialedDirectly = $DialedDirectly;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if (0 !== $this->OutboundListenerPort) {
+ $out->OutboundListenerPort = $this->OutboundListenerPort;
+ }
+ if ($this->DialedDirectly) {
+ $out->DialedDirectly = $this->DialedDirectly;
+ }
+ return $out;
+ }
}
diff --git a/src/ConfigEntry/TransparentProxyMeshConfig.php b/src/ConfigEntry/TransparentProxyMeshConfig.php
new file mode 100644
index 00000000..aea2d7d4
--- /dev/null
+++ b/src/ConfigEntry/TransparentProxyMeshConfig.php
@@ -0,0 +1,64 @@
+MeshDestinationsOnly = $MeshDestinationsOnly;
+ }
+
+ public function isMeshDestinationsOnly(): bool
+ {
+ return $this->MeshDestinationsOnly;
+ }
+
+ public function setMeshDestinationsOnly(bool $MeshDestinationsOnly): self
+ {
+ $this->MeshDestinationsOnly = $MeshDestinationsOnly;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('mesh_destinations_only' === $k) {
+ $n->MeshDestinationsOnly = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $o = new \stdClass();
+ $o->MeshDestinationsOnly = $this->MeshDestinationsOnly;
+ return $o;
+ }
+}
diff --git a/src/ConfigEntry/UpstreamConfig.php b/src/ConfigEntry/UpstreamConfig.php
new file mode 100644
index 00000000..ef846510
--- /dev/null
+++ b/src/ConfigEntry/UpstreamConfig.php
@@ -0,0 +1,264 @@
+Name = $Name;
+ $this->Partition = $Partition;
+ $this->Namespace = $Namespace;
+ $this->Peer = $Peer;
+ $this->EnvoyListenerJSON = $EnvoyListenerJSON;
+ $this->EnvoyClusterJSON = $EnvoyClusterJSON;
+ $this->Protocol = $Protocol;
+ $this->ConnectTimeoutMs = $ConnectTimeoutMs;
+ $this->Limits = $Limits;
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ $this->MeshGateway = $MeshGateway ?? new MeshGatewayConfig();
+ $this->BalanceOutboundConnections = $BalanceOutboundConnections;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getNamespace(): string
+ {
+ return $this->Namespace;
+ }
+
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getPeer(): string
+ {
+ return $this->Peer;
+ }
+
+ public function setPeer(string $Peer): self
+ {
+ $this->Peer = $Peer;
+ return $this;
+ }
+
+ public function getEnvoyListenerJSON(): string
+ {
+ return $this->EnvoyListenerJSON;
+ }
+
+ public function setEnvoyListenerJSON(string $EnvoyListenerJSON): self
+ {
+ $this->EnvoyListenerJSON = $EnvoyListenerJSON;
+ return $this;
+ }
+
+ public function getEnvoyClusterJSON(): string
+ {
+ return $this->EnvoyClusterJSON;
+ }
+
+ public function setEnvoyClusterJSON(string $EnvoyClusterJSON): self
+ {
+ $this->EnvoyClusterJSON = $EnvoyClusterJSON;
+ return $this;
+ }
+
+ public function getProtocol(): string
+ {
+ return $this->Protocol;
+ }
+
+ public function setProtocol(string $Protocol): self
+ {
+ $this->Protocol = $Protocol;
+ return $this;
+ }
+
+ public function getConnectTimeoutMs(): int
+ {
+ return $this->ConnectTimeoutMs;
+ }
+
+ public function setConnectTimeoutMs(int $ConnectTimeoutMs): self
+ {
+ $this->ConnectTimeoutMs = $ConnectTimeoutMs;
+ return $this;
+ }
+
+ public function getLimits(): null|UpstreamLimits
+ {
+ return $this->Limits;
+ }
+
+ public function setLimits(null|UpstreamLimits $Limits): self
+ {
+ $this->Limits = $Limits;
+ return $this;
+ }
+
+ public function getPassiveHealthCheck(): null|PassiveHealthCheck
+ {
+ return $this->PassiveHealthCheck;
+ }
+
+ public function setPassiveHealthCheck(null|PassiveHealthCheck $PassiveHealthCheck): self
+ {
+ $this->PassiveHealthCheck = $PassiveHealthCheck;
+ return $this;
+ }
+
+ public function getMeshGateway(): MeshGatewayConfig
+ {
+ return $this->MeshGateway;
+ }
+
+ public function setMeshGateway(MeshGatewayConfig $MeshGateway): self
+ {
+ $this->MeshGateway = $MeshGateway;
+ return $this;
+ }
+
+ public function getBalanceOutboundConnections(): string
+ {
+ return $this->BalanceOutboundConnections;
+ }
+
+ public function setBalanceOutboundConnections(string $BalanceOutboundConnections): self
+ {
+ $this->BalanceOutboundConnections = $BalanceOutboundConnections;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('envoy_listener_json' === $k) {
+ $n->EnvoyListenerJSON = $v;
+ } elseif ('connect_timeout_ms' === $k) {
+ $n->ConnectTimeoutMs = $v;
+ } elseif ('Limits' === $k) {
+ $n->Limits = null === $v ? null : UpstreamLimits::jsonUnserialize($v);
+ } elseif ('PassiveHealthCheck' === $k || 'passive_health_check' === $k) {
+ $n->PassiveHealthCheck = null === $v ? null : PassiveHealthCheck::jsonUnserialize($v);
+ } elseif ('MeshGateway' === $k) {
+ $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v);
+ } elseif ('balance_outbound_connections' === $k) {
+ $n->BalanceOutboundConnections = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ('' !== $this->Name) {
+ $out->Name = $this->Name;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Peer) {
+ $out->Peer = $this->Peer;
+ }
+ if ('' !== $this->EnvoyListenerJSON) {
+ $out->EnvoyListenerJSON = $this->EnvoyListenerJSON;
+ }
+ if ('' !== $this->EnvoyClusterJSON) {
+ $out->EnvoyClusterJSON = $this->EnvoyClusterJSON;
+ }
+ if ('' !== $this->Protocol) {
+ $out->Protocol = $this->Protocol;
+ }
+ if (0 !== $this->ConnectTimeoutMs) {
+ $out->ConnectTimeoutMs = $this->ConnectTimeoutMs;
+ }
+ if (null !== $this->Limits) {
+ $out->Limits = $this->Limits;
+ }
+ if (null !== $this->PassiveHealthCheck) {
+ $out->PassiveHealthCheck = $this->PassiveHealthCheck;
+ }
+ _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway);
+ if ('' !== $this->BalanceOutboundConnections) {
+ $out->BalanceOutboundConnections = $this->BalanceOutboundConnections;
+ }
+ return $out;
+ }
+}
diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php
index 7aa0b584..4564c3b8 100644
--- a/src/ConfigEntry/UpstreamConfiguration.php
+++ b/src/ConfigEntry/UpstreamConfiguration.php
@@ -20,154 +20,77 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class UpstreamConfiguration extends AbstractModel
+class UpstreamConfiguration extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_ENJOY_LISTENER_JSON => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_ENVOY_CLUSTER_JSON => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_CONNECT_TIMEOUT_MS => Transcoding::OMITEMPTY_INTEGER_FIELD,
- self::FIELD_LIMITS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => UpstreamLimits::class,
- Transcoding::FIELD_OMITEMPTY => true,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_PASSIVE_HEALTH_CHECK => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => PassiveHealthCheck::class,
- Transcoding::FIELD_OMITEMPTY => true,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_MESH_GATEWAY => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => MeshGatewayConfig::class,
- Transcoding::FIELD_OMITEMPTY => true,
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
+ /** @var array */
+ public array $Overrides;
+ public null|UpstreamConfig $Defaults;
- private const FIELD_NAME = 'Name';
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_ENJOY_LISTENER_JSON = 'EnvoyListenerJSON';
- private const FIELD_ENVOY_CLUSTER_JSON = 'EnvoyClusterJSON';
- private const FIELD_PROTOCOL = 'Protocol';
- private const FIELD_CONNECT_TIMEOUT_MS = 'ConnectTimeoutMs';
- private const FIELD_LIMITS = 'Limits';
- private const FIELD_PASSIVE_HEALTH_CHECK = 'PassiveHealthCheck';
- private const FIELD_MESH_GATEWAY = 'MeshGateway';
-
- public string $Name = '';
- public string $Namespace = '';
- public string $EnvoyListenerJSON = '';
- public string $EnvoyClusterJSON = '';
- public string $Protocol = '';
- public int $ConnectTimeoutMs = 0;
- public ?UpstreamLimits $UpstreamLimits = null;
- public ?PassiveHealthCheck $PassiveHealthCheck = null;
- public ?MeshGatewayConfig $MeshGateway = null;
-
- public function getName(): string
- {
- return $this->Name;
- }
-
- public function setName(string $Name): self
- {
- $this->Name = $Name;
- return $this;
- }
-
- public function getNamespace(): string
- {
- return $this->Namespace;
- }
-
- public function setNamespace(string $Namespace): self
- {
- $this->Namespace = $Namespace;
- return $this;
- }
-
- public function getEnvoyListenerJSON(): string
- {
- return $this->EnvoyListenerJSON;
- }
-
- public function setEnvoyListenerJSON(string $EnvoyListenerJSON): self
- {
- $this->EnvoyListenerJSON = $EnvoyListenerJSON;
- return $this;
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\UpstreamConfig> $Overrides
+ */
+ public function __construct(
+ array $Overrides = [],
+ null|UpstreamConfig $Defaults = null
+ ) {
+ $this->setOverrides(...$Overrides);
+ $this->Defaults = $Defaults;
}
- public function getEnvoyClusterJSON(): string
+ /**
+ * @return array
+ */
+ public function getOverrides(): array
{
- return $this->EnvoyClusterJSON;
+ return $this->Overrides;
}
- public function setEnvoyClusterJSON(string $EnvoyClusterJSON): self
+ public function setOverrides(null|UpstreamConfig ...$Overrides): self
{
- $this->EnvoyClusterJSON = $EnvoyClusterJSON;
+ $this->Overrides = $Overrides;
return $this;
}
- public function getProtocol(): string
+ public function getDefaults(): null|UpstreamConfig
{
- return $this->Protocol;
+ return $this->Defaults;
}
- public function setProtocol(string $Protocol): self
+ public function setDefaults(null|UpstreamConfig $Defaults): self
{
- $this->Protocol = $Protocol;
+ $this->Defaults = $Defaults;
return $this;
}
- public function getConnectTimeoutMs(): int
- {
- return $this->ConnectTimeoutMs;
- }
-
- public function setConnectTimeoutMs(int $ConnectTimeoutMs): self
- {
- $this->ConnectTimeoutMs = $ConnectTimeoutMs;
- return $this;
- }
-
- public function getUpstreamLimits(): ?UpstreamLimits
- {
- return $this->UpstreamLimits;
- }
-
- public function setUpstreamLimits(?UpstreamLimits $UpstreamLimits): self
- {
- $this->UpstreamLimits = $UpstreamLimits;
- return $this;
- }
-
- public function getPassiveHealthCheck(): ?PassiveHealthCheck
- {
- return $this->PassiveHealthCheck;
- }
-
- public function setPassiveHealthCheck(?PassiveHealthCheck $PassiveHealthCheck): self
- {
- $this->PassiveHealthCheck = $PassiveHealthCheck;
- return $this;
- }
-
- public function getMeshGateway(): ?MeshGatewayConfig
- {
- return $this->MeshGateway;
- }
-
- public function setMeshGateway(?MeshGatewayConfig $MeshGateway): self
- {
- $this->MeshGateway = $MeshGateway;
- return $this;
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Overrides' === $k) {
+ $n->Overrides = [];
+ foreach ($v as $vv) {
+ $n->Overrides[] = UpstreamConfig::jsonUnserialize($vv);
+ }
+ } elseif ('Defaults' === $k) {
+ $n->Defaults = null === $v ? null : UpstreamConfig::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ if ([] !== $this->Overrides) {
+ $out->Overrides = $this->Overrides;
+ }
+ if (null !== $this->Defaults) {
+ $out->Defaults = $this->Defaults;
+ }
+ return $out;
}
}
diff --git a/src/ConfigEntry/UpstreamLimits.php b/src/ConfigEntry/UpstreamLimits.php
index 10868d89..290dd042 100644
--- a/src/ConfigEntry/UpstreamLimits.php
+++ b/src/ConfigEntry/UpstreamLimits.php
@@ -20,61 +20,80 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class UpstreamLimits extends AbstractModel
+class UpstreamLimits extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_MAX_CONNECTIONS => [
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_MAX_PENDING_REQUESTS => [
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_MAX_CONCURRENT_REQUESTS => [
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
-
- private const FIELD_MAX_CONNECTIONS = 'MaxConnections';
- private const FIELD_MAX_PENDING_REQUESTS = 'MaxPendingRequests';
- private const FIELD_MAX_CONCURRENT_REQUESTS = 'MaxConcurrentRequests';
-
- public ?int $MaxConnections = null;
- public ?int $MaxPendingRequests = null;
- public ?int $MaxConcurrentRequests = null;
-
- public function getMaxConnections(): ?int
+ public null|int $MaxConnections;
+ public null|int $MaxPendingRequests;
+ public null|int $MaxConcurrentRequests;
+
+ public function __construct(
+ null|int $MaxConnections = null,
+ null|int $MaxPendingRequests = null,
+ null|int $MaxConcurrentRequests = null,
+ ) {
+ $this->MaxConnections = $MaxConnections;
+ $this->MaxPendingRequests = $MaxPendingRequests;
+ $this->MaxConcurrentRequests = $MaxConcurrentRequests;
+ }
+
+ public function getMaxConnections(): null|int
{
return $this->MaxConnections;
}
- public function setMaxConnections(?int $MaxConnections): self
+ public function setMaxConnections(null|int $MaxConnections): self
{
$this->MaxConnections = $MaxConnections;
return $this;
}
- public function getMaxPendingRequests(): ?int
+ public function getMaxPendingRequests(): null|int
{
return $this->MaxPendingRequests;
}
- public function setMaxPendingRequests(?int $MaxPendingRequests): self
+ public function setMaxPendingRequests(null|int $MaxPendingRequests): self
{
$this->MaxPendingRequests = $MaxPendingRequests;
return $this;
}
- public function getMaxConcurrentRequests(): ?int
+ public function getMaxConcurrentRequests(): null|int
{
return $this->MaxConcurrentRequests;
}
- public function setMaxConcurrentRequests(?int $MaxConcurrentRequests): self
+ public function setMaxConcurrentRequests(null|int $MaxConcurrentRequests): self
{
$this->MaxConcurrentRequests = $MaxConcurrentRequests;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('max_connections' === $k) {
+ $n->MaxConnections = $v;
+ } elseif ('max_pending_requests' === $k) {
+ $n->MaxPendingRequests = $v;
+ } elseif ('max_concurrent_requests' === $k) {
+ $n->MaxConcurrentRequests = $v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->MaxConnections = $this->MaxConnections;
+ $out->MaxPendingRequests = $this->MaxPendingRequests;
+ $out->MaxConcurrentRequests = $this->MaxConcurrentRequests;
+ return $out;
+ }
}
diff --git a/src/Consul.php b/src/Consul.php
index 3f0aa212..cb7959df 100644
--- a/src/Consul.php
+++ b/src/Consul.php
@@ -73,43 +73,6 @@ class Consul
public const SessionBehaviorRelease = 'release';
public const SessionBehaviorDelete = 'delete';
- public const ServiceKindTypical = '';
- public const ServiceKindConnectProxy = 'connect-proxy';
- public const ServiceKindMeshGateway = 'mesh-gateway';
- public const ServiceKindTerminatingGateway = 'terminating-gateway';
- public const ServiceKindIngressGateway = 'ingress-gateway';
-
- public const UpstreamDestTypeService = 'service';
- public const UpstreamDestTypePreparedQuery = 'prepared_query';
-
- public const AutopilotServerNone = 'none';
- public const AutopilotServerLeader = 'leader';
- public const AutopilotServerVoter = 'voter';
- public const AutopilotServerNonVoter = 'non-voter';
- public const AutopilotServerStaging = 'staging';
-
- public const AutopilotTypeVoter = 'voter';
- public const AutopilotTypeReadReplica = 'read-replica';
- public const AutopilotTypeZoneVoter = 'zone-voter';
- public const AutopilotTypeZoneExtraVoter = 'zone-extra-voter';
- public const AutopilotTypeZoneStandby = 'zone-standby';
-
- public const AutopilotUpgradeIdle = 'idle';
- public const AutopilotUpgradeAwaitNewVoters = 'await-new-voters';
- public const AutopilotUpgradePromoting = 'promoting';
- public const AutopilotUpgradeDemoting = 'demoting';
- public const AutopilotUpgradeLeaderTransfer = 'leader-transfer';
- public const AutopilotUpgradeAwaitNewServers = 'await-new-servers';
- public const AutopilotUpgradeAwaitServerRemoval = 'await-server-removal';
- public const AutopilotUpgradeDisabled = 'disabled';
-
- public const BindingRuleBindTypeService = 'service';
- public const BindingRuleBindTypeRole = 'role';
-
- public const MeshGatewayModeDefault = '';
- public const MeshGatewayModeNone = 'none';
- public const MeshGatewayModeLocal = 'local';
- public const MeshGatewayModeRemote = 'remote';
public const MemberTagKeyACLMode = 'acls';
public const MemberTagKeyRole = 'role';
@@ -123,14 +86,27 @@ class Consul
public const MemberTagKeyReadReplica = 'read_replica';
public const MemberTagValueReadReplica = '1';
- public const ACLModeDisabled = '0';
- public const ACLModeEnabled = '1';
- public const ACLModeLegacy = '2';
- public const ACLModeUnknown = '3';
-
- public const ProxyModeDefault = '';
- public const ProxyModeTransparent = 'transparent';
- public const ProxyModeDirect = 'direct';
+ // config_entry.go
+ public const ServiceDefaults = 'service-defaults';
+ public const ProxyDefaults = 'proxy-defaults';
+ public const ServiceRouter = 'service-router';
+ public const ServiceSplitter = 'service-splitter';
+ public const ServiceResolver = 'service-resolver';
+ public const IngressGateway = 'ingress-gateway';
+ public const TerminatingGateway = 'terminating-gateway';
+ public const ServiceIntentions = 'service-intentions';
+ public const MeshConfig = 'mesh';
+ public const ExportedServices = 'exported-services';
+ public const SamenessGroup = 'sameness-group';
+ public const RateLimitIPConfig = 'control-plane-request-limit';
+
+ public const ProxyConfigGlobal = 'global';
+ public const MeshConfigMesh = 'mesh';
+ public const APIGateway = "api-gateway";
+ public const TCPRoute = "tcp-route";
+ public const InlineCertificate = 'inline-certificate';
+ public const HTTPRoute = 'http-route';
+ public const JWTProvider = 'jwt-provider';
// "private" constants
@@ -154,7 +130,7 @@ class Consul
public SessionClient $Session;
public StatusClient $Status;
- public function __construct(?Config $config = null)
+ public function __construct(null|Config $config = null)
{
$config = Config::merge($config);
@@ -240,4 +216,20 @@ public function Status(): StatusClient
{
return $this->Status;
}
+
+ public static function MakeConfigEntry(string $kind, string $name): ConfigEntry\ConfigEntry
+ {
+ return match ($kind) {
+ Consul::ServiceDefaults => new ConfigEntry\ServiceConfigEntry(Kind: $kind, Name: $name),
+ Consul::ProxyDefaults => new ConfigEntry\ProxyConfigEntry(Kind: $kind, Name: $name),
+ Consul::ServiceRouter => new ConfigEntry\ServiceRouterConfigEntry(Kind: $kind, Name: $name),
+ Consul::ServiceSplitter => new ConfigEntry\ServiceSplitterConfigEntry(Kind: $kind, Name: $name),
+ Consul::ServiceResolver => new ConfigEntry\ServiceResolverConfigEntry(Kind: $kind, Name: $name),
+ Consul::IngressGateway => new ConfigEntry\IngressGatewayConfigEntry(Kind: $kind, Name: $name),
+ Consul::TerminatingGateway => new ConfigEntry\TerminatingGatewayConfigEntry(Kind: $kind, Name: $name),
+ Consul::ServiceIntentions => new ConfigEntry\ServiceIntentionsConfigEntry(Kind: $kind, name: $name),
+
+ default => throw new \InvalidArgumentException(sprintf('Unknown kind "%s"', $kind)),
+ };
+ }
}
diff --git a/src/Coordinate/Coordinate.php b/src/Coordinate/Coordinate.php
index 5ccb6a58..9d90253e 100644
--- a/src/Coordinate/Coordinate.php
+++ b/src/Coordinate/Coordinate.php
@@ -21,67 +21,95 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
/**
* Class Coordinate
*
* From github.com/hashicorp/serf/coordinate/coordinate.go
*/
-class Coordinate extends AbstractModel
+class Coordinate extends AbstractType
{
- public array $Vec = [];
- public float $Error = 0.0;
- public float $Adjustment = 0.0;
- public float $Height = 0.0;
-
- public function __construct($data = [])
- {
- if (\is_array($data)) {
- parent::__construct($data);
- } elseif ($data instanceof CoordinateConfig) {
- $this->Vec = array_fill(0, $data->Dimensionality, 0.0);
- $this->Error = $data->VivaldiErrorMax;
+ public const ZeroThreshold = 1.0e-6;
+ private const secondsToNanoseconds = 1.0e9;
+
+ /** @var array */
+ public array $Vec;
+ public float $Error;
+ public float $Adjustment;
+ public float $Height;
+
+ /**
+ * @param array $Vec
+ */
+ public function __construct(
+ null|CoordinateConfig $config = null,
+ array $Vec = [],
+ float $Error = 0.0,
+ float $Adjustment = 0.0,
+ float $Height = 0.0,
+ ) {
+ if (null !== $config) {
+ $this->Vec = array_fill(0, $config->Dimensionality, 0.0);
+ $this->Error = $config->VivaldiErrorMax;
$this->Adjustment = 0.0;
- $this->Height = $data->HeightMin;
+ $this->Height = $config->HeightMin;
} else {
- throw new \InvalidArgumentException(
- sprintf(
- '%s::__construct - Argument 1 must be array of values or instance of %s, %s seen',
- static::class,
- CoordinateConfig::class,
- \is_object($data) ? \get_class($data) : \gettype($data)
- )
- );
+ $this->setVec(...$Vec);
+ $this->Error = $Error;
+ $this->Adjustment = $Adjustment;
+ $this->Height = $Height;
}
}
+ /**
+ * @return float[]
+ */
public function getVec(): array
{
return $this->Vec;
}
+ public function setVec(float ...$Vec): self
+ {
+ $this->Vec = $Vec;
+ return $this;
+ }
+
public function getError(): float
{
return $this->Error;
}
+ public function setError(float $Error): self
+ {
+ $this->Error = $Error;
+ return $this;
+ }
+
public function getAdjustment(): float
{
return $this->Adjustment;
}
+ public function setAdjustment(float $Adjustment): self
+ {
+ $this->Adjustment = $Adjustment;
+ return $this;
+ }
+
public function getHeight(): float
{
return $this->Height;
}
- /**
- * todo: prevent php-cs-fixer from being dumb.
- *
- * @return \DCarbone\PHPConsulAPI\Coordinate\Coordinate
- */
- public function Clone(): Coordinate|static
+ public function setHeight(float $Height): self
+ {
+ $this->Height = $Height;
+ return $this;
+ }
+
+ public function Clone(): self
{
return clone $this;
}
@@ -89,16 +117,18 @@ public function Clone(): Coordinate|static
public function IsValid(): bool
{
foreach ($this->Vec as $vec) {
- if (!is_finite($vec)) {
+ if (!self::_componentIsValid($vec)) {
return false;
}
}
- return is_finite($this->Error) && is_finite($this->Adjustment) && is_finite($this->Height);
+ return self::_componentIsValid($this->Error) &&
+ self::_componentIsValid($this->Adjustment) &&
+ self::_componentIsValid($this->Height);
}
public function IsCompatibleWith(self $other): bool
{
- return \count($this->Vec) === \count($other->Vec);
+ return count($this->Vec) === count($other->Vec);
}
public function ApplyForce(CoordinateConfig $config, float $force, self $other): self
@@ -107,11 +137,11 @@ public function ApplyForce(CoordinateConfig $config, float $force, self $other):
throw new DimensionalityConflictException();
}
- $ret = clone $this;
- [$unit, $mag] = unitVectorAt($this->Vec, $other->Vec);
- $ret->Vec = add($ret->Vec, mul($unit, $force));
- if ($mag > ZeroThreshold) {
- $ret->Height = max(($ret->Height + $other->Height) * $force / $mag + $ret->Height, $config->HeightMin);
+ $ret = clone $this;
+ $va = self::_unitVectorAt($this->Vec, $other->Vec);
+ $ret->Vec = self::_add($ret->Vec, self::_mul($va->vec, $force));
+ if ($va->mag > self::ZeroThreshold) {
+ $ret->Height = max(($ret->Height + $other->Height) * $force / $va->mag + $ret->Height, $config->HeightMin);
}
return $ret;
@@ -119,22 +149,127 @@ public function ApplyForce(CoordinateConfig $config, float $force, self $other):
public function DistanceTo(self $other): Time\Duration
{
- static $secondsToNanoseconds = 1.0e9;
-
if (!$this->IsCompatibleWith($other)) {
throw new DimensionalityConflictException();
}
- $dist = $this->rawDistanceTo($other);
+ $dist = $this->rawDistanceTo($other);
$adjustedDist = $dist + $this->Adjustment + $other->Adjustment;
if ($adjustedDist > 0.0) {
$dist = $adjustedDist;
}
- return Time::Duration($dist * $secondsToNanoseconds);
+ return Time::Duration($dist * self::secondsToNanoseconds);
}
protected function rawDistanceTo(self $other): float
{
- return magnitude(diff($this->Vec, $other->Vec)) + $this->Height + $other->Height;
+ return self::_magnitude(self::_diff($this->Vec, $other->Vec)) + $this->Height + $other->Height;
+ }
+
+ private static function _componentIsValid(float $f): bool
+ {
+ return !is_nan($f) && is_finite($f);
+ }
+
+ /**
+ * @param array $vec1
+ * @param array $vec2
+ * @return array
+ */
+ public static function _add(array $vec1, array $vec2): array
+ {
+ $ret = [];
+ foreach ($vec1 as $k => $v) {
+ $ret[$k] = $v + $vec2[$k];
+ }
+ return $ret;
+ }
+
+ /**
+ * @param array $vec1
+ * @param array $vec2
+ * @return array
+ */
+ public static function _diff(array $vec1, array $vec2): array
+ {
+ $ret = [];
+ foreach ($vec1 as $k => $v) {
+ $ret[$k] = $v - $vec2[$k];
+ }
+ return $ret;
+ }
+
+ /**
+ * @param array $vec
+ * @return array
+ */
+ private static function _mul(array $vec, float $factor): array
+ {
+ $ret = [];
+ foreach ($vec as $k => $v) {
+ $ret[$k] = $v * $factor;
+ }
+ return $ret;
+ }
+
+ /**
+ * @param array $vec
+ * @return float
+ */
+ public static function _magnitude(array $vec): float
+ {
+ $sum = 0.0;
+ foreach ($vec as $k => $v) {
+ $sum += ($v * $v);
+ }
+ return sqrt($sum);
+ }
+
+ /**
+ * @param array $vec1
+ * @param array $vec2
+ */
+ public static function _unitVectorAt(array $vec1, array $vec2): CoordinateUnitVectorAt
+ {
+ $ret = self::_diff($vec1, $vec2);
+
+ if (($mag = self::_magnitude($ret)) && $mag > self::ZeroThreshold) {
+ return new CoordinateUnitVectorAt(vec: self::_mul($ret, 1.0 / $mag), mag: $mag);
+ }
+
+ foreach ($ret as $k => &$v) {
+ $v = lcg_value() - 0.5;
+ }
+
+ if (($mag = self::_magnitude($ret)) && $mag > self::ZeroThreshold) {
+ return new CoordinateUnitVectorAt(vec: self::_mul($ret, 1.0 / $mag), mag: 0.0);
+ }
+
+ $ret = array_fill(0, count($ret), 0.0);
+ $ret[0] = 1.0;
+ return new CoordinateUnitVectorAt(vec: $ret, mag: 0.0);
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Vec' === $k) {
+ $n->Vec = (array)$v;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Vec = $this->Vec;
+ $out->Error = $this->Error;
+ $out->Adjustment = $this->Adjustment;
+ $out->Height = $this->Height;
+ return $out;
}
}
diff --git a/src/Coordinate/CoordinateClient.php b/src/Coordinate/CoordinateClient.php
index 42aed10e..47ebf65d 100644
--- a/src/Coordinate/CoordinateClient.php
+++ b/src/Coordinate/CoordinateClient.php
@@ -20,11 +20,10 @@
limitations under the License.
*/
-use DCarbone\Go\HTTP;
-use DCarbone\PHPConsulAPI\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\WriteResponse;
use DCarbone\PHPConsulAPI\QueryOptions;
use DCarbone\PHPConsulAPI\WriteOptions;
-use DCarbone\PHPConsulAPI\WriteResponse;
class CoordinateClient extends AbstractClient
{
@@ -36,7 +35,7 @@ public function Datacenters(): CoordinateDatacentersResponse
return $ret;
}
- public function Nodes(?QueryOptions $opts = null): CoordinateEntriesResponse
+ public function Nodes(null|QueryOptions $opts = null): CoordinateEntriesResponse
{
$resp = $this->_requireOK($this->_doGet('v1/coordinate/nodes', $opts));
$ret = new CoordinateEntriesResponse();
@@ -44,12 +43,12 @@ public function Nodes(?QueryOptions $opts = null): CoordinateEntriesResponse
return $ret;
}
- public function Update(CoordinateEntry $coordinateEntry, ?WriteOptions $opts = null): WriteResponse
+ public function Update(CoordinateEntry $coordinateEntry, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executePut('v1/coordinate/update', $coordinateEntry, $opts);
}
- public function Node(string $node, ?QueryOptions $opts = null): CoordinateEntriesResponse
+ public function Node(string $node, null|QueryOptions $opts = null): CoordinateEntriesResponse
{
$resp = $this->_requireOK($this->_doGet(sprintf('v1/coordinate/node/%s', $node), $opts));
$ret = new CoordinateEntriesResponse();
diff --git a/src/Coordinate/CoordinateConfig.php b/src/Coordinate/CoordinateConfig.php
index 9ec4d450..d89949fd 100644
--- a/src/Coordinate/CoordinateConfig.php
+++ b/src/Coordinate/CoordinateConfig.php
@@ -20,9 +20,10 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\Metrics\Label;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CoordinateConfig extends AbstractModel
+class CoordinateConfig extends AbstractType
{
public const DefaultDimensionality = 8;
public const DefaultVivaldiErrorMax = 1.5;
@@ -33,29 +34,51 @@ class CoordinateConfig extends AbstractModel
public const DefaultLatencyFilterSize = 3;
public const DefaultGravityRho = 150.0;
- public int $Dimensionality = 0;
- public float $VivaldiErrorMax = 0.0;
- public float $VivaldiCE = 0.0;
- public float $VivaldiCC = 0.0;
- public int $AdjustmentWindowSize = 0;
- public float $HeightMin = 0.0;
- public int $LatencyFilterSize = 0;
- public float $GravityRho = 0.0;
-
+ public int $Dimensionality;
+ public float $VivaldiErrorMax;
+ public float $VivaldiCE;
+ public float $VivaldiCC;
+ public int $AdjustmentWindowSize;
+ public float $HeightMin;
+ public int $LatencyFilterSize;
+ public float $GravityRho;
+ /** @var array<\DCarbone\PHPConsulAPI\Metrics\Label> */
+ public array $MetricsLabels;
+
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\Metrics\Label> $MetricsLabels
+ */
+ public function __construct(
+ int $Dimensionality = self::DefaultDimensionality,
+ float $VivaldiErrorMax = self::DefaultVivaldiErrorMax,
+ float $VivaldiCE = self::DefaultVivaldiCE,
+ float $VivaldiCC = self::DefaultVivaldiCC,
+ int $AdjustmentWindowSize = self::DefaultAdjustmentWindowSize,
+ float $HeightMin = self::DefaultHeightMin,
+ int $LatencyFilterSize = self::DefaultLatencyFilterSize,
+ float $GravityRho = self::DefaultGravityRho,
+ array $MetricsLabels = [],
+ ) {
+ $this->Dimensionality = $Dimensionality;
+ $this->VivaldiErrorMax = $VivaldiErrorMax;
+ $this->VivaldiCE = $VivaldiCE;
+ $this->VivaldiCC = $VivaldiCC;
+ $this->AdjustmentWindowSize = $AdjustmentWindowSize;
+ $this->HeightMin = $HeightMin;
+ $this->LatencyFilterSize = $LatencyFilterSize;
+ $this->GravityRho = $GravityRho;
+ $this->setMetricsLabels(...$MetricsLabels);
+ }
+
+ /**
+ * Create a new CoordinateConfig with default values.
+ *
+ * @deprecated Just call new CoordinateConfig() instead.
+ * @return self
+ */
public static function Default(): self
{
- return new static(
- [
- 'Dimensionality' => static::DefaultDimensionality,
- 'VivaldiErrorMax' => static::DefaultVivaldiErrorMax,
- 'VivaldiCE' => static::DefaultVivaldiCE,
- 'VivaldiCC' => static::DefaultVivaldiCC,
- 'AdjustmentWindowSize' => static::DefaultAdjustmentWindowSize,
- 'HeightMin' => static::DefaultHeightMin,
- 'LatencyFilterSize' => static::DefaultLatencyFilterSize,
- 'GravityRho' => static::DefaultGravityRho,
- ]
- );
+ return new self();
}
public function getDimensionality(): int
@@ -63,9 +86,9 @@ public function getDimensionality(): int
return $this->Dimensionality;
}
- public function setDimensionality(int $dimensionality): self
+ public function setDimensionality(int $Dimensionality): self
{
- $this->Dimensionality = $dimensionality;
+ $this->Dimensionality = $Dimensionality;
return $this;
}
@@ -74,9 +97,9 @@ public function getVivaldiErrorMax(): float
return $this->VivaldiErrorMax;
}
- public function setVivaldiErrorMax(float $vivaldiErrorMax): self
+ public function setVivaldiErrorMax(float $VivaldiErrorMax): self
{
- $this->VivaldiErrorMax = $vivaldiErrorMax;
+ $this->VivaldiErrorMax = $VivaldiErrorMax;
return $this;
}
@@ -85,9 +108,9 @@ public function getVivaldiCE(): float
return $this->VivaldiCE;
}
- public function setVivaldiCE(float $vivaldiCE): self
+ public function setVivaldiCE(float $VivaldiCE): self
{
- $this->VivaldiCE = $vivaldiCE;
+ $this->VivaldiCE = $VivaldiCE;
return $this;
}
@@ -96,9 +119,9 @@ public function getVivaldiCC(): float
return $this->VivaldiCC;
}
- public function setVivaldiCC(float $vivaldiCC): self
+ public function setVivaldiCC(float $VivaldiCC): self
{
- $this->VivaldiCC = $vivaldiCC;
+ $this->VivaldiCC = $VivaldiCC;
return $this;
}
@@ -107,9 +130,9 @@ public function getAdjustmentWindowSize(): int
return $this->AdjustmentWindowSize;
}
- public function setAdjustmentWindowSize(int $adjustmentWindowSize): self
+ public function setAdjustmentWindowSize(int $AdjustmentWindowSize): self
{
- $this->AdjustmentWindowSize = $adjustmentWindowSize;
+ $this->AdjustmentWindowSize = $AdjustmentWindowSize;
return $this;
}
@@ -118,9 +141,9 @@ public function getHeightMin(): float
return $this->HeightMin;
}
- public function setHeightMin(float $heightMin): self
+ public function setHeightMin(float $HeightMin): self
{
- $this->HeightMin = $heightMin;
+ $this->HeightMin = $HeightMin;
return $this;
}
@@ -129,9 +152,9 @@ public function getLatencyFilterSize(): int
return $this->LatencyFilterSize;
}
- public function setLatencyFilterSize(int $latencyFilterSize): self
+ public function setLatencyFilterSize(int $LatencyFilterSize): self
{
- $this->LatencyFilterSize = $latencyFilterSize;
+ $this->LatencyFilterSize = $LatencyFilterSize;
return $this;
}
@@ -140,9 +163,54 @@ public function getGravityRho(): float
return $this->GravityRho;
}
- public function setGravityRho(float $gravityRho): self
+ public function setGravityRho(float $GravityRho): self
+ {
+ $this->GravityRho = $GravityRho;
+ return $this;
+ }
+
+ /**
+ * @return array<\DCarbone\PHPConsulAPI\Metrics\Label>
+ */
+ public function getMetricsLabels(): array
{
- $this->GravityRho = $gravityRho;
+ return $this->MetricsLabels;
+ }
+
+ public function setMetricsLabels(Label ...$MetricsLabels): self
+ {
+ $this->MetricsLabels = $MetricsLabels;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('MetricsLabels' === $k) {
+ $n->MetricsLabels = [];
+ foreach ($v as $vv) {
+ $n->MetricsLabels[] = Label::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Dimensionality = $this->Dimensionality;
+ $out->VivaldiErrorMax = $this->VivaldiErrorMax;
+ $out->VivaldiCE = $this->VivaldiCE;
+ $out->VivaldiCC = $this->VivaldiCC;
+ $out->AdjustmentWindowSize = $this->AdjustmentWindowSize;
+ $out->HeightMin = $this->HeightMin;
+ $out->LatencyFilterSize = $this->LatencyFilterSize;
+ $out->GravityRho = $this->GravityRho;
+ $out->MetricsLabels = $this->MetricsLabels;
+ return $out;
+ }
}
diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php
index 6cf83530..d8cf52ee 100644
--- a/src/Coordinate/CoordinateDatacenterMap.php
+++ b/src/Coordinate/CoordinateDatacenterMap.php
@@ -20,37 +20,86 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CoordinateDatacenterMap extends AbstractModel
+class CoordinateDatacenterMap extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_COORDINATES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => Coordinate::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- ];
+ public string $Datacenter;
+ public string $AreaID;
+ /** @var array<\DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry> */
+ public array $Coordinates;
- private const FIELD_COORDINATES = 'Coordinates';
-
- public string $Datacenter = '';
- public string $AreaID = '';
- public array $Coordinates = [];
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry> $Coordinates
+ */
+ public function __construct(
+ string $Datacenter = '',
+ string $AreaID = '',
+ array $Coordinates = [],
+ ) {
+ $this->Datacenter = $Datacenter;
+ $this->AreaID = $AreaID;
+ $this->setCoordinates(...$Coordinates);
+ }
public function getDatacenter(): string
{
return $this->Datacenter;
}
+ public function setDatacenter(string $Datacenter): self
+ {
+ $this->Datacenter = $Datacenter;
+ return $this;
+ }
+
public function getAreaID(): string
{
return $this->AreaID;
}
+ public function setAreaID(string $AreaID): self
+ {
+ $this->AreaID = $AreaID;
+ return $this;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry[]
+ */
public function getCoordinates(): array
{
return $this->Coordinates;
}
+
+ public function setCoordinates(CoordinateEntry ...$Coordinates): self
+ {
+ $this->Coordinates = $Coordinates;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Coordinates' === $k) {
+ $n->Coordinates = [];
+ foreach ($v as $vv) {
+ $n->Coordinates[] = CoordinateEntry::jsonUnserialize($vv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Datacenter = $this->Datacenter;
+ $out->AreaID = $this->AreaID;
+ $out->Coordinates = $this->Coordinates;
+ return $out;
+ }
}
diff --git a/src/Coordinate/CoordinateDatacentersResponse.php b/src/Coordinate/CoordinateDatacentersResponse.php
index 7953d3b4..6ee8c599 100644
--- a/src/Coordinate/CoordinateDatacentersResponse.php
+++ b/src/Coordinate/CoordinateDatacentersResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class CoordinateDatacentersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?array $DatacenterMap = null;
+ /** @var \DCarbone\PHPConsulAPI\Coordinate\CoordinateDatacenterMap[] */
+ public array $DatacenterMap = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Coordinate\CoordinateDatacenterMap[]
+ */
+ public function getValue(): array
{
return $this->DatacenterMap;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->DatacenterMap = [];
- foreach ($decodedData as $item) {
- $this->DatacenterMap[] = new CoordinateDatacenterMap($item);
+ foreach ($decoded as $item) {
+ $this->DatacenterMap[] = CoordinateDatacenterMap::jsonUnserialize($item);
}
}
}
diff --git a/src/Coordinate/CoordinateEntriesResponse.php b/src/Coordinate/CoordinateEntriesResponse.php
index af95e426..863b44f9 100644
--- a/src/Coordinate/CoordinateEntriesResponse.php
+++ b/src/Coordinate/CoordinateEntriesResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class CoordinateEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $Nodes = null;
+ /** @var \DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry[] */
+ public array $Nodes = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry[]
+ */
+ public function getValue(): array
{
return $this->Nodes;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->Nodes = [];
- foreach ($decodedData as $node) {
- $this->Nodes[] = new CoordinateEntry($node);
+ foreach ($decoded as $node) {
+ $this->Nodes[] = CoordinateEntry::jsonUnserialize($node);
}
}
}
diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php
index d6503694..7cbba1a6 100644
--- a/src/Coordinate/CoordinateEntry.php
+++ b/src/Coordinate/CoordinateEntry.php
@@ -20,24 +20,26 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class CoordinateEntry extends AbstractModel
+class CoordinateEntry extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_COORDINATE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Coordinate::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
-
- private const FIELD_COORDINATE = 'Coord';
-
- public string $Node = '';
- public string $Segment = '';
- public ?Coordinate $Coord = null;
+ public string $Node;
+ public string $Segment;
+ public string $Partition;
+ public null|Coordinate $Coord;
+
+ public function __construct(
+ string $Node = '',
+ string $Segment = '',
+ string $Partition = '',
+ null|Coordinate $Coord = null,
+ ) {
+ $this->Node = $Node;
+ $this->Segment = $Segment;
+ $this->Partition = $Partition;
+ $this->Coord = $Coord;
+ }
public function getNode(): string
{
@@ -61,14 +63,50 @@ public function setSegment(string $Segment): self
return $this;
}
- public function getCoord(): ?Coordinate
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getCoord(): null|Coordinate
{
return $this->Coord;
}
- public function setCoord(?Coordinate $Coord): self
+ public function setCoord(null|Coordinate $Coord): self
{
$this->Coord = $Coord;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Coord' === $k) {
+ $n->Coord = Coordinate::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ $out->Segment = $this->Segment;
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ $out->Coord = $this->Coord;
+ return $out;
+ }
}
diff --git a/src/Coordinate/CoordinateUnitVectorAt.php b/src/Coordinate/CoordinateUnitVectorAt.php
new file mode 100644
index 00000000..7e9bb395
--- /dev/null
+++ b/src/Coordinate/CoordinateUnitVectorAt.php
@@ -0,0 +1,67 @@
+|float>
+ */
+final class CoordinateUnitVectorAt implements \ArrayAccess
+{
+ /** @var array */
+ public array $vec;
+ public float $mag;
+
+ /**
+ * @param array $vec
+ */
+ public function __construct(array $vec, float $mag)
+ {
+ $this->vec = $vec;
+ $this->mag = $mag;
+ }
+
+ public function offsetExists(mixed $offset): bool
+ {
+ return 0 === $offset || 1 === $offset;
+ }
+
+ /**
+ * @return array|float
+ */
+ public function offsetGet(mixed $offset): array|float
+ {
+ return match ($offset) {
+ 0 => $this->vec,
+ 1 => $this->mag,
+ default => throw new \OutOfBoundsException("Invalid offset: $offset"),
+ };
+ }
+
+ public function offsetSet(mixed $offset, mixed $value): void
+ {
+ throw new \BadMethodCallException('CoordinateUnitVectorAt cannot be mutated as if it were an array.');
+ }
+
+ public function offsetUnset(mixed $offset): void
+ {
+ throw new \BadMethodCallException('CoordinateUnitVectorAt cannot be mutated as if it were an array.');
+ }
+}
diff --git a/src/Coordinate/funcs.php b/src/Coordinate/funcs.php
deleted file mode 100644
index 88d0eadd..00000000
--- a/src/Coordinate/funcs.php
+++ /dev/null
@@ -1,100 +0,0 @@
- ZeroThreshold) {
- return [mul($ret, 1.0 / $mag), $mag];
- }
-
- foreach ($ret as $k => &$v) {
- $v = lcg_value() - 0.5;
- }
-
- if (($mag = magnitude($ret)) && $mag > ZeroThreshold) {
- return [mul($ret, 1.0 / $mag), 0.0];
- }
-
- $ret = array_fill(0, \count($ret), 0.0);
- $ret[0] = 1.0;
- return $ret;
-}
-
-/**
- * @param array $vec1
- * @param array $vec2
- * @return array
- */
-function add(array $vec1, array $vec2): array
-{
- $ret = [];
- foreach ($vec1 as $k => $v) {
- $ret[$k] = $v + $vec2[$k];
- }
- return $ret;
-}
-
-/**
- * @param array $vec1
- * @param array $vec2
- * @return array
- */
-function diff(array $vec1, array $vec2): array
-{
- $ret = [];
- foreach ($vec1 as $k => $v) {
- $ret[$k] = $v - $vec2[$k];
- }
- return $ret;
-}
-
-function mul(array $vec, float $factor): array
-{
- $ret = [];
- foreach ($vec as $k => $v) {
- $ret[$k] = $v * $factor;
- }
- return $ret;
-}
-
-function magnitude(array $vec): float
-{
- $sum = 0.0;
- foreach ($vec as $k => $v) {
- $sum += ($v * $v);
- }
- return sqrt($sum);
-}
diff --git a/src/Debug/DebugClient.php b/src/Debug/DebugClient.php
index a96f89aa..0ee42b07 100644
--- a/src/Debug/DebugClient.php
+++ b/src/Debug/DebugClient.php
@@ -21,9 +21,9 @@
*/
use DCarbone\Go\HTTP;
-use DCarbone\PHPConsulAPI\AbstractClient;
-use DCarbone\PHPConsulAPI\Error;
-use DCarbone\PHPConsulAPI\ValuedStringResponse;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedStringResponse;
class DebugClient extends AbstractClient
{
diff --git a/src/Event/EventClient.php b/src/Event/EventClient.php
index aa76bed0..07a51a3a 100644
--- a/src/Event/EventClient.php
+++ b/src/Event/EventClient.php
@@ -20,13 +20,13 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
use DCarbone\PHPConsulAPI\QueryOptions;
use DCarbone\PHPConsulAPI\WriteOptions;
class EventClient extends AbstractClient
{
- public function Fire(UserEvent $event, ?WriteOptions $opts = null): UserEventResponse
+ public function Fire(UserEvent $event, null|WriteOptions $opts = null): UserEventResponse
{
$r = $this->_newPutRequest(sprintf('v1/event/fire/%s', $event->Name), '' !== $event->Payload ? $event->Payload : null, $opts);
if ('' !== ($nf = $event->NodeFilter)) {
@@ -44,7 +44,7 @@ public function Fire(UserEvent $event, ?WriteOptions $opts = null): UserEventRes
return $ret;
}
- public function List(string $name = '', ?QueryOptions $opts = null): UserEventsResponse
+ public function List(string $name = '', null|QueryOptions $opts = null): UserEventsResponse
{
$r = $this->_newGetRequest('v1/event/list', $opts);
if ('' !== $name) {
@@ -58,17 +58,17 @@ public function List(string $name = '', ?QueryOptions $opts = null): UserEventsR
public function IDToIndex(string $uuid): int
{
- if (36 !== \strlen($uuid)) {
+ if (36 !== strlen($uuid)) {
throw new \InvalidArgumentException("{$uuid} is not a valid UUID");
}
- $lower = substr($uuid, 0, 8) + substr($uuid, 9, 4) + substr($uuid, 14, 4);
- $upper = substr($uuid, 19, 4) + substr($uuid, 24, 12);
- $lowVal = \intval($lower, 10);
+ $lower = sprintf('%s%s%s', substr($uuid, 0, 8), substr($uuid, 9, 4), substr($uuid, 14, 4));
+ $upper = sprintf('%s%s', substr($uuid, 19, 4), substr($uuid, 24, 12));
+ $lowVal = intval($lower, 10);
if (0 >= $lowVal) {
throw new \InvalidArgumentException("{$lower} is not greater than 0");
}
- $highVal = \intval($upper, 10);
+ $highVal = intval($upper, 10);
if (0 >= $highVal) {
throw new \InvalidArgumentException("{$upper} is not greater than 0");
}
diff --git a/src/Event/UserEvent.php b/src/Event/UserEvent.php
index ae640733..50fbf991 100644
--- a/src/Event/UserEvent.php
+++ b/src/Event/UserEvent.php
@@ -20,35 +20,37 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class UserEvent extends AbstractModel
+class UserEvent extends AbstractType
{
- public string $ID = '';
- public string $Name = '';
- public string $Payload = '';
- public string $NodeFilter = '';
- public string $ServiceFilter = '';
- public string $TagFilter = '';
- public int $Version = 0;
- public int $LTime = 0;
-
- /**
- * UserEvent constructor.
- *
- * @param array $data
- * @param bool $_decodeValue
- */
- public function __construct(array $data = [], bool $_decodeValue = false)
- {
- parent::__construct($data);
- if ($_decodeValue) {
- $dec = base64_decode($this->Payload, true);
- if (false === $dec) {
- throw new \InvalidArgumentException(sprintf('Could not base64 decode payload "%s"', $this->Payload));
- }
- $this->Payload = $dec;
- }
+ public string $ID;
+ public string $Name;
+ public string $Payload;
+ public string $NodeFilter;
+ public string $ServiceFilter;
+ public string $TagFilter;
+ public int $Version;
+ public int $LTime;
+
+ public function __construct(
+ string $ID = '',
+ string $Name = '',
+ string $Payload = '',
+ string $NodeFilter = '',
+ string $ServiceFilter = '',
+ string $TagFilter = '',
+ int $Version = 0,
+ int $LTime = 0,
+ ) {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Payload = $Payload;
+ $this->NodeFilter = $NodeFilter;
+ $this->ServiceFilter = $ServiceFilter;
+ $this->TagFilter = $TagFilter;
+ $this->Version = $Version;
+ $this->LTime = $LTime;
}
public function getID(): string
@@ -56,38 +58,109 @@ public function getID(): string
return $this->ID;
}
+ public function setID(string $ID): self
+ {
+ $this->ID = $ID;
+ return $this;
+ }
+
public function getName(): string
{
return $this->Name;
}
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
public function getPayload(): string
{
return $this->Payload;
}
+ public function setPayload(string $Payload): self
+ {
+ $this->Payload = $Payload;
+ return $this;
+ }
+
public function getNodeFilter(): string
{
return $this->NodeFilter;
}
+ public function setNodeFilter(string $NodeFilter): self
+ {
+ $this->NodeFilter = $NodeFilter;
+ return $this;
+ }
+
public function getServiceFilter(): string
{
return $this->ServiceFilter;
}
+ public function setServiceFilter(string $ServiceFilter): self
+ {
+ $this->ServiceFilter = $ServiceFilter;
+ return $this;
+ }
+
public function getTagFilter(): string
{
return $this->TagFilter;
}
+ public function setTagFilter(string $TagFilter): self
+ {
+ $this->TagFilter = $TagFilter;
+ return $this;
+ }
+
public function getVersion(): int
{
return $this->Version;
}
+ public function setVersion(int $Version): self
+ {
+ $this->Version = $Version;
+ return $this;
+ }
+
public function getLTime(): int
{
return $this->LTime;
}
+
+ public function setLTime(int $LTime): self
+ {
+ $this->LTime = $LTime;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Payload = $this->Payload;
+ $out->NodeFilter = $this->NodeFilter;
+ $out->ServiceFilter = $this->ServiceFilter;
+ $out->TagFilter = $this->TagFilter;
+ $out->Version = $this->Version;
+ $out->LTime = $this->LTime;
+ return $out;
+ }
}
diff --git a/src/Event/UserEventResponse.php b/src/Event/UserEventResponse.php
index 1b854d71..eb03c7c4 100644
--- a/src/Event/UserEventResponse.php
+++ b/src/Event/UserEventResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedWriteResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class UserEventResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface
{
- public ?UserEvent $UserEvent = null;
+ public null|UserEvent $UserEvent = null;
- public function getValue(): ?UserEvent
+ public function getValue(): null|UserEvent
{
return $this->UserEvent;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->UserEvent = new UserEvent((array)$decodedData);
+ if (null === $decoded) {
+ $this->UserEvent = null;
+ return;
+ }
+ $this->UserEvent = UserEvent::jsonUnserialize($decoded);
}
}
diff --git a/src/Event/UserEventsResponse.php b/src/Event/UserEventsResponse.php
index b9eb5f61..50b967b1 100644
--- a/src/Event/UserEventsResponse.php
+++ b/src/Event/UserEventsResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class UserEventsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $UserEvents = null;
+ /** @var \DCarbone\PHPConsulAPI\Event\UserEvent[] */
+ public array $UserEvents = [];
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Event\UserEvent[]
+ */
+ public function getValue(): array
{
return $this->UserEvents;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->UserEvents = [];
- foreach ($decodedData as $datum) {
- $this->UserEvents[] = new UserEvent($datum);
+ foreach ($decoded as $datum) {
+ $this->UserEvents[] = UserEvent::jsonUnserialize($datum);
}
}
}
diff --git a/src/FakeMap.php b/src/FakeMap.php
deleted file mode 100644
index 5376a1b2..00000000
--- a/src/FakeMap.php
+++ /dev/null
@@ -1,108 +0,0 @@
-_map = $data;
- }
-
- public static function parse(array|FakeMap|\stdClass|null $input): ?self
- {
- if (null === $input) {
- return null;
- }
- if (\is_object($input)) {
- if ($input instanceof self) {
- return $input;
- }
- return new self((array)$input);
- }
- if (\is_array($input)) {
- return new self($input);
- }
- throw new \InvalidArgumentException(
- sprintf('Cannot parse input of type %s to %s', \gettype($input), self::class)
- );
- }
-
- public function current(): mixed
- {
- return current($this->_map);
- }
-
- public function next(): void
- {
- next($this->_map);
- }
-
- public function key(): int|string|null
- {
- return key($this->_map);
- }
-
- public function valid(): bool
- {
- return null !== key($this->_map);
- }
-
- public function rewind(): void
- {
- reset($this->_map);
- }
-
- public function offsetExists(mixed $offset): bool
- {
- return isset($this->_map[$offset]) || \array_key_exists($offset, $this->_map);
- }
-
- public function offsetGet(mixed $offset): mixed
- {
- return $this->_map[$offset] ?? null;
- }
-
- public function offsetSet(mixed $offset, mixed $value): void
- {
- $this->_map[$offset] = $value;
- }
-
- public function offsetUnset(mixed $offset): void
- {
- unset($this->_map[$offset]);
- }
-
- public function count(): int
- {
- return \count($this->_map);
- }
-
- public function jsonSerialize(): object
- {
- return (object)$this->getArrayCopy();
- }
-}
diff --git a/src/FakeSlice.php b/src/FakeSlice.php
deleted file mode 100644
index 255bdf4d..00000000
--- a/src/FakeSlice.php
+++ /dev/null
@@ -1,188 +0,0 @@
-containedClass)) {
- throw new \DomainException(
- sprintf(
- 'Class "%s" must define $containedClass',
- static::class
- )
- );
- }
- // fastpath for "empty"
- if (null === $children || [] === $children) {
- return;
- }
- foreach ($children as $child) {
- $this->append($child);
- }
- }
-
- public function append(array|AbstractModel|null $value): void
- {
- // validate provided value is either null or instance of allowed child class
- $value = $this->_validateValue($value);
-
- // set offset to current value of _size, and iterate size by 1
- $offset = $this->_size++;
-
- // if value is passed, clone then set.
- $this->_list[$offset] = $value;
- }
-
- public function current(): bool|AbstractModel
- {
- return current($this->_list);
- }
-
- public function next(): void
- {
- next($this->_list);
- }
-
- public function key(): ?int
- {
- return key($this->_list);
- }
-
- public function valid(): bool
- {
- return null !== key($this->_list);
- }
-
- public function rewind(): void
- {
- reset($this->_list);
- }
-
- public function offsetExists(mixed $offset): bool
- {
- return \is_int($offset) && isset($this->_list[$offset]);
- }
-
- public function offsetGet(mixed $offset): ?AbstractModel
- {
- $this->_validateOffset($offset);
- return $this->_list[$offset];
- }
-
- public function offsetSet(mixed $offset, mixed $value): void
- {
- // if incoming offset is null, assume [] (append) operation.
- if (null === $offset) {
- $this->append($value);
- return;
- }
-
- // validate provided offset value
- $this->_validateOffset($offset);
-
- // validate value input and set
- $this->_list[$offset] = $this->_validateValue($value);
- }
-
- public function offsetUnset(mixed $offset): void
- {
- // validate provided offset value
- $this->_validateOffset($offset);
-
- // null out value in list
- $this->_list[$offset] = null;
- }
-
- public function count(): int
- {
- return $this->_size;
- }
-
- public function jsonSerialize(): array
- {
- if (0 === $this->_size) {
- return [];
- }
-
- $out = [];
- foreach ($this->_list as $i => $item) {
- if (null === $item) {
- $out[$i] = null;
- } else {
- $out[$i] = clone $item;
- }
- }
- return $out;
- }
-
- abstract protected function newChild(array $data): AbstractModel;
-
- private function _validateOffset(mixed $offset): void
- {
- if (!\is_int($offset)) {
- throw new \InvalidArgumentException(
- sprintf(
- 'Cannot use offset of type "%s" with "%s"',
- \gettype($offset),
- static::class
- )
- );
- }
- if (0 > $offset || $offset >= $this->_size) {
- throw new \OutOfRangeException(sprintf('Offset %d does not exist in this list', $offset));
- }
- }
-
- private function _validateValue(mixed $value): ?AbstractModel
- {
- // fast path for null values
- if (null === $value) {
- return null;
- }
-
- // if instance of contained class, clone and move on
- if ($value instanceof $this->containedClass) {
- return clone $value;
- }
-
- // if array, construct new child
- if (\is_array($value)) {
- return $this->newChild($value);
- }
-
- // if we make it down here, fail.
- throw new \InvalidArgumentException(
- sprintf(
- '%s accepts only objects of type %s, null, or associative array definition as values',
- static::class,
- $this->containedClass,
- )
- );
- }
-}
diff --git a/src/Health/HealthCheck.php b/src/Health/HealthCheck.php
index 6b6e88c1..441ef412 100644
--- a/src/Health/HealthCheck.php
+++ b/src/Health/HealthCheck.php
@@ -20,43 +20,68 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class HealthCheck extends AbstractModel
+class HealthCheck extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_DEFINITION => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthCheckDefinition::class,
- ],
- ];
-
- private const FIELD_NAMESPACE = 'Namespace';
- private const FIELD_DEFINITION = 'Definition';
-
- public string $Node = '';
- public string $CheckID = '';
- public string $Name = '';
- public string $Status = '';
- public string $Notes = '';
- public string $Output = '';
- public string $ServiceID = '';
- public string $ServiceName = '';
- public array $ServiceTags = [];
- public string $Type = '';
- public string $Namespace = '';
+ public string $Node;
+ public string $CheckID;
+ public string $Name;
+ public string $Status;
+ public string $Notes;
+ public string $Output;
+ public string $ServiceID;
+ public string $ServiceName;
+ /** @var array */
+ public array $ServiceTags;
+ public string $Type;
+ public string $Namespace;
+ public string $Partition;
+ public int $ExposedPort;
+ public string $PeerName;
public HealthCheckDefinition $Definition;
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Definition)) {
- $this->Definition = new HealthCheckDefinition(null);
- }
+ public int $CreateIndex;
+ public int $ModifyIndex;
+
+ /**
+ * @param array $ServiceTags
+ */
+ public function __construct(
+ string $Node = '',
+ string $CheckID = '',
+ string $Name = '',
+ string $Status = '',
+ string $Notes = '',
+ string $Output = '',
+ string $ServiceID = '',
+ string $ServiceName = '',
+ array $ServiceTags = [],
+ string $Type = '',
+ string $Namespace = '',
+ string $Partition = '',
+ int $ExposedPort = 0,
+ string $PeerName = '',
+ null|HealthCheckDefinition $Definition = null,
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->Node = $Node;
+ $this->CheckID = $CheckID;
+ $this->Name = $Name;
+ $this->Status = $Status;
+ $this->Notes = $Notes;
+ $this->Output = $Output;
+ $this->ServiceID = $ServiceID;
+ $this->ServiceName = $ServiceName;
+ $this->setServiceTags(...$ServiceTags);
+ $this->Type = $Type;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
+ $this->ExposedPort = $ExposedPort;
+ $this->PeerName = $PeerName;
+ $this->Definition = $Definition ?? new HealthCheckDefinition();
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
}
public function getNode(): string
@@ -147,12 +172,15 @@ public function setServiceName(string $ServiceName): self
return $this;
}
+ /**
+ * @return array
+ */
public function getServiceTags(): array
{
return $this->ServiceTags;
}
- public function setServiceTags(array $ServiceTags): self
+ public function setServiceTags(string ...$ServiceTags): self
{
$this->ServiceTags = $ServiceTags;
return $this;
@@ -180,6 +208,39 @@ public function setNamespace(string $Namespace): self
return $this;
}
+ public function getPartition(): string
+ {
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
+ return $this;
+ }
+
+ public function getExposedPort(): int
+ {
+ return $this->ExposedPort;
+ }
+
+ public function setExposedPort(int $ExposedPort): self
+ {
+ $this->ExposedPort = $ExposedPort;
+ return $this;
+ }
+
+ public function getPeerName(): string
+ {
+ return $this->PeerName;
+ }
+
+ public function setPeerName(string $PeerName): self
+ {
+ $this->PeerName = $PeerName;
+ return $this;
+ }
+
public function getDefinition(): HealthCheckDefinition
{
return $this->Definition;
@@ -212,4 +273,48 @@ public function setModifyIndex(int $ModifyIndex): self
$this->ModifyIndex = $ModifyIndex;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Definition' === $k) {
+ $n->Definition = HealthCheckDefinition::jsonUnserialize($v);
+ } elseif ('ServiceTags' === $k) {
+ $n->setServiceTags(...$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ $out->CheckID = $this->CheckID;
+ $out->Name = $this->Name;
+ $out->Status = $this->Status;
+ $out->Notes = $this->Notes;
+ $out->Output = $this->Output;
+ $out->ServiceID = $this->ServiceID;
+ $out->ServiceName = $this->ServiceName;
+ $out->ServiceTags = $this->ServiceTags;
+ $out->Type = $this->Type;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ $out->ExposedPort = $this->ExposedPort;
+ if ('' !== $this->PeerName) {
+ $out->PeerName = $this->PeerName;
+ }
+ $out->Definition = $this->Definition;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php
index 1c6a1e1e..f03397fd 100644
--- a/src/Health/HealthCheckDefinition.php
+++ b/src/Health/HealthCheckDefinition.php
@@ -21,96 +21,59 @@
*/
use DCarbone\Go\Time;
-use DCarbone\Go\Time\Duration;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Operator\ReadableDuration;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\Values;
-class HealthCheckDefinition extends AbstractModel implements \JsonSerializable
+class HealthCheckDefinition extends AbstractType implements \JsonSerializable
{
- protected const FIELDS = [
- self::FIELD_INTERVAL_DURATION => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_SKIP => true,
- ],
- self::FIELD_TIMEOUT_DURATION => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_SKIP => true,
- ],
- self::FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER_DURATION => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION,
- Transcoding::FIELD_SKIP => true,
- ],
- self::FIELD_TIMEOUT => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- ],
- self::FIELD_INTERVAL => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- ],
- self::FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- ],
- ];
-
- private const FIELD_HTTP = 'HTTP';
- private const FIELD_HEADER = 'Header';
- private const FIELD_METHOD = 'Method';
- private const FIELD_BODY = 'Body';
- private const FIELD_TLS_SKIP_VERIFY = 'TLSSkipVerify';
- private const FIELD_TCP = 'TCP';
- private const FIELD_INTERVAL_DURATION = 'IntervalDuration';
- private const FIELD_TIMEOUT_DURATION = 'TimeoutDuration';
- private const FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER_DURATION = 'DeregisterCriticalServiceAfterDuration';
- private const FIELD_INTERVAL = 'Interval';
- private const FIELD_TIMEOUT = 'Timeout';
- private const FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER = 'DeregisterCriticalServiceAfter';
-
- public string $HTTP = '';
- public array $Header = [];
- public string $Method = '';
- public string $Body = '';
- public bool $TLSSkipVerify = false;
- public string $TCP = '';
- public Duration $IntervalDuration;
- public Duration $TimeoutDuration;
- public Duration $DeregisterCriticalServiceAfterDuration;
-
- public ReadableDuration $Interval;
- public ReadableDuration $Timeout;
- public ReadableDuration $DeregisterCriticalServiceAfter;
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->Interval)) {
- $this->Interval = new ReadableDuration();
- }
- if (!isset($this->Timeout)) {
- $this->Timeout = new ReadableDuration();
- }
- if (!isset($this->DeregisterCriticalServiceAfter)) {
- $this->DeregisterCriticalServiceAfter = new ReadableDuration();
- }
+ public string $HTTP;
+ public Values $Header;
+ public string $Method;
+ public string $Body;
+ public bool $TLSSkipVerify;
+ public string $TCP;
+ public bool $TCPUseTLS;
+ public string $UDP;
+ public string $GRPC;
+ public string $OSService;
+ public bool $GRPCUseTLS;
+ public Time\Duration $IntervalDuration;
+ public Time\Duration $TimeoutDuration;
+ public Time\Duration $DeregisterCriticalServiceAfterDuration;
- if (!isset($this->IntervalDuration)) {
- $this->IntervalDuration = Time::ParseDuration((string)$this->Interval);
- } else {
- $this->Interval = ReadableDuration::fromDuration((string)$this->IntervalDuration);
- }
- if (!isset($this->TimeoutDuration)) {
- $this->TimeoutDuration = Time::ParseDuration((string)$this->Timeout);
- } else {
- $this->Timeout = ReadableDuration::fromDuration((string)$this->TimeoutDuration);
- }
- if (!isset($this->DeregisterCriticalServiceAfterDuration)) {
- $this->DeregisterCriticalServiceAfterDuration = Time::ParseDuration(
- (string)$this->DeregisterCriticalServiceAfter
- );
- } else {
- $this->DeregisterCriticalServiceAfter = ReadableDuration::fromDuration(
- (string)$this->DeregisterCriticalServiceAfterDuration
- );
- }
+ /**
+ * @param array>|\DCarbone\PHPConsulAPI\PHPLib\Values|null $Header
+ */
+ public function __construct(
+ string $HTTP = '',
+ null|array|\stdClass|Values $Header = null,
+ string $Method = '',
+ string $Body = '',
+ bool $TLSSkipVerify = false,
+ string $TCP = '',
+ bool $TCPUseTLS = false,
+ string $UDP = '',
+ string $GRPC = '',
+ string $OSService = '',
+ bool $GRPCUseTLS = false,
+ null|int|float|string|\DateInterval|Time\Duration $IntervalDuration = null,
+ null|int|float|string|\DateInterval|Time\Duration $TimeoutDuration = null,
+ null|int|float|string|\DateInterval|Time\Duration $DeregisterCriticalServiceAfterDuration = null,
+ ) {
+ $this->HTTP = $HTTP;
+ $this->setHeader($Header);
+ $this->Method = $Method;
+ $this->Body = $Body;
+ $this->TLSSkipVerify = $TLSSkipVerify;
+ $this->TCP = $TCP;
+ $this->TCPUseTLS = $TCPUseTLS;
+ $this->UDP = $UDP;
+ $this->GRPC = $GRPC;
+ $this->OSService = $OSService;
+ $this->GRPCUseTLS = $GRPCUseTLS;
+ $this->IntervalDuration = Time::Duration($IntervalDuration);
+ $this->TimeoutDuration = Time::Duration($TimeoutDuration);
+ $this->DeregisterCriticalServiceAfterDuration = Time::Duration($DeregisterCriticalServiceAfterDuration);
}
public function getHTTP(): string
@@ -118,16 +81,45 @@ public function getHTTP(): string
return $this->HTTP;
}
- public function getHeader(): array
+ public function setHTTP(string $HTTP): self
+ {
+ $this->HTTP = $HTTP;
+ return $this;
+ }
+
+ public function getHeader(): Values
{
return $this->Header;
}
+ /**
+ * @param array>|\DCarbone\PHPConsulAPI\PHPLib\Values|null $Header
+ * @return $this
+ */
+ public function setHeader(null|array|\stdClass|Values $Header = []): self
+ {
+ if (null === $Header) {
+ $this->Header = new Values();
+ return $this;
+ }
+ if (!$Header instanceof Values) {
+ $Header = Values::fromArray((array)$Header);
+ }
+ $this->Header = $Header;
+ return $this;
+ }
+
public function getMethod(): string
{
return $this->Method;
}
+ public function setMethod(string $Method): self
+ {
+ $this->Method = $Method;
+ return $this;
+ }
+
public function getBody(): string
{
return $this->Body;
@@ -144,75 +136,148 @@ public function isTLSSkipVerify(): bool
return $this->TLSSkipVerify;
}
+ public function setTLSSkipVerify(bool $TLSSkipVerify): self
+ {
+ $this->TLSSkipVerify = $TLSSkipVerify;
+ return $this;
+ }
+
public function getTCP(): string
{
return $this->TCP;
}
- public function getIntervalDuration(): ?Duration
+ public function setTCP(string $TCP): self
{
- return $this->IntervalDuration;
+ $this->TCP = $TCP;
+ return $this;
}
- public function getTimeoutDuration(): ?Duration
+ public function isTCPUseTLS(): bool
{
- return $this->TimeoutDuration;
+ return $this->TCPUseTLS;
}
- public function getDeregisterCriticalServiceAfterDuration(): ?Duration
+ public function setTCPUseTLS(bool $TCPUseTLS): self
{
- return $this->DeregisterCriticalServiceAfterDuration;
+ $this->TCPUseTLS = $TCPUseTLS;
+ return $this;
}
- public function getInterval(): ?ReadableDuration
+ public function getUDP(): string
{
- return $this->Interval;
+ return $this->UDP;
}
- public function getTimeout(): ?ReadableDuration
+ public function setUDP(string $UDP): self
{
- return $this->Timeout;
+ $this->UDP = $UDP;
+ return $this;
}
- public function getDeregisterCriticalServiceAfter(): ?ReadableDuration
+ public function getGRPC(): string
{
- return $this->DeregisterCriticalServiceAfter;
+ return $this->GRPC;
}
- public function jsonSerialize(): array
+ public function setGRPC(string $GRPC): self
{
- // prepare base definition
- $prep = [
- self::FIELD_HTTP => $this->HTTP,
- self::FIELD_HEADER => $this->Header,
- self::FIELD_METHOD => $this->Method,
- self::FIELD_BODY => $this->Body,
- self::FIELD_TLS_SKIP_VERIFY => $this->TLSSkipVerify,
- self::FIELD_TCP => $this->TCP,
+ $this->GRPC = $GRPC;
+ return $this;
+ }
- ];
- if (0 !== $this->IntervalDuration->Nanoseconds()) {
- $prep[self::FIELD_INTERVAL] = (string)$this->IntervalDuration;
- } elseif (0 !== $this->Interval->Nanoseconds()) {
- $prep[self::FIELD_INTERVAL] = (string)$this->Interval;
- }
- if (0 !== $this->TimeoutDuration->Nanoseconds()) {
- $prep[self::FIELD_TIMEOUT] = (string)$this->TimeoutDuration;
- } elseif (0 !== $this->Timeout->Nanoseconds()) {
- $prep[self::FIELD_TIMEOUT] = (string)$this->Timeout;
- }
- if (0 !== $this->DeregisterCriticalServiceAfterDuration->Nanoseconds()) {
- $prep[self::FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER] = (string)$this->DeregisterCriticalServiceAfterDuration;
- } elseif (0 !== $this->DeregisterCriticalServiceAfter->Nanoseconds()) {
- $prep[self::FIELD_DEREGISTER_CRITICAL_SERVICE_AFTER] = (string)$this->DeregisterCriticalServiceAfter;
- }
+ public function getOSService(): string
+ {
+ return $this->OSService;
+ }
- // handle per-field marshalling
- $out = [];
- foreach ($prep as $field => $value) {
- $this->marshalField($out, $field, $value);
+ public function setOSService(string $OSService): self
+ {
+ $this->OSService = $OSService;
+ return $this;
+ }
+
+ public function isGRPCUseTLS(): bool
+ {
+ return $this->GRPCUseTLS;
+ }
+
+ public function setGRPCUseTLS(bool $GRPCUseTLS): self
+ {
+ $this->GRPCUseTLS = $GRPCUseTLS;
+ return $this;
+ }
+
+ public function getIntervalDuration(): Time\Duration
+ {
+ return $this->IntervalDuration;
+ }
+
+ public function setIntervalDuration(null|int|float|string|\DateInterval|Time\Duration $IntervalDuration): self
+ {
+ $this->IntervalDuration = Time::Duration($IntervalDuration);
+ return $this;
+ }
+
+ public function getTimeoutDuration(): Time\Duration
+ {
+ return $this->TimeoutDuration;
+ }
+
+ public function setTimeoutDuration(null|int|float|string|\DateInterval|Time\Duration $TimeoutDuration): self
+ {
+ $this->TimeoutDuration = Time::Duration($TimeoutDuration);
+ return $this;
+ }
+
+ public function getDeregisterCriticalServiceAfterDuration(): Time\Duration
+ {
+ return $this->DeregisterCriticalServiceAfterDuration;
+ }
+
+ public function setDeregisterCriticalServiceAfterDuration(
+ null|int|float|string|\DateInterval|Time\Duration $DeregisterCriticalServiceAfterDuration
+ ): self {
+ $this->DeregisterCriticalServiceAfterDuration = Time::Duration($DeregisterCriticalServiceAfterDuration);
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Interval' === $k || 'IntervalDuration' === $k) {
+ $n->IntervalDuration = Time::Duration($v);
+ } elseif ('Timeout' === $k || 'TimeoutDuration' === $k) {
+ $n->TimeoutDuration = Time::Duration($v);
+ } elseif ('DeregisterCriticalServiceAfter' === $k || 'DeregisterCriticalServiceAfterDuration' === $k) {
+ $n->DeregisterCriticalServiceAfterDuration = Time::Duration($v);
+ } elseif ('Header' === $k) {
+ $n->setHeader($v);
+ } else {
+ $n->{$k} = $v;
+ }
}
+ return $n;
+ }
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->HTTP = $this->HTTP;
+ $out->Header = $this->Header;
+ $out->Method = $this->Method;
+ $out->Body = $this->Body;
+ $out->TLSSkipVerify = $this->TLSSkipVerify;
+ $out->TCP = $this->TCP;
+ $out->TCPUseTLS = $this->TCPUseTLS;
+ $out->UDP = $this->UDP;
+ $out->GRPC = $this->GRPC;
+ $out->OSService = $this->OSService;
+ $out->GRPCUseTLS = $this->GRPCUseTLS;
+ $out->Interval = (string)$this->IntervalDuration;
+ $out->Timeout = (string)$this->TimeoutDuration;
+ $out->DeregisterCriticalServiceAfter = (string)$this->DeregisterCriticalServiceAfterDuration;
return $out;
}
}
diff --git a/src/Health/HealthChecks.php b/src/Health/HealthChecks.php
index f764dd26..bb5c56ac 100644
--- a/src/Health/HealthChecks.php
+++ b/src/Health/HealthChecks.php
@@ -20,19 +20,28 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Consul;
-use DCarbone\PHPConsulAPI\FakeSlice;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class HealthChecks extends FakeSlice
+/**
+ * @implements \ArrayAccess
+ * @implements \IteratorAggregate
+ */
+class HealthChecks extends AbstractType implements \IteratorAggregate, \Countable, \ArrayAccess
{
- protected string $containedClass = HealthCheck::class;
+ /** @var \DCarbone\PHPConsulAPI\Health\HealthCheck[] */
+ protected array $Checks = [];
+
+ public function __construct(HealthCheck ...$Checks)
+ {
+ $this->Checks = $Checks;
+ }
public function AggregatedStatus(): string
{
$passing = $warning = $critical = $maintenance = false;
- foreach ($this as $check) {
- if (Consul::NodeMaint === $check->CheckID || 0 === strpos($check->CheckID, Consul::ServiceMaintPrefix)) {
+ foreach ($this->Checks as $check) {
+ if (Consul::NodeMaint === $check->CheckID || str_starts_with($check->CheckID, Consul::ServiceMaintPrefix)) {
// TODO: Maybe just return maintenance right now...?
$maintenance = true;
continue;
@@ -68,8 +77,65 @@ public function AggregatedStatus(): string
return Consul::HealthPassing;
}
- protected function newChild(array $data): AbstractModel
+ public function getIterator(): \Traversable
+ {
+ return new \ArrayIterator($this->Checks);
+ }
+
+ public function count(): int
+ {
+ return count($this->Checks);
+ }
+
+ public function offsetExists($offset): bool
+ {
+ return is_int($offset) && isset($this->Checks[$offset]);
+ }
+
+ public function offsetGet($offset): null|HealthCheck
+ {
+ if (!isset($this[$offset])) {
+ throw new \OutOfRangeException("Offset $offset does not exist");
+ }
+ return $this->Checks[$offset];
+ }
+
+ public function offsetSet($offset, $value): void
+ {
+ if (!$value instanceof HealthCheck) {
+ throw new \InvalidArgumentException(sprintf("Value must be an instance of %s", HealthCheck::class));
+ }
+ if (null === $offset) {
+ $this->Checks[] = $value;
+ } elseif (!is_int($offset)) {
+ throw new \InvalidArgumentException('Offset must be an integer');
+ } else {
+ $this->Checks[$offset] = $value;
+ }
+ }
+
+ public function offsetUnset($offset): void
+ {
+ unset($this->Checks[$offset]);
+ }
+
+ /**
+ * @param array<\stdClass> $decoded
+ */
+ public static function jsonUnserialize(array $decoded): self
+ {
+ $n = new self();
+ foreach ($decoded as $d) {
+ $n->Checks[] = HealthCheck::jsonUnserialize($d);
+ }
+ return $n;
+ }
+
+ /**
+ * @return \DCarbone\PHPConsulAPI\Health\HealthCheck[]
+ */
+ public function jsonSerialize(): array
{
- return new HealthCheck($data);
+ return $this->Checks;
}
}
diff --git a/src/Health/HealthChecksResponse.php b/src/Health/HealthChecksResponse.php
index 54852a40..94013bc9 100644
--- a/src/Health/HealthChecksResponse.php
+++ b/src/Health/HealthChecksResponse.php
@@ -20,20 +20,29 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class HealthChecksResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?HealthChecks $HealthChecks = null;
+ public HealthChecks $HealthChecks;
- public function getValue(): ?HealthChecks
+ public function __construct()
+ {
+ $this->HealthChecks = new HealthChecks();
+ }
+
+ public function getValue(): HealthChecks
{
return $this->HealthChecks;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->HealthChecks = new HealthChecks((array)$decodedData);
+ if (null === $decoded) {
+ $this->HealthChecks = new HealthChecks();
+ return;
+ }
+ $this->HealthChecks = HealthChecks::jsonUnserialize($decoded);
}
}
diff --git a/src/Health/HealthClient.php b/src/Health/HealthClient.php
index b7ff2704..ffb45da4 100644
--- a/src/Health/HealthClient.php
+++ b/src/Health/HealthClient.php
@@ -20,8 +20,8 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractClient;
-use DCarbone\PHPConsulAPI\Error;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
use DCarbone\PHPConsulAPI\QueryOptions;
class HealthClient extends AbstractClient
@@ -30,21 +30,24 @@ class HealthClient extends AbstractClient
private const connectHealth = 'connect';
private const ingressHealth = 'ingress';
- public function Node(string $node, ?QueryOptions $opts = null): HealthChecksResponse
+ public function Node(string $node, null|QueryOptions $opts = null): HealthChecksResponse
{
return $this->_getHealthChecks(sprintf('v1/health/node/%s', $node), $opts);
}
- public function Checks(string $service, ?QueryOptions $opts = null): HealthChecksResponse
+ public function Checks(string $service, null|QueryOptions $opts = null): HealthChecksResponse
{
return $this->_getHealthChecks(sprintf('v1/health/checks/%s', $service), $opts);
}
+ /**
+ * @param array $tags
+ */
public function ServiceMultipleTags(
string $service,
array $tags = [],
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->_getServiceEntries($service, $tags, $passingOnly, $opts, self::serviceHealth);
}
@@ -53,16 +56,19 @@ public function Service(
string $service,
string $tag = '',
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->ServiceMultipleTags($service, '' !== $tag ? [$tag] : [], $passingOnly, $opts);
}
+ /**
+ * @param array $tags
+ */
public function IngressMultipleTags(
string $service,
array $tags = [],
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->_getServiceEntries($service, $tags, $passingOnly, $opts, self::ingressHealth);
}
@@ -71,16 +77,19 @@ public function Ingress(
string $service,
string $tag = '',
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->IngressMultipleTags($service, '' !== $tag ? [$tag] : [], $passingOnly, $opts);
}
+ /**
+ * @param array $tags
+ */
public function ConnectMultipleTags(
string $service,
array $tags = [],
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->_getServiceEntries($service, $tags, $passingOnly, $opts, self::connectHealth);
}
@@ -89,16 +98,16 @@ public function Connect(
string $service,
string $tag = '',
bool $passingOnly = false,
- ?QueryOptions $opts = null
+ null|QueryOptions $opts = null
): ServiceEntriesResponse {
return $this->ConnectMultipleTags($service, '' !== $tag ? [$tag] : [], $passingOnly, $opts);
}
- public function State(string $state, ?QueryOptions $opts = null): HealthChecksResponse
+ public function State(string $state, null|QueryOptions $opts = null): HealthChecksResponse
{
static $validStates = ['any', 'warning', 'critical', 'passing', 'unknown'];
- if (!\in_array($state, $validStates, true)) {
+ if (!in_array($state, $validStates, true)) {
$ret = new HealthChecksResponse();
$ret->Err = new Error(
sprintf(
@@ -114,7 +123,7 @@ public function State(string $state, ?QueryOptions $opts = null): HealthChecksRe
return $this->_getHealthChecks(sprintf('v1/health/state/%s', $state), $opts);
}
- protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthChecksResponse
+ protected function _getHealthChecks(string $path, null|QueryOptions $opts): HealthChecksResponse
{
$resp = $this->_requireOK($this->_doGet($path, $opts));
$ret = new HealthChecksResponse();
@@ -122,11 +131,14 @@ protected function _getHealthChecks(string $path, ?QueryOptions $opts): HealthCh
return $ret;
}
+ /**
+ * @param array $tags
+ */
private function _getServiceEntries(
string $service,
array $tags,
bool $passingOnly,
- ?QueryOptions $opts,
+ null|QueryOptions $opts,
string $healthType
): ServiceEntriesResponse {
$uri = match ($healthType) {
diff --git a/src/Health/ServiceEntriesResponse.php b/src/Health/ServiceEntriesResponse.php
index 5ed674ea..81ba41c1 100644
--- a/src/Health/ServiceEntriesResponse.php
+++ b/src/Health/ServiceEntriesResponse.php
@@ -20,23 +20,27 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class ServiceEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?array $ServiceEntries = null;
+ /** @var \DCarbone\PHPConsulAPI\Health\ServiceEntry[] */
+ public array $ServiceEntries;
- public function getValue(): ?array
+ /**
+ * @return \DCarbone\PHPConsulAPI\Health\ServiceEntry[]
+ */
+ public function getValue(): array
{
return $this->ServiceEntries;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
$this->ServiceEntries = [];
- foreach ($decodedData as $entry) {
- $this->ServiceEntries[] = new ServiceEntry($entry);
+ foreach ($decoded as $entry) {
+ $this->ServiceEntries[] = ServiceEntry::jsonUnserialize($entry);
}
}
}
diff --git a/src/Health/ServiceEntry.php b/src/Health/ServiceEntry.php
index 96773463..eaa1c0f6 100644
--- a/src/Health/ServiceEntry.php
+++ b/src/Health/ServiceEntry.php
@@ -20,63 +20,43 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
use DCarbone\PHPConsulAPI\Agent\AgentService;
use DCarbone\PHPConsulAPI\Catalog\Node;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class ServiceEntry extends AbstractModel
+class ServiceEntry extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NODE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Node::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentService::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_CHECKS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthChecks::class,
- ],
- ];
-
- private const FIELD_NODE = 'Node';
- private const FIELD_SERVICE = 'Service';
- private const FIELD_CHECKS = 'Checks';
-
- public ?Node $Node = null;
- public ?AgentService $Service = null;
+ public null|Node $Node;
+ public null|AgentService $Service;
public HealthChecks $Checks;
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Checks)) {
- $this->Checks = new HealthChecks(null);
- }
+ public function __construct(
+ null|Node $Node = null,
+ null|AgentService $Service = null,
+ null|HealthChecks $Checks = null,
+ ) {
+ $this->Node = $Node;
+ $this->Service = $Service;
+ $this->setChecks($Checks);
}
- public function getNode(): ?Node
+ public function getNode(): null|Node
{
return $this->Node;
}
- public function setNode(?Node $Node): self
+ public function setNode(null|Node $Node): self
{
$this->Node = $Node;
return $this;
}
- public function getService(): ?AgentService
+ public function getService(): null|AgentService
{
return $this->Service;
}
- public function setService(?AgentService $Service): self
+ public function setService(null|AgentService $Service): self
{
$this->Service = $Service;
return $this;
@@ -87,9 +67,38 @@ public function getChecks(): HealthChecks
return $this->Checks;
}
- public function setChecks(HealthChecks $Checks): self
+ public function setChecks(null|HealthChecks $Checks): self
{
+ if (null === $Checks) {
+ $Checks = new HealthChecks();
+ }
$this->Checks = $Checks;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Node' === $k) {
+ $n->Node = null === $v ? null : Node::jsonUnserialize($v);
+ } elseif ('Service' === $k) {
+ $n->Service = null === $v ? null : AgentService::jsonUnserialize($v);
+ } elseif ('Checks' === $k) {
+ $n->Checks = HealthChecks::jsonUnserialize((array)$v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Node = $this->Node;
+ $out->Service = $this->Service;
+ $out->Checks = $this->Checks;
+ return $out;
+ }
}
diff --git a/src/HttpAuth.php b/src/HttpAuth.php
index 0e26216f..97057e30 100644
--- a/src/HttpAuth.php
+++ b/src/HttpAuth.php
@@ -22,11 +22,8 @@
class HttpAuth implements \JsonSerializable
{
- private const FIELD_USERNAME = 'username';
- private const FIELD_PASSWORD = 'password';
-
- public string $username = '';
- public string $password = '';
+ public string $username;
+ public string $password;
public function __construct(string $username = '', string $password = '')
{
@@ -49,18 +46,23 @@ public function compileAuthString(): string
return (string)$this;
}
- public function jsonSerialize(): array
+ public function jsonSerialize(): \stdClass
{
- return [self::FIELD_USERNAME => $this->username, self::FIELD_PASSWORD => $this->password];
+ $out = new \stdClass();
+ $out->username = $this->username;
+ if ('' !== $this->password) {
+ $out->password = $this->password;
+ }
+ return $out;
}
public function __debugInfo(): array
{
- return [self::FIELD_USERNAME => $this->username];
+ return ['username' => $this->username];
}
public function __toString(): string
{
- return trim(sprintf('%s:%s', $this->username, $this->password), ':');
+ return $this->password !== '' ? "{$this->username}:{$this->password}" : $this->username;
}
}
diff --git a/src/KV/CheckTxnOp.php b/src/KV/CheckTxnOp.php
deleted file mode 100644
index 0ffce250..00000000
--- a/src/KV/CheckTxnOp.php
+++ /dev/null
@@ -1,70 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthCheck::class,
- ],
- ];
-
- private const FIELD_CHECK = 'Check';
-
- public string $Verb = '';
- public HealthCheck $Check;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Check)) {
- $this->Check = new HealthCheck(null);
- }
- }
-
- public function getVerb(): string
- {
- return $this->Verb;
- }
-
- public function setVerb(string $Verb): self
- {
- $this->Verb = $Verb;
- return $this;
- }
-
- public function getCheck(): HealthCheck
- {
- return $this->Check;
- }
-
- public function setCheck(HealthCheck $Check): self
- {
- $this->Check = $Check;
- return $this;
- }
-}
diff --git a/src/KV/KVClient.php b/src/KV/KVClient.php
index 2fb51783..b59cb459 100644
--- a/src/KV/KVClient.php
+++ b/src/KV/KVClient.php
@@ -21,20 +21,24 @@
*/
use DCarbone\Go\HTTP;
-use DCarbone\PHPConsulAPI\AbstractClient;
-use DCarbone\PHPConsulAPI\Error;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractClient;
+use DCarbone\PHPConsulAPI\PHPLib\Error;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedQueryStringsResponse;
+use DCarbone\PHPConsulAPI\PHPLib\ValuedWriteBoolResponse;
+use DCarbone\PHPConsulAPI\PHPLib\WriteResponse;
use DCarbone\PHPConsulAPI\QueryOptions;
-use DCarbone\PHPConsulAPI\ValuedQueryStringsResponse;
-use DCarbone\PHPConsulAPI\ValuedWriteBoolResponse;
+use DCarbone\PHPConsulAPI\Txn\KVTxnAPIResponse;
+use DCarbone\PHPConsulAPI\Txn\KVTxnResponse;
+use DCarbone\PHPConsulAPI\Txn\TxnOp;
+use DCarbone\PHPConsulAPI\Txn\TxnResponse;
use DCarbone\PHPConsulAPI\WriteOptions;
-use DCarbone\PHPConsulAPI\WriteResponse;
class KVClient extends AbstractClient
{
- public function Get(string $key, ?QueryOptions $opts = null): KVPairResponse
+ public function Get(string $key, null|QueryOptions $opts = null): KVPairResponse
{
- $resp = $this->_doGet(sprintf('v1/kv/%s', $key), $opts);
- $ret = new KVPairResponse();
+ $resp = $this->_doGet(sprintf('v1/kv/%s', $key), $opts);
+ $ret = new KVPairResponse();
$ret->Err = $resp->Err;
if (null !== $resp->Err) {
return $ret;
@@ -59,44 +63,45 @@ public function Get(string $key, ?QueryOptions $opts = null): KVPairResponse
return $ret;
}
- public function Put(KVPair $p, ?WriteOptions $opts = null): WriteResponse
+ public function Put(KVPair $p, null|WriteOptions $opts = null): WriteResponse
{
$r = $this->_newPutRequest(sprintf('v1/kv/%s', $p->Key), $p->Value, $opts);
if (0 !== $p->Flags) {
$r->params->set('flags', (string)$p->Flags);
}
+ $r->header->set('Content-Type', 'application/octet-stream');
$resp = $this->_requireOK($this->_do($r));
- $ret = new WriteResponse();
+ $ret = new WriteResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function Delete(string $key, ?WriteOptions $opts = null): WriteResponse
+ public function Delete(string $key, null|WriteOptions $opts = null): WriteResponse
{
return $this->_executeDelete(sprintf('v1/kv/%s', $key), $opts);
}
- public function List(string $prefix = '', ?QueryOptions $opts = null): KVPairsResponse
+ public function List(string $prefix = '', null|QueryOptions $opts = null): KVPairsResponse
{
$r = $this->_newGetRequest(sprintf('v1/kv/%s', $prefix), $opts);
$r->params->set('recurse', '');
- $ret = new KVPairsResponse();
+ $ret = new KVPairsResponse();
$resp = $this->_requireOK($this->_do($r));
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function Keys(string $prefix = '', ?QueryOptions $opts = null): ValuedQueryStringsResponse
+ public function Keys(string $prefix = '', null|QueryOptions $opts = null): ValuedQueryStringsResponse
{
$r = $this->_newGetRequest(sprintf('v1/kv/%s', $prefix), $opts);
$r->params->set('keys', '');
- $ret = new ValuedQueryStringsResponse();
+ $ret = new ValuedQueryStringsResponse();
$resp = $this->_requireOK($this->_do($r));
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function CAS(KVPair $p, ?WriteOptions $opts = null): ValuedWriteBoolResponse
+ public function CAS(KVPair $p, null|WriteOptions $opts = null): ValuedWriteBoolResponse
{
$r = $this->_newPutRequest(sprintf('v1/kv/%s', $p->Key), $p->Value, $opts);
$r->params->set('cas', (string)$p->ModifyIndex);
@@ -104,12 +109,12 @@ public function CAS(KVPair $p, ?WriteOptions $opts = null): ValuedWriteBoolRespo
$r->params->set('flags', (string)$p->Flags);
}
$resp = $this->_requireOK($this->_do($r));
- $ret = new ValuedWriteBoolResponse();
+ $ret = new ValuedWriteBoolResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function Acquire(KVPair $p, ?WriteOptions $opts = null): WriteResponse
+ public function Acquire(KVPair $p, null|WriteOptions $opts = null): WriteResponse
{
$r = $this->_newPutRequest(sprintf('v1/kv/%s', $p->Key), $p->Value, $opts);
$r->params->set('acquire', $p->Session);
@@ -117,22 +122,22 @@ public function Acquire(KVPair $p, ?WriteOptions $opts = null): WriteResponse
$r->params->set('flags', (string)$p->Flags);
}
$resp = $this->_requireOK($this->_do($r));
- $ret = new WriteResponse();
+ $ret = new WriteResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function DeleteCAS(KVPair $p, ?WriteOptions $opts = null): ValuedWriteBoolResponse
+ public function DeleteCAS(KVPair $p, null|WriteOptions $opts = null): ValuedWriteBoolResponse
{
- $r = $this->_newDeleteRequest(sprintf('v1/kv/%s', ltrim($p->Key, '/')), $opts);
- $r->params['cas'] = (string)$p->ModifyIndex;
- $resp = $this->_requireOK($this->_do($r));
- $ret = new ValuedWriteBoolResponse();
+ $r = $this->_newDeleteRequest(sprintf('v1/kv/%s', ltrim($p->Key, '/')), $opts);
+ $r->params->set('cas', (string)$p->ModifyIndex);
+ $resp = $this->_requireOK($this->_do($r));
+ $ret = new ValuedWriteBoolResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function Release(KVPair $p, ?WriteOptions $opts = null): WriteResponse
+ public function Release(KVPair $p, null|WriteOptions $opts = null): WriteResponse
{
$r = $this->_newPutRequest(sprintf('v1/kv/%s', $p->Key), $p->Value, $opts);
$r->params->set('release', $p->Session);
@@ -145,26 +150,32 @@ public function Release(KVPair $p, ?WriteOptions $opts = null): WriteResponse
return $ret;
}
- public function DeleteTree(string $prefix, ?WriteOptions $opts = null): WriteResponse
+ public function DeleteTree(string $prefix, null|WriteOptions $opts = null): WriteResponse
{
- $r = $this->_newDeleteRequest(sprintf('v1/kv/%s', $prefix), $opts);
- $r->params['recurse'] = '';
- $resp = $this->_requireOK($this->_do($r));
- $ret = new WriteResponse();
+ $r = $this->_newDeleteRequest(sprintf('v1/kv/%s', $prefix), $opts);
+ $r->params->set('recurse', '');
+ $resp = $this->_requireOK($this->_do($r));
+ $ret = new WriteResponse();
$this->_unmarshalResponse($resp, $ret);
return $ret;
}
- public function Txn(KVTxnOps $txn, ?QueryOptions $opts = null): KVTxnAPIResponse
+ /**
+ * @param array<\DCarbone\PHPConsulAPI\Txn\TxnOp> $txn
+ * @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
+ * @return \DCarbone\PHPConsulAPI\Txn\KVTxnAPIResponse
+ */
+ public function Txn(array $txn, null|QueryOptions $opts = null): KVTxnAPIResponse
{
- $txnOps = new KVTxnOps();
foreach ($txn as $op) {
- $txnOps->append(clone $op);
+ if (!($op instanceof TxnOp)) {
+ throw new \InvalidArgumentException(sprintf('$txn must be array of %s, saw %s', TxnOp::class, gettype($op)));
+ }
}
$ret = new KVTxnAPIResponse();
- $resp = $this->_doPut('v1/txn', $txnOps, $opts);
+ $resp = $this->_doPut('v1/txn', $txn, $opts);
if (null !== $resp->Err) {
$ret->Err = $resp->Err;
return $ret;
@@ -183,8 +194,11 @@ public function Txn(KVTxnOps $txn, ?QueryOptions $opts = null): KVTxnAPIResponse
}
$ret->OK = true;
// TODO: Maybe go straight to actual response? What is the benefit of this...
- $internal = new TxnResponse($dec->Decoded);
- $ret->KVTxnResponse = new KVTxnResponse(['Errors' => $internal->Errors, 'Results' => $internal->Results]);
+ $internal = new TxnResponse($dec->Decoded);
+ $kvr = new KVTxnResponse();
+ $kvr->Errors = $internal->Errors;
+ $kvr->Results = $internal->Results;
+ $ret->KVTxnResponse = $kvr;
return $ret;
}
@@ -196,78 +210,4 @@ public function Txn(KVTxnOps $txn, ?QueryOptions $opts = null): KVTxnAPIResponse
$ret->Err = new Error('Failed request: ' . $body);
return $ret;
}
-
- /**
- * @param string $prefix
- * @param \DCarbone\PHPConsulAPI\QueryOptions|null $opts
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @return array(
- * @var \DCarbone\PHPConsulAPI\KV\KVPair[]|\DCarbone\PHPConsulAPI\KV\KVTree[]|null array of trees, values, or null on error
- * @var \DCarbone\PHPConsulAPI\Error|null error, if any
- * )
- */
- public function Tree(string $prefix = '', ?QueryOptions $opts = null): array
- {
- [$valueList, $_, $err] = $this->List($prefix, $opts);
-
- if (null !== $err) {
- return [null, $err];
- }
-
- $treeHierarchy = [];
- foreach ($valueList as $kvp) {
- $path = $kvp->getKey();
- $slashPos = strpos($path, '/');
- if (false === $slashPos) {
- $treeHierarchy[$path] = $kvp;
- continue;
- }
-
- $root = substr($path, 0, $slashPos + 1);
-
- if (!isset($treeHierarchy[$root])) {
- $treeHierarchy[$root] = new KVTree($root);
- }
-
- if (str_ends_with($path, '/')) {
- $_path = '';
- foreach (explode('/', $prefix) as $part) {
- if ('' === $part) {
- continue;
- }
-
- $_path .= "{$part}/";
-
- if ($root === $_path) {
- continue;
- }
-
- if (!isset($treeHierarchy[$root][$_path])) {
- $treeHierarchy[$root][$_path] = new KVTree($_path);
- }
- }
- } else {
- $kvPrefix = substr($path, 0, strrpos($path, '/') + 1);
- $_path = '';
- foreach (explode('/', $kvPrefix) as $part) {
- if ('' === $part) {
- continue;
- }
-
- $_path .= "{$part}/";
-
- if ($root === $_path) {
- continue;
- }
-
- if (!isset($treeHierarchy[$root][$_path])) {
- $treeHierarchy[$root][$_path] = new KVTree($_path);
- }
- }
-
- $treeHierarchy[$root][$path] = $kvp;
- }
- }
- return [$treeHierarchy, null];
- }
}
diff --git a/src/KV/KVPair.php b/src/KV/KVPair.php
index 0a81ec7a..79da0286 100644
--- a/src/KV/KVPair.php
+++ b/src/KV/KVPair.php
@@ -20,41 +20,40 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class KVPair extends AbstractModel
+class KVPair extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_NAMESPACE = 'Namespace';
-
- public string $Key = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
- public int $LockIndex = 0;
- public int $Flags = 0;
- public string $Value = '';
- public string $Session = '';
- public string $Namespace = '';
-
- /**
- * KVPair constructor.
- * @param array $data
- * @param bool $_decodeValue
- */
- public function __construct(array $data = [], bool $_decodeValue = false)
- {
- parent::__construct($data);
- if ($_decodeValue) {
- $dec = base64_decode($this->Value, true);
- if (false === $dec) {
- throw new \InvalidArgumentException(sprintf('Could not base64 decode value "%s"', $this->Value));
- }
- $this->Value = $dec;
- }
+ public string $Key;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+ public int $LockIndex;
+ public int $Flags;
+ public string $Value;
+ public string $Session;
+ public string $Namespace;
+ public string $Partition;
+
+ public function __construct(
+ string $Key = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ int $LockIndex = 0,
+ int $Flags = 0,
+ string $Value = '',
+ string $Session = '',
+ string $Namespace = '',
+ string $Partition = '',
+ ) {
+ $this->Key = $Key;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ $this->LockIndex = $LockIndex;
+ $this->Flags = $Flags;
+ $this->Value = $Value;
+ $this->Session = $Session;
+ $this->Namespace = $Namespace;
+ $this->Partition = $Partition;
}
public function getKey(): string
@@ -62,9 +61,9 @@ public function getKey(): string
return $this->Key;
}
- public function setKey(string $key): self
+ public function setKey(string $Key): self
{
- $this->Key = $key;
+ $this->Key = $Key;
return $this;
}
@@ -73,9 +72,9 @@ public function getCreateIndex(): int
return $this->CreateIndex;
}
- public function setCreateIndex(int $createIndex): self
+ public function setCreateIndex(int $CreateIndex): self
{
- $this->CreateIndex = $createIndex;
+ $this->CreateIndex = $CreateIndex;
return $this;
}
@@ -84,9 +83,9 @@ public function getModifyIndex(): int
return $this->ModifyIndex;
}
- public function setModifyIndex(int $modifyIndex): self
+ public function setModifyIndex(int $ModifyIndex): self
{
- $this->ModifyIndex = $modifyIndex;
+ $this->ModifyIndex = $ModifyIndex;
return $this;
}
@@ -95,9 +94,9 @@ public function getLockIndex(): int
return $this->LockIndex;
}
- public function setLockIndex(int $lockIndex): self
+ public function setLockIndex(int $LockIndex): self
{
- $this->LockIndex = $lockIndex;
+ $this->LockIndex = $LockIndex;
return $this;
}
@@ -106,9 +105,9 @@ public function getFlags(): int
return $this->Flags;
}
- public function setFlags(int $flags): self
+ public function setFlags(int $Flags): self
{
- $this->Flags = $flags;
+ $this->Flags = $Flags;
return $this;
}
@@ -117,9 +116,9 @@ public function getValue(): string
return $this->Value;
}
- public function setValue(string $value): self
+ public function setValue(string $Value): self
{
- $this->Value = $value;
+ $this->Value = $Value;
return $this;
}
@@ -128,9 +127,9 @@ public function getSession(): string
return $this->Session;
}
- public function setSession(string $session): self
+ public function setSession(string $Session): self
{
- $this->Session = $session;
+ $this->Session = $Session;
return $this;
}
@@ -139,9 +138,20 @@ public function getNamespace(): string
return $this->Namespace;
}
- public function setNamespace(string $namespace): self
+ public function setNamespace(string $Namespace): self
+ {
+ $this->Namespace = $Namespace;
+ return $this;
+ }
+
+ public function getPartition(): string
{
- $this->Namespace = $namespace;
+ return $this->Partition;
+ }
+
+ public function setPartition(string $Partition): self
+ {
+ $this->Partition = $Partition;
return $this;
}
@@ -149,4 +159,40 @@ public function __toString(): string
{
return $this->Value;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Value' === $k) {
+ $val = base64_decode($v, true);
+ if (false === $val) {
+ throw new \DomainException(sprintf('Could not base64 decode value "%s"', $v));
+ }
+ $n->Value = $val;
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Key = $this->Key;
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ $out->LockIndex = $this->LockIndex;
+ $out->Flags = $this->Flags;
+ $out->Value = $this->Value;
+ $out->Session = $this->Session;
+ if ('' !== $this->Namespace) {
+ $out->Namespace = $this->Namespace;
+ }
+ if ('' !== $this->Partition) {
+ $out->Partition = $this->Partition;
+ }
+ return $out;
+ }
}
diff --git a/src/KV/KVPairResponse.php b/src/KV/KVPairResponse.php
index f6abca82..a74bd6ae 100644
--- a/src/KV/KVPairResponse.php
+++ b/src/KV/KVPairResponse.php
@@ -20,20 +20,24 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class KVPairResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?KVPair $KVPair = null;
+ public null|KVPair $KVPair = null;
- public function getValue(): ?KVPair
+ public function getValue(): null|KVPair
{
return $this->KVPair;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->KVPair = new KVPair((array)$decodedData, true);
+ if (null === $decoded) {
+ $this->KVPair = null;
+ return;
+ }
+ $this->KVPair = KVPair::jsonUnserialize($decoded);
}
}
diff --git a/src/KV/KVPairs.php b/src/KV/KVPairs.php
index 1003b6aa..d4e5bf4d 100644
--- a/src/KV/KVPairs.php
+++ b/src/KV/KVPairs.php
@@ -20,15 +20,95 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\FakeSlice;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class KVPairs extends FakeSlice
+/**
+ * @implements \ArrayAccess
+ * @implements \IteratorAggregate
+ */
+class KVPairs extends AbstractType implements \IteratorAggregate, \Countable, \ArrayAccess
{
- protected string $containedClass = KVPair::class;
+ /** @var array<\DCarbone\PHPConsulAPI\KV\KVPair> */
+ protected array $KVPairs = [];
+
+ public function __construct(KVPair ...$KVPairs)
+ {
+ $this->KVPairs = $KVPairs;
+ }
+
+ /**
+ * @return array
+ */
+ public function getKVPairs(): array
+ {
+ return $this->KVPairs;
+ }
+
+ public function setKVPairs(KVPair ...$KVPairs): self
+ {
+ $this->KVPairs = $KVPairs;
+ return $this;
+ }
+
+ public function getIterator(): \Traversable
+ {
+ return new \ArrayIterator($this->KVPairs);
+ }
+
+ public function offsetExists(mixed $offset): bool
+ {
+ return is_int($offset) && isset($this->KVPairs[$offset]);
+ }
+
+ public function offsetGet(mixed $offset): mixed
+ {
+ if (!isset($this[$offset])) {
+ throw new \OutOfRangeException("Offset $offset does not exist");
+ }
+ return $this->KVPairs[$offset];
+ }
+
+ public function offsetSet(mixed $offset, mixed $value): void
+ {
+ if (!$value instanceof KVPair) {
+ throw new \InvalidArgumentException(sprintf("Value must be instance of %s", KVPair::class));
+ }
+ if (null === $offset) {
+ $this->KVPairs[] = $value;
+ } elseif (!is_int($offset)) {
+ throw new \InvalidArgumentException('Offset must be an integer');
+ } else {
+ $this->KVPairs[$offset] = $value;
+ }
+ }
+
+ public function offsetUnset(mixed $offset): void
+ {
+ unset($this->KVPairs[$offset]);
+ }
+
+ public function count(): int
+ {
+ return count($this->KVPairs);
+ }
+
+ /**
+ * @param array<\stdClass> $decoded
+ */
+ public static function jsonUnserialize(array $decoded): self
+ {
+ $n = new self();
+ foreach ($decoded as $kv) {
+ $n->KVPairs[] = KVPair::jsonUnserialize($kv);
+ }
+ return $n;
+ }
- protected function newChild(array $data): AbstractModel
+ /**
+ * @return \DCarbone\PHPConsulAPI\KV\KVPair[]
+ */
+ public function jsonSerialize(): array
{
- return new KVPair($data, true);
+ return $this->KVPairs;
}
}
diff --git a/src/KV/KVPairsResponse.php b/src/KV/KVPairsResponse.php
index 2c5a1a65..a8eb6c25 100644
--- a/src/KV/KVPairsResponse.php
+++ b/src/KV/KVPairsResponse.php
@@ -20,20 +20,29 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedQueryResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class KVPairsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface
{
- public ?KVPairs $KVPairs = null;
+ public KVPairs $KVPairs;
- public function getValue(): ?KVPairs
+ public function __construct()
+ {
+ $this->KVPairs = new KVPairs();
+ }
+
+ public function getValue(): KVPairs
{
return $this->KVPairs;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->KVPairs = new KVPairs((array)$decodedData);
+ if (null === $decoded) {
+ $this->KVPairs = new KVPairs();
+ return;
+ }
+ $this->KVPairs = KVPairs::jsonUnserialize($decoded);
}
}
diff --git a/src/KV/KVTree.php b/src/KV/KVTree.php
deleted file mode 100644
index ecfd21e9..00000000
--- a/src/KV/KVTree.php
+++ /dev/null
@@ -1,172 +0,0 @@
-_prefix = $prefix;
- }
-
- public function getPrefix(): string
- {
- return $this->_prefix;
- }
-
- public function current(): KVTree|KVPair
- {
- return current($this->_children);
- }
-
- public function next(): void
- {
- next($this->_children);
- }
-
- /**
- * @return string scalar on success, or null on failure
- */
- public function key(): string
- {
- return key($this->_children);
- }
-
- public function valid(): bool
- {
- return null !== key($this->_children);
- }
-
- public function rewind(): void
- {
- reset($this->_children);
- }
-
- /**
- * @return bool true if the current entry can be iterated over, otherwise returns false
- */
- public function hasChildren(): bool
- {
- return $this->current() instanceof self;
- }
-
- public function getChildren(): \RecursiveIterator|KVTree|KVPair
- {
- return $this->current();
- }
-
- public function count(): int
- {
- return \count($this->_children);
- }
-
- public function offsetExists(mixed $offset): bool
- {
- if (\is_string($offset)) {
- $subPath = str_replace($this->_prefix, '', $offset);
- $cnt = substr_count($subPath, '/');
-
- if (1 < $cnt || (1 === $cnt && '/' !== substr($subPath, -1))) {
- $childKey = $this->_prefix . substr($subPath, 0, strpos($subPath, '/') + 1);
- if (isset($this->_children[$childKey])) {
- return isset($this->_children[$childKey][$offset]);
- }
- }
- }
-
- return isset($this->_children[$offset]) || \array_key_exists($offset, $this->_children);
- }
-
- public function offsetGet(mixed $offset): KVTree|KVPair|null
- {
- if (\is_string($offset)) {
- $subPath = str_replace($this->_prefix, '', $offset);
- $cnt = substr_count($subPath, '/');
- if (1 < $cnt || (1 === $cnt && '/' !== substr($subPath, -1))) {
- $childKey = $this->_prefix . substr($subPath, 0, strpos($subPath, '/') + 1);
- if (isset($this[$childKey])) {
- return $this->_children[$childKey][$offset];
- }
- }
- }
-
- if (isset($this[$offset])) {
- return $this->_children[$offset];
- }
-
- trigger_error(
- sprintf(
- '%s - Requested offset %s does not exist in tree with prefix "%s".',
- static::class,
- $offset,
- $this->getPrefix()
- )
- );
-
- return null;
- }
-
- public function offsetSet(mixed $offset, mixed $value): void
- {
- if ('string' === \gettype($offset)) {
- $subPath = str_replace($this->_prefix, '', $offset);
- $cnt = substr_count($subPath, '/');
-
- if (1 < $cnt || (1 === $cnt && '/' !== substr($subPath, -1))) {
- $childKey = $this->_prefix . substr($subPath, 0, strpos($subPath, '/') + 1);
- $this->_children[$childKey][$offset] = $value;
- } else {
- $this->_children[$offset] = $value;
- }
- } elseif (null === $offset) {
- $this->_children[] = $value;
- } else {
- $this->_children[$offset] = $value;
- }
- }
-
- public function offsetUnset(mixed $offset): void
- {
- // do nothing, yo...
- }
-
- public function jsonSerialize(): array
- {
- $json = [$this->_prefix => []];
- foreach ($this->_children as $k => $child) {
- if ($child instanceof self) {
- $json[$this->_prefix] = $child;
- } elseif ($child instanceof KVPair) {
- $json[$this->_prefix][$child->Key] = $child;
- }
- }
- return $json;
- }
-
- public function __toString()
- {
- return $this->_prefix;
- }
-}
diff --git a/src/KV/KVTxnOp.php b/src/KV/KVTxnOp.php
deleted file mode 100644
index f7cf0622..00000000
--- a/src/KV/KVTxnOp.php
+++ /dev/null
@@ -1,80 +0,0 @@
-Value, true);
- if (false === $dec) {
- throw new \InvalidArgumentException(sprintf('Could not base64 decode value "%s"', $this->Value));
- }
- $this->Value = $dec;
- }
- }
-
- public function getVerb(): string
- {
- return $this->Verb;
- }
-
- public function getKey(): string
- {
- return $this->Key;
- }
-
- public function getValue(): string
- {
- return $this->Value;
- }
-
- public function getFlags(): int
- {
- return $this->Flags;
- }
-
- public function getIndex(): int
- {
- return $this->Index;
- }
-
- public function getSession(): string
- {
- return $this->Session;
- }
-}
diff --git a/src/KV/KVTxnResponse.php b/src/KV/KVTxnResponse.php
deleted file mode 100644
index dfd2d9f1..00000000
--- a/src/KV/KVTxnResponse.php
+++ /dev/null
@@ -1,55 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => KVPair::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- self::FIELD_ERRORS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TxnErrors::class,
- ],
- ];
-
- private const FIELD_RESULTS = 'Results';
- private const FIELD_ERRORS = 'Errors';
-
- public array $Results = [];
- public ?TxnErrors $Errors = null;
-
- public function getResults(): array
- {
- return $this->Results;
- }
-
- public function getErrors(): ?TxnErrors
- {
- return $this->Errors;
- }
-}
diff --git a/src/KV/NodeTxnOp.php b/src/KV/NodeTxnOp.php
deleted file mode 100644
index 872f7d5d..00000000
--- a/src/KV/NodeTxnOp.php
+++ /dev/null
@@ -1,70 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Node::class,
- ],
- ];
-
- private const FIELD_NODE = 'Node';
-
- public string $Verb = '';
- public Node $Node;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->Node)) {
- $this->Node = new Node(null);
- }
- }
-
- public function getVerb(): string
- {
- return $this->Verb;
- }
-
- public function setVerb(string $Verb): self
- {
- $this->Verb = $Verb;
- return $this;
- }
-
- public function getNode(): Node
- {
- return $this->Node;
- }
-
- public function setNode(Node $Node): self
- {
- $this->Node = $Node;
- return $this;
- }
-}
diff --git a/src/KV/ServiceTxnOp.php b/src/KV/ServiceTxnOp.php
deleted file mode 100644
index 52c50964..00000000
--- a/src/KV/ServiceTxnOp.php
+++ /dev/null
@@ -1,80 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AgentService::class,
- ],
- ];
-
- private const FIELD_SERVICE = 'Service';
-
- public string $Verb = '';
- public string $Node = '';
- public AgentService $Service;
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- $this->Service = new AgentService(null);
- }
-
- public function getVerb(): string
- {
- return $this->Verb;
- }
-
- public function setVerb(string $Verb): self
- {
- $this->Verb = $Verb;
- return $this;
- }
-
- public function getNode(): string
- {
- return $this->Node;
- }
-
- public function setNode(string $Node): self
- {
- $this->Node = $Node;
- return $this;
- }
-
- public function getService(): AgentService
- {
- return $this->Service;
- }
-
- public function setService(AgentService $Service): self
- {
- $this->Service = $Service;
- return $this;
- }
-}
diff --git a/src/KV/TxnErrors.php b/src/KV/TxnErrors.php
deleted file mode 100644
index e09430bb..00000000
--- a/src/KV/TxnErrors.php
+++ /dev/null
@@ -1,34 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => KVTxnOp::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_NODE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => NodeTxnOp::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => ServiceTxnOp::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_CHECK => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => CheckTxnOp::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
-
- private const FIELD_KV = 'KV';
- private const FIELD_NODE = 'Node';
- private const FIELD_SERVICE = 'Service';
- private const FIELD_CHECK = 'Check';
-
- public ?KVTxnOp $KV = null;
- public ?NodeTxnOp $Node = null;
- public ?ServiceTxnOp $Service = null;
- public ?CheckTxnOp $Check = null;
-
- public function getKV(): ?KVTxnOp
- {
- return $this->KV;
- }
-
- public function setKV(?KVTxnOp $KV): self
- {
- $this->KV = $KV;
- return $this;
- }
-
- public function getNode(): ?NodeTxnOp
- {
- return $this->Node;
- }
-
- public function setNode(?NodeTxnOp $Node): self
- {
- $this->Node = $Node;
- return $this;
- }
-
- public function getService(): ?ServiceTxnOp
- {
- return $this->Service;
- }
-
- public function setService(?ServiceTxnOp $Service): self
- {
- $this->Service = $Service;
- return $this;
- }
-
- public function getCheck(): ?CheckTxnOp
- {
- return $this->Check;
- }
-
- public function setCheck(?CheckTxnOp $Check): self
- {
- $this->Check = $Check;
- return $this;
- }
-}
diff --git a/src/KV/TxnOps.php b/src/KV/TxnOps.php
deleted file mode 100644
index 28a37cc1..00000000
--- a/src/KV/TxnOps.php
+++ /dev/null
@@ -1,34 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TxnResults::class,
- ],
- self::FIELD_ERRORS => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => TxnErrors::class,
- ],
- ];
-
- private const FIELD_RESULTS = 'Results';
- private const FIELD_ERRORS = 'Errors';
-
- public TxnResults $Results;
- public TxnErrors $Errors;
-
- public function __construct(?array $data = null)
- {
- parent::__construct($data);
- if (!isset($this->Results)) {
- $this->Results = new TxnResults();
- }
- if (!isset($this->Errors)) {
- $this->Errors = new TxnErrors();
- }
- }
-
- public function getResults(): TxnResults
- {
- return $this->Results;
- }
-
- public function setResults(TxnResults $Results): self
- {
- $this->Results = $Results;
- return $this;
- }
-
- public function getErrors(): TxnErrors
- {
- return $this->Errors;
- }
-
- public function setErrors(TxnErrors $Errors): self
- {
- $this->Errors = $Errors;
- return $this;
- }
-}
diff --git a/src/KV/TxnResult.php b/src/KV/TxnResult.php
deleted file mode 100644
index 1f7af537..00000000
--- a/src/KV/TxnResult.php
+++ /dev/null
@@ -1,107 +0,0 @@
- [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => KVPair::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_NODE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => Node::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_SERVICE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => CatalogService::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_CHECK => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => HealthCheck::class,
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
-
- private const FIELD_KV = 'KV';
- private const FIELD_NODE = 'Node';
- private const FIELD_SERVICE = 'Service';
- private const FIELD_CHECK = 'Check';
-
- public ?KVPair $KV = null;
- public ?Node $Node = null;
- public ?CatalogService $Service = null;
- public ?HealthCheck $Check = null;
-
- public function getKV(): ?KVPair
- {
- return $this->KV;
- }
-
- public function setKV(?KVPair $KV): self
- {
- $this->KV = $KV;
- return $this;
- }
-
- public function getNode(): ?Node
- {
- return $this->Node;
- }
-
- public function setNode(?Node $Node): self
- {
- $this->Node = $Node;
- return $this;
- }
-
- public function getService(): ?CatalogService
- {
- return $this->Service;
- }
-
- public function setService(?CatalogService $Service): self
- {
- $this->Service = $Service;
- return $this;
- }
-
- public function getCheck(): ?HealthCheck
- {
- return $this->Check;
- }
-
- public function setCheck(?HealthCheck $Check): self
- {
- $this->Check = $Check;
- return $this;
- }
-}
diff --git a/src/KV/TxnResults.php b/src/KV/TxnResults.php
deleted file mode 100644
index d4a87fb5..00000000
--- a/src/KV/TxnResults.php
+++ /dev/null
@@ -1,34 +0,0 @@
- (string)$value,
- Transcoding::INTEGER => (int)$value,
- Transcoding::DOUBLE => (float)$value,
- Transcoding::BOOLEAN => (bool)$value,
- default => throw new \InvalidArgumentException(
- sprintf('Unable to handle serializing to %s', $def[Transcoding::FIELD_MARSHAL_AS])
- ),
- };
- }
-
- // if this field is NOT explicitly marked as "omitempty", set and move on.
- if (!isset($def[Transcoding::FIELD_OMITEMPTY]) || true !== $def[Transcoding::FIELD_OMITEMPTY]) {
- $output[$field] = $value;
- return;
- }
-
- // otherwise, handle value setting on a per-type basis
-
- $type = \gettype($value);
-
- // strings must be non empty
- if (Transcoding::STRING === $type) {
- if ('' !== $value) {
- $output[$field] = $value;
- }
- return;
- }
-
- // integers must be non-zero (negatives are ok)
- if (Transcoding::INTEGER === $type) {
- if (0 !== $value) {
- $output[$field] = $value;
- }
- return;
- }
-
- // floats must be non-zero (negatives are ok)
- if (Transcoding::DOUBLE === $type) {
- if (0.0 !== $value) {
- $output[$field] = $value;
- }
- return;
- }
-
- // bools must be true
- if (Transcoding::BOOLEAN === $type) {
- if ($value) {
- $output[$field] = $value;
- }
- return;
- }
-
- // object "non-zero" calculations require a bit more finesse...
- if (Transcoding::OBJECT === $type) {
- // AbstractModels are collections, and are non-zero if they contain at least 1 entry
- if ($value instanceof FakeSlice || $value instanceof FakeMap) {
- if (0 < \count($value)) {
- $output[$field] = $value;
- }
- return;
- }
-
- // Time\Duration types are non-zero if their internal value is > 0
- if ($value instanceof Time\Duration) {
- if (0 < $value->Nanoseconds()) {
- $output[$field] = $value;
- }
- return;
- }
-
- // Time\Time values are non-zero if they are anything greater than epoch
- if ($value instanceof Time\Time) {
- if (!$value->IsZero()) {
- $output[$field] = $value;
- }
- return;
- }
-
- // otherwise, by being defined it is non-zero, so add it.
- $output[$field] = $value;
- return;
- }
-
- // arrays must have at least 1 value
- if (Transcoding::ARRAY === $type) {
- if ([] !== $value) {
- $output[$field] = $value;
- }
- return;
- }
-
- // todo: be more better about resources
- if (Transcoding::RESOURCE === $type) {
- $output[$field] = $value;
- return;
- }
-
- // once we get here the only possible value type is "NULL", which are always considered "empty". thus, do not
- // set any value.
- }
-}
diff --git a/src/Metrics/Label.php b/src/Metrics/Label.php
new file mode 100644
index 00000000..9691cdd2
--- /dev/null
+++ b/src/Metrics/Label.php
@@ -0,0 +1,74 @@
+Name = $Name;
+ $this->Value = $Value;
+ }
+
+ public function getName(): string
+ {
+ return $this->Name;
+ }
+
+ public function setName(string $Name): self
+ {
+ $this->Name = $Name;
+ return $this;
+ }
+
+ public function getValue(): string
+ {
+ return $this->Value;
+ }
+
+ public function setValue(string $Value): self
+ {
+ $this->Value = $Value;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Name = $this->Name;
+ $out->Value = $this->Value;
+ return $out;
+ }
+}
diff --git a/src/Operator/Area.php b/src/Operator/Area.php
index d922cf5c..e9e866b2 100644
--- a/src/Operator/Area.php
+++ b/src/Operator/Area.php
@@ -20,23 +20,39 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class Area extends AbstractModel
+class Area extends AbstractType
{
- public string $ID = '';
- public string $PeerDatacenter = '';
- public array $RetryJoin = [];
- public bool $UseTLS = false;
+ public string $ID;
+ public string $PeerDatacenter;
+ /** @var array */
+ public array $RetryJoin;
+ public bool $UseTLS;
+
+ /**
+ * @param array $RetryJoin
+ */
+ public function __construct(
+ string $ID = '',
+ string $PeerDatacenter = '',
+ array $RetryJoin = [],
+ bool $UseTLS = false,
+ ) {
+ $this->ID = $ID;
+ $this->PeerDatacenter = $PeerDatacenter;
+ $this->setRetryJoin(...$RetryJoin);
+ $this->UseTLS = $UseTLS;
+ }
public function getID(): string
{
return $this->ID;
}
- public function setID(string $id): self
+ public function setID(string $ID): self
{
- $this->ID = $id;
+ $this->ID = $ID;
return $this;
}
@@ -45,20 +61,23 @@ public function getPeerDatacenter(): string
return $this->PeerDatacenter;
}
- public function setPeerDatacenter(string $peerDatacenter): self
+ public function setPeerDatacenter(string $PeerDatacenter): self
{
- $this->PeerDatacenter = $peerDatacenter;
+ $this->PeerDatacenter = $PeerDatacenter;
return $this;
}
+ /**
+ * @return array
+ */
public function getRetryJoin(): array
{
return $this->RetryJoin;
}
- public function setRetryJoin(array $retryJoin): self
+ public function setRetryJoin(string ...$RetryJoin): self
{
- $this->RetryJoin = $retryJoin;
+ $this->RetryJoin = $RetryJoin;
return $this;
}
@@ -67,9 +86,28 @@ public function isUseTLS(): bool
return $this->UseTLS;
}
- public function setUseTLS(bool $useTLS): self
+ public function setUseTLS(bool $UseTLS): self
{
- $this->UseTLS = $useTLS;
+ $this->UseTLS = $UseTLS;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->PeerDatacenter = $this->PeerDatacenter;
+ $out->RetryJoin = $this->RetryJoin;
+ $out->UseTLS = $this->UseTLS;
+ return $out;
+ }
}
diff --git a/src/Operator/AreaJoinResponse.php b/src/Operator/AreaJoinResponse.php
index 895c24e5..c1f0c815 100644
--- a/src/Operator/AreaJoinResponse.php
+++ b/src/Operator/AreaJoinResponse.php
@@ -20,26 +20,72 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AreaJoinResponse extends AbstractModel
+class AreaJoinResponse extends AbstractType
{
- public string $Address = '';
- public bool $Joined = false;
- public string $Error = '';
+ public string $Address;
+ public bool $Joined;
+ public string $Error;
+
+ public function __construct(
+ string $Address = '',
+ bool $Joined = false,
+ string $Error = '',
+ ) {
+ $this->Address = $Address;
+ $this->Joined = $Joined;
+ $this->Error = $Error;
+ }
public function getAddress(): string
{
return $this->Address;
}
+ public function setAddress(string $Address): self
+ {
+ $this->Address = $Address;
+ return $this;
+ }
+
public function isJoined(): bool
{
return $this->Joined;
}
+ public function setJoined(bool $Joined): self
+ {
+ $this->Joined = $Joined;
+ return $this;
+ }
+
public function getError(): string
{
return $this->Error;
}
+
+ public function setError(string $Error): self
+ {
+ $this->Error = $Error;
+ return $this;
+ }
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Address = $this->Address;
+ $out->Joined = $this->Joined;
+ $out->Error = $this->Error;
+ return $out;
+ }
}
diff --git a/src/Operator/AutopilotConfiguration.php b/src/Operator/AutopilotConfiguration.php
index 0e2916f6..08744dfa 100644
--- a/src/Operator/AutopilotConfiguration.php
+++ b/src/Operator/AutopilotConfiguration.php
@@ -20,35 +20,45 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\Go\Time;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AutopilotConfiguration extends AbstractModel
+class AutopilotConfiguration extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_LAST_CONTACT_THRESHOLD => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_SERVER_STABILIZATION_TIME => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- Transcoding::FIELD_NULLABLE => true,
- ],
- ];
-
- private const FIELD_LAST_CONTACT_THRESHOLD = 'LastContactThreshold';
- private const FIELD_SERVER_STABILIZATION_TIME = 'ServerStabilizationTime';
-
- public bool $CleanupDeadServers = false;
- public ?ReadableDuration $LastContactThreshold = null;
- public int $MaxTrailingLogs = 0;
- public int $MinQuorum = 0;
- public ?ReadableDuration $ServerStabilizationTime = null;
- public string $RedundancyZoneTag = '';
- public bool $DisableUpgradeMigration = false;
- public string $UpgradeVersionTag = '';
- public int $CreateIndex = 0;
- public int $ModifyIndex = 0;
+ public bool $CleanupDeadServers;
+ public null|Time\Duration $LastContactThreshold;
+ public int $MaxTrailingLogs;
+ public int $MinQuorum;
+ public null|Time\Duration $ServerStabilizationTime;
+ public string $RedundancyZoneTag;
+ public bool $DisableUpgradeMigration;
+ public string $UpgradeVersionTag;
+ public int $CreateIndex;
+ public int $ModifyIndex;
+
+ public function __construct(
+ bool $CleanupDeadServers = false,
+ null|string|int|float|\DateInterval|Time\Duration $LastContactThreshold = null,
+ int $MaxTrailingLogs = 0,
+ int $MinQuorum = 0,
+ null|string|int|float|\DateInterval|Time\Duration $ServerStabilizationTime = null,
+ string $RedundancyZoneTag = '',
+ bool $DisableUpgradeMigration = false,
+ string $UpgradeVersionTag = '',
+ int $CreateIndex = 0,
+ int $ModifyIndex = 0,
+ ) {
+ $this->CleanupDeadServers = $CleanupDeadServers;
+ $this->setLastContactThreshold($LastContactThreshold);
+ $this->MaxTrailingLogs = $MaxTrailingLogs;
+ $this->MinQuorum = $MinQuorum;
+ $this->setServerStabilizationTime($ServerStabilizationTime);
+ $this->RedundancyZoneTag = $RedundancyZoneTag;
+ $this->DisableUpgradeMigration = $DisableUpgradeMigration;
+ $this->UpgradeVersionTag = $UpgradeVersionTag;
+ $this->CreateIndex = $CreateIndex;
+ $this->ModifyIndex = $ModifyIndex;
+ }
public function isCleanupDeadServers(): bool
{
@@ -61,14 +71,18 @@ public function setCleanupDeadServers(bool $CleanupDeadServers): self
return $this;
}
- public function getLastContactThreshold(): ?ReadableDuration
+ public function getLastContactThreshold(): null|Time\Duration
{
return $this->LastContactThreshold;
}
- public function setLastContactThreshold(?ReadableDuration $LastContactThreshold): self
+ public function setLastContactThreshold(null|string|int|float|\DateInterval|Time\Duration $LastContactThreshold): self
{
- $this->LastContactThreshold = $LastContactThreshold;
+ if (null === $LastContactThreshold) {
+ $this->LastContactThreshold = null;
+ return $this;
+ }
+ $this->LastContactThreshold = Time::Duration($LastContactThreshold);
return $this;
}
@@ -94,14 +108,18 @@ public function setMinQuorum(int $MinQuorum): self
return $this;
}
- public function getServerStabilizationTime(): ?ReadableDuration
+ public function getServerStabilizationTime(): null|Time\Duration
{
return $this->ServerStabilizationTime;
}
- public function setServerStabilizationTime(?ReadableDuration $ServerStabilizationTime): self
+ public function setServerStabilizationTime(null|string|int|float|\DateInterval|Time\Duration $ServerStabilizationTime): self
{
- $this->ServerStabilizationTime = $ServerStabilizationTime;
+ if (null === $ServerStabilizationTime) {
+ $this->ServerStabilizationTime = null;
+ return $this;
+ }
+ $this->ServerStabilizationTime = Time::Duration($ServerStabilizationTime);
return $this;
}
@@ -159,4 +177,43 @@ public function setModifyIndex(int $ModifyIndex): self
$this->ModifyIndex = $ModifyIndex;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('LastContactThreshold' === $k) {
+ $n->setLastContactThreshold($v);
+ } elseif ('ServerStabilizationTime' === $k) {
+ $n->setServerStabilizationTime($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->CleanupDeadServers = $this->CleanupDeadServers;
+ if (null !== $this->LastContactThreshold) {
+ $out->LastContactThreshold = (string)$this->LastContactThreshold;
+ }
+ $out->MaxTrailingLogs = $this->MaxTrailingLogs;
+ $out->MinQuorum = $this->MinQuorum;
+ if (null !== $this->ServerStabilizationTime) {
+ $out->ServerStabilizationTime = (string)$this->ServerStabilizationTime;
+ }
+ if ('' !== $this->RedundancyZoneTag) {
+ $out->RedundancyZoneTag = $this->RedundancyZoneTag;
+ }
+ $out->DisableUpgradeMigration = $this->DisableUpgradeMigration;
+ if ('' !== $this->UpgradeVersionTag) {
+ $out->UpgradeVersionTag = $this->UpgradeVersionTag;
+ }
+ $out->CreateIndex = $this->CreateIndex;
+ $out->ModifyIndex = $this->ModifyIndex;
+ return $out;
+ }
}
diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php
index 3e0ff8d0..e772131a 100644
--- a/src/Operator/AutopilotServer.php
+++ b/src/Operator/AutopilotServer.php
@@ -21,51 +21,67 @@
*/
use DCarbone\Go\Time;
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
+use DCarbone\PHPConsulAPI\PHPLib\MetaField;
+use function DCarbone\PHPConsulAPI\PHPLib\parse_time;
-class AutopilotServer extends AbstractModel implements \JsonSerializable
+class AutopilotServer extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_LAST_CONTACT => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'],
- Transcoding::FIELD_NULLABLE => true,
- ],
- self::FIELD_STABLE_SINCE => [
- Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_TIME,
- ],
- self::FIELD_REDUNDANCY_ZONE => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_UPGRADE_VERSION => Transcoding::OMITEMPTY_STRING_FIELD,
- ];
-
- private const FIELD_LAST_CONTACT = 'LastContact';
- private const FIELD_STABLE_SINCE = 'StableSince';
- private const FIELD_REDUNDANCY_ZONE = 'RedundancyZone';
- private const FIELD_UPGRADE_VERSION = 'UpgradeVersion';
-
- public string $ID = '';
- public string $Name = '';
- public string $Address = '';
- public string $NodeStatus = '';
- public string $Version = '';
- public ?ReadableDuration $LastContact = null;
- public int $LastTerm = 0;
- public int $LastIndex = 0;
- public bool $Healthy = false;
+ use MetaField;
+
+ public string $ID;
+ public string $Name;
+ public string $Address;
+ public string $NodeStatus;
+ public string $Version;
+ public null|Time\Duration $LastContact = null;
+ public int $LastTerm;
+ public int $LastIndex;
+ public bool $Healthy;
public Time\Time $StableSince;
- public string $RedundancyZone = '';
- public string $UpgradeVersion = '';
- public bool $ReadReplica = false;
- public string $Status = '';
- public array $Meta = [];
- public string $NodeType = '';
-
- public function __construct(?array $data = [])
- {
- parent::__construct($data);
- if (!isset($this->StableSince)) {
- $this->StableSince = Time::New();
- }
+ public string $RedundancyZone;
+ public string $UpgradeVersion;
+ public bool $ReadReplica;
+ public AutopilotServerStatus $Status;
+ public AutopilotServerType $NodeType;
+
+ /**
+ * @param \stdClass|array|null $Meta
+ */
+ public function __construct(
+ string $ID = '',
+ string $Name = '',
+ string $Address = '',
+ string $NodeStatus = '',
+ string $Version = '',
+ null|string|int|float|\DateInterval|Time\Duration $LastContact = null,
+ int $LastTerm = 0,
+ int $LastIndex = 0,
+ bool $Healthy = false,
+ null|Time\Time $StableSince = null,
+ string $RedundancyZone = '',
+ string $UpgradeVersion = '',
+ bool $readReplica = false,
+ string|AutopilotServerStatus $status = AutopilotServerStatus::UNDEFINED,
+ null|\stdClass|array $Meta = null,
+ string|AutopilotServerType $NodeType = AutopilotServerType::UNDEFINED,
+ ) {
+ $this->ID = $ID;
+ $this->Name = $Name;
+ $this->Address = $Address;
+ $this->NodeStatus = $NodeStatus;
+ $this->Version = $Version;
+ $this->setLastContact($LastContact);
+ $this->LastTerm = $LastTerm;
+ $this->LastIndex = $LastIndex;
+ $this->Healthy = $Healthy;
+ $this->StableSince = $StableSince ?? new TIme\Time();
+ $this->RedundancyZone = $RedundancyZone;
+ $this->UpgradeVersion = $UpgradeVersion;
+ $this->ReadReplica = $readReplica;
+ $this->setStatus($status);
+ $this->setMeta($Meta);
+ $this->setNodeType($NodeType);
}
public function getID(): string
@@ -123,14 +139,18 @@ public function setVersion(string $Version): self
return $this;
}
- public function getLastContact(): ?ReadableDuration
+ public function getLastContact(): null|Time\Duration
{
return $this->LastContact;
}
- public function setLastContact(?ReadableDuration $LastContact): self
+ public function setLastContact(null|string|int|float|\DateInterval|Time\Duration $LastContact): self
{
- $this->LastContact = $LastContact;
+ if (null === $LastContact) {
+ $this->LastContact = null;
+ return $this;
+ }
+ $this->LastContact = Time::Duration($LastContact);
return $this;
}
@@ -211,45 +231,71 @@ public function setReadReplica(bool $ReadReplica): self
return $this;
}
- public function getStatus(): string
+ public function getStatus(): AutopilotServerStatus
{
return $this->Status;
}
- public function setStatus(string $Status): self
+ public function setStatus(string|AutopilotServerStatus $Status): self
{
- $this->Status = $Status;
+ $this->Status = is_string($Status) ? AutopilotServerStatus::from($Status) : $Status;
return $this;
}
- public function getMeta(): array
- {
- return $this->Meta;
- }
-
- public function setMeta(array $Meta): self
- {
- $this->Meta = $Meta;
- return $this;
- }
-
- public function getNodeType(): string
+ public function getNodeType(): AutopilotServerType
{
return $this->NodeType;
}
- public function setNodeType(string $NodeType): self
+ public function setNodeType(string|AutopilotServerType $NodeType): self
{
- $this->NodeType = $NodeType;
+ $this->NodeType = is_string($NodeType) ? AutopilotServerType::from($NodeType) : $NodeType;
return $this;
}
- public function jsonSerialize(): array
- {
- $arr = parent::jsonSerialize();
- if (isset($this->StableSince)) {
- $arr[self::FIELD_STABLE_SINCE] = $this->StableSince->format(Time\Time::DefaultFormat);
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('lastContact' === $k) {
+ $n->setLastContact($v);
+ } elseif ('StableSince' === $k) {
+ $n->StableSince = parse_time($v);
+ } elseif ('Meta' === $k) {
+ $n->setMeta($v);
+ } elseif ('Status' === $k) {
+ $n->setStatus($v);
+ } elseif ('NodeType' === $k) {
+ $n->setNodeType($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->ID = $this->ID;
+ $out->Name = $this->Name;
+ $out->Address = $this->Address;
+ $out->NodeStatus = $this->NodeStatus;
+ $out->Version = $this->Version;
+ $out->lastContact = null !== $this->LastContact ? (string)$this->LastContact : null;
+ $out->LastTerm = $this->LastTerm;
+ $out->LastIndex = $this->LastIndex;
+ $out->Healthy = $this->Healthy;
+ $out->StableSince = $this->StableSince;
+ if ('' !== $this->RedundancyZone) {
+ $out->RedundancyZone = $this->RedundancyZone;
+ }
+ if ('' !== $this->UpgradeVersion) {
+ $out->UpgradeVersion = $this->UpgradeVersion;
}
- return $arr;
+ $out->ReadReplica = $this->ReadReplica;
+ $out->Meta = $this->getMeta();
+ $out->NodeType = $this->NodeType;
+ return $out;
}
}
diff --git a/src/Operator/AutopilotServerStatus.php b/src/Operator/AutopilotServerStatus.php
new file mode 100644
index 00000000..e16fbaa1
--- /dev/null
+++ b/src/Operator/AutopilotServerStatus.php
@@ -0,0 +1,32 @@
+Tags = $tags;
- return $this;
- }
-
- public function addTag(string $tag): static
- {
- $this->Tags[] = $tag;
- return $this;
- }
+ case Voter = 'voter';
+ case ReadReplica = 'read-replica';
+ case ZoneVoter = 'zone-voter';
+ case ZoneExtraVoter = 'zone-extra-voter';
+ case ZoneStandby = 'zone-standby';
+
+ case UNDEFINED = '';
}
diff --git a/src/Operator/AutopilotState.php b/src/Operator/AutopilotState.php
index 881d8247..03437e79 100644
--- a/src/Operator/AutopilotState.php
+++ b/src/Operator/AutopilotState.php
@@ -20,47 +20,51 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AutopilotState extends AbstractModel
+class AutopilotState extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_SERVERS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AutopilotServer::class,
- ],
- self::FIELD_READ_REPLICAS => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::STRING,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_REDUNDANCY_ZONE => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AutopilotZone::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- self::FIELD_UPGRADE => [
- Transcoding::FIELD_TYPE => Transcoding::OBJECT,
- Transcoding::FIELD_CLASS => AutopilotUpgrade::class,
- Transcoding::FIELD_OMITEMPTY => true,
- ],
- ];
-
- private const FIELD_SERVERS = 'Servers';
- private const FIELD_READ_REPLICAS = 'ReadReplicas';
- private const FIELD_REDUNDANCY_ZONE = 'RedundancyZone';
- private const FIELD_UPGRADE = 'Upgrade';
-
- public bool $Healthy = false;
- public int $FailureTolerance = 0;
- public int $OptimisticFailureTolerance = 0;
- public array $Servers = [];
- public string $Leader = '';
- public array $Voters = [];
- public array $ReadReplicas = [];
- public array $RedundancyZone = [];
- public ?AutopilotUpgrade $Upgrade = null;
+ public bool $Healthy;
+ public int $FailureTolerance;
+ public int $OptimisticFailureTolerance;
+ /** @var array */
+ public array $Servers;
+ public string $Leader;
+ /** @var array */
+ public array $Voters;
+ /** @var array */
+ public array $ReadReplicas;
+ /** @var array */
+ public array $RedundancyZone;
+ public null|AutopilotUpgrade $Upgrade;
+
+ /**
+ * @param array $Servers
+ * @param array $Voters
+ * @param array $ReadReplicas
+ * @param array $RedundancyZone
+ */
+ public function __construct(
+ bool $Healthy = false,
+ int $FailureTolerance = 0,
+ int $OptimisticFailureTolerance = 0,
+ array $Servers = [],
+ string $Leader = '',
+ array $Voters = [],
+ array $ReadReplicas = [],
+ array $RedundancyZone = [],
+ null|AutopilotUpgrade $Upgrade = null,
+ ) {
+ $this->Healthy = $Healthy;
+ $this->FailureTolerance = $FailureTolerance;
+ $this->OptimisticFailureTolerance = $OptimisticFailureTolerance;
+ $this->Servers = $Servers;
+ $this->Leader = $Leader;
+ $this->setVoters(...$Voters);
+ $this->setReadReplicas(...$ReadReplicas);
+ $this->RedundancyZone = $RedundancyZone;
+ $this->Upgrade = $Upgrade;
+ }
public function isHealthy(): bool
{
@@ -95,11 +99,17 @@ public function setOptimisticFailureTolerance(int $OptimisticFailureTolerance):
return $this;
}
+ /**
+ * @return array
+ */
public function getServers(): array
{
return $this->Servers;
}
+ /**
+ * @param array $Servers
+ */
public function setServers(array $Servers): self
{
$this->Servers = $Servers;
@@ -117,47 +127,103 @@ public function setLeader(string $Leader): self
return $this;
}
+ /**
+ * @return array
+ */
public function getVoters(): array
{
return $this->Voters;
}
- public function setVoters(array $Voters): self
+ public function setVoters(string ...$Voters): self
{
$this->Voters = $Voters;
return $this;
}
+ /**
+ * @return array
+ */
public function getReadReplicas(): array
{
return $this->ReadReplicas;
}
- public function setReadReplicas(array $ReadReplicas): self
+ public function setReadReplicas(string ...$ReadReplicas): self
{
$this->ReadReplicas = $ReadReplicas;
return $this;
}
+ /**
+ * @return array
+ */
public function getRedundancyZone(): array
{
return $this->RedundancyZone;
}
+ /**
+ * @param array $RedundancyZone
+ */
public function setRedundancyZone(array $RedundancyZone): self
{
$this->RedundancyZone = $RedundancyZone;
return $this;
}
- public function getUpgrade(): ?AutopilotUpgrade
+ public function getUpgrade(): null|AutopilotUpgrade
{
return $this->Upgrade;
}
- public function setUpgrade(?AutopilotUpgrade $Upgrade): self
+ public function setUpgrade(null|AutopilotUpgrade $Upgrade): self
{
$this->Upgrade = $Upgrade;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('Servers' === $k) {
+ $n->Servers = [];
+ foreach ($v as $sk => $sv) {
+ $n->Servers[$sk] = AutopilotServer::jsonUnserialize($sv);
+ }
+ } elseif ('RedundancyZone' === $k) {
+ $n->RedundancyZone = [];
+ foreach ($v as $zk => $zv) {
+ $n->RedundancyZone[$zk] = AutopilotZone::jsonUnserialize($zv);
+ }
+ } elseif ('Upgrade' === $k) {
+ $n->Upgrade = null === $v ? null : AutopilotUpgrade::jsonUnserialize($v);
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Healthy = $this->Healthy;
+ $out->FailureTolerance = $this->FailureTolerance;
+ $out->OptimisticFailureTolerance = $this->OptimisticFailureTolerance;
+ $out->Servers = $this->Servers;
+ $out->Leader = $this->Leader;
+ $out->Voters = $this->Voters;
+ if ([] !== $this->ReadReplicas) {
+ $out->ReadReplicas = $this->ReadReplicas;
+ }
+ if ([] !== $this->RedundancyZone) {
+ $out->RedundancyZone = $this->RedundancyZone;
+ }
+ if (null !== $this->Upgrade) {
+ $out->Upgrade = $this->Upgrade;
+ }
+ return $out;
+ }
}
diff --git a/src/Operator/AutopilotStateResponse.php b/src/Operator/AutopilotStateResponse.php
index bf4add88..e889a8e0 100644
--- a/src/Operator/AutopilotStateResponse.php
+++ b/src/Operator/AutopilotStateResponse.php
@@ -20,20 +20,20 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractValuedResponse;
-use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractValuedResponse;
+use DCarbone\PHPConsulAPI\PHPLib\UnmarshalledResponseInterface;
class AutopilotStateResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface
{
- public ?AutopilotState $AutopilotState = null;
+ public null|AutopilotState $AutopilotState;
- public function getValue(): ?AutopilotState
+ public function getValue(): null|AutopilotState
{
return $this->AutopilotState;
}
- public function unmarshalValue(mixed $decodedData): void
+ public function unmarshalValue(mixed $decoded): void
{
- $this->AutopilotState = new AutopilotState($decodedData);
+ $this->AutopilotState = AutopilotState::jsonUnserialize($decoded);
}
}
diff --git a/src/Operator/AutopilotUpgrade.php b/src/Operator/AutopilotUpgrade.php
index fa372a69..0d789a77 100644
--- a/src/Operator/AutopilotUpgrade.php
+++ b/src/Operator/AutopilotUpgrade.php
@@ -20,44 +20,57 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AutopilotUpgrade extends AbstractModel
+class AutopilotUpgrade extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_TARGET_VERSION => Transcoding::OMITEMPTY_STRING_FIELD,
- self::FIELD_TARGET_VERSION_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_TARGET_VERSION_NON_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_TARGET_VERSION_READ_REPLICAS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_OTHER_VERSION_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_OTHER_VERSION_NON_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_OTHER_VERSION_READ_REPLICAS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_REDUNDANCY_ZONES => [
- Transcoding::FIELD_TYPE => Transcoding::ARRAY,
- Transcoding::FIELD_CLASS => AutopilotZoneUpgradeVersions::class,
- Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT,
- ],
- ];
-
- private const FIELD_TARGET_VERSION = 'TargetVersion';
- private const FIELD_TARGET_VERSION_VOTERS = 'TargetVersionVoters';
- private const FIELD_TARGET_VERSION_NON_VOTERS = 'TargetVersionNonVoters';
- private const FIELD_TARGET_VERSION_READ_REPLICAS = 'TargetVersionReadReplicas';
- private const FIELD_OTHER_VERSION_VOTERS = 'OtherVersionVoters';
- private const FIELD_OTHER_VERSION_NON_VOTERS = 'OtherVersionNonVoters';
- private const FIELD_OTHER_VERSION_READ_REPLICAS = 'OtherVersionReadReplicas';
- private const FIELD_REDUNDANCY_ZONES = 'RedundancyZones';
-
- public string $Status = '';
- public string $TargetVersion = '';
- public array $TargetVersionVoters = [];
- public array $TargetVersionNonVoters = [];
- public array $TargetVersionReadReplicas = [];
- public array $OtherVersionVoters = [];
- public array $OtherVersionNonVoters = [];
- public array $OtherVersionReadReplicas = [];
- public array $RedundancyZones = [];
+ public string $Status;
+ public string $TargetVersion;
+ /** @var array */
+ public array $TargetVersionVoters;
+ /** @var array */
+ public array $TargetVersionNonVoters;
+ /** @var array */
+ public array $TargetVersionReadReplicas;
+ /** @var array */
+ public array $OtherVersionVoters;
+ /** @var array */
+ public array $OtherVersionNonVoters;
+ /** @var array */
+ public array $OtherVersionReadReplicas;
+ /** @var array */
+ public array $RedundancyZones;
+
+ /**
+ * @param array $TargetVersionVoters
+ * @param array $TargetVersionNonVoters
+ * @param array $TargetVersionReadReplicas
+ * @param array $OtherVersionVoters
+ * @param array $OtherVersionNonVoters
+ * @param array $OtherVersionReadReplicas
+ * @param array $RedundancyZones
+ */
+ public function __construct(
+ string $Status = '',
+ string $TargetVersion = '',
+ array $TargetVersionVoters = [],
+ array $TargetVersionNonVoters = [],
+ array $TargetVersionReadReplicas = [],
+ array $OtherVersionVoters = [],
+ array $OtherVersionNonVoters = [],
+ array $OtherVersionReadReplicas = [],
+ array $RedundancyZones = [],
+ ) {
+ $this->Status = $Status;
+ $this->TargetVersion = $TargetVersion;
+ $this->setTargetVersionVoters(...$TargetVersionVoters);
+ $this->setTargetVersionNonVoters(...$TargetVersionNonVoters);
+ $this->setTargetVersionReadReplicas(...$TargetVersionReadReplicas);
+ $this->setOtherVersionVoters(...$OtherVersionVoters);
+ $this->setOtherVersionNonVoters(...$OtherVersionNonVoters);
+ $this->setOtherVersionReadReplicas(...$OtherVersionReadReplicas);
+ $this->RedundancyZones = $RedundancyZones;
+ }
public function getStatus(): string
{
@@ -81,80 +94,151 @@ public function setTargetVersion(string $TargetVersion): self
return $this;
}
+ /**
+ * @return array
+ */
public function getTargetVersionVoters(): array
{
return $this->TargetVersionVoters;
}
- public function setTargetVersionVoters(array $TargetVersionVoters): self
+ public function setTargetVersionVoters(string ...$TargetVersionVoters): self
{
$this->TargetVersionVoters = $TargetVersionVoters;
return $this;
}
+ /**
+ * @return array
+ */
public function getTargetVersionNonVoters(): array
{
return $this->TargetVersionNonVoters;
}
- public function setTargetVersionNonVoters(array $TargetVersionNonVoters): self
+ public function setTargetVersionNonVoters(string ...$TargetVersionNonVoters): self
{
$this->TargetVersionNonVoters = $TargetVersionNonVoters;
return $this;
}
+ /**
+ * @return array
+ */
public function getTargetVersionReadReplicas(): array
{
return $this->TargetVersionReadReplicas;
}
- public function setTargetVersionReadReplicas(array $TargetVersionReadReplicas): self
+ public function setTargetVersionReadReplicas(string ...$TargetVersionReadReplicas): self
{
$this->TargetVersionReadReplicas = $TargetVersionReadReplicas;
return $this;
}
+ /**
+ * @return array
+ */
public function getOtherVersionVoters(): array
{
return $this->OtherVersionVoters;
}
- public function setOtherVersionVoters(array $OtherVersionVoters): self
+ public function setOtherVersionVoters(string ...$OtherVersionVoters): self
{
$this->OtherVersionVoters = $OtherVersionVoters;
return $this;
}
+ /**
+ * @return array
+ */
public function getOtherVersionNonVoters(): array
{
return $this->OtherVersionNonVoters;
}
- public function setOtherVersionNonVoters(array $OtherVersionNonVoters): self
+ public function setOtherVersionNonVoters(string ...$OtherVersionNonVoters): self
{
$this->OtherVersionNonVoters = $OtherVersionNonVoters;
return $this;
}
+ /**
+ * @return array
+ */
public function getOtherVersionReadReplicas(): array
{
return $this->OtherVersionReadReplicas;
}
- public function setOtherVersionReadReplicas(array $OtherVersionReadReplicas): self
+ public function setOtherVersionReadReplicas(string ...$OtherVersionReadReplicas): self
{
$this->OtherVersionReadReplicas = $OtherVersionReadReplicas;
return $this;
}
+ /**
+ * @return array
+ */
public function getRedundancyZones(): array
{
return $this->RedundancyZones;
}
+ /**
+ * @param array $RedundancyZones
+ */
public function setRedundancyZones(array $RedundancyZones): self
{
$this->RedundancyZones = $RedundancyZones;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ if ('RedundancyZones' === $k) {
+ $n->RedundancyZones = [];
+ foreach ($v as $zk => $zv) {
+ $n->RedundancyZones[$zk] = AutopilotZoneUpgradeVersions::jsonUnserialize($zv);
+ }
+ } else {
+ $n->{$k} = $v;
+ }
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Status = $this->Status;
+ if ('' !== $this->TargetVersion) {
+ $out->TargetVersion = $this->TargetVersion;
+ }
+ if ([] !== $this->TargetVersionVoters) {
+ $out->TargetVersionVoters = $this->TargetVersionVoters;
+ }
+ if ([] !== $this->TargetVersionNonVoters) {
+ $out->TargetVersionNonVoters = $this->TargetVersionNonVoters;
+ }
+ if ([] !== $this->TargetVersionReadReplicas) {
+ $out->TargetVersionReadReplicas = $this->TargetVersionReadReplicas;
+ }
+ if ([] !== $this->OtherVersionVoters) {
+ $out->OtherVersionVoters = $this->OtherVersionVoters;
+ }
+ if ([] !== $this->OtherVersionNonVoters) {
+ $out->OtherVersionNonVoters = $this->OtherVersionNonVoters;
+ }
+ if ([] !== $this->OtherVersionReadReplicas) {
+ $out->OtherVersionReadReplicas = $this->OtherVersionReadReplicas;
+ }
+ if ([] !== $this->RedundancyZones) {
+ $out->RedundancyZones = $this->RedundancyZones;
+ }
+ return $out;
+ }
}
diff --git a/src/Operator/AutopilotUpgradeStatus.php b/src/Operator/AutopilotUpgradeStatus.php
new file mode 100644
index 00000000..1c40f86f
--- /dev/null
+++ b/src/Operator/AutopilotUpgradeStatus.php
@@ -0,0 +1,33 @@
+ */
+ public array $Servers;
+ /** @var array */
+ public array $Voters;
+ public int $FailureTolerance;
+ /**
+ * @param array $Servers
+ * @param array $Voters
+ */
+ public function __construct(
+ array $Servers = [],
+ array $Voters = [],
+ int $FailureTolerance = 0,
+ ) {
+ $this->setServers(...$Servers);
+ $this->setVoters(...$Voters);
+ $this->FailureTolerance = $FailureTolerance;
+ }
+
+ /**
+ * @return array
+ */
public function getServers(): array
{
return $this->Servers;
}
- public function setServers(array $Servers): self
+ public function setServers(string ...$Servers): self
{
$this->Servers = $Servers;
return $this;
}
+ /**
+ * @return array
+ */
public function getVoters(): array
{
return $this->Voters;
}
- public function setVoters(array $Voters): self
+ public function setVoters(string ...$Voters): self
{
$this->Voters = $Voters;
return $this;
@@ -60,4 +82,22 @@ public function setFailureTolerance(int $FailureTolerance): self
$this->FailureTolerance = $FailureTolerance;
return $this;
}
+
+ public static function jsonUnserialize(\stdClass $decoded): self
+ {
+ $n = new self();
+ foreach ((array)$decoded as $k => $v) {
+ $n->{$k} = $v;
+ }
+ return $n;
+ }
+
+ public function jsonSerialize(): \stdClass
+ {
+ $out = $this->_startJsonSerialize();
+ $out->Servers = $this->Servers;
+ $out->Voters = $this->Voters;
+ $out->FailureTolerance = $this->FailureTolerance;
+ return $out;
+ }
}
diff --git a/src/Operator/AutopilotZoneUpgradeVersions.php b/src/Operator/AutopilotZoneUpgradeVersions.php
index 9b07c349..9a3272a1 100644
--- a/src/Operator/AutopilotZoneUpgradeVersions.php
+++ b/src/Operator/AutopilotZoneUpgradeVersions.php
@@ -20,69 +20,117 @@
limitations under the License.
*/
-use DCarbone\PHPConsulAPI\AbstractModel;
-use DCarbone\PHPConsulAPI\Transcoding;
+use DCarbone\PHPConsulAPI\PHPLib\AbstractType;
-class AutopilotZoneUpgradeVersions extends AbstractModel
+class AutopilotZoneUpgradeVersions extends AbstractType
{
- protected const FIELDS = [
- self::FIELD_TARGET_VERSION_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_TARGET_VERSION_NON_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_OTHER_VERSION_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- self::FIELD_OTHER_VERSION_NON_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD,
- ];
-
- private const FIELD_TARGET_VERSION_VOTERS = 'TargetVersionVoters';
- private const FIELD_TARGET_VERSION_NON_VOTERS = 'TargetVersionNonVoters';
- private const FIELD_OTHER_VERSION_VOTERS = 'OtherVersionVoters';
- private const FIELD_OTHER_VERSION_NON_VOTERS = 'OtherVersionNonVoters';
-
- public array $TargetVersionVoters = [];
- public array $TargetVersionNonVoters = [];
- public array $OtherVersionVoters = [];
- public array $OtherVersionNonVoters = [];
+ /** @var array