From cc0831e0ae7c20fc1688ab1d4fd0d61fcc89f96f Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 20:41:42 -0500 Subject: [PATCH 01/79] working on v3 --- composer.lock | 508 ++++++++---------- src/ACL/ACLAuthMethod.php | 146 +++-- src/ACL/ACLAuthMethodListEntry.php | 104 ++-- .../ACLAuthMethodListEntryQueryResponse.php | 7 +- src/ACL/ACLAuthMethodNamespaceRule.php | 41 +- src/ACL/ACLAuthMethodQueryResponse.php | 10 +- src/ACL/ACLAuthMethodWriteResponse.php | 10 +- src/ACL/ACLBindingRule.php | 76 ++- src/ACL/ACLBindingRuleQueryResponse.php | 8 +- src/ACL/ACLBindingRuleWriteResponse.php | 10 +- src/ACL/ACLBindingRulesQueryResponse.php | 6 +- src/ACL/ACLClient.php | 80 +-- src/ACL/ACLEntriesResponse.php | 4 +- src/ACL/ACLEntry.php | 52 +- src/ACL/ACLLink.php | 42 +- src/ACL/ACLLoginParams.php | 55 +- src/ACL/ACLNodeIdentity.php | 30 +- src/ACL/ACLOIDCAuthURLParams.php | 65 ++- src/ACL/ACLOIDCCallbackParams.php | 42 +- src/ACL/ACLPolicy.php | 83 ++- src/ACL/ACLPolicyListEntry.php | 77 ++- src/ACL/ACLPolicyListEntryQueryResponse.php | 7 +- src/ACL/ACLPolicyQueryResponse.php | 10 +- src/ACL/ACLPolicyWriteResponse.php | 10 +- src/ACL/ACLReplicationStatus.php | 84 ++- src/ACL/ACLReplicationStatusResponse.php | 10 +- src/ACL/ACLRole.php | 128 +++-- src/ACL/ACLRoleQueryResponse.php | 10 +- src/ACL/ACLRoleWriteResponse.php | 10 +- src/ACL/ACLRolesQueryResponse.php | 7 +- src/ACL/ACLServiceIdentity.php | 51 +- src/ACL/ACLToken.php | 229 +++++--- src/ACL/ACLTokenListEntry.php | 196 ++++--- src/ACL/ACLTokenListEntryQueryResponse.php | 7 +- src/ACL/ACLTokenQueryResponse.php | 10 +- src/ACL/ACLTokenWriteResponse.php | 8 +- src/ACL/KubernetesAuthMethodConfig.php | 66 ++- src/ACL/OIDCAuthMethodConfig.php | 17 + src/AbstractClient.php | 29 +- src/AbstractModel.php | 53 +- src/AbstractValuedQueryResponse.php | 2 +- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentCheckRegistration.php | 2 +- src/Agent/AgentService.php | 2 +- src/Agent/AgentServiceCheck.php | 2 +- src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 2 +- src/Agent/AgentServiceConnectProxyConfig.php | 2 +- src/Agent/AgentServiceRegistration.php | 2 +- src/Agent/EnvoyExtension.php | 2 +- src/Agent/MetricsInfo.php | 2 +- src/Agent/Upstream.php | 2 +- src/Catalog/CatalogDeregistration.php | 2 +- src/Catalog/CatalogNode.php | 2 +- src/Catalog/CatalogNodeServiceList.php | 2 +- src/Catalog/CatalogRegistration.php | 2 +- src/Catalog/CatalogService.php | 2 +- src/Catalog/CompoundServiceName.php | 2 +- src/Catalog/GatewayService.php | 2 +- src/Catalog/Node.php | 2 +- src/Config.php | 238 ++++---- src/ConfigEntry/ExposeConfig.php | 2 +- src/ConfigEntry/ExposePath.php | 2 +- src/ConfigEntry/MeshConfigEntry.php | 2 +- src/ConfigEntry/MeshGatewayConfig.php | 2 +- src/ConfigEntry/PassiveHealthCheck.php | 2 +- src/ConfigEntry/ProxyConfigEntry.php | 2 +- src/ConfigEntry/RingHashConfig.php | 2 +- src/ConfigEntry/ServiceConfigEntry.php | 2 +- src/ConfigEntry/ServiceResolverFailover.php | 2 +- src/ConfigEntry/ServiceResolverRedirect.php | 2 +- src/ConfigEntry/ServiceResolverSubset.php | 2 +- src/ConfigEntry/ServiceRoute.php | 2 +- src/ConfigEntry/ServiceRouteDestination.php | 2 +- src/ConfigEntry/ServiceRouteHTTPMatch.php | 2 +- .../ServiceRouteHTTPMatchHeader.php | 2 +- .../ServiceRouteHTTPMatchQueryParam.php | 2 +- src/ConfigEntry/ServiceRouteMatch.php | 2 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 2 +- src/ConfigEntry/ServiceSplit.php | 2 +- .../ServiceSplitterConfigEntry.php | 2 +- src/ConfigEntry/TransparentProxyConfig.php | 2 +- src/ConfigEntry/UpstreamConfiguration.php | 2 +- src/ConfigEntry/UpstreamLimits.php | 2 +- src/Coordinate/CoordinateDatacenterMap.php | 2 +- src/Coordinate/CoordinateEntry.php | 2 +- src/FakeMap.php | 108 ---- src/FakeSlice.php | 188 ------- src/Health/HealthCheck.php | 2 +- src/Health/HealthCheckDefinition.php | 2 +- src/Health/ServiceEntry.php | 2 +- src/KV/CheckTxnOp.php | 2 +- src/KV/KVPair.php | 2 +- src/KV/KVTxnResponse.php | 2 +- src/KV/NodeTxnOp.php | 2 +- src/KV/ServiceTxnOp.php | 2 +- src/KV/TxnOp.php | 2 +- src/KV/TxnResponse.php | 2 +- src/KV/TxnResult.php | 2 +- src/Marshaller.php | 42 +- src/Operator/AutopilotConfiguration.php | 2 +- src/Operator/AutopilotServer.php | 2 +- src/Operator/AutopilotState.php | 2 +- src/Operator/AutopilotUpgrade.php | 2 +- src/Operator/AutopilotZoneUpgradeVersions.php | 2 +- src/Operator/OperatorHealthReply.php | 2 +- src/Operator/RaftConfiguration.php | 2 +- src/Operator/SerfMember.php | 2 +- src/Operator/ServerHealth.php | 2 +- src/PreparedQuery/PreparedQueryDefinition.php | 2 +- .../PreparedQueryExecuteResponse.php | 2 +- src/PreparedQuery/ServiceQuery.php | 2 +- src/QueryOptions.php | 2 +- src/QueryResponseInterface.php | 26 + src/Session/SessionEntry.php | 2 +- src/Unmarshaller.php | 99 ++-- src/WriteResponse.php | 2 +- src/WriteResponseInterface.php | 26 + tools/php-cs-fixer/composer.lock | 200 +++---- 119 files changed, 1912 insertions(+), 1555 deletions(-) delete mode 100644 src/FakeMap.php delete mode 100644 src/FakeSlice.php create mode 100644 src/QueryResponseInterface.php create mode 100644 src/WriteResponseInterface.php diff --git a/composer.lock b/composer.lock index c2e968d1..ec3229c1 100644 --- a/composer.lock +++ b/composer.lock @@ -943,35 +943,35 @@ }, { "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 +980,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "11.0.x-dev" + "dev-main": "10.1.x-dev" } }, "autoload": { @@ -1009,7 +1009,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 +1017,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 +1070,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 +1078,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 +1107,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -1133,8 +1133,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 +1141,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 +1193,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 +1201,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 +1252,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 +1260,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.45", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c" + "reference": "bd68a781d8e30348bc297449f5234b3458267ae8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c", - "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bd68a781d8e30348bc297449f5234b3458267ae8", + "reference": "bd68a781d8e30348bc297449f5234b3458267ae8", "shasum": "" }, "require": { @@ -1285,26 +1283,26 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.13.0", + "myclabs/deep-copy": "^1.12.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 +1313,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "11.5-dev" + "dev-main": "10.5-dev" } }, "autoload": { @@ -1347,7 +1345,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.45" }, "funding": [ { @@ -1363,32 +1361,32 @@ "type": "tidelift" } ], - "time": "2025-03-23T16:02:11+00:00" + "time": "2025-02-06T16:08:12+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 +1410,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 +1418,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 +1466,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 +1474,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 +1521,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 +1529,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 +1598,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 +1606,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 +1656,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 +1664,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 +1723,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 +1731,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 +1759,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "7.2-dev" + "dev-main": "6.1-dev" } }, "autoload": { @@ -1794,7 +1787,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 +1795,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 +1865,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 +1873,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 +1927,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 +1935,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 +1985,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 +1993,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 +2042,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 +2050,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 +2097,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 +2105,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 +2160,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 +2168,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 +2216,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 +2224,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 +2269,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 +2277,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/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index bb7d2d9d..4433978a 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -22,54 +22,46 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLAuthMethod extends AbstractModel { - 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 $ID; + 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 string $TokenLocality; + public array $config; + public int $CreateIndex; + public int $ModifyIndex; + public array $NamespaceRules; + public string $Namespace; + + public function __construct( + string $ID = '', + 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, + iterable $NamespaceRules = [], + string $Namespace = '' + ) { + $this->ID = $ID; + $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->setNamespaceRules(...$NamespaceRules); + $this->Namespace = $Namespace; } public function getID(): string @@ -132,9 +124,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; } @@ -187,9 +179,15 @@ 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 +201,56 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + switch ($k) { + case 'MaxTokenTTL': + $n->setMaxTokenTTL($v); + break; + case 'NamespaceRules': + foreach ($v as $vv) { + $n->addNamespaceRule(ACLAuthMethodNamespaceRule::jsonUnserialize($vv)); + } + break; + + default: + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ID = $this->ID; + $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->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + if ([] !== $this->NamespaceRules) { + $out->NamespaceRules = $this->NamespaceRules; + } + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + return $out; + } } diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 3a54d9f7..809b2f71 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -22,32 +22,13 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLAuthMethodListEntry extends AbstractModel { - 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. @@ -55,9 +36,31 @@ class ACLAuthMethodListEntry extends AbstractModel * @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,9 +111,9 @@ 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; } @@ -171,13 +174,46 @@ 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 static(); + foreach ($decoded as $k => $v) { + if (null === $v) { + continue; + } + if ('MaxTokenTTL' === $k) { + $n->setMaxTokenTTL($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..9d37f527 100644 --- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php +++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php @@ -25,18 +25,17 @@ class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $ACLAuthMethodListEntries = []; + public array $ACLAuthMethodListEntries = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLAuthMethodListEntries; } public function unmarshalValue(mixed $decodedData): void { - $this->ACLAuthMethodListEntries = []; foreach ($decodedData as $datum) { - $this->ACLAuthMethodListEntries[] = new ACLAuthMethodListEntry($datum); + $this->ACLAuthMethodListEntries[] = ACLAuthMethodListEntry::jsonUnserialize($datum); } } } diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index c6b76694..387c000e 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -21,20 +21,17 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLAuthMethodNamespaceRule extends AbstractModel { - 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,28 @@ public function setBindNamespace(string $BindNamespace): self $this->BindNamespace = $BindNamespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..30b5c4fd 100644 --- a/src/ACL/ACLAuthMethodQueryResponse.php +++ b/src/ACL/ACLAuthMethodQueryResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLAuthMethod = new ACLAuthMethod((array)$decodedData); + if (null === $decodedData) { + $this->ACLAuthMethod = null; + return; + } + $this->ACLAuthMethod = $this->ACLAuthMethod::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLAuthMethodWriteResponse.php b/src/ACL/ACLAuthMethodWriteResponse.php index 0a609b71..44056647 100644 --- a/src/ACL/ACLAuthMethodWriteResponse.php +++ b/src/ACL/ACLAuthMethodWriteResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLAuthMethod = new ACLAuthMethod((array)$decodedData); + if (null === $decodedData) { + $this->ACLAuthMethod = null; + return; + } + $this->ACLAuthMethod = ACLAuthMethod::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 0a359399..7af0e99e 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -21,25 +21,40 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLBindingRule extends AbstractModel { - 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 string $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 $BindType = '', + 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; + $this->BindName = $BindName; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->Namespace = $Namespace; + } public function getID(): string { @@ -139,4 +154,33 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..6c3480fc 100644 --- a/src/ACL/ACLBindingRuleQueryResponse.php +++ b/src/ACL/ACLBindingRuleQueryResponse.php @@ -25,7 +25,7 @@ class ACLBindingRuleQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?ACLBindingRule $ACLBindingRule = null; + public null|ACLBindingRule $ACLBindingRule = null; public function getValue(): ?ACLBindingRule { @@ -34,6 +34,10 @@ public function getValue(): ?ACLBindingRule public function unmarshalValue(mixed $decodedData): void { - $this->ACLBindingRule = new ACLBindingRule((array)$decodedData); + if (null === $decodedData) { + $this->ACLBindingRule = null; + return; + } + $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLBindingRuleWriteResponse.php b/src/ACL/ACLBindingRuleWriteResponse.php index c1ba51c1..983da782 100644 --- a/src/ACL/ACLBindingRuleWriteResponse.php +++ b/src/ACL/ACLBindingRuleWriteResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLBindingRule = new ACLBindingRule((array)$decodedData); + if (null === $decodedData) { + $this->ACLBindingRule = null; + return; + } + $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php index 59d77a58..4607e0fe 100644 --- a/src/ACL/ACLBindingRulesQueryResponse.php +++ b/src/ACL/ACLBindingRulesQueryResponse.php @@ -25,9 +25,9 @@ class ACLBindingRulesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $ACLBindingRules = []; + public array $ACLBindingRules = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLBindingRules; } @@ -36,7 +36,7 @@ public function unmarshalValue(mixed $decodedData): void { $this->ACLBindingRules = []; foreach ($decodedData as $datum) { - $this->ACLBindingRules[] = new ACLBindingRule($datum); + $this->ACLBindingRules[] = ACLBindingRule::jsonUnserialize($datum); } } } diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php index 79e3daa0..ed9e6d70 100644 --- a/src/ACL/ACLClient.php +++ b/src/ACL/ACLClient.php @@ -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,7 +98,7 @@ 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 $tokenID, string $description, null|WriteOptions $opts = null): ACLTokenWriteResponse { $ret = new ACLTokenWriteResponse(); if ('' === $tokenID) { @@ -112,12 +112,12 @@ public function TokenClone(string $tokenID, string $description, ?WriteOptions $ return $ret; } - public function TokenDelete(string $tokenID, ?WriteOptions $opts = null): WriteResponse + public function TokenDelete(string $tokenID, null|WriteOptions $opts = null): WriteResponse { return $this->_executeDelete(sprintf('/v1/acl/token/%s', $tokenID), $opts); } - public function TokenRead(string $tokenID, ?QueryOptions $opts = null): ACLTokenQueryResponse + public function TokenRead(string $tokenID, null|QueryOptions $opts = null): ACLTokenQueryResponse { $resp = $this->_requireOK($this->_doGet(sprintf('/v1/acl/token/%s', $tokenID), $opts)); $ret = new ACLTokenQueryResponse(); @@ -125,7 +125,7 @@ public function TokenRead(string $tokenID, ?QueryOptions $opts = null): ACLToken return $ret; } - public function TokenReadSelf(?QueryOptions $opts = null): ACLTokenQueryResponse + public function TokenReadSelf(null|QueryOptions $opts = null): ACLTokenQueryResponse { $resp = $this->_requireOK($this->_doGet('/v1/acl/token/self', $opts)); $ret = new ACLTokenQueryResponse(); @@ -133,7 +133,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 +141,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 +153,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 +165,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 +178,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 +186,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 +194,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 +206,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 +218,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 +231,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 +239,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 +247,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,7 +259,7 @@ 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) { @@ -271,12 +271,12 @@ public function AuthMethodUpdate(ACLAuthMethod $authMethod, ?WriteOptions $opts 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 +284,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(); @@ -294,7 +294,7 @@ public function AuthMethodList(?QueryOptions $opts = null): ACLAuthMethodListEnt public function BindingRuleCreate( ACLBindingRule $bindingRule, - ?WriteOptions $opts = null + null|WriteOptions $opts = null ): ACLBindingRuleWriteResponse { $ret = new ACLBindingRuleWriteResponse(); if ('' !== $bindingRule->ID) { @@ -308,7 +308,7 @@ public function BindingRuleCreate( public function BindingRuleUpdate( ACLBindingRule $bindingRule, - ?WriteOptions $opts = null + null|WriteOptions $opts = null ): ACLBindingRuleWriteResponse { $ret = new ACLBindingRuleWriteResponse(); if ('' === $bindingRule->ID) { @@ -320,12 +320,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 +333,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 +341,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 +349,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 +366,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..d26bacc3 100644 --- a/src/ACL/ACLEntriesResponse.php +++ b/src/ACL/ACLEntriesResponse.php @@ -27,7 +27,7 @@ class ACLEntriesResponse extends AbstractValuedQueryResponse implements Unmarsha { public array $ACLEntries = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLEntries; } @@ -35,7 +35,7 @@ public function getValue(): ?array public function unmarshalValue(mixed $decodedData): void { foreach ($decodedData as $entry) { - $this->ACLEntries[] = new ACLEntry($entry); + $this->ACLEntries[] = ACLEntry::jsonUnserialize($entry); } } } diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index 4bc149f5..8c8ba4c9 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -24,12 +24,28 @@ class ACLEntry extends AbstractModel { - 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 { @@ -96,4 +112,28 @@ public function setRules(string $rules): self $this->Rules = $rules; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..806bb44a 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -24,16 +24,54 @@ class ACLLink extends AbstractModel { - 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 static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ID = $this->ID; + $out->Name = $this->Name; + return $out; + } } diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index 19ce55aa..ea6f6ff4 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -21,20 +21,19 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; class ACLLoginParams extends AbstractModel { - protected const FIELDS = [ - self::FIELD_META => Transcoding::MAP_FIELD + [Transcoding::FIELD_OMITEMPTY => true], - ]; + public string $AuthMethod; + public string $BearerToken; + public null|array $Meta; - private const FIELD_META = 'Meta'; - - public string $AuthMethod = ''; - public string $BearerToken = ''; - public ?FakeMap $Meta = null; + public function __construct(string $AuthMethod = '', string $BearerToken = '', null|array|\stdClass $Meta = null) + { + $this->AuthMethod = $AuthMethod; + $this->BearerToken = $BearerToken; + $this->setMeta($Meta); + } public function getAuthMethod(): string { @@ -58,14 +57,44 @@ public function setBearerToken(string $BearerToken): self return $this; } - public function getMeta(): ?FakeMap + public function getMeta(): array { return $this->Meta; } - public function setMeta(mixed $Meta): self + public function setMeta(null|array|\stdClass $Meta): self { - $this->Meta = FakeMap::parse($Meta); + $this->Meta = match($Meta) { + null => null, + default => (array)$Meta, + }; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('Meta' === $k) { + $n->setMeta($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->AuthMethod = $this->AuthMethod; + $out->BearerToken = $this->BearerToken; + if (null !== $this->Meta && [] !== $this->Meta) { + $out->Meta = $this->Meta; + } + return $out; + } } diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 400aca2d..5fc5b8a7 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -24,8 +24,14 @@ class ACLNodeIdentity extends AbstractModel { - 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 { @@ -36,4 +42,24 @@ public function getDatacenter(): string { return $this->Datacenter; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->NodeName = $this->NodeName; + $out->Datacenter = $this->Datacenter; + return $out; + } } diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index e5384cb7..65c920db 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -21,21 +21,25 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; class ACLOIDCAuthURLParams extends AbstractModel { - 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; + public string $AuthMethod; + public string $RedirectURI; + public string $ClientNonce; + public null|array $Meta; + + public function __construct( + string $AuthMethod = '', + string $RedirectURI = '', + string $ClientNonce = '', + null|array|\stdClass $Meta = null + ) { + $this->AuthMethod = $AuthMethod; + $this->RedirectURI = $RedirectURI; + $this->ClientNonce = $ClientNonce; + $this->setMeta($Meta); + } public function getAuthMethod(): string { @@ -70,14 +74,45 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public function getMeta(): ?FakeMap + public function getMeta(): null|array { return $this->Meta; } - public function setMeta(mixed $Meta): self + public function setMeta(null|array|\stdClass $Meta): self { - $this->Meta = FakeMap::parse($Meta); + $this->Meta = match($Meta) { + null => null, + default => (array)$Meta, + }; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('Meta' === $k) { + $n->setMeta($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->AuthMethod = $this->AuthMethod; + $out->RedirectURI = $this->RedirectURI; + $out->ClientNonce = $this->ClientNonce; + if (null !== $this->Meta && [] !== $this->Meta) { + $out->Meta = $this->Meta; + } + return $out; + } } diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 1d7b196a..251c5230 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -24,10 +24,22 @@ class ACLOIDCCallbackParams extends AbstractModel { - 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,26 @@ public function setClientNonce(string $ClientNonce): self $this->ClientNonce = $ClientNonce; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..a0107a7a 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -21,25 +21,41 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLPolicy extends AbstractModel { - 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; + public array $Datacenters; + public string $Hash; + public int $CreateIndex; + public int $ModifyIndex; + public string $Namespace; + + public function __construct( + string $ID = '', + string $Name = '', + string $Description = '', + string $Rules = '', + iterable $Datacenters = [], + string $Hash = '', + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $Namespace = '' + ) { + $this->ID = $ID; + $this->Name = $Name; + $this->Description = $Description; + $this->Rules = $Rules; + $this->setDatacenters(...$Datacenters); + $this->Datacenters = $Datacenters; + $this->Hash = $Hash; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->Namespace = $Namespace; + } public function getID(): string { @@ -90,7 +106,7 @@ 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 +155,37 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('Datacenters' === $k) { + $n->setDatacenters(...$v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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; + } + return $out; + } } diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index 6cb4e67e..e7c95419 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -21,24 +21,37 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLPolicyListEntry extends AbstractModel { - 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; + public array $Datacenters; + public string $Hash; + public int $CreateIndex; + public int $ModifyIndex; + public string $Namespace; + + public function __construct( + string $ID = '', + string $Name = '', + string $Description = '', + iterable $Datacenters = [], + string $Hash = '', + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $Namespace = '', + ) { + $this->ID = $ID; + $this->Name = $Name; + $this->Description = $Description; + $this->setDatacenters(...$Datacenters); + $this->Hash = $Hash; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->Namespace = $Namespace; + } public function getID(): string { @@ -78,7 +91,7 @@ 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 +140,36 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('Datacenters' === $k) { + $n->setDatacenters(...$v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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; + } + return $out; + } } diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php index 96f28700..131a8211 100644 --- a/src/ACL/ACLPolicyListEntryQueryResponse.php +++ b/src/ACL/ACLPolicyListEntryQueryResponse.php @@ -25,18 +25,17 @@ class ACLPolicyListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $ACLPolicyListEntries = []; + public array $ACLPolicyListEntries = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLPolicyListEntries; } public function unmarshalValue(mixed $decodedData): void { - $this->ACLPolicyListEntries = []; foreach ($decodedData as $datum) { - $this->ACLPolicyListEntries[] = new ACLPolicyListEntry($datum); + $this->ACLPolicyListEntries[] = ACLPolicyListEntry::jsonUnserialize($datum); } } } diff --git a/src/ACL/ACLPolicyQueryResponse.php b/src/ACL/ACLPolicyQueryResponse.php index e8aeb668..d5e0e05a 100644 --- a/src/ACL/ACLPolicyQueryResponse.php +++ b/src/ACL/ACLPolicyQueryResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLPolicy = new ACLPolicy((array)$decodedData); + if (null === $decodedData) { + $this->ACLPolicy = null; + return; + } + $this->ACLPolicy = ACLPolicy::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLPolicyWriteResponse.php b/src/ACL/ACLPolicyWriteResponse.php index 1e9439d5..74f6e693 100644 --- a/src/ACL/ACLPolicyWriteResponse.php +++ b/src/ACL/ACLPolicyWriteResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLPolicy = new ACLPolicy((array)$decodedData); + if (null === $decodedData) { + $this->ACLPolicy = null; + return; + } + $this->ACLPolicy = ACLPolicy::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 479bc9c2..8bea3f33 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -22,40 +22,36 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLReplicationStatus extends AbstractModel { - 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 @@ -97,4 +93,36 @@ public function getLastError(): Time\Time { return $this->LastError; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('LastSuccess' === $k) { + $n->LastSuccess = Time\Time::createFromFormat(DATE_RFC3339, $v); + } elseif ('LastError' === $k) { + $n->LastError = Time\Time::createFromFormat(DATE_RFC3339, $v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..f355ae90 100644 --- a/src/ACL/ACLReplicationStatusResponse.php +++ b/src/ACL/ACLReplicationStatusResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLReplicationStatus = new ACLReplicationStatus((array)$decodedData); + if (null === $decodedData) { + $this->ACLReplicationStatus = null; + return; + } + $this->ACLReplicationStatus = ACLReplicationStatus::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 1913ea18..4eba107e 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -21,47 +21,43 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLRole extends AbstractModel { - 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; + public array $Policies; + public array $ServiceIdentities; + public array $NodeIdentities; + public string $Hash; + public int $CreateIndex; + public int $ModifyIndex; + public string $Namespace; + + public function __construct( + string $ID = '', + string $Name = '', + string $Description = '', + iterable $Policies = [], + iterable $ServiceIdentities = [], + iterable $NodeIdentities = [], + string $Hash = '', + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $Namespace = '' + ) { + $this->ID = $ID; + $this->Name = $Name; + $this->Description = $Description; + $this->setPolicies(...$Policies); + $this->setServiceIdentities(...$ServiceIdentities); + $this->setNodeIdentities(...$NodeIdentities); + $this->Hash = $Hash; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->Namespace = $Namespace; + } public function getID(): string { @@ -101,7 +97,7 @@ public function getPolicies(): array return $this->Policies; } - public function setPolicies(array $Policies): self + public function setPolicies(ACLTokenPolicyLink ...$Policies): self { $this->Policies = $Policies; return $this; @@ -112,7 +108,7 @@ public function getServiceIdentities(): array return $this->ServiceIdentities; } - public function setServiceIdentities(array $ServiceIdentities): self + public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self { $this->ServiceIdentities = $ServiceIdentities; return $this; @@ -123,7 +119,7 @@ public function getNodeIdentities(): array return $this->NodeIdentities; } - public function setNodeIdentities(array $NodeIdentities): self + public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self { $this->NodeIdentities = $NodeIdentities; return $this; @@ -172,4 +168,54 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + if ('Policies' === $k) { + foreach ($v as $vv) { + $n->Policies[] = ACLTokenPolicyLink::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); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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; + } + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + return $out; + } } diff --git a/src/ACL/ACLRoleQueryResponse.php b/src/ACL/ACLRoleQueryResponse.php index 4ffbe236..cc727773 100644 --- a/src/ACL/ACLRoleQueryResponse.php +++ b/src/ACL/ACLRoleQueryResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLRole = new ACLRole((array)$decodedData); + if (null === $decodedData) { + $this->ACLRole = null; + return; + } + $this->ACLRole = ACLRole::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLRoleWriteResponse.php b/src/ACL/ACLRoleWriteResponse.php index cb94ff4e..62f747eb 100644 --- a/src/ACL/ACLRoleWriteResponse.php +++ b/src/ACL/ACLRoleWriteResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLRole = new ACLRole((array)$decodedData); + if (null === $decodedData) { + $this->ACLRole = null; + return; + } + $this->ACLRole = ACLRole::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php index 37d58657..541421ef 100644 --- a/src/ACL/ACLRolesQueryResponse.php +++ b/src/ACL/ACLRolesQueryResponse.php @@ -25,18 +25,17 @@ class ACLRolesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $ACLRoles = []; + public array $ACLRoles = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLRoles; } public function unmarshalValue(mixed $decodedData): void { - $this->ACLRoles = []; foreach ($decodedData as $datum) { - $this->ACLRoles[] = new ACLRole($datum); + $this->ACLRoles[] = ACLRole::jsonUnserialize($datum); } } } diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 99d7d938..61d43436 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -21,22 +21,19 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLServiceIdentity extends AbstractModel { - protected const FIELDS = [ - self::FIELD_DATACENTERS => [ - Transcoding::FIELD_TYPE => Transcoding::ARRAY, - Transcoding::FIELD_ARRAY_TYPE => Transcoding::STRING, - Transcoding::FIELD_OMITEMPTY => true, - ], - ]; - private const FIELD_DATACENTERS = 'Datacenters'; - public string $ServiceName = ''; - public array $Datacenters = []; + public string $ServiceName; + public array $Datacenters; + + public function __construct(string $ServiceName = '', iterable $Datacenters = []) + { + $this->ServiceName = $ServiceName; + $this->Datacenters = $Datacenters; + } public function getServiceName(): string { @@ -47,4 +44,36 @@ 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 static(); + foreach ($decoded as $k => $v) { + if ('Datacenters' === $k) { + $n->setDatacenters(...$v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ServiceName = $this->ServiceName; + if ([] !== $this->Datacenters) { + $out->Datacenters = $this->Datacenters; + } + return $out; + } } diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index d417a98d..f5e1edef 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -22,92 +22,64 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLToken extends AbstractModel { - 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 int $CreateIndex; + public int $ModifyIndex; + public string $AccessorID; + public string $SecretID; + public string $Description; + public array $Policies; + public array $Roles; + public array $ServiceIdentities; + public array $NodeIdentities; + public bool $Local; + public string $AuthMethod; public Time\Duration $ExpirationTTL; - public ?Time\Time $ExpirationTime = null; + public null|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 string $Hash; + public string $Namespace; + + public string $Rules; + + public function __construct( + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $AccessorID = '', + string $SecretID = '', + string $Description = '', + iterable $Policies = [], + iterable $Roles = [], + iterable $ServiceIdentities = [], + iterable $NodeIdentities = [], + 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 = '', + ) { + $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->Local = $Local; + $this->AuthMethod = $AuthMethod; + $this->setExpirationTTL($ExpirationTTL); + $this->setExpirationTime($ExpirationTime); + $this->CreateTime = $CreateTime ?? Time::New(); + $this->Hash = $Hash; + $this->Namespace = $Namespace; + $this->Rules = $Rules; } public function getCreateIndex(): int @@ -170,7 +142,7 @@ public function getPolicies(): array return $this->Policies; } - public function setPolicies(array $Policies): self + public function setPolicies(ACLTokenPolicyLink ...$Policies): self { $this->Policies = $Policies; return $this; @@ -181,7 +153,7 @@ public function getRoles(): array return $this->Roles; } - public function setRoles(array $Roles): self + public function setRoles(ACLTokenRoleLink ...$Roles): self { $this->Roles = $Roles; return $this; @@ -192,7 +164,7 @@ public function getServiceIdentities(): array return $this->ServiceIdentities; } - public function setServiceIdentities(array $ServiceIdentities): self + public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self { $this->ServiceIdentities = $ServiceIdentities; return $this; @@ -203,7 +175,7 @@ public function getNodeIdentities(): array return $this->NodeIdentities; } - public function setNodeIdentities(array $NodeIdentities): self + public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self { $this->NodeIdentities = $NodeIdentities; return $this; @@ -236,18 +208,18 @@ public function getExpirationTTL(): Time\Duration return $this->ExpirationTTL; } - public function setExpirationTTL(Time\Duration $ExpirationTTL): self + public function setExpirationTTL(null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL): self { - $this->ExpirationTTL = $ExpirationTTL; + $this->ExpirationTTL = Time::Duration($ExpirationTTL); return $this; } - public function getExpirationTime(): ?Time\Time + public function getExpirationTime(): 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; @@ -296,4 +268,83 @@ public function setRules(string $Rules): self $this->Rules = $Rules; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($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 ('ExpirationTTL' === $k) { + $n->setExpirationTTL($v); + } elseif ('ExpirationTime' === $k) { + $n->ExpirationTime = (null === $v ? $v : Time\Time::createFromFormat(DATE_RFC3339, $v)); + } elseif ('CreateTime' === $k) { + $n->CreateTime = Time\Time::createFromFormat(DATE_RFC3339, $v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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; + } + $out->Local = $this->Local; + if ('' !== $this->AuthMethod) { + $out->AuthMethod = $this->AuthMethod; + } + if (0 !== $this->ExpirationTTL->Nanoseconds()) { + $out->ExpirationTTL = (string)$this->ExpirationTTL; + } + if (null !== $this->ExpirationTime) { + $out->ExpirationTime = $this->ExpirationTime->format(DATE_RFC3339); + } + if (!$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; + } + return $out; + } } diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index eff21026..17fc46fd 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -22,78 +22,57 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ACLTokenListEntry extends AbstractModel { - 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 int $CreateIndex; + public int $ModifyIndex; + public string $AccessorID; + public string $Description; + public array $Policies; + public array $Roles; + public array $ServiceIdentities; + public array $NodeIdentities; + public bool $Local; + public string $AuthMethod; + public null|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 string $Hash; + public bool $Legacy; + public string $Namespace; + + public function __construct( + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $AccessorID = '', + string $Description = '', + iterable $Policies = [], + iterable $Roles = [], + iterable $ServiceIdentities = [], + iterable $NodeIdentities = [], + bool $Local = false, + string $AuthMethod = '', + null|Time\Time $ExpirationTime = null, + null|Time\Time $CreateTime = null, + string $Hash = '', + bool $Legacy = false, + string $Namespace = '' + ) { + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->AccessorID = $AccessorID; + $this->Description = $Description; + $this->setPolicies(...$Policies); + $this->setRoles(...$Roles); + $this->setServiceIdentities(...$ServiceIdentities); + $this->setNodeIdentities(...$NodeIdentities); + $this->Local = $Local; + $this->AuthMethod = $AuthMethod; + $this->setExpirationTime($ExpirationTime); + $this->CreateTime = $CreateTime ?? Time::New(); + $this->Hash = $Hash; + $this->Legacy = $Legacy; + $this->Namespace = $Namespace; } public function getCreateIndex(): int @@ -145,7 +124,7 @@ public function getPolicies(): array return $this->Policies; } - public function setPolicies(array $Policies): self + public function setPolicies(ACLTokenPolicyLink ...$Policies): self { $this->Policies = $Policies; return $this; @@ -156,7 +135,7 @@ public function getRoles(): array return $this->Roles; } - public function setRoles(array $Roles): self + public function setRoles(ACLTokenRoleLink ...$Roles): self { $this->Roles = $Roles; return $this; @@ -167,7 +146,7 @@ public function getServiceIdentities(): array return $this->ServiceIdentities; } - public function setServiceIdentities(array $ServiceIdentities): self + public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self { $this->ServiceIdentities = $ServiceIdentities; return $this; @@ -178,7 +157,7 @@ public function getNodeIdentities(): array return $this->NodeIdentities; } - public function setNodeIdentities(array $NodeIdentities): self + public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self { $this->NodeIdentities = $NodeIdentities; return $this; @@ -206,12 +185,12 @@ 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; @@ -260,4 +239,73 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($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 ('ExpirationTime' === $k) { + $n->ExpirationTime = (null === $v ? null : Time\Time::createFromFormat(DATE_RFC3339, $v)); + } elseif ('CreateTime' === $k) { + $n->CreateTime = Time\Time::createFromFormat(DATE_RFC3339, $v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + $out->AccessorID = $this->AccessorID; + $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; + } + $out->Local = $this->Local; + if ('' !== $this->AuthMethod) { + $out->AuthMethod = $this->AuthMethod; + } + if (null !== $this->ExpirationTime) { + $out->ExpirationTime = $this->ExpirationTime->format(DATE_RFC3339); + } + $out->CreateTime = $this->CreateTime->format(DATE_RFC3339); + $out->Hash = $this->Hash; + $out->Legacy = $this->Legacy; + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + return $out; + } } diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php index 529e314b..bf08d930 100644 --- a/src/ACL/ACLTokenListEntryQueryResponse.php +++ b/src/ACL/ACLTokenListEntryQueryResponse.php @@ -25,18 +25,17 @@ class ACLTokenListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $ACLTokenListEntries = []; + public array $ACLTokenListEntries = []; - public function getValue(): ?array + public function getValue(): array { return $this->ACLTokenListEntries; } public function unmarshalValue(mixed $decodedData): void { - $this->ACLTokenListEntries = []; foreach ($decodedData as $datum) { - $this->ACLTokenListEntries[] = new ACLTokenListEntry($datum); + $this->ACLTokenListEntries[] = ACLTokenListEntry::jsonUnserialize($datum); } } } diff --git a/src/ACL/ACLTokenQueryResponse.php b/src/ACL/ACLTokenQueryResponse.php index 5092f215..47ca20a6 100644 --- a/src/ACL/ACLTokenQueryResponse.php +++ b/src/ACL/ACLTokenQueryResponse.php @@ -25,15 +25,19 @@ 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 { - $this->ACLToken = new ACLToken((array)$decodedData); + if (null === $decodedData) { + $this->ACLToken = null; + return; + } + $this->ACLToken = ACLToken::jsonUnserialize($decodedData); } } diff --git a/src/ACL/ACLTokenWriteResponse.php b/src/ACL/ACLTokenWriteResponse.php index 1a1a4d91..291c4196 100644 --- a/src/ACL/ACLTokenWriteResponse.php +++ b/src/ACL/ACLTokenWriteResponse.php @@ -25,7 +25,7 @@ class ACLTokenWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { - public ?ACLToken $ACLToken = null; + public null|ACLToken $ACLToken = null; public function getValue(): ?ACLToken { @@ -34,6 +34,10 @@ public function getValue(): ?ACLToken public function unmarshalValue(mixed $decodedData): void { - $this->ACLToken = new ACLToken((array)$decodedData); + if (null === $decodedData) { + $this->ACLToken = null; + return; + } + $this->ACLToken = ACLToken::jsonUnserialize($decodedData); } } diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 15459bbe..707cae59 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -21,24 +21,19 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; class KubernetesAuthMethodConfig extends AbstractModel { - protected const FIELDS = [ - self::FIELD_HOST => 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,41 @@ 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 static(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..91fd3afb 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -24,4 +24,21 @@ class OIDCAuthMethodConfig extends AbstractModel { + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + return $out; + } } diff --git a/src/AbstractClient.php b/src/AbstractClient.php index 0a9b322e..93327660 100644 --- a/src/AbstractClient.php +++ b/src/AbstractClient.php @@ -217,9 +217,15 @@ protected function _doDelete(string $path, ?WriteOptions $opts): RequestResponse protected function _decodeBody(StreamInterface $body): DecodedBody { - $data = @json_decode((string)$body, true); + $data = @json_decode( + json: (string)$body, + associative: false, + depth: $this->_config->JSONDecodeMaxDepth, + flags: $this->_config->JSONDecodeOpts, + ); - if (\JSON_ERROR_NONE === json_last_error()) { + $jsonErr = json_last_error(); + if (\JSON_ERROR_NONE === $jsonErr) { return new DecodedBody($data, null); } @@ -227,8 +233,9 @@ protected function _decodeBody(StreamInterface $body): DecodedBody null, new Error( sprintf( - '%s - Unable to parse response as JSON. Message: %s', + '%s - Unable to parse response as JSON: (%d) %s', static::class, + $jsonErr, json_last_error_msg() ) ) @@ -296,21 +303,15 @@ protected function _executeGetValuedStrs(string $path, ?QueryOptions $opts): Val protected function _unmarshalResponse(RequestResponse $resp, AbstractResponse $ret): void { // determine if this response contains a *Meta field - // TODO: change to use interfaces + instanceof? - if (property_exists($ret, Transcoding::FIELD_QUERY_META)) { + if ($ret instanceof QueryResponseInterface) { $ret->QueryMeta = $resp->buildQueryMeta(); - } elseif (property_exists($ret, Transcoding::FIELD_WRITE_META)) { + } elseif ($ret instanceof WriteResponseInterface) { $ret->WriteMeta = $resp->buildWriteMeta(); } - // todo: can probably assume that all responses have an Err field... - $hasErrField = property_exists($ret, Transcoding::FIELD_ERR); - // if there was an error in the response, set and return if (null !== $resp->Err) { - if ($hasErrField) { - $ret->Err = $resp->Err; - } + $ret->Err = $resp->Err; return; } @@ -322,9 +323,7 @@ protected function _unmarshalResponse(RequestResponse $resp, AbstractResponse $r // attempt response decode $dec = $this->_decodeBody($resp->Response->getBody()); if (null !== $dec->Err) { - if ($hasErrField) { - $ret->Err = $dec->Err; - } + $ret->Err = $dec->Err; return; } diff --git a/src/AbstractModel.php b/src/AbstractModel.php index d38bae8b..e566be2c 100644 --- a/src/AbstractModel.php +++ b/src/AbstractModel.php @@ -22,32 +22,8 @@ abstract class AbstractModel implements \JsonSerializable { - use Marshaller; - use Unmarshaller; - - protected const FIELDS = []; - private array $_dyn = []; - /** - * AbstractModel constructor. - * - * Convenience method to help set scalar types. Any extending class must have a constructor that builds any - * array / object properties it may have. - * - * @param array|null $data - */ - public function __construct(?array $data = []) - { - // fast path for "empty" - if (null === $data || [] === $data) { - return; - } - foreach ($data as $field => $value) { - $this->unmarshalField($field, $value); - } - } - public function __set(string $field, $value): void { $this->_dyn[$field] = $value; @@ -61,29 +37,14 @@ public function &__get(string $field) return $this->_dyn[$field]; } - /** - * todo: this picks up non-public fields. externalize this at some point. - * - * @return array - */ - public function jsonSerialize(): array + public function __unset(string $field): void { - $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; + unset($this->_dyn[$field]); + } + + public function _getDynamicFields(): array + { + return $this->_dyn; } public function __toString(): string diff --git a/src/AbstractValuedQueryResponse.php b/src/AbstractValuedQueryResponse.php index c56bec8a..efb69211 100644 --- a/src/AbstractValuedQueryResponse.php +++ b/src/AbstractValuedQueryResponse.php @@ -20,7 +20,7 @@ limitations under the License. */ -abstract class AbstractValuedQueryResponse extends AbstractResponse implements ValuedResponseInterface +abstract class AbstractValuedQueryResponse extends AbstractResponse implements QueryResponseInterface, ValuedResponseInterface { use QueryMetaContainer; use ErrorContainer; diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 55235175..eccd2025 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -26,7 +26,7 @@ class AgentCheck extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_DEFINITION => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => HealthCheckDefinition::class, diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 0a2210f0..5d15f4c0 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -24,7 +24,7 @@ class AgentCheckRegistration extends AgentServiceCheck { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SERVICE_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index dd4de64e..74a62444 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -30,7 +30,7 @@ class AgentService extends AbstractModel { use HasStringTags; - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_META => Transcoding::MAP_FIELD, self::FIELD_TAGGED_ADDRESSES => [ diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index c31a3319..a5a071ab 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -25,7 +25,7 @@ class AgentServiceCheck extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_CHECK_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SCRIPT_ARGS => [ diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index f2fb3dd6..18dfdf77 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -26,7 +26,7 @@ class AgentServiceChecksInfo extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => AgentService::class, diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 3f629e57..a2318e7d 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -25,7 +25,7 @@ class AgentServiceConnect extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NATIVE => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_SIDECAR_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 0fc59582..8999ecd7 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -28,7 +28,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_ENVOY_EXTENSIONS => [ Transcoding::FIELD_CLASS => EnvoyExtension::class, Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index f565821b..ee362c59 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -31,7 +31,7 @@ class AgentServiceRegistration extends AbstractModel use HasSettableStringTags; use HasStringTags; - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/Agent/EnvoyExtension.php b/src/Agent/EnvoyExtension.php index e433e843..61552129 100644 --- a/src/Agent/EnvoyExtension.php +++ b/src/Agent/EnvoyExtension.php @@ -26,7 +26,7 @@ class EnvoyExtension extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_ARGUMENTS => Transcoding::MAP_FIELD, ]; diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index d580ab99..8ab711a4 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -25,7 +25,7 @@ class MetricsInfo extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_GAUGES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => GaugeValue::class, diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 96672596..a4379b0e 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -26,7 +26,7 @@ class Upstream extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 139008fc..88a33cae 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -25,7 +25,7 @@ class CatalogDeregistration extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index 1f947d62..fc7c57d4 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -26,7 +26,7 @@ class CatalogNode extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index abae0f3a..90cd0be3 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -26,7 +26,7 @@ class CatalogNodeServiceList extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index 5175edc2..22fe3e79 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -29,7 +29,7 @@ class CatalogRegistration extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD, self::FIELD_NODE_META => Transcoding::MAP_FIELD, self::FIELD_SERVICE => [ diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index deb51345..29157d72 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -27,7 +27,7 @@ class CatalogService extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE_TAGGED_ADDRESSES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServiceAddress::class, diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 31d32162..67323218 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -25,7 +25,7 @@ class CompoundServiceName extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 2a47bee2..786691c9 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -25,7 +25,7 @@ class GatewayService extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_GATEWAY => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => CompoundServiceName::class, diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 2a6d19fa..26210256 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -26,7 +26,7 @@ class Node extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD, self::FIELD_META => Transcoding::MAP_FIELD, ]; diff --git a/src/Config.php b/src/Config.php index 7f652148..6d0c0910 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,71 @@ 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); + $scheme = strtolower(self::_resolveValue($Scheme, Consul::HTTPSSLEnvName, self::DEFAULT_SCHEME)); + $this->Scheme = match ($scheme) { + 'true' => 'https', + 'false' => 'http', + 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 = match($skipVerify) { + is_string($skipVerify) => strtolower($skipVerify) === 'true', + default => $skipVerify, + }; // quick validation on key/cert combo $c = $this->CertFile; @@ -136,13 +147,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) { @@ -190,12 +202,16 @@ public static function merge(?self $inc): self 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 static(); } public function getAddress(): string @@ -214,7 +230,7 @@ public function getScheme(): string return $this->Scheme; } - public function setScheme(string $scheme): self + public function setScheme(bool|string $scheme): self { $this->Scheme = $scheme; return $this; @@ -246,7 +262,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 +306,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 +325,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 +384,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): Config { - 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): Config + { + $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/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index de9d7867..feb19db3 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -25,7 +25,7 @@ class ExposeConfig extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_CHECKS => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_PATHS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index 78d0ddb4..964aa202 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -25,7 +25,7 @@ class ExposePath extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 27414433..76fb2454 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -27,7 +27,7 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - protected const FIELDS = COnfigEntry::INTERFACE_FIELDS + [ + public const FIELDS = COnfigEntry::INTERFACE_FIELDS + [ self::FIELD_TRANSPARENT_PROXY => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => TransparentProxyConfig::class, diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 68074e57..673ba46a 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -25,7 +25,7 @@ class MeshGatewayConfig extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index cec65118..b5c00bf8 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -26,7 +26,7 @@ class PassiveHealthCheck extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_INTERVAL => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, Transcoding::FIELD_OMITEMPTY => true, diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index d8896dd8..e3d30eeb 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -28,7 +28,7 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_CONFIG => Transcoding::MAP_FIELD, self::FIELD_TRANSPARENT_PROXY => [ diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php index 6b7fad97..59208639 100644 --- a/src/ConfigEntry/RingHashConfig.php +++ b/src/ConfigEntry/RingHashConfig.php @@ -25,7 +25,7 @@ class RingHashConfig extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_MINIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD, self::FIELD_MAXIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD, ]; diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index 750fe4ce..d2cf8772 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -27,7 +27,7 @@ class ServiceConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_TRANSPARENT_PROXY => [ diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php index 54fad4ca..2e9d9918 100644 --- a/src/ConfigEntry/ServiceResolverFailover.php +++ b/src/ConfigEntry/ServiceResolverFailover.php @@ -25,7 +25,7 @@ class ServiceResolverFailover extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php index a8410274..0e203dd9 100644 --- a/src/ConfigEntry/ServiceResolverRedirect.php +++ b/src/ConfigEntry/ServiceResolverRedirect.php @@ -25,7 +25,7 @@ class ServiceResolverRedirect extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceResolverSubset.php b/src/ConfigEntry/ServiceResolverSubset.php index 7a1f8909..5aae849c 100644 --- a/src/ConfigEntry/ServiceResolverSubset.php +++ b/src/ConfigEntry/ServiceResolverSubset.php @@ -25,7 +25,7 @@ class ServiceResolverSubset extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_FILTER => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_ONLY_PASSING => Transcoding::OMITEMPTY_BOOLEAN_FIELD, ]; diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php index c8c60400..636ca3d5 100644 --- a/src/ConfigEntry/ServiceRoute.php +++ b/src/ConfigEntry/ServiceRoute.php @@ -24,7 +24,7 @@ class ServiceRoute extends AbstractModel { - protected const FIELDS = []; + public const FIELDS = []; private const FIELD_MATCH = 'Match'; private const FIELD_DESTINATION = 'Destination'; diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index 22db2b68..e5fb321b 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -26,7 +26,7 @@ class ServiceRouteDestination extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php index 6e0e4211..598372ed 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatch extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php index b7181eea..f03b496c 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatchHeader extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_PREFIX => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php index 0063f23b..b89fc091 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatchQueryParam extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_REGEX => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php index dfb7f5d6..ab43074f 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -25,7 +25,7 @@ class ServiceRouteMatch extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_HTTP => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => ServiceRouteHTTPMatch::class, diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 5ae2d93c..5f4b684f 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -27,7 +27,7 @@ class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_ROUTES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT, diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php index 96319b07..a70e916f 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -25,7 +25,7 @@ class ServiceSplit extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SERVICE_SUBSET => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index b821f2cb..b08d9d2b 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -27,7 +27,7 @@ class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_SPLITS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT, diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index 0f6d5b30..3c71050d 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -25,7 +25,7 @@ class TransparentProxyConfig extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_OUTBOUND_LISTENER_PORT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_DIALED_DIRECTLY => Transcoding::OMITEMPTY_BOOLEAN_FIELD, ]; diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php index 7aa0b584..fa4049c0 100644 --- a/src/ConfigEntry/UpstreamConfiguration.php +++ b/src/ConfigEntry/UpstreamConfiguration.php @@ -25,7 +25,7 @@ class UpstreamConfiguration extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/ConfigEntry/UpstreamLimits.php b/src/ConfigEntry/UpstreamLimits.php index 10868d89..83a224f9 100644 --- a/src/ConfigEntry/UpstreamLimits.php +++ b/src/ConfigEntry/UpstreamLimits.php @@ -25,7 +25,7 @@ class UpstreamLimits extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_MAX_CONNECTIONS => [ Transcoding::FIELD_NULLABLE => true, ], diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php index 6cf83530..87d0fd33 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -25,7 +25,7 @@ class CoordinateDatacenterMap extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_COORDINATES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => Coordinate::class, diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index d6503694..a8dc7c62 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -25,7 +25,7 @@ class CoordinateEntry extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_COORDINATE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Coordinate::class, 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..87ea63c4 100644 --- a/src/Health/HealthCheck.php +++ b/src/Health/HealthCheck.php @@ -25,7 +25,7 @@ class HealthCheck extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_DEFINITION => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index 1c6a1e1e..afcdc12c 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -28,7 +28,7 @@ class HealthCheckDefinition extends AbstractModel implements \JsonSerializable { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_INTERVAL_DURATION => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, Transcoding::FIELD_SKIP => true, diff --git a/src/Health/ServiceEntry.php b/src/Health/ServiceEntry.php index 96773463..aab2b77a 100644 --- a/src/Health/ServiceEntry.php +++ b/src/Health/ServiceEntry.php @@ -27,7 +27,7 @@ class ServiceEntry extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/KV/CheckTxnOp.php b/src/KV/CheckTxnOp.php index 0ffce250..8132b558 100644 --- a/src/KV/CheckTxnOp.php +++ b/src/KV/CheckTxnOp.php @@ -26,7 +26,7 @@ class CheckTxnOp extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_CHECK => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => HealthCheck::class, diff --git a/src/KV/KVPair.php b/src/KV/KVPair.php index 0a81ec7a..ef4c9826 100644 --- a/src/KV/KVPair.php +++ b/src/KV/KVPair.php @@ -25,7 +25,7 @@ class KVPair extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/KV/KVTxnResponse.php b/src/KV/KVTxnResponse.php index dfd2d9f1..e3370260 100644 --- a/src/KV/KVTxnResponse.php +++ b/src/KV/KVTxnResponse.php @@ -25,7 +25,7 @@ class KVTxnResponse extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_RESULTS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => KVPair::class, diff --git a/src/KV/NodeTxnOp.php b/src/KV/NodeTxnOp.php index 872f7d5d..d1f8c701 100644 --- a/src/KV/NodeTxnOp.php +++ b/src/KV/NodeTxnOp.php @@ -26,7 +26,7 @@ class NodeTxnOp extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/KV/ServiceTxnOp.php b/src/KV/ServiceTxnOp.php index 52c50964..3e8089b2 100644 --- a/src/KV/ServiceTxnOp.php +++ b/src/KV/ServiceTxnOp.php @@ -26,7 +26,7 @@ class ServiceTxnOp extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => AgentService::class, diff --git a/src/KV/TxnOp.php b/src/KV/TxnOp.php index f5f50a44..a4f33aef 100644 --- a/src/KV/TxnOp.php +++ b/src/KV/TxnOp.php @@ -25,7 +25,7 @@ class TxnOp extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_KV => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => KVTxnOp::class, diff --git a/src/KV/TxnResponse.php b/src/KV/TxnResponse.php index 7bcdfd9c..23369f77 100644 --- a/src/KV/TxnResponse.php +++ b/src/KV/TxnResponse.php @@ -25,7 +25,7 @@ class TxnResponse extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_RESULTS => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => TxnResults::class, diff --git a/src/KV/TxnResult.php b/src/KV/TxnResult.php index 1f7af537..0a772d27 100644 --- a/src/KV/TxnResult.php +++ b/src/KV/TxnResult.php @@ -28,7 +28,7 @@ class TxnResult extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_KV => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => KVPair::class, diff --git a/src/Marshaller.php b/src/Marshaller.php index bc9b5ce0..86a07ed7 100644 --- a/src/Marshaller.php +++ b/src/Marshaller.php @@ -22,27 +22,18 @@ use DCarbone\Go\Time; -trait Marshaller +abstract class Marshaller { - /** - * Marshal field is designed to replicate (to ao point) what Golang does during the json.Marshal call - * - * @param array $output - * @param string $field - * @param mixed $value - */ - protected function marshalField(array &$output, string $field, mixed $value): void + protected static function marshalField(\stdClass $output, string $field, null|array $def, mixed $value): void { - $def = static::FIELDS[$field] ?? null; - // if this field has no special handling, set as-is and move on. if (null === $def) { - $output[$field] = $value; + $output->{$field} = $value; return; } // if this field is marked as being "skipped", do not set, then move on. - if (isset($def[Transcoding::FIELD_SKIP]) && true === $def[Transcoding::FIELD_SKIP]) { + if ($def[Transcoding::FIELD_SKIP] ?? false) { return; } @@ -72,7 +63,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // strings must be non empty if (Transcoding::STRING === $type) { if ('' !== $value) { - $output[$field] = $value; + $output->{$field} = $value; } return; } @@ -80,7 +71,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // integers must be non-zero (negatives are ok) if (Transcoding::INTEGER === $type) { if (0 !== $value) { - $output[$field] = $value; + $output->{$field} = $value; } return; } @@ -88,7 +79,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // floats must be non-zero (negatives are ok) if (Transcoding::DOUBLE === $type) { if (0.0 !== $value) { - $output[$field] = $value; + $output->{$field} = $value; } return; } @@ -96,7 +87,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // bools must be true if (Transcoding::BOOLEAN === $type) { if ($value) { - $output[$field] = $value; + $output->{$field} = $value; } return; } @@ -106,7 +97,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // 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; + $output->{$field} = $value; } return; } @@ -114,7 +105,7 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // Time\Duration types are non-zero if their internal value is > 0 if ($value instanceof Time\Duration) { if (0 < $value->Nanoseconds()) { - $output[$field] = $value; + $output->{$field} = $value; } return; } @@ -122,31 +113,36 @@ protected function marshalField(array &$output, string $field, mixed $value): vo // Time\Time values are non-zero if they are anything greater than epoch if ($value instanceof Time\Time) { if (!$value->IsZero()) { - $output[$field] = $value; + $output->{$field} = $value; } return; } // otherwise, by being defined it is non-zero, so add it. - $output[$field] = $value; + $output->{$field} = $value; return; } // arrays must have at least 1 value if (Transcoding::ARRAY === $type) { if ([] !== $value) { - $output[$field] = $value; + $output->{$field} = $value; } return; } // todo: be more better about resources if (Transcoding::RESOURCE === $type) { - $output[$field] = $value; + $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. } + + public static function marshalJSON(object $obj, array $fields, array $dynamic): \stdClass + { + + } } diff --git a/src/Operator/AutopilotConfiguration.php b/src/Operator/AutopilotConfiguration.php index 0e2916f6..00893130 100644 --- a/src/Operator/AutopilotConfiguration.php +++ b/src/Operator/AutopilotConfiguration.php @@ -25,7 +25,7 @@ class AutopilotConfiguration extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_LAST_CONTACT_THRESHOLD => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index 3e0ff8d0..6239790a 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -26,7 +26,7 @@ class AutopilotServer extends AbstractModel implements \JsonSerializable { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_LAST_CONTACT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/Operator/AutopilotState.php b/src/Operator/AutopilotState.php index 881d8247..4c8384b4 100644 --- a/src/Operator/AutopilotState.php +++ b/src/Operator/AutopilotState.php @@ -25,7 +25,7 @@ class AutopilotState extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => AutopilotServer::class, diff --git a/src/Operator/AutopilotUpgrade.php b/src/Operator/AutopilotUpgrade.php index fa372a69..8002f117 100644 --- a/src/Operator/AutopilotUpgrade.php +++ b/src/Operator/AutopilotUpgrade.php @@ -25,7 +25,7 @@ class AutopilotUpgrade extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/Operator/AutopilotZoneUpgradeVersions.php b/src/Operator/AutopilotZoneUpgradeVersions.php index 9b07c349..93843053 100644 --- a/src/Operator/AutopilotZoneUpgradeVersions.php +++ b/src/Operator/AutopilotZoneUpgradeVersions.php @@ -25,7 +25,7 @@ class AutopilotZoneUpgradeVersions extends AbstractModel { - protected const FIELDS = [ + public 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, diff --git a/src/Operator/OperatorHealthReply.php b/src/Operator/OperatorHealthReply.php index a837eb7a..624ed577 100644 --- a/src/Operator/OperatorHealthReply.php +++ b/src/Operator/OperatorHealthReply.php @@ -25,7 +25,7 @@ class OperatorHealthReply extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServerHealth::class, diff --git a/src/Operator/RaftConfiguration.php b/src/Operator/RaftConfiguration.php index 525f4e4a..e2fc7675 100644 --- a/src/Operator/RaftConfiguration.php +++ b/src/Operator/RaftConfiguration.php @@ -25,7 +25,7 @@ class RaftConfiguration extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => RaftServer::class, diff --git a/src/Operator/SerfMember.php b/src/Operator/SerfMember.php index 3c22bf53..8afedd0b 100644 --- a/src/Operator/SerfMember.php +++ b/src/Operator/SerfMember.php @@ -26,7 +26,7 @@ class SerfMember extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_RTT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, ], diff --git a/src/Operator/ServerHealth.php b/src/Operator/ServerHealth.php index e50af771..bd719b8d 100644 --- a/src/Operator/ServerHealth.php +++ b/src/Operator/ServerHealth.php @@ -26,7 +26,7 @@ class ServerHealth extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_LAST_CONTACT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/PreparedQuery/PreparedQueryDefinition.php b/src/PreparedQuery/PreparedQueryDefinition.php index 236b1ca1..c6df12ea 100644 --- a/src/PreparedQuery/PreparedQueryDefinition.php +++ b/src/PreparedQuery/PreparedQueryDefinition.php @@ -25,7 +25,7 @@ class PreparedQueryDefinition extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => ServiceQuery::class, diff --git a/src/PreparedQuery/PreparedQueryExecuteResponse.php b/src/PreparedQuery/PreparedQueryExecuteResponse.php index 1a28093b..18597462 100644 --- a/src/PreparedQuery/PreparedQueryExecuteResponse.php +++ b/src/PreparedQuery/PreparedQueryExecuteResponse.php @@ -26,7 +26,7 @@ class PreparedQueryExecuteResponse extends AbstractModel { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NODES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServiceEntry::class, diff --git a/src/PreparedQuery/ServiceQuery.php b/src/PreparedQuery/ServiceQuery.php index f3c9f612..9089d89c 100644 --- a/src/PreparedQuery/ServiceQuery.php +++ b/src/PreparedQuery/ServiceQuery.php @@ -30,7 +30,7 @@ class ServiceQuery extends AbstractModel use HasSettableStringTags; use HasStringTags; - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_FAILOVER => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, diff --git a/src/QueryOptions.php b/src/QueryOptions.php index cf6fff29..e06f1420 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -24,7 +24,7 @@ class QueryOptions extends AbstractModel implements RequestOptions { - protected const FIELDS = [ + public const FIELDS = [ self::FIELD_MAX_AGE => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, ], diff --git a/src/QueryResponseInterface.php b/src/QueryResponseInterface.php new file mode 100644 index 00000000..389a2e26 --- /dev/null +++ b/src/QueryResponseInterface.php @@ -0,0 +1,26 @@ + [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, ], diff --git a/src/Unmarshaller.php b/src/Unmarshaller.php index 5b55c234..552a4217 100644 --- a/src/Unmarshaller.php +++ b/src/Unmarshaller.php @@ -24,36 +24,41 @@ use DCarbone\PHPConsulAPI\KV\KVPair; use DCarbone\PHPConsulAPI\KV\KVTxnOp; -trait Unmarshaller +abstract class Unmarshaller { - protected function unmarshalField(string $field, mixed $value): void + public static function unmarshalJSON(mixed $decoded, AbstractModel $model): void { - if (isset(static::FIELDS[$field])) { + if (null === $decoded) { + return; + } + if (is_scalar($decoded)) { + + } + if (isset($model::FIELDS[$field])) { // if the implementing class has some explicitly defined overrides - $this->unmarshalComplex($field, $value, static::FIELDS[$field]); - } elseif (!property_exists($this, $field)) { + self::unmarshalComplex(model: $model, field: $field, value: $value, def: $model::FIELDS[$field]); + } elseif (!property_exists($model, $field)) { // if the field isn't explicitly defined on the implementing class, just set it to whatever the incoming // value is - $this->{$field} = $value; + $model->{$field} = $value; } elseif (null !== $value) { // at this point, value must be non-null to be operable - if (isset($this->{$field}) && is_scalar($this->{$field})) { + if (isset($model->{$field}) && is_scalar($model->{$field})) { // if the property has a scalar default value, unmarshal it as such. - $this->unmarshalScalar($field, $value, false); + self::unmarshalScalar(model: $model, field: $field, value: $value, nullable: false); } else { // if we fall down here, try to set the value as-is. if this barfs, it indicates we have a bug to be // squished. // todo: should this be an exception? - $this->{$field} = $value; + $model->{$field} = $value; } } - // if the value is null at this point, ignore and move on. // note: this is not checked prior to the property_exists call as if the field is not explicitly defined but // is seen with a null value, we still want to define it as null on the implementing type. } - protected function fieldIsNullable(array $fieldDef): bool + protected static function fieldIsNullable(array $fieldDef): bool { // todo: make sure this key is always a bool... return $fieldDef[Transcoding::FIELD_NULLABLE] ?? false; @@ -70,15 +75,15 @@ protected static function scalarZeroVal(string $type): float|bool|int|string|nul }; } - private function buildScalarValue(string $field, mixed $value, string $type, bool $nullable): float|bool|int|string|null + private static function buildScalarValue(mixed $value, string $type, bool $nullable): float|bool|int|string|null { if (null === $value) { - return $nullable ? null : self::scalarZeroVal($type); + return $nullable ? null : self::scalarZeroVal(type: $type); } return match ($type) { Transcoding::STRING => (string)$value, - Transcoding::INTEGER => \intval($value, 10), + Transcoding::INTEGER => (int)$value, Transcoding::DOUBLE => (float)$value, Transcoding::BOOLEAN => (bool)$value, @@ -87,11 +92,11 @@ private function buildScalarValue(string $field, mixed $value, string $type, boo }; } - private function buildObjectValue(string $field, null|object|array $value, string $class, bool $nullable): ?object + private static function buildObjectValue(null|object|array $value, string $class, bool $nullable): ?object { // if the incoming value is null... if (null === $value) { - return $nullable ? null : new $class([]); + return $nullable ? null : new $class(); } // if the incoming value is already an instance of the class, clone it and return if ($value instanceof $class) { @@ -101,40 +106,41 @@ private function buildObjectValue(string $field, null|object|array $value, strin if (KVPair::class === $class || KVTxnOp::class === $class || UserEvent::class === $class) { // special case for KVPair and KVTxnOp // todo: find cleaner way to do this... + $inst = new $class(); + self::unmarshalJSON(); return new $class((array)$value, true); } return new $class((array)$value); } - private function unmarshalScalar(string $field, mixed $value, bool $nullable): void + private static function unmarshalScalar(AbstractModel $model, string $field, mixed $value, bool $nullable): void { - $this->{$field} = $this->buildScalarValue( - $field, - $value, - isset($this->{$field}) ? \gettype($this->{$field}) : Transcoding::MIXED, - $nullable + $model->{$field} = self::buildScalarValue( + value: $value, + type: isset($model->{$field}) ? \gettype($model->{$field}) : Transcoding::MIXED, + nullable: $nullable ); } - private function unmarshalComplex(string $field, mixed $value, array $def): void + private static function unmarshalComplex(AbstractModel $model, string $field, mixed $value, array $def): void { // check if a callable has been defined if (isset($def[Transcoding::FIELD_UNMARSHAL_CALLBACK])) { $cb = $def[Transcoding::FIELD_UNMARSHAL_CALLBACK]; // allow for using a "setter" method - if (\is_string($cb) && method_exists($this, $cb)) { - $this->{$cb}($value); + if (\is_string($cb) && method_exists($model, $cb)) { + $model->{$cb}($value); return; } // handle all other callable input - $err = \call_user_func($def[Transcoding::FIELD_UNMARSHAL_CALLBACK], $this, $field, $value); + $err = \call_user_func($def[Transcoding::FIELD_UNMARSHAL_CALLBACK], $model, $field, $value); if (false === $err) { throw new \RuntimeException( sprintf( 'Error calling hydration callback "%s" for field "%s" on class "%s"', var_export($def[Transcoding::FIELD_UNMARSHAL_CALLBACK], true), $field, - static::class + $model::class ) ); } @@ -150,57 +156,56 @@ private function unmarshalComplex(string $field, mixed $value, array $def): void if (isset($def[Transcoding::FIELD_TYPE])) { // if the field has a FIELD_TYPE value in the definition map $fieldType = $def[Transcoding::FIELD_TYPE]; - } elseif (isset($this->{$field})) { + } elseif (isset($model->{$field})) { // if the field is set and non-null - $fieldType = \gettype($this->{$field}); + $fieldType = \gettype($model->{$field}); } else { throw new \LogicException( sprintf( 'Field "%s" on type "%s" is missing a FIELD_TYPE hydration entry: %s', $field, - static::class, + $model::class, var_export($def, true) ) ); } if (Transcoding::OBJECT === $fieldType) { - $this->unmarshalObject($field, $value, $def); + self::unmarshalObject($model, $field, $value, $def); return; } if (Transcoding::ARRAY === $fieldType) { - $this->unmarshalArray($field, $value, $def); + self::unmarshalArray($model, $field, $value, $def); return; } // at this point, assume scalar // todo: handle non-scalar types here - $this->unmarshalScalar($field, $value, self::fieldIsNullable($def)); + self::unmarshalScalar($model, $field, $value, self::fieldIsNullable($def)); } - private function unmarshalObject(string $field, mixed $value, array $def): void + private static function unmarshalObject(AbstractModel $model, string $field, mixed $value, array $def): void { if (!isset($def[Transcoding::FIELD_CLASS])) { throw new \LogicException( sprintf( 'Field "%s" on type "%s" is missing FIELD_CLASS hydration entry: %s', $field, - static::class, + $model::class, var_export($def, true) ) ); } - $this->{$field} = $this->buildObjectValue( - $field, + $model->{$field} = self::buildObjectValue( $value, $def[Transcoding::FIELD_CLASS], self::fieldIsNullable($def) ); } - private function unmarshalArray(string $field, mixed $value, array $def): void + private static function unmarshalArray(AbstractModel $model, string $field, mixed $value, array $def): void { // attempt to extract the two possible keys $type = $def[Transcoding::FIELD_ARRAY_TYPE] ?? null; @@ -212,7 +217,7 @@ private function unmarshalArray(string $field, mixed $value, array $def): void sprintf( 'Field "%s" on type "%s" definition is missing FIELD_ARRAY_TYPE value: %s', $field, - static::class, + $model::class, var_export($def, true) ) ); @@ -221,8 +226,8 @@ private function unmarshalArray(string $field, mixed $value, array $def): void // is the incoming value null? if (null === $value) { // if this value can be null'd, allow it. - if (static::fieldIsNullable($def)) { - $this->{$field} = null; + if (self::fieldIsNullable($def)) { + $model->{$field} = null; } return; } @@ -233,7 +238,7 @@ private function unmarshalArray(string $field, mixed $value, array $def): void sprintf( 'Field "%s" on type "%s" is an array but provided value is "%s"', $field, - static::class, + $model::class, \gettype($value) ) ); @@ -248,7 +253,7 @@ private function unmarshalArray(string $field, mixed $value, array $def): void sprintf( 'Field "%s" on type "%s" definition is missing FIELD_CLASS value: %s', $field, - static::class, + $model::class, var_export($def, true) ) ); @@ -257,9 +262,9 @@ private function unmarshalArray(string $field, mixed $value, array $def): void foreach ($value as $k => $v) { // short circuit to prevent additional func call if (null === $v) { - $this->{$field}[$k] = null; + $model->{$field}[$k] = null; } else { - $this->{$field}[$k] = $this->buildObjectValue($field, $v, $class, false); + $model->{$field}[$k] = self::buildObjectValue($v, $class, false); } } } else { @@ -267,9 +272,9 @@ private function unmarshalArray(string $field, mixed $value, array $def): void foreach ($value as $k => $v) { // short circuit to prevent additional func call if (null === $v) { - $this->{$field}[$k] = null; + $model->{$field}[$k] = null; } else { - $this->{$field}[$k] = $this->buildScalarValue($field, $v, $type, false); + $model->{$field}[$k] = self::buildScalarValue($v, $type, false); } } } diff --git a/src/WriteResponse.php b/src/WriteResponse.php index c6fa61db..82145329 100644 --- a/src/WriteResponse.php +++ b/src/WriteResponse.php @@ -20,7 +20,7 @@ limitations under the License. */ -class WriteResponse extends AbstractResponse +class WriteResponse extends AbstractResponse implements WriteResponseInterface { use WriteMetaContainer; use ErrorContainer; diff --git a/src/WriteResponseInterface.php b/src/WriteResponseInterface.php new file mode 100644 index 00000000..c3218f94 --- /dev/null +++ b/src/WriteResponseInterface.php @@ -0,0 +1,26 @@ +=8.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^12.0", - "symfony/process": "^7.2" + "phpunit/phpunit": "^10.0", + "symfony/process": "^6.4" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "7.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -1289,7 +1289,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/7.0.0" + "source": "https://github.com/sebastianbergmann/diff/tree/5.1.1" }, "funding": [ { @@ -1297,50 +1297,51 @@ "type": "github" } ], - "time": "2025-02-07T04:55:46+00:00" + "time": "2024-03-02T07:15:17+00:00" }, { "name": "symfony/console", - "version": "v7.2.1", + "version": "v6.4.20", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3" + "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/fefcc18c0f5d0efe3ab3152f15857298868dc2c3", - "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3", + "url": "https://api.github.com/repos/symfony/console/zipball/2e4af9c952617cc3f9559ff706aee420a8464c36", + "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^6.4|^7.0" + "symfony/string": "^5.4|^6.0|^7.0" }, "conflict": { - "symfony/dependency-injection": "<6.4", - "symfony/dotenv": "<6.4", - "symfony/event-dispatcher": "<6.4", - "symfony/lock": "<6.4", - "symfony/process": "<6.4" + "symfony/dependency-injection": "<5.4", + "symfony/dotenv": "<5.4", + "symfony/event-dispatcher": "<5.4", + "symfony/lock": "<5.4", + "symfony/process": "<5.4" }, "provide": { "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/event-dispatcher": "^5.4|^6.0|^7.0", "symfony/http-foundation": "^6.4|^7.0", "symfony/http-kernel": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" + "symfony/lock": "^5.4|^6.0|^7.0", + "symfony/messenger": "^5.4|^6.0|^7.0", + "symfony/process": "^5.4|^6.0|^7.0", + "symfony/stopwatch": "^5.4|^6.0|^7.0", + "symfony/var-dumper": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -1374,7 +1375,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.2.1" + "source": "https://github.com/symfony/console/tree/v6.4.20" }, "funding": [ { @@ -1390,7 +1391,7 @@ "type": "tidelift" } ], - "time": "2024-12-11T03:49:26+00:00" + "time": "2025-03-03T17:16:38+00:00" }, { "name": "symfony/deprecation-contracts", @@ -1461,24 +1462,24 @@ }, { "name": "symfony/event-dispatcher", - "version": "v7.2.0", + "version": "v6.4.13", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "910c5db85a5356d0fea57680defec4e99eb9c8c1" + "reference": "0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/910c5db85a5356d0fea57680defec4e99eb9c8c1", - "reference": "910c5db85a5356d0fea57680defec4e99eb9c8c1", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e", + "reference": "0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/event-dispatcher-contracts": "^2.5|^3" }, "conflict": { - "symfony/dependency-injection": "<6.4", + "symfony/dependency-injection": "<5.4", "symfony/service-contracts": "<2.5" }, "provide": { @@ -1487,13 +1488,13 @@ }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/error-handler": "^5.4|^6.0|^7.0", + "symfony/expression-language": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", "symfony/service-contracts": "^2.5|^3", - "symfony/stopwatch": "^6.4|^7.0" + "symfony/stopwatch": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -1521,7 +1522,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.2.0" + "source": "https://github.com/symfony/event-dispatcher/tree/v6.4.13" }, "funding": [ { @@ -1537,7 +1538,7 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:21:43+00:00" + "time": "2024-09-25T14:18:03+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -1617,25 +1618,25 @@ }, { "name": "symfony/filesystem", - "version": "v7.2.0", + "version": "v6.4.13", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb" + "reference": "4856c9cf585d5a0313d8d35afd681a526f038dd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/b8dce482de9d7c9fe2891155035a7248ab5c7fdb", - "reference": "b8dce482de9d7c9fe2891155035a7248ab5c7fdb", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/4856c9cf585d5a0313d8d35afd681a526f038dd3", + "reference": "4856c9cf585d5a0313d8d35afd681a526f038dd3", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^6.4|^7.0" + "symfony/process": "^5.4|^6.4|^7.0" }, "type": "library", "autoload": { @@ -1663,7 +1664,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.2.0" + "source": "https://github.com/symfony/filesystem/tree/v6.4.13" }, "funding": [ { @@ -1679,27 +1680,27 @@ "type": "tidelift" } ], - "time": "2024-10-25T15:15:23+00:00" + "time": "2024-10-25T15:07:50+00:00" }, { "name": "symfony/finder", - "version": "v7.2.2", + "version": "v6.4.17", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb" + "reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/87a71856f2f56e4100373e92529eed3171695cfb", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb", + "url": "https://api.github.com/repos/symfony/finder/zipball/1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7", + "reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.1" }, "require-dev": { - "symfony/filesystem": "^6.4|^7.0" + "symfony/filesystem": "^6.0|^7.0" }, "type": "library", "autoload": { @@ -1727,7 +1728,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.2.2" + "source": "https://github.com/symfony/finder/tree/v6.4.17" }, "funding": [ { @@ -1743,24 +1744,24 @@ "type": "tidelift" } ], - "time": "2024-12-30T19:00:17+00:00" + "time": "2024-12-29T13:51:37+00:00" }, { "name": "symfony/options-resolver", - "version": "v7.2.0", + "version": "v6.4.16", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50" + "reference": "368128ad168f20e22c32159b9f761e456cec0c78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/7da8fbac9dcfef75ffc212235d76b2754ce0cf50", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/368128ad168f20e22c32159b9f761e456cec0c78", + "reference": "368128ad168f20e22c32159b9f761e456cec0c78", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/deprecation-contracts": "^2.5|^3" }, "type": "library", @@ -1794,7 +1795,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.2.0" + "source": "https://github.com/symfony/options-resolver/tree/v6.4.16" }, "funding": [ { @@ -1810,7 +1811,7 @@ "type": "tidelift" } ], - "time": "2024-11-20T11:17:29+00:00" + "time": "2024-11-20T10:57:02+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2288,20 +2289,20 @@ }, { "name": "symfony/process", - "version": "v7.2.4", + "version": "v6.4.20", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "d8f411ff3c7ddc4ae9166fb388d1190a2df5b5cf" + "reference": "e2a61c16af36c9a07e5c9906498b73e091949a20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/d8f411ff3c7ddc4ae9166fb388d1190a2df5b5cf", - "reference": "d8f411ff3c7ddc4ae9166fb388d1190a2df5b5cf", + "url": "https://api.github.com/repos/symfony/process/zipball/e2a61c16af36c9a07e5c9906498b73e091949a20", + "reference": "e2a61c16af36c9a07e5c9906498b73e091949a20", "shasum": "" }, "require": { - "php": ">=8.2" + "php": ">=8.1" }, "type": "library", "autoload": { @@ -2329,7 +2330,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.2.4" + "source": "https://github.com/symfony/process/tree/v6.4.20" }, "funding": [ { @@ -2345,7 +2346,7 @@ "type": "tidelift" } ], - "time": "2025-02-05T08:33:46+00:00" + "time": "2025-03-10T17:11:00+00:00" }, { "name": "symfony/service-contracts", @@ -2432,20 +2433,20 @@ }, { "name": "symfony/stopwatch", - "version": "v7.2.4", + "version": "v6.4.19", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd" + "reference": "dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", - "reference": "5a49289e2b308214c8b9c2fda4ea454d8b8ad7cd", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c", + "reference": "dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/service-contracts": "^2.5|^3" }, "type": "library", @@ -2474,7 +2475,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v7.2.4" + "source": "https://github.com/symfony/stopwatch/tree/v6.4.19" }, "funding": [ { @@ -2490,24 +2491,24 @@ "type": "tidelift" } ], - "time": "2025-02-24T10:49:57+00:00" + "time": "2025-02-21T10:06:30+00:00" }, { "name": "symfony/string", - "version": "v7.2.0", + "version": "v6.4.15", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "446e0d146f991dde3e73f45f2c97a9faad773c82" + "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/446e0d146f991dde3e73f45f2c97a9faad773c82", - "reference": "446e0d146f991dde3e73f45f2c97a9faad773c82", + "url": "https://api.github.com/repos/symfony/string/zipball/73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", + "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.1", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-intl-grapheme": "~1.0", "symfony/polyfill-intl-normalizer": "~1.0", @@ -2517,12 +2518,11 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/emoji": "^7.1", - "symfony/error-handler": "^6.4|^7.0", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/error-handler": "^5.4|^6.0|^7.0", + "symfony/http-client": "^5.4|^6.0|^7.0", + "symfony/intl": "^6.2|^7.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^5.4|^6.0|^7.0" }, "type": "library", "autoload": { @@ -2561,7 +2561,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.2.0" + "source": "https://github.com/symfony/string/tree/v6.4.15" }, "funding": [ { @@ -2577,7 +2577,7 @@ "type": "tidelift" } ], - "time": "2024-11-13T13:31:26+00:00" + "time": "2024-11-13T13:31:12+00:00" } ], "packages-dev": [], From 480e352ec1507b67ec954fb3f583c000066ef757 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 20:53:58 -0500 Subject: [PATCH 02/79] bit of readme update --- README.md | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 41bc3880..5765664c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ 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 @@ -28,7 +29,7 @@ Require Entry: ```json { "require": { - "dcarbone/php-consul-api": "^v2.0" + "dcarbone/php-consul-api": "^v3.0" } } ``` @@ -53,22 +54,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: @@ -84,10 +91,10 @@ As an example: ```php $proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']]); -$config = new \DCarbone\PHPConsulAPI\Config([ - 'HttpClient' => $proxyClient, - 'Address' => 'address of server', -]); +$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 From 50e62680365aacdfb0cf7c931e75b602bbd08372 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:05:52 -0500 Subject: [PATCH 03/79] readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 5765664c..14714cb2 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,18 @@ This library is loosely based upon the [official GO client](https://github.com/h 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 three big breaking changes between v2 and v3: + +1. The `FakeMap` class has been removed. It sucked. +2. The `FakeSlice` class has been removed. It sucked. +3. 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). +4. All of that `Transcoding` nonsense has been removed. + ## Composer This lib is designed to be used with [Composer](https://getcomposer.org) From c1b73737b93ee9599478b6ad61c796fe1afdf572 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:18:05 -0500 Subject: [PATCH 04/79] allowing old map-style construction --- src/ACL/ACLAuthMethod.php | 9 +++++++-- src/ACL/ACLAuthMethodListEntry.php | 9 +++++++-- src/ACL/ACLAuthMethodNamespaceRule.php | 15 +++++++++++---- src/ACL/ACLBindingRule.php | 9 +++++++-- src/ACL/ACLEntry.php | 9 +++++++-- src/ACL/ACLLink.php | 15 +++++++++++---- src/ACL/ACLLoginParams.php | 16 ++++++++++++---- src/ACL/ACLNodeIdentity.php | 15 +++++++++++---- src/ACL/ACLOIDCAuthURLParams.php | 10 ++++++++-- src/ACL/ACLOIDCCallbackParams.php | 9 +++++++-- src/ACL/ACLPolicy.php | 9 +++++++-- src/ACL/ACLPolicyListEntry.php | 9 +++++++-- src/ACL/ACLReplicationStatus.php | 9 +++++++-- src/ACL/ACLRole.php | 9 +++++++-- src/ACL/ACLServiceIdentity.php | 15 +++++++++++---- src/ACL/ACLToken.php | 9 +++++++-- src/ACL/ACLTokenListEntry.php | 9 +++++++-- src/ACL/KubernetesAuthMethodConfig.php | 16 ++++++++++++---- src/ACL/OIDCAuthMethodConfig.php | 12 ++++++++++-- 19 files changed, 163 insertions(+), 50 deletions(-) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 4433978a..1d29a9c5 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -39,6 +39,7 @@ class ACLAuthMethod extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $ID = '', string $Name = '', string $Type = '', @@ -51,6 +52,10 @@ public function __construct( iterable $NamespaceRules = [], string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Name = $Name; $this->Type = $Type; @@ -202,9 +207,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { switch ($k) { case 'MaxTokenTTL': diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 809b2f71..90db03a0 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -41,6 +41,7 @@ class ACLAuthMethodListEntry extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $Name = '', string $Type = '', string $DisplayName = '', @@ -51,6 +52,10 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->Name = $Name; $this->Type = $Type; $this->DisplayName = $DisplayName; @@ -174,9 +179,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if (null === $v) { continue; diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 387c000e..42f76fe9 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -27,8 +27,15 @@ class ACLAuthMethodNamespaceRule extends AbstractModel public string $Selector; public string $BindNamespace; - public function __construct(string $Selector = '', string $BindNamespace = '') - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $Selector = '', + string $BindNamespace = '', + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->Selector = $Selector; $this->BindNamespace = $BindNamespace; } @@ -55,9 +62,9 @@ public function setBindNamespace(string $BindNamespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 7af0e99e..4ef3550c 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -35,6 +35,7 @@ class ACLBindingRule extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $ID = '', string $Description = '', string $AuthMethod = '', @@ -45,6 +46,10 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Description = $Description; $this->AuthMethod = $AuthMethod; @@ -155,9 +160,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index 8c8ba4c9..eeb833e9 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -32,6 +32,7 @@ class ACLEntry extends AbstractModel public string $Rules; public function __construct( + array $data = [], // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $ID = '', @@ -39,6 +40,10 @@ public function __construct( string $Type = '', string $Rules = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->ID = $ID; @@ -113,9 +118,9 @@ public function setRules(string $rules): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index 806bb44a..007edfc5 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -27,8 +27,15 @@ class ACLLink extends AbstractModel public string $ID; public string $Name; - public function __construct(string $ID = '', string $Name = '') - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $ID = '', + string $Name = '', + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Name = $Name; } @@ -55,9 +62,9 @@ public function setName(string $Name): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index ea6f6ff4..db40356a 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -28,8 +28,16 @@ class ACLLoginParams extends AbstractModel public string $BearerToken; public null|array $Meta; - public function __construct(string $AuthMethod = '', string $BearerToken = '', null|array|\stdClass $Meta = null) - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $AuthMethod = '', + string $BearerToken = '', + null|array|\stdClass $Meta = null, + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; $this->setMeta($Meta); @@ -71,9 +79,9 @@ public function setMeta(null|array|\stdClass $Meta): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 5fc5b8a7..7c1ea03f 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -27,8 +27,15 @@ class ACLNodeIdentity extends AbstractModel public string $NodeName; public string $Datacenter; - public function __construct(string $NodeName = '', string $Datacenter = '') - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $NodeName = '', + string $Datacenter = '' + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->NodeName = $NodeName; $this->Datacenter = $Datacenter; } @@ -43,9 +50,9 @@ public function getDatacenter(): string return $this->Datacenter; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 65c920db..ec2461a6 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -30,11 +30,16 @@ class ACLOIDCAuthURLParams extends AbstractModel public null|array $Meta; public function __construct( + array $data = [], // Deprecated, will be removed. string $AuthMethod = '', string $RedirectURI = '', string $ClientNonce = '', null|array|\stdClass $Meta = null ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->AuthMethod = $AuthMethod; $this->RedirectURI = $RedirectURI; $this->ClientNonce = $ClientNonce; @@ -88,9 +93,10 @@ public function setMeta(null|array|\stdClass $Meta): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 251c5230..580454a1 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -30,11 +30,16 @@ class ACLOIDCCallbackParams extends AbstractModel public string $ClientNonce; public function __construct( + array $data = [], // Deprecated, will be removed. string $AuthMethod = '', string $State = '', string $Code = '', string $ClientNonce = '', ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->AuthMethod = $AuthMethod; $this->State = $State; $this->Code = $Code; @@ -85,9 +90,9 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index a0107a7a..379b2312 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -35,6 +35,7 @@ class ACLPolicy extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -45,6 +46,10 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -156,9 +161,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index e7c95419..2e301caf 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -34,6 +34,7 @@ class ACLPolicyListEntry extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -43,6 +44,10 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '', ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -141,9 +146,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 8bea3f33..fe0962fd 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -35,6 +35,7 @@ class ACLReplicationStatus extends AbstractModel public Time\Time $LastError; public function __construct( + array $data = [], // Deprecated, will be removed. bool $Enabled = false, bool $Running = false, string $SourceDatacenter = '', @@ -44,6 +45,10 @@ public function __construct( null|Time\Time $LastSuccess = null, null|Time\Time $LastError = null, ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->Enabled = $Enabled; $this->Running = $Running; $this->SourceDatacenter = $SourceDatacenter; @@ -94,9 +99,9 @@ public function getLastError(): Time\Time return $this->LastError; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('LastSuccess' === $k) { $n->LastSuccess = Time\Time::createFromFormat(DATE_RFC3339, $v); diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 4eba107e..ea9833c0 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -36,6 +36,7 @@ class ACLRole extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -47,6 +48,10 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -169,9 +174,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 61d43436..2c6f75a2 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -29,8 +29,15 @@ class ACLServiceIdentity extends AbstractModel public string $ServiceName; public array $Datacenters; - public function __construct(string $ServiceName = '', iterable $Datacenters = []) - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $ServiceName = '', + iterable $Datacenters = [] + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->ServiceName = $ServiceName; $this->Datacenters = $Datacenters; } @@ -51,9 +58,9 @@ public function setDatacenters(string ...$datacenters): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index f5e1edef..98773471 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -45,6 +45,7 @@ class ACLToken extends AbstractModel public string $Rules; public function __construct( + array $data = [], // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -63,6 +64,10 @@ public function __construct( string $Namespace = '', string $Rules = '', ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->AccessorID = $AccessorID; @@ -269,9 +274,9 @@ public function setRules(string $Rules): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index 17fc46fd..a2e4c82f 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -42,6 +42,7 @@ class ACLTokenListEntry extends AbstractModel public string $Namespace; public function __construct( + array $data = [], // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -58,6 +59,10 @@ public function __construct( bool $Legacy = false, string $Namespace = '' ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->AccessorID = $AccessorID; @@ -240,9 +245,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 707cae59..9767237c 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -28,8 +28,16 @@ class KubernetesAuthMethodConfig extends AbstractModel public string $CACert; public string $ServiceAccountJWT; - public function __construct(string $Host = '', string $CACert = '', string $ServiceAccountJWT = '') - { + public function __construct( + array $data = [], // Deprecated, will be removed. + string $Host = '', + string $CACert = '', + string $ServiceAccountJWT = '' + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; + } $this->Host = $Host; $this->CACert = $CACert; $this->ServiceAccountJWT = $ServiceAccountJWT; @@ -83,9 +91,9 @@ public function RenderToConfig(): array ]; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index 91fd3afb..c559082e 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -24,9 +24,17 @@ class OIDCAuthMethodConfig extends AbstractModel { - public static function jsonUnserialize(\stdClass $decoded): self + public function __construct( + array $data = [], // Deprecated, will be removed. + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { - $n = new static(); + $n = $into ?? new static(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } From 97dfca787394ca695718294a036ffad0de5cf145 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:19:37 -0500 Subject: [PATCH 05/79] small readme, may change... --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 14714cb2..6091b848 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ There are three big breaking changes between v2 and v3: constructors are the preferred method of construction. * Construction via associative array will be removed entirely in V4 (whenever I get around to that). 4. All of that `Transcoding` nonsense has been removed. +5. The `Config` class may no longer be constructed with a map. You must use construction parameters. ## Composer From 1a899308f2187b0abc1dd16395bd2dc39df2f258 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:20:06 -0500 Subject: [PATCH 06/79] lets be correct. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6091b848..1073712f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ is made and backwards compatibility issues will not be addressed. ### V3 Breaking Changes -There are three big breaking changes between v2 and v3: +There are a couple breaking changes between v2 and v3: 1. The `FakeMap` class has been removed. It sucked. 2. The `FakeSlice` class has been removed. It sucked. From 9519d4364b51d830c09dcaab142bd94602cbfa2d Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:23:22 -0500 Subject: [PATCH 07/79] reduce pointless line changes in PR. --- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentCheckRegistration.php | 2 +- src/Agent/AgentService.php | 2 +- src/Agent/AgentServiceCheck.php | 2 +- src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 2 +- src/Agent/AgentServiceConnectProxyConfig.php | 2 +- src/Agent/AgentServiceRegistration.php | 2 +- src/Agent/EnvoyExtension.php | 2 +- src/Agent/MetricsInfo.php | 2 +- src/Agent/Upstream.php | 2 +- src/Catalog/CatalogDeregistration.php | 2 +- src/Catalog/CatalogNode.php | 2 +- src/Catalog/CatalogNodeServiceList.php | 2 +- src/Catalog/CatalogRegistration.php | 2 +- src/Catalog/CatalogService.php | 2 +- src/Catalog/CompoundServiceName.php | 2 +- src/Catalog/GatewayService.php | 2 +- src/Catalog/Node.php | 2 +- src/ConfigEntry/ExposeConfig.php | 2 +- src/ConfigEntry/ExposePath.php | 2 +- src/ConfigEntry/MeshConfigEntry.php | 2 +- src/ConfigEntry/MeshGatewayConfig.php | 2 +- src/ConfigEntry/PassiveHealthCheck.php | 2 +- src/ConfigEntry/ProxyConfigEntry.php | 2 +- src/ConfigEntry/RingHashConfig.php | 2 +- src/ConfigEntry/ServiceConfigEntry.php | 2 +- src/ConfigEntry/ServiceResolverFailover.php | 2 +- src/ConfigEntry/ServiceResolverRedirect.php | 2 +- src/ConfigEntry/ServiceResolverSubset.php | 2 +- src/ConfigEntry/ServiceRoute.php | 2 +- src/ConfigEntry/ServiceRouteDestination.php | 2 +- src/ConfigEntry/ServiceRouteHTTPMatch.php | 2 +- src/ConfigEntry/ServiceRouteHTTPMatchHeader.php | 2 +- src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php | 2 +- src/ConfigEntry/ServiceRouteMatch.php | 2 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 2 +- src/ConfigEntry/ServiceSplit.php | 2 +- src/ConfigEntry/ServiceSplitterConfigEntry.php | 2 +- src/ConfigEntry/TransparentProxyConfig.php | 2 +- src/ConfigEntry/UpstreamConfiguration.php | 2 +- src/ConfigEntry/UpstreamLimits.php | 2 +- src/Coordinate/CoordinateDatacenterMap.php | 2 +- src/Coordinate/CoordinateEntry.php | 2 +- src/Health/HealthCheck.php | 2 +- src/Health/HealthCheckDefinition.php | 2 +- src/Health/ServiceEntry.php | 2 +- src/KV/CheckTxnOp.php | 2 +- src/KV/KVPair.php | 2 +- src/KV/KVTxnResponse.php | 2 +- src/KV/NodeTxnOp.php | 2 +- src/KV/ServiceTxnOp.php | 2 +- src/KV/TxnOp.php | 2 +- src/KV/TxnResponse.php | 2 +- src/KV/TxnResult.php | 2 +- src/Operator/AutopilotConfiguration.php | 2 +- src/Operator/AutopilotServer.php | 2 +- src/Operator/AutopilotState.php | 2 +- src/Operator/AutopilotUpgrade.php | 2 +- src/Operator/AutopilotZoneUpgradeVersions.php | 2 +- src/Operator/OperatorHealthReply.php | 2 +- src/Operator/RaftConfiguration.php | 2 +- src/Operator/SerfMember.php | 2 +- src/Operator/ServerHealth.php | 2 +- src/PreparedQuery/PreparedQueryDefinition.php | 2 +- src/PreparedQuery/PreparedQueryExecuteResponse.php | 2 +- src/PreparedQuery/ServiceQuery.php | 2 +- src/QueryOptions.php | 2 +- src/Session/SessionEntry.php | 2 +- 69 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index eccd2025..55235175 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -26,7 +26,7 @@ class AgentCheck extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_DEFINITION => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => HealthCheckDefinition::class, diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 5d15f4c0..0a2210f0 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -24,7 +24,7 @@ class AgentCheckRegistration extends AgentServiceCheck { - public const FIELDS = [ + 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, diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 74a62444..dd4de64e 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -30,7 +30,7 @@ class AgentService extends AbstractModel { use HasStringTags; - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_META => Transcoding::MAP_FIELD, self::FIELD_TAGGED_ADDRESSES => [ diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index a5a071ab..c31a3319 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -25,7 +25,7 @@ class AgentServiceCheck extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_CHECK_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_SCRIPT_ARGS => [ diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 18dfdf77..f2fb3dd6 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -26,7 +26,7 @@ class AgentServiceChecksInfo extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => AgentService::class, diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index a2318e7d..3f629e57 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -25,7 +25,7 @@ class AgentServiceConnect extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NATIVE => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_SIDECAR_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 8999ecd7..0fc59582 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -28,7 +28,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_ENVOY_EXTENSIONS => [ Transcoding::FIELD_CLASS => EnvoyExtension::class, Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index ee362c59..f565821b 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -31,7 +31,7 @@ class AgentServiceRegistration extends AbstractModel use HasSettableStringTags; use HasStringTags; - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_KIND => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_ID => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAME => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/Agent/EnvoyExtension.php b/src/Agent/EnvoyExtension.php index 61552129..e433e843 100644 --- a/src/Agent/EnvoyExtension.php +++ b/src/Agent/EnvoyExtension.php @@ -26,7 +26,7 @@ class EnvoyExtension extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_ARGUMENTS => Transcoding::MAP_FIELD, ]; diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index 8ab711a4..d580ab99 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -25,7 +25,7 @@ class MetricsInfo extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_GAUGES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => GaugeValue::class, diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index a4379b0e..96672596 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -26,7 +26,7 @@ class Upstream extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 88a33cae..139008fc 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -25,7 +25,7 @@ class CatalogDeregistration extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_ADDRESS => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index fc7c57d4..1f947d62 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -26,7 +26,7 @@ class CatalogNode extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index 90cd0be3..abae0f3a 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -26,7 +26,7 @@ class CatalogNodeServiceList extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index 22fe3e79..5175edc2 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -29,7 +29,7 @@ class CatalogRegistration extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD, self::FIELD_NODE_META => Transcoding::MAP_FIELD, self::FIELD_SERVICE => [ diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 29157d72..deb51345 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -27,7 +27,7 @@ class CatalogService extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVICE_TAGGED_ADDRESSES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServiceAddress::class, diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 67323218..31d32162 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -25,7 +25,7 @@ class CompoundServiceName extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 786691c9..2a47bee2 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -25,7 +25,7 @@ class GatewayService extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_GATEWAY => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => CompoundServiceName::class, diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 26210256..2a6d19fa 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -26,7 +26,7 @@ class Node extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_TAGGED_ADDRESSES => Transcoding::MAP_FIELD, self::FIELD_META => Transcoding::MAP_FIELD, ]; diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index feb19db3..de9d7867 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -25,7 +25,7 @@ class ExposeConfig extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_CHECKS => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_PATHS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index 964aa202..78d0ddb4 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -25,7 +25,7 @@ class ExposePath extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 76fb2454..27414433 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -27,7 +27,7 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - public const FIELDS = COnfigEntry::INTERFACE_FIELDS + [ + protected const FIELDS = COnfigEntry::INTERFACE_FIELDS + [ self::FIELD_TRANSPARENT_PROXY => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => TransparentProxyConfig::class, diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 673ba46a..68074e57 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -25,7 +25,7 @@ class MeshGatewayConfig extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index b5c00bf8..cec65118 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -26,7 +26,7 @@ class PassiveHealthCheck extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_INTERVAL => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, Transcoding::FIELD_OMITEMPTY => true, diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index e3d30eeb..d8896dd8 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -28,7 +28,7 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_CONFIG => Transcoding::MAP_FIELD, self::FIELD_TRANSPARENT_PROXY => [ diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php index 59208639..6b7fad97 100644 --- a/src/ConfigEntry/RingHashConfig.php +++ b/src/ConfigEntry/RingHashConfig.php @@ -25,7 +25,7 @@ class RingHashConfig extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_MINIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD, self::FIELD_MAXIMUM_RING_SIZE => Transcoding::OMITEMPTY_INTEGER_FIELD, ]; diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index d2cf8772..750fe4ce 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -27,7 +27,7 @@ class ServiceConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_PROTOCOL => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_TRANSPARENT_PROXY => [ diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php index 2e9d9918..54fad4ca 100644 --- a/src/ConfigEntry/ServiceResolverFailover.php +++ b/src/ConfigEntry/ServiceResolverFailover.php @@ -25,7 +25,7 @@ class ServiceResolverFailover extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php index 0e203dd9..a8410274 100644 --- a/src/ConfigEntry/ServiceResolverRedirect.php +++ b/src/ConfigEntry/ServiceResolverRedirect.php @@ -25,7 +25,7 @@ class ServiceResolverRedirect extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/ServiceResolverSubset.php b/src/ConfigEntry/ServiceResolverSubset.php index 5aae849c..7a1f8909 100644 --- a/src/ConfigEntry/ServiceResolverSubset.php +++ b/src/ConfigEntry/ServiceResolverSubset.php @@ -25,7 +25,7 @@ class ServiceResolverSubset extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_FILTER => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_ONLY_PASSING => Transcoding::OMITEMPTY_BOOLEAN_FIELD, ]; diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php index 636ca3d5..c8c60400 100644 --- a/src/ConfigEntry/ServiceRoute.php +++ b/src/ConfigEntry/ServiceRoute.php @@ -24,7 +24,7 @@ class ServiceRoute extends AbstractModel { - public const FIELDS = []; + protected const FIELDS = []; private const FIELD_MATCH = 'Match'; private const FIELD_DESTINATION = 'Destination'; diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index e5fb321b..22db2b68 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -26,7 +26,7 @@ class ServiceRouteDestination extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php index 598372ed..6e0e4211 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatch extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php index f03b496c..b7181eea 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatchHeader extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_PREFIX => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php index b89fc091..0063f23b 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -25,7 +25,7 @@ class ServiceRouteHTTPMatchQueryParam extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_PRESENT => Transcoding::OMITEMPTY_BOOLEAN_FIELD, self::FIELD_EXACT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_REGEX => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/ConfigEntry/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php index ab43074f..dfb7f5d6 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -25,7 +25,7 @@ class ServiceRouteMatch extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_HTTP => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => ServiceRouteHTTPMatch::class, diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 5f4b684f..5ae2d93c 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -27,7 +27,7 @@ class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_ROUTES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT, diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php index a70e916f..96319b07 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -25,7 +25,7 @@ class ServiceSplit extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index b08d9d2b..b821f2cb 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -27,7 +27,7 @@ class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; - public const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ + protected const FIELDS = ConfigEntry::INTERFACE_FIELDS + [ self::FIELD_SPLITS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT, diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index 3c71050d..0f6d5b30 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -25,7 +25,7 @@ class TransparentProxyConfig extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_OUTBOUND_LISTENER_PORT => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_DIALED_DIRECTLY => Transcoding::OMITEMPTY_BOOLEAN_FIELD, ]; diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php index fa4049c0..7aa0b584 100644 --- a/src/ConfigEntry/UpstreamConfiguration.php +++ b/src/ConfigEntry/UpstreamConfiguration.php @@ -25,7 +25,7 @@ class UpstreamConfiguration extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/ConfigEntry/UpstreamLimits.php b/src/ConfigEntry/UpstreamLimits.php index 83a224f9..10868d89 100644 --- a/src/ConfigEntry/UpstreamLimits.php +++ b/src/ConfigEntry/UpstreamLimits.php @@ -25,7 +25,7 @@ class UpstreamLimits extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_MAX_CONNECTIONS => [ Transcoding::FIELD_NULLABLE => true, ], diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php index 87d0fd33..6cf83530 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -25,7 +25,7 @@ class CoordinateDatacenterMap extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_COORDINATES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => Coordinate::class, diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index a8dc7c62..d6503694 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -25,7 +25,7 @@ class CoordinateEntry extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_COORDINATE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Coordinate::class, diff --git a/src/Health/HealthCheck.php b/src/Health/HealthCheck.php index 87ea63c4..6b6e88c1 100644 --- a/src/Health/HealthCheck.php +++ b/src/Health/HealthCheck.php @@ -25,7 +25,7 @@ class HealthCheck extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_DEFINITION => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index afcdc12c..1c6a1e1e 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -28,7 +28,7 @@ class HealthCheckDefinition extends AbstractModel implements \JsonSerializable { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_INTERVAL_DURATION => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, Transcoding::FIELD_SKIP => true, diff --git a/src/Health/ServiceEntry.php b/src/Health/ServiceEntry.php index aab2b77a..96773463 100644 --- a/src/Health/ServiceEntry.php +++ b/src/Health/ServiceEntry.php @@ -27,7 +27,7 @@ class ServiceEntry extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/KV/CheckTxnOp.php b/src/KV/CheckTxnOp.php index 8132b558..0ffce250 100644 --- a/src/KV/CheckTxnOp.php +++ b/src/KV/CheckTxnOp.php @@ -26,7 +26,7 @@ class CheckTxnOp extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_CHECK => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => HealthCheck::class, diff --git a/src/KV/KVPair.php b/src/KV/KVPair.php index ef4c9826..0a81ec7a 100644 --- a/src/KV/KVPair.php +++ b/src/KV/KVPair.php @@ -25,7 +25,7 @@ class KVPair extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, ]; diff --git a/src/KV/KVTxnResponse.php b/src/KV/KVTxnResponse.php index e3370260..dfd2d9f1 100644 --- a/src/KV/KVTxnResponse.php +++ b/src/KV/KVTxnResponse.php @@ -25,7 +25,7 @@ class KVTxnResponse extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_RESULTS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => KVPair::class, diff --git a/src/KV/NodeTxnOp.php b/src/KV/NodeTxnOp.php index d1f8c701..872f7d5d 100644 --- a/src/KV/NodeTxnOp.php +++ b/src/KV/NodeTxnOp.php @@ -26,7 +26,7 @@ class NodeTxnOp extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NODE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => Node::class, diff --git a/src/KV/ServiceTxnOp.php b/src/KV/ServiceTxnOp.php index 3e8089b2..52c50964 100644 --- a/src/KV/ServiceTxnOp.php +++ b/src/KV/ServiceTxnOp.php @@ -26,7 +26,7 @@ class ServiceTxnOp extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => AgentService::class, diff --git a/src/KV/TxnOp.php b/src/KV/TxnOp.php index a4f33aef..f5f50a44 100644 --- a/src/KV/TxnOp.php +++ b/src/KV/TxnOp.php @@ -25,7 +25,7 @@ class TxnOp extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_KV => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => KVTxnOp::class, diff --git a/src/KV/TxnResponse.php b/src/KV/TxnResponse.php index 23369f77..7bcdfd9c 100644 --- a/src/KV/TxnResponse.php +++ b/src/KV/TxnResponse.php @@ -25,7 +25,7 @@ class TxnResponse extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_RESULTS => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => TxnResults::class, diff --git a/src/KV/TxnResult.php b/src/KV/TxnResult.php index 0a772d27..1f7af537 100644 --- a/src/KV/TxnResult.php +++ b/src/KV/TxnResult.php @@ -28,7 +28,7 @@ class TxnResult extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_KV => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => KVPair::class, diff --git a/src/Operator/AutopilotConfiguration.php b/src/Operator/AutopilotConfiguration.php index 00893130..0e2916f6 100644 --- a/src/Operator/AutopilotConfiguration.php +++ b/src/Operator/AutopilotConfiguration.php @@ -25,7 +25,7 @@ class AutopilotConfiguration extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_LAST_CONTACT_THRESHOLD => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index 6239790a..3e0ff8d0 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -26,7 +26,7 @@ class AutopilotServer extends AbstractModel implements \JsonSerializable { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_LAST_CONTACT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/Operator/AutopilotState.php b/src/Operator/AutopilotState.php index 4c8384b4..881d8247 100644 --- a/src/Operator/AutopilotState.php +++ b/src/Operator/AutopilotState.php @@ -25,7 +25,7 @@ class AutopilotState extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => AutopilotServer::class, diff --git a/src/Operator/AutopilotUpgrade.php b/src/Operator/AutopilotUpgrade.php index 8002f117..fa372a69 100644 --- a/src/Operator/AutopilotUpgrade.php +++ b/src/Operator/AutopilotUpgrade.php @@ -25,7 +25,7 @@ class AutopilotUpgrade extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/Operator/AutopilotZoneUpgradeVersions.php b/src/Operator/AutopilotZoneUpgradeVersions.php index 93843053..9b07c349 100644 --- a/src/Operator/AutopilotZoneUpgradeVersions.php +++ b/src/Operator/AutopilotZoneUpgradeVersions.php @@ -25,7 +25,7 @@ class AutopilotZoneUpgradeVersions extends AbstractModel { - public const FIELDS = [ + 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, diff --git a/src/Operator/OperatorHealthReply.php b/src/Operator/OperatorHealthReply.php index 624ed577..a837eb7a 100644 --- a/src/Operator/OperatorHealthReply.php +++ b/src/Operator/OperatorHealthReply.php @@ -25,7 +25,7 @@ class OperatorHealthReply extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServerHealth::class, diff --git a/src/Operator/RaftConfiguration.php b/src/Operator/RaftConfiguration.php index e2fc7675..525f4e4a 100644 --- a/src/Operator/RaftConfiguration.php +++ b/src/Operator/RaftConfiguration.php @@ -25,7 +25,7 @@ class RaftConfiguration extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVERS => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => RaftServer::class, diff --git a/src/Operator/SerfMember.php b/src/Operator/SerfMember.php index 8afedd0b..3c22bf53 100644 --- a/src/Operator/SerfMember.php +++ b/src/Operator/SerfMember.php @@ -26,7 +26,7 @@ class SerfMember extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_RTT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, ], diff --git a/src/Operator/ServerHealth.php b/src/Operator/ServerHealth.php index bd719b8d..e50af771 100644 --- a/src/Operator/ServerHealth.php +++ b/src/Operator/ServerHealth.php @@ -26,7 +26,7 @@ class ServerHealth extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_LAST_CONTACT => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => [ReadableDuration::class, 'unmarshalJSON'], Transcoding::FIELD_NULLABLE => true, diff --git a/src/PreparedQuery/PreparedQueryDefinition.php b/src/PreparedQuery/PreparedQueryDefinition.php index c6df12ea..236b1ca1 100644 --- a/src/PreparedQuery/PreparedQueryDefinition.php +++ b/src/PreparedQuery/PreparedQueryDefinition.php @@ -25,7 +25,7 @@ class PreparedQueryDefinition extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_SERVICE => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, Transcoding::FIELD_CLASS => ServiceQuery::class, diff --git a/src/PreparedQuery/PreparedQueryExecuteResponse.php b/src/PreparedQuery/PreparedQueryExecuteResponse.php index 18597462..1a28093b 100644 --- a/src/PreparedQuery/PreparedQueryExecuteResponse.php +++ b/src/PreparedQuery/PreparedQueryExecuteResponse.php @@ -26,7 +26,7 @@ class PreparedQueryExecuteResponse extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NODES => [ Transcoding::FIELD_TYPE => Transcoding::ARRAY, Transcoding::FIELD_CLASS => ServiceEntry::class, diff --git a/src/PreparedQuery/ServiceQuery.php b/src/PreparedQuery/ServiceQuery.php index 9089d89c..f3c9f612 100644 --- a/src/PreparedQuery/ServiceQuery.php +++ b/src/PreparedQuery/ServiceQuery.php @@ -30,7 +30,7 @@ class ServiceQuery extends AbstractModel use HasSettableStringTags; use HasStringTags; - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, self::FIELD_FAILOVER => [ Transcoding::FIELD_TYPE => Transcoding::OBJECT, diff --git a/src/QueryOptions.php b/src/QueryOptions.php index e06f1420..cf6fff29 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -24,7 +24,7 @@ class QueryOptions extends AbstractModel implements RequestOptions { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_MAX_AGE => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, ], diff --git a/src/Session/SessionEntry.php b/src/Session/SessionEntry.php index 8a206382..e269c2b1 100644 --- a/src/Session/SessionEntry.php +++ b/src/Session/SessionEntry.php @@ -28,7 +28,7 @@ class SessionEntry extends AbstractModel { - public const FIELDS = [ + protected const FIELDS = [ self::FIELD_LOCK_DELAY => [ Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, ], From 7a4f1c87e0f7a44b65737fa59bea1a9c03d11235 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 21:28:45 -0500 Subject: [PATCH 08/79] well that was dumb. --- src/Config.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Config.php b/src/Config.php index 6d0c0910..7cf39382 100644 --- a/src/Config.php +++ b/src/Config.php @@ -128,10 +128,7 @@ public function __construct( $this->CertFile = self::_resolveValue($CertFile, Consul::HTTPClientCertEnvName, ''); $this->KeyFile = self::_resolveValue($KeyFile, Consul::HTTPClientKeyEnvName, ''); $skipVerify = self::_resolveValue($InsecureSkipVerify, Consul::HTTPSSLVerifyEnvName, false); - $this->InsecureSkipVerify = match($skipVerify) { - is_string($skipVerify) => strtolower($skipVerify) === 'true', - default => $skipVerify, - }; + $this->InsecureSkipVerify = is_string($skipVerify) ? strtolower($skipVerify) === 'true' : $skipVerify; // quick validation on key/cert combo $c = $this->CertFile; From f847aeeea77163c5780b4e9792904b281d3440d2 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:04:43 -0500 Subject: [PATCH 09/79] removing trash, updating some base classes --- src/MapResponse.php | 10 +- src/Marshaller.php | 148 ---------------- src/Operator/ReadableDuration.php | 3 +- src/QueryMeta.php | 45 +++-- src/QueryOptions.php | 169 +++++++++++------- src/RequestResponse.php | 25 ++- src/ScalarType.php | 31 ---- src/Transcoding.php | 130 -------------- src/Unmarshaller.php | 282 ------------------------------ src/Values.php | 39 ++--- src/WriteMeta.php | 9 +- src/WriteOptions.php | 60 +++++-- 12 files changed, 218 insertions(+), 733 deletions(-) delete mode 100644 src/Marshaller.php delete mode 100644 src/ScalarType.php delete mode 100644 src/Transcoding.php delete mode 100644 src/Unmarshaller.php diff --git a/src/MapResponse.php b/src/MapResponse.php index cecfec0f..7887998f 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -22,15 +22,19 @@ class MapResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?array $Map = null; + public null|array $Map = null; - public function getValue(): ?array + public function getValue(): null|array { return $this->Map; } public function unmarshalValue(mixed $decodedData): void { - $this->Map = $decodedData; + if (null === $decodedData) { + $this->Map = null; + return; + } + $this->Map = (array)$decodedData; } } diff --git a/src/Marshaller.php b/src/Marshaller.php deleted file mode 100644 index 86a07ed7..00000000 --- a/src/Marshaller.php +++ /dev/null @@ -1,148 +0,0 @@ -{$field} = $value; - return; - } - - // if this field is marked as being "skipped", do not set, then move on. - if ($def[Transcoding::FIELD_SKIP] ?? false) { - return; - } - - // if this field is marked as needing to be typecast to a specific type for output - if (isset($def[Transcoding::FIELD_MARSHAL_AS])) { - $value = match ($def[Transcoding::FIELD_MARSHAL_AS]) { - Transcoding::STRING => (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. - } - - public static function marshalJSON(object $obj, array $fields, array $dynamic): \stdClass - { - - } -} diff --git a/src/Operator/ReadableDuration.php b/src/Operator/ReadableDuration.php index 303c6720..ccabca3f 100644 --- a/src/Operator/ReadableDuration.php +++ b/src/Operator/ReadableDuration.php @@ -21,9 +21,8 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\ScalarType; -class ReadableDuration extends Time\Duration implements \JsonSerializable, ScalarType +class ReadableDuration extends Time\Duration implements \JsonSerializable { public static function unmarshalJSON(object $instance, string $field, mixed $value): void { diff --git a/src/QueryMeta.php b/src/QueryMeta.php index ea23adef..cb2c5497 100644 --- a/src/QueryMeta.php +++ b/src/QueryMeta.php @@ -24,15 +24,38 @@ class QueryMeta { - public string $RequestUrl = ''; - public int $LastIndex = 0; - public string $LastContentHash = ''; - public int $LastContact = 0; - public bool $KnownLeader = false; - public ?Time\Duration $RequestTime = null; - public bool $AddressTranslationEnabled = false; - public bool $CacheHit = false; - public ?Time\Duration $CacheAge = null; + public string $RequestUrl; + public int $LastIndex; + public string $LastContentHash; + public int $LastContact; + public bool $KnownLeader; + public Time\Duration $RequestTime; + public bool $AddressTranslationEnabled; + public bool $CacheHit; + public Time\Duration $CacheAge; + + public function __construct( + string $RequestUrl, + null|int|float|string|\DateInterval|Time\Duration $RequestTime, + int $LastIndex = 0, + string $LastContentHash = '', + int $LastContact = 0, + bool $KnownLeader = false, + bool $AddressTranslationEnabled = false, + bool $CacheHit = false, + null|int|float|string|\DateInterval|Time\Duration $CacheAge = null + ) { + $this->RequestUrl = $RequestUrl; + $this->RequestTime = Time::Duration($RequestTime); + + $this->LastIndex = $LastIndex; + $this->LastContentHash = $LastContentHash; + $this->LastContact = $LastContact; + $this->KnownLeader = $KnownLeader; + $this->AddressTranslationEnabled = $AddressTranslationEnabled; + $this->CacheHit = $CacheHit; + $this->CacheAge = Time::Duration($CacheAge); + } public function getRequestUrl(): string { @@ -59,7 +82,7 @@ public function isKnownLeader(): bool return $this->KnownLeader; } - public function getRequestTime(): ?Time\Duration + public function getRequestTime(): null|Time\Duration { return $this->RequestTime; } @@ -74,7 +97,7 @@ public function isCacheHit(): bool return $this->CacheHit; } - public function getCacheAge(): ?Time\Duration + public function getCacheAge(): null|Time\Duration { return $this->CacheAge; } diff --git a/src/QueryOptions.php b/src/QueryOptions.php index cf6fff29..80682718 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -22,65 +22,75 @@ use DCarbone\Go\Time; -class QueryOptions extends AbstractModel implements RequestOptions +class QueryOptions implements RequestOptions { - protected const FIELDS = [ - self::FIELD_MAX_AGE => [ - Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, - ], - self::FIELD_STALE_IF_ERROR => [ - Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, - ], - self::FIELD_WAIT_TIME => [ - Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, - ], - self::FIELD_TIMEOUT => [ - Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_NULLABLE_DURATION, - ], - ]; - - private const FIELD_MAX_AGE = 'MaxAge'; - private const FIELD_STALE_IF_ERROR = 'StaleIfError'; - private const FIELD_WAIT_TIME = 'WaitTime'; - private const FIELD_TIMEOUT = 'Timeout'; - - public string $Namespace = ''; - public string $Datacenter = ''; - public bool $AllowStale = false; - public bool $RequireConsistent = false; - public bool $UseCache = false; - public ?Time\Duration $MaxAge = null; - public ?Time\Duration $StaleIfError = null; - public int $WaitIndex = 0; - public string $WaitHash = ''; - public ?Time\Duration $WaitTime = null; - public string $Token = ''; - public string $Near = ''; - public string $Filter = ''; - public array $NodeMeta = []; - public int $RelayFactor = 0; - public bool $LocalOnly = false; - public bool $Connect = false; - - public ?Time\Duration $Timeout = null; - - public bool $Pretty = false; - - public function __construct(?array $data = null) - { - parent::__construct($data); - if (!($this->MaxAge instanceof Time\Duration)) { - $this->MaxAge = Time::Duration($this->MaxAge); - } - if (!($this->StaleIfError instanceof Time\Duration)) { - $this->StaleIfError = Time::Duration($this->StaleIfError); - } - if (!($this->WaitTime instanceof Time\Duration)) { - $this->WaitTime = Time::Duration($this->WaitTime); - } - if (!($this->Timeout instanceof Time\Duration)) { - $this->Timeout = Time::Duration($this->Timeout); + public string $Namespace; + public string $Datacenter; + public bool $AllowStale; + public bool $RequireConsistent; + public bool $UseCache; + public Time\Duration $MaxAge; + public Time\Duration $StaleIfError; + public int $WaitIndex; + public string $WaitHash; + public Time\Duration $WaitTime; + public string $Token; + public string $Near; + public string $Filter; + public array $NodeMeta; + public int $RelayFactor; + public bool $LocalOnly; + public bool $Connect; + + public Time\Duration $Timeout; + + public bool $Pretty; + + public function __construct( + array $data = [], // Deprecated do not use. + string $Namespace = '', + string $Datacenter = '', + bool $AllowStale = false, + bool $RequireConsistent = false, + bool $UseCache = false, + null|int|float|string|\DateInterval|Time\Duration $MaxAge = null, + null|int|float|string|\DateInterval|Time\Duration $StaleIfError = null, + int $WaitIndex = 0, + string $WaitHash = '', + null|int|float|string|\DateInterval|Time\Duration $WaitTime = null, + string $Token = '', + string $Near = '', + string $Filter = '', + array $NodeMeta = [], + int $RelayFactor = 0, + bool $LocalOnly = false, + bool $Connect = false, + null|int|float|string|\DateInterval|Time\Duration $Timeout = null, + bool $Pretty = false, + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; } + $this->Namespace = $Namespace; + $this->Datacenter = $Datacenter; + $this->AllowStale = $AllowStale; + $this->RequireConsistent = $RequireConsistent; + $this->UseCache = $UseCache; + $this->MaxAge = Time::Duration($MaxAge); + $this->StaleIfError = Time::Duration($StaleIfError); + $this->WaitIndex = $WaitIndex; + $this->WaitHash = $WaitHash; + $this->WaitTime = Time::Duration($WaitTime); + $this->Token = $Token; + $this->Near = $Near; + $this->Filter = $Filter; + $this->NodeMeta = $NodeMeta; + $this->RelayFactor = $RelayFactor; + $this->LocalOnly = $LocalOnly; + $this->Connect = $Connect; + $this->Timeout = Time::Duration($Timeout); + $this->Pretty = $Pretty; } public function getNamespace(): string @@ -138,7 +148,7 @@ public function getMaxAge(): Time\Duration return $this->MaxAge; } - public function setMaxAge(float|int|string|Time\Duration|null $maxAge): void + public function setMaxAge(null|int|float|string|\DateInterval|Time\Duration $maxAge): void { $this->MaxAge = Time::Duration($maxAge); } @@ -148,7 +158,7 @@ public function getStaleIfError(): Time\Duration return $this->StaleIfError; } - public function setStaleIfError(float|int|string|Time\Duration|null $staleIfError): void + public function setStaleIfError(null|int|float|string|\DateInterval|Time\Duration $staleIfError): void { $this->StaleIfError = Time::Duration($staleIfError); } @@ -168,7 +178,7 @@ public function getWaitTime(): Time\Duration return $this->WaitTime; } - public function setWaitTime(mixed $waitTime): void + public function setWaitTime(null|int|float|string|\DateInterval|Time\Duration $waitTime): void { $this->WaitTime = Time::Duration($waitTime); } @@ -253,12 +263,12 @@ public function setConnect(bool $connect): void $this->Connect = $connect; } - public function getTimeout(): ?Time\Duration + public function getTimeout(): Time\Duration { return $this->Timeout; } - public function setTimeout(float|int|string|Time\Duration|null $timeout): void + public function setTimeout(null|int|float|string|\DateInterval|Time\Duration $timeout): void { $this->Timeout = Time::Duration($timeout); } @@ -288,9 +298,9 @@ public function apply(Request $r): void $r->params->set('consistent', ''); } if (0 !== $this->WaitIndex) { - $r->params->set('index', (string) $this->WaitIndex); + $r->params->set('index', (string)$this->WaitIndex); } - if (isset($this->WaitTime) && 0 < $this->WaitTime->Microseconds()) { + if (0 < $this->WaitTime->Microseconds()) { $r->params->set('wait', dur_to_millisecond($this->WaitTime)); } if ('' !== $this->WaitHash) { @@ -305,13 +315,13 @@ public function apply(Request $r): void if ('' !== $this->Filter) { $r->params->set('filter', $this->Filter); } - if (isset($this->NodeMeta) && [] !== $this->NodeMeta) { + if ([] !== $this->NodeMeta) { foreach ($this->NodeMeta as $k => $v) { $r->params->add('node-meta', "{$k}:{$v}"); } } if (0 !== $this->RelayFactor) { - $r->params->set('relay-factor', (string) $this->RelayFactor); + $r->params->set('relay-factor', (string)$this->RelayFactor); } if ($this->LocalOnly) { $r->params->set('local-only', 'true'); @@ -335,7 +345,7 @@ public function apply(Request $r): void } } - if (null !== $this->Timeout) { + if (0 < $this->Timeout->Nanoseconds()) { $r->timeout = $this->Timeout; } @@ -343,4 +353,29 @@ public function apply(Request $r): void $r->params->set('pretty', ''); } } + + /** + * @param \stdClass $decoded + * @param \DCarbone\PHPConsulAPI\QueryOptions|null $into + * @return self + * @deprecated This is only here to support construction with map. It will be removed in a future version. + */ + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('MaxAge' === $k) { + $n->MaxAge = Time::Duration($v); + } elseif ('StaleIfError' === $k) { + $n->StaleIfError = Time::Duration($v); + } elseif ('WaitTime' === $k) { + $n->WaitTime = Time::Duration($v); + } elseif ('Timeout' === $k) { + $n->Timeout = Time::Duration($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } } diff --git a/src/RequestResponse.php b/src/RequestResponse.php index 00b3a2e3..29dfe33e 100644 --- a/src/RequestResponse.php +++ b/src/RequestResponse.php @@ -27,10 +27,10 @@ final class RequestResponse { public RequestMeta $RequestMeta; public Time\Duration $Duration; - public ?ResponseInterface $Response; - public ?Error $Err; + public null|ResponseInterface $Response; + public null|Error $Err; - public function __construct(RequestMeta $meta, Time\Duration $dur, ?ResponseInterface $resp, ?Error $err) + public function __construct(RequestMeta $meta, Time\Duration $dur, null|ResponseInterface $resp, null|Error $err) { $this->RequestMeta = $meta; $this->Duration = $dur; @@ -48,24 +48,23 @@ public function getDuration(): Time\Duration return $this->Duration; } - public function getResponse(): ?ResponseInterface + public function getResponse(): null|ResponseInterface { return $this->Response; } - public function getErr(): ?Error + public function getErr(): null|Error { return $this->Err; } public function buildQueryMeta(): QueryMeta { - // init class - $qm = new QueryMeta(); - // set some always-defined values - $qm->RequestTime = $this->Duration; - $qm->RequestUrl = (string)$this->RequestMeta->uri; + $qm = new QueryMeta( + RequestUrl: (string)$this->RequestMeta->uri, + RequestTime: $this->Duration, + ); // if there was no response, return as-is // note: should never see this in the wild. @@ -95,7 +94,7 @@ public function buildQueryMeta(): QueryMeta } if ('' !== ($h = $this->Response->getHeaderLine(Consul::_headerCache))) { - $qm->CacheAge = Time::Duration(\intval($h, 10) * Time::Second); + $qm->CacheAge = Time::Duration((int)$h * Time::Second); } return $qm; @@ -103,8 +102,6 @@ public function buildQueryMeta(): QueryMeta public function buildWriteMeta(): WriteMeta { - $wm = new WriteMeta(); - $wm->RequestTime = $this->Duration; - return $wm; + return new WriteMeta($this->Duration); } } diff --git a/src/ScalarType.php b/src/ScalarType.php deleted file mode 100644 index 3dc28b72..00000000 --- a/src/ScalarType.php +++ /dev/null @@ -1,31 +0,0 @@ - self::OBJECT, self::FIELD_CLASS => FakeMap::class]; - public const DURATION_FIELD = [ - self::FIELD_TYPE => self::OBJECT, - self::FIELD_CLASS => Time\Duration::class, - ] + self::UNMARSHAL_DURATION; - - //-- common field type definitions with omitempty - - public const OMITEMPTY_FIELD = [self::FIELD_OMITEMPTY => true]; - - public const OMITEMPTY_STRING_FIELD = [self::FIELD_TYPE => self::STRING] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_INTEGER_FIELD = [self::FIELD_TYPE => self::INTEGER] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_DOUBLE_FIELD = [self::FIELD_TYPE => self::DOUBLE] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_BOOLEAN_FIELD = [self::FIELD_TYPE => self::BOOLEAN] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_STRING_ARRAY_FIELD = [ - self::FIELD_TYPE => self::ARRAY, - self::FIELD_ARRAY_TYPE => self::STRING, - ] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_INTEGER_ARRAY_FIELD = [ - self::FIELD_TYPE => self::ARRAY, - self::FIELD_ARRAY_TYPE => self::INTEGER, - ] + self::OMITEMPTY_FIELD; - public const OMITEMPTY_MAP_FIELD = self::MAP_FIELD + self::OMITEMPTY_FIELD; - - public static function isScalar(string $type): bool - { - return \in_array($type, self::SCALAR, true); - } - - public static function unmarshalTime(object $instance, string $field, Time\Time|string $value): void - { - if ($value instanceof Time\Time) { - $instance->{$field} = clone $value; - return; - } - $instance->{$field} = Time\Time::createFromFormat(\DATE_RFC3339, $value); - } - - public static function unmarshalNullableTime(object $instance, string $field, Time\Time|string|null $value): void - { - if (null === $value) { - $instance->{$field} = null; - return; - } - self::unmarshalTime($instance, $field, $value); - } - - /** - * This accepts a multitude of $value types. See Time::Duration for implementation details. - * - * @param object $instance - * @param string $field - * @param mixed $value - */ - public static function unmarshalDuration(object $instance, string $field, mixed $value): void - { - $instance->{$field} = Time::Duration($value); - } - - public static function unmarshalNullableDuration(object $instance, string $field, mixed $value): void - { - if (null === $value) { - $instance->{$field} = null; - return; - } - self::unmarshalDuration($instance, $field, $value); - } -} diff --git a/src/Unmarshaller.php b/src/Unmarshaller.php deleted file mode 100644 index 552a4217..00000000 --- a/src/Unmarshaller.php +++ /dev/null @@ -1,282 +0,0 @@ -{$field} = $value; - } elseif (null !== $value) { - // at this point, value must be non-null to be operable - if (isset($model->{$field}) && is_scalar($model->{$field})) { - // if the property has a scalar default value, unmarshal it as such. - self::unmarshalScalar(model: $model, field: $field, value: $value, nullable: false); - } else { - // if we fall down here, try to set the value as-is. if this barfs, it indicates we have a bug to be - // squished. - // todo: should this be an exception? - $model->{$field} = $value; - } - } - // if the value is null at this point, ignore and move on. - // note: this is not checked prior to the property_exists call as if the field is not explicitly defined but - // is seen with a null value, we still want to define it as null on the implementing type. - } - - protected static function fieldIsNullable(array $fieldDef): bool - { - // todo: make sure this key is always a bool... - return $fieldDef[Transcoding::FIELD_NULLABLE] ?? false; - } - - protected static function scalarZeroVal(string $type): float|bool|int|string|null - { - return match ($type) { - Transcoding::STRING => '', - Transcoding::INTEGER => 0, - Transcoding::DOUBLE => 0.0, - Transcoding::BOOLEAN => false, - default => null, - }; - } - - private static function buildScalarValue(mixed $value, string $type, bool $nullable): float|bool|int|string|null - { - if (null === $value) { - return $nullable ? null : self::scalarZeroVal(type: $type); - } - - return match ($type) { - Transcoding::STRING => (string)$value, - Transcoding::INTEGER => (int)$value, - Transcoding::DOUBLE => (float)$value, - Transcoding::BOOLEAN => (bool)$value, - - // if we fall down to here, default to try to set the value to whatever it happens to be. - default => $value, - }; - } - - private static function buildObjectValue(null|object|array $value, string $class, bool $nullable): ?object - { - // if the incoming value is null... - if (null === $value) { - return $nullable ? null : new $class(); - } - // if the incoming value is already an instance of the class, clone it and return - if ($value instanceof $class) { - return clone $value; - } - // otherwise, attempt to cast whatever was provided as an array and construct a new instance of $class - if (KVPair::class === $class || KVTxnOp::class === $class || UserEvent::class === $class) { - // special case for KVPair and KVTxnOp - // todo: find cleaner way to do this... - $inst = new $class(); - self::unmarshalJSON(); - return new $class((array)$value, true); - } - return new $class((array)$value); - } - - private static function unmarshalScalar(AbstractModel $model, string $field, mixed $value, bool $nullable): void - { - $model->{$field} = self::buildScalarValue( - value: $value, - type: isset($model->{$field}) ? \gettype($model->{$field}) : Transcoding::MIXED, - nullable: $nullable - ); - } - - private static function unmarshalComplex(AbstractModel $model, string $field, mixed $value, array $def): void - { - // check if a callable has been defined - if (isset($def[Transcoding::FIELD_UNMARSHAL_CALLBACK])) { - $cb = $def[Transcoding::FIELD_UNMARSHAL_CALLBACK]; - // allow for using a "setter" method - if (\is_string($cb) && method_exists($model, $cb)) { - $model->{$cb}($value); - return; - } - // handle all other callable input - $err = \call_user_func($def[Transcoding::FIELD_UNMARSHAL_CALLBACK], $model, $field, $value); - if (false === $err) { - throw new \RuntimeException( - sprintf( - 'Error calling hydration callback "%s" for field "%s" on class "%s"', - var_export($def[Transcoding::FIELD_UNMARSHAL_CALLBACK], true), - $field, - $model::class - ) - ); - } - return; - } - - // try to determine field type by first looking up the field in the definition map, then by inspecting the - // the field's default value. - // - // objects _must_ have an entry in the map, as they are either un-initialized at class instantiation time or - // set to "NULL", at which point we cannot automatically determine the value type. - - if (isset($def[Transcoding::FIELD_TYPE])) { - // if the field has a FIELD_TYPE value in the definition map - $fieldType = $def[Transcoding::FIELD_TYPE]; - } elseif (isset($model->{$field})) { - // if the field is set and non-null - $fieldType = \gettype($model->{$field}); - } else { - throw new \LogicException( - sprintf( - 'Field "%s" on type "%s" is missing a FIELD_TYPE hydration entry: %s', - $field, - $model::class, - var_export($def, true) - ) - ); - } - - if (Transcoding::OBJECT === $fieldType) { - self::unmarshalObject($model, $field, $value, $def); - return; - } - - if (Transcoding::ARRAY === $fieldType) { - self::unmarshalArray($model, $field, $value, $def); - return; - } - - // at this point, assume scalar - // todo: handle non-scalar types here - self::unmarshalScalar($model, $field, $value, self::fieldIsNullable($def)); - } - - private static function unmarshalObject(AbstractModel $model, string $field, mixed $value, array $def): void - { - if (!isset($def[Transcoding::FIELD_CLASS])) { - throw new \LogicException( - sprintf( - 'Field "%s" on type "%s" is missing FIELD_CLASS hydration entry: %s', - $field, - $model::class, - var_export($def, true) - ) - ); - } - - $model->{$field} = self::buildObjectValue( - $value, - $def[Transcoding::FIELD_CLASS], - self::fieldIsNullable($def) - ); - } - - private static function unmarshalArray(AbstractModel $model, string $field, mixed $value, array $def): void - { - // attempt to extract the two possible keys - $type = $def[Transcoding::FIELD_ARRAY_TYPE] ?? null; - $class = $def[Transcoding::FIELD_CLASS] ?? null; - - // type is required - if (null === $type) { - throw new \DomainException( - sprintf( - 'Field "%s" on type "%s" definition is missing FIELD_ARRAY_TYPE value: %s', - $field, - $model::class, - var_export($def, true) - ) - ); - } - - // is the incoming value null? - if (null === $value) { - // if this value can be null'd, allow it. - if (self::fieldIsNullable($def)) { - $model->{$field} = null; - } - return; - } - - // by the time we get here, $value must be an array - if (!\is_array($value)) { - throw new \RuntimeException( - sprintf( - 'Field "%s" on type "%s" is an array but provided value is "%s"', - $field, - $model::class, - \gettype($value) - ) - ); - } - - // currently the only supported array types are scalar or objects. everything else will require - // a custom callback for hydration purposes. - - if (Transcoding::OBJECT === $type) { - if (null === $class) { - throw new \DomainException( - sprintf( - 'Field "%s" on type "%s" definition is missing FIELD_CLASS value: %s', - $field, - $model::class, - var_export($def, true) - ) - ); - } - - foreach ($value as $k => $v) { - // short circuit to prevent additional func call - if (null === $v) { - $model->{$field}[$k] = null; - } else { - $model->{$field}[$k] = self::buildObjectValue($v, $class, false); - } - } - } else { - // in all other cases, just set as-is - foreach ($value as $k => $v) { - // short circuit to prevent additional func call - if (null === $v) { - $model->{$field}[$k] = null; - } else { - $model->{$field}[$k] = self::buildScalarValue($v, $type, false); - } - } - } - } -} diff --git a/src/Values.php b/src/Values.php index e43fdc08..23e382f8 100644 --- a/src/Values.php +++ b/src/Values.php @@ -20,7 +20,7 @@ limitations under the License. */ -class Values implements \Iterator, \ArrayAccess, \Countable, \JsonSerializable +class Values implements \ArrayAccess, \Countable, \JsonSerializable { private array $values = []; @@ -63,7 +63,7 @@ public function delete(string $key): void public function count(): int { - return \count($this->values); + return count($this->values); } public function toPsr7Array(): array @@ -71,47 +71,30 @@ public function toPsr7Array(): array return $this->values; } - public function current(): array + public function getIterator(): iterable { - return current($this->values); - } - - public function next(): void - { - next($this->values); - } - - public function key(): ?string - { - return key($this->values); - } - - public function valid(): bool - { - return null !== key($this->values); - } - - public function rewind(): void - { - reset($this->values); + if ([] === $this->values) { + return new \EmptyIterator(); + } + return new \ArrayIterator($this->values); } public function offsetExists(mixed $offset): bool { - return isset($this->values[$offset]); + return array_key_exists($offset, $this->values); } - public function offsetGet($offset): string + public function offsetGet(mixed $offset): string { return $this->get($offset); } - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->set($offset, $value); } - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { $this->delete($offset); } diff --git a/src/WriteMeta.php b/src/WriteMeta.php index 326960ec..d911ecca 100644 --- a/src/WriteMeta.php +++ b/src/WriteMeta.php @@ -24,9 +24,14 @@ class WriteMeta { - public ?Time\Duration $RequestTime = null; + public Time\Duration $RequestTime; - public function getRequestTime(): ?Time\Duration + public function __construct(Time\Duration $RequestTime) + { + $this->RequestTime = $RequestTime; + } + + public function getRequestTime(): Time\Duration { return $this->RequestTime; } diff --git a/src/WriteOptions.php b/src/WriteOptions.php index 6b750702..ab29e899 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -22,21 +22,32 @@ use DCarbone\Go\Time; -class WriteOptions extends AbstractModel implements RequestOptions +class WriteOptions implements RequestOptions { - public string $Namespace = ''; - public string $Datacenter = ''; - public string $Token = ''; - public int $RelayFactor = 0; - - public ?Time\Duration $Timeout = null; - - public function __construct(?array $data = null) - { - parent::__construct($data); - if (!($this->Timeout instanceof Time\Duration)) { - $this->Timeout = Time::Duration($this->Timeout); + public string $Namespace; + public string $Datacenter; + public string $Token; + public int $RelayFactor; + + public Time\Duration $Timeout; + + public function __construct( + array $data = [], // Deprecated do not use. + string $Namespace = '', + string $Datacenter = '', + string $Token = '', + int $RelayFactor = 0, + null|int|float|string|\DateInterval|Time\Duration $Timeout = null, + ) { + if ([] !== $data) { + $this->jsonUnserialize((object)$data, $this); + return; } + $this->Namespace = $Namespace; + $this->Datacenter = $Datacenter; + $this->Token = $Token; + $this->RelayFactor = $RelayFactor; + $this->Timeout = Time::Duration($Timeout); } public function getNamespace(): string @@ -84,7 +95,7 @@ public function getTimeout(): ?Time\Duration return $this->Timeout; } - public function setTimeout(float|int|string|Time\Duration|null $timeout): void + public function setTimeout(null|int|float|string|\DateInterval|Time\Duration $timeout): void { $this->Timeout = Time::Duration($timeout); } @@ -104,8 +115,27 @@ public function apply(Request $r): void $r->params->set('relay-factor', (string) $this->RelayFactor); } - if (null !== $this->Timeout) { + if (0 < $this->Timeout->Nanoseconds()) { $r->timeout = $this->Timeout; } } + + /** + * @param \stdClass $decoded + * @param \DCarbone\PHPConsulAPI\WriteOptions|null $into + * @return self + * @deprecated This is only here to support construction with map. It will be removed in a future version. + */ + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Timeout' === $k) { + $n->Timeout = Time::Duration($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } } From 838eda59139e37da00d9d6251a5019dee9487301 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:06:41 -0500 Subject: [PATCH 10/79] it can't be null --- src/QueryMeta.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QueryMeta.php b/src/QueryMeta.php index cb2c5497..97d4ccb3 100644 --- a/src/QueryMeta.php +++ b/src/QueryMeta.php @@ -82,7 +82,7 @@ public function isKnownLeader(): bool return $this->KnownLeader; } - public function getRequestTime(): null|Time\Duration + public function getRequestTime(): Time\Duration { return $this->RequestTime; } @@ -97,7 +97,7 @@ public function isCacheHit(): bool return $this->CacheHit; } - public function getCacheAge(): null|Time\Duration + public function getCacheAge(): Time\Duration { return $this->CacheAge; } From 65e8e8520f5fefff149c3f5c07b0acbdbf05e9e5 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:12:06 -0500 Subject: [PATCH 11/79] Fine. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1073712f..e8125e2c 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ is made and backwards compatibility issues will not be addressed. There are a couple breaking changes between v2 and v3: -1. The `FakeMap` class has been removed. It sucked. -2. The `FakeSlice` class has been removed. It sucked. +1. The `FakeMap` class has been removed. +2. The `FakeSlice` class has been removed. 3. 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. From 0301bec66b1594f158f160c1a48cca3250abf948 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:12:36 -0500 Subject: [PATCH 12/79] grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8125e2c..52e7ad04 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ There are a couple breaking changes between v2 and v3: constructors are the preferred method of construction. * Construction via associative array will be removed entirely in V4 (whenever I get around to that). 4. All of that `Transcoding` nonsense has been removed. -5. The `Config` class may no longer be constructed with a map. You must use construction parameters. +5. The `Config` class may no longer be constructed with a map. You must use constructorc parameters. ## Composer From 99f810d5547080e98c071cf9b1a61e5251acf426 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:13:22 -0500 Subject: [PATCH 13/79] dangit, the boy is right. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52e7ad04..f5221c1c 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ prior to constructing a PHPConsulAPI Config object. As an example: ```php -$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']]); +$proxyClient = new \GuzzleHttp\Client(['proxy' => 'whatever proxy you want']); $config = new \DCarbone\PHPConsulAPI\Config( HttpClient: $proxyClient, Address: 'address of server', From 7b5bb042a4a0a9566ac744307f802d2586b10b6b Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 10 Apr 2025 22:14:07 -0500 Subject: [PATCH 14/79] thanx fren. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Daniel Carbone --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index f5221c1c..91bbb2a9 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,7 @@ There are a couple breaking changes between v2 and v3: constructors are the preferred method of construction. * Construction via associative array will be removed entirely in V4 (whenever I get around to that). 4. All of that `Transcoding` nonsense has been removed. -5. The `Config` class may no longer be constructed with a map. You must use constructorc parameters. - +5. The `Config` class may no longer be constructed with a map. You must use constructor parameters. ## Composer This lib is designed to be used with [Composer](https://getcomposer.org) From 279b0fb9085d15d0aab5c1a1ce0bb7f54ac2e5ed Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 11 Apr 2025 17:16:30 -0500 Subject: [PATCH 15/79] allow default in $data, starting work on Agent --- README.md | 7 +- src/ACL/ACLAuthMethod.php | 9 +- src/ACL/ACLAuthMethodListEntry.php | 9 +- src/ACL/ACLAuthMethodNamespaceRule.php | 9 +- src/ACL/ACLBindingRule.php | 9 +- src/ACL/ACLClient.php | 12 +- src/ACL/ACLEntry.php | 9 +- src/ACL/ACLLink.php | 9 +- src/ACL/ACLLoginParams.php | 9 +- src/ACL/ACLNodeIdentity.php | 9 +- src/ACL/ACLOIDCAuthURLParams.php | 9 +- src/ACL/ACLOIDCCallbackParams.php | 9 +- src/ACL/ACLPolicy.php | 9 +- src/ACL/ACLPolicyListEntry.php | 9 +- src/ACL/ACLReplicationStatus.php | 9 +- src/ACL/ACLRole.php | 9 +- src/ACL/ACLServiceIdentity.php | 9 +- src/ACL/ACLToken.php | 9 +- src/ACL/ACLTokenListEntry.php | 9 +- src/ACL/KubernetesAuthMethodConfig.php | 9 +- src/ACL/OIDCAuthMethodConfig.php | 4 +- src/Agent/AgentCheck.php | 102 +++++--- src/Agent/AgentCheckRegistration.php | 59 +++-- src/Agent/AgentCheckUpdate.php | 36 ++- src/Agent/AgentChecksResponse.php | 4 +- src/Agent/AgentClient.php | 43 ++-- src/Agent/AgentHealthServiceResponse.php | 2 +- src/Agent/AgentHealthServicesResponse.php | 2 +- src/Agent/AgentMember.php | 20 +- src/Agent/AgentService.php | 10 +- src/Agent/AgentServiceCheck.php | 14 +- src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 4 +- src/Agent/AgentServiceConnectProxyConfig.php | 16 +- src/Agent/AgentServiceRegistration.php | 16 +- src/Agent/AgentToken.php | 2 +- src/Agent/AgentWeights.php | 4 +- src/Agent/EnvoyExtension.php | 8 +- src/Agent/GaugeValue.php | 6 +- src/Agent/MemberOpts.php | 4 +- src/Agent/MetricsInfo.php | 10 +- src/Agent/PointValue.php | 4 +- src/Agent/SampledValue.php | 16 +- src/Agent/ServiceRegisterOpts.php | 2 +- src/Agent/TransparentProxyConfig.php | 4 +- src/Agent/Upstream.php | 14 +- src/Health/HealthCheckDefinition.php | 240 +++++++++---------- src/Operator/ReadableDuration.php | 41 ---- 48 files changed, 448 insertions(+), 422 deletions(-) delete mode 100644 src/Operator/ReadableDuration.php diff --git a/README.md b/README.md index 91bbb2a9..b87b90f7 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,13 @@ 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. All models now have parameterized constructors. +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). -4. All of that `Transcoding` nonsense has been removed. -5. The `Config` class may no longer be constructed with a map. You must use constructor parameters. +5. All of that `Transcoding` nonsense has been removed. +6. The `Config` class may no longer be constructed with a map. You must use constructor parameters. ## Composer This lib is designed to be used with [Composer](https://getcomposer.org) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 1d29a9c5..1c4ef290 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -39,7 +39,7 @@ class ACLAuthMethod extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Type = '', @@ -52,10 +52,6 @@ public function __construct( iterable $NamespaceRules = [], string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Name = $Name; $this->Type = $Type; @@ -67,6 +63,9 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->setNamespaceRules(...$NamespaceRules); $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 90db03a0..3259ace7 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -41,7 +41,7 @@ class ACLAuthMethodListEntry extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Type = '', string $DisplayName = '', @@ -52,10 +52,6 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Name = $Name; $this->Type = $Type; $this->DisplayName = $DisplayName; @@ -65,6 +61,9 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getName(): string diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 42f76fe9..36a4664d 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -28,16 +28,15 @@ class ACLAuthMethodNamespaceRule extends AbstractModel public string $BindNamespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $Selector = '', string $BindNamespace = '', ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Selector = $Selector; $this->BindNamespace = $BindNamespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getSelector(): string diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 4ef3550c..0e041aea 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -35,7 +35,7 @@ class ACLBindingRule extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Description = '', string $AuthMethod = '', @@ -46,10 +46,6 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Description = $Description; $this->AuthMethod = $AuthMethod; @@ -59,6 +55,9 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php index ed9e6d70..72738c72 100644 --- a/src/ACL/ACLClient.php +++ b/src/ACL/ACLClient.php @@ -292,10 +292,8 @@ public function AuthMethodList(null|QueryOptions $opts = null): ACLAuthMethodLis return $ret; } - public function BindingRuleCreate( - ACLBindingRule $bindingRule, - null|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 +304,8 @@ public function BindingRuleCreate( return $ret; } - public function BindingRuleUpdate( - ACLBindingRule $bindingRule, - null|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'); diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index eeb833e9..97555cae 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -32,7 +32,7 @@ class ACLEntry extends AbstractModel public string $Rules; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $ID = '', @@ -40,16 +40,15 @@ public function __construct( string $Type = '', string $Rules = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->ID = $ID; $this->Name = $Name; $this->Type = $Type; $this->Rules = $Rules; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getCreateIndex(): int diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index 007edfc5..8fe661cd 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -28,16 +28,15 @@ class ACLLink extends AbstractModel public string $Name; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Name = $Name; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index db40356a..4a1221a5 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -29,18 +29,17 @@ class ACLLoginParams extends AbstractModel public null|array $Meta; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $BearerToken = '', null|array|\stdClass $Meta = null, ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; $this->setMeta($Meta); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getAuthMethod(): string diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 7c1ea03f..59820809 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -28,16 +28,15 @@ class ACLNodeIdentity extends AbstractModel public string $Datacenter; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $NodeName = '', string $Datacenter = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->NodeName = $NodeName; $this->Datacenter = $Datacenter; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getNodeName(): string diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index ec2461a6..39367264 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -30,20 +30,19 @@ class ACLOIDCAuthURLParams extends AbstractModel public null|array $Meta; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $RedirectURI = '', string $ClientNonce = '', null|array|\stdClass $Meta = null ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->AuthMethod = $AuthMethod; $this->RedirectURI = $RedirectURI; $this->ClientNonce = $ClientNonce; $this->setMeta($Meta); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getAuthMethod(): string diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 580454a1..3beb692a 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -30,20 +30,19 @@ class ACLOIDCCallbackParams extends AbstractModel public string $ClientNonce; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $State = '', string $Code = '', string $ClientNonce = '', ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->AuthMethod = $AuthMethod; $this->State = $State; $this->Code = $Code; $this->ClientNonce = $ClientNonce; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getAuthMethod(): string diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 379b2312..315d9d62 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -35,7 +35,7 @@ class ACLPolicy extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -46,10 +46,6 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -60,6 +56,9 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index 2e301caf..0651d313 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -34,7 +34,7 @@ class ACLPolicyListEntry extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -44,10 +44,6 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '', ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -56,6 +52,9 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index fe0962fd..761fd96b 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -35,7 +35,7 @@ class ACLReplicationStatus extends AbstractModel public Time\Time $LastError; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. bool $Enabled = false, bool $Running = false, string $SourceDatacenter = '', @@ -45,10 +45,6 @@ public function __construct( null|Time\Time $LastSuccess = null, null|Time\Time $LastError = null, ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Enabled = $Enabled; $this->Running = $Running; $this->SourceDatacenter = $SourceDatacenter; @@ -57,6 +53,9 @@ public function __construct( $this->ReplicatedTokenIndex = $ReplicatedTokenIndex; $this->LastSuccess = $LastSuccess ?? Time::New(); $this->LastError = $LastError ?? Time::New(); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function isEnabled(): bool diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index ea9833c0..9af96845 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -36,7 +36,7 @@ class ACLRole extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -48,10 +48,6 @@ public function __construct( int $ModifyIndex = 0, string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ID = $ID; $this->Name = $Name; $this->Description = $Description; @@ -62,6 +58,9 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getID(): string diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 2c6f75a2..78ec9b63 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -30,16 +30,15 @@ class ACLServiceIdentity extends AbstractModel public array $Datacenters; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $ServiceName = '', iterable $Datacenters = [] ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->ServiceName = $ServiceName; $this->Datacenters = $Datacenters; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getServiceName(): string diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index 98773471..8a5d90e3 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -45,7 +45,7 @@ class ACLToken extends AbstractModel public string $Rules; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -64,10 +64,6 @@ public function __construct( string $Namespace = '', string $Rules = '', ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->AccessorID = $AccessorID; @@ -85,6 +81,9 @@ public function __construct( $this->Hash = $Hash; $this->Namespace = $Namespace; $this->Rules = $Rules; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getCreateIndex(): int diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index a2e4c82f..a57043d7 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -42,7 +42,7 @@ class ACLTokenListEntry extends AbstractModel public string $Namespace; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -59,10 +59,6 @@ public function __construct( bool $Legacy = false, string $Namespace = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->AccessorID = $AccessorID; @@ -78,6 +74,9 @@ public function __construct( $this->Hash = $Hash; $this->Legacy = $Legacy; $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getCreateIndex(): int diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 9767237c..a46c21da 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -29,18 +29,17 @@ class KubernetesAuthMethodConfig extends AbstractModel public string $ServiceAccountJWT; public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. string $Host = '', string $CACert = '', string $ServiceAccountJWT = '' ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Host = $Host; $this->CACert = $CACert; $this->ServiceAccountJWT = $ServiceAccountJWT; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } } public function getHost(): string diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index c559082e..a853af50 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -25,9 +25,9 @@ class OIDCAuthMethodConfig extends AbstractModel { public function __construct( - array $data = [], // Deprecated, will be removed. + null|array $data = null, // Deprecated, will be removed. ) { - if ([] !== $data) { + if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 55235175..4f7fd201 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -22,38 +22,48 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Health\HealthCheckDefinition; -use DCarbone\PHPConsulAPI\Transcoding; class AgentCheck extends AbstractModel { - 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 function __construct( + null|array $data = null, + string $Node = '', + string $CheckID = '', + string $Name = '', + string $Status = '', + string $Notes = '', + string $Output = '', + string $ServiceID = '', + string $ServiceName = '', + string $Type = '', + null|HealthCheckDefinition $Definition = null, + string $Namespace = '' + ) { + $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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } @@ -177,6 +187,42 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Definition' === $k) { + $n->Definition = HealthCheckDefinition::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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->jsonSerialize(); + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + return $out; + } + public function __toString(): string { return $this->CheckID; diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 0a2210f0..1fef04e2 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -20,23 +20,25 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\Transcoding; - 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 function __construct( + string $ID = '', + string $ServiceID = '', + string $Namespace = '', + null|array $data = null, + ) { + $this->ID = $ID; + $this->ServiceID = $ServiceID; + $this->Namespace = $Namespace; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getID(): string { @@ -70,4 +72,31 @@ public function setNamespace(string $Namespace): self $this->Namespace = $Namespace; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->ID) { + $out->ID = $this->ID; + } + if ('' !== $this->ServiceID) { + $out->ServiceID = $this->ServiceID; + } + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + return $out; + } } diff --git a/src/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php index aed5f53a..04cfcb6d 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -24,8 +24,20 @@ final class AgentCheckUpdate extends AbstractModel { - public string $Status = ''; - public string $Output = ''; + public string $Status; + public string $Output; + + public function __construct( + null|array $data = null, + string $Status = '', + string $Output = '' + ) { + $this->Status = $Status; + $this->Output = $Output; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } public function getStatus(): string { @@ -49,6 +61,26 @@ public function setOutput(string $output): self return $this; } + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..537feca8 100644 --- a/src/Agent/AgentChecksResponse.php +++ b/src/Agent/AgentChecksResponse.php @@ -25,7 +25,7 @@ class AgentChecksResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?array $Checks = null; + public array $Checks = []; public function getValue(): ?array { @@ -36,7 +36,7 @@ public function unmarshalValue(mixed $decodedData): void { $this->Checks = []; foreach ($decodedData as $k => $v) { - $this->Checks[$k] = new AgentCheck($v); + $this->Checks[$k] = AgentCheck::jsonUnserialize($v); } } } diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index 7e896ead..52bda315 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -31,7 +31,7 @@ class AgentClient extends AbstractClient { - private ?MapResponse $_self = null; + private null|MapResponse $_self = null; public function Self(bool $refresh = false): MapResponse { @@ -63,7 +63,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; } @@ -161,14 +161,13 @@ public function AgentHealthServiceByName(string $service): AgentHealthServicesRe $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 +196,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 +205,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: @@ -262,17 +261,17 @@ public function UpdateTTL(string $checkID, string $output, string $status): ?Err 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 +280,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 +305,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 +320,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..35280160 100644 --- a/src/Agent/AgentHealthServiceResponse.php +++ b/src/Agent/AgentHealthServiceResponse.php @@ -28,7 +28,7 @@ class AgentHealthServiceResponse extends AbstractResponse { use ErrorContainer; - public string $AggregatedStatus = ''; + public string $AggregatedStatus; public ?AgentServiceChecksInfo $AgentServiceChecksInfo = null; public function __construct(string $aggregatedStatus, ?array $checkInfo, ?Error $err) diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php index d6d3a4c6..a924c885 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -28,7 +28,7 @@ class AgentHealthServicesResponse extends AbstractResponse { use ErrorContainer; - public string $AggregatedStatus = ''; + public string $AggregatedStatus; public ?array $AgentServiceChecksInfos = null; public function __construct(string $aggregatedStatus, ?array $checkInfos, ?Error $err) diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 80167a8c..a0241db4 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -28,16 +28,16 @@ class AgentMember extends AbstractModel { 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; + public string $Status; + public int $ProtocolMin; + public int $ProtocolMax; + public int $ProtocolCur; + public int $DelegateMin; + public int $DelegateMax; + public int $DelegateCur; public function getName(): string { diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index dd4de64e..6b59fec8 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -74,12 +74,12 @@ class AgentService extends AbstractModel private const FIELD_NAMESPACE = 'Namespace'; private const FIELD_DATACENTER = 'Datacenter'; - public string $Kind = ''; - public string $ID = ''; - public string $Service = ''; + public string $Kind; + public string $ID; + public string $Service; public FakeMap $Meta; - public int $Port = 0; - public string $Address = ''; + public int $Port; + public string $Address; public array $TaggedAddresses = []; public AgentWeights $Weights; public bool $EnableTagOverride = false; diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index c31a3319..75fc6431 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -83,13 +83,13 @@ class AgentServiceCheck extends AbstractModel 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 $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 = []; diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index f2fb3dd6..7c9201d7 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -41,7 +41,7 @@ class AgentServiceChecksInfo extends AbstractModel private const FIELD_SERVICE = 'Service'; private const FIELD_CHECKS = 'Checks'; - public string $AggregatedStatus = ''; + public string $AggregatedStatus; public ?AgentService $Service = null; public HealthChecks $Checks; diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 3f629e57..8f88adbf 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -37,8 +37,8 @@ class AgentServiceConnect extends AbstractModel private const FIELD_NATIVE = 'Native'; private const FIELD_SIDECAR_SERVICE = 'SidecarService'; - public bool $Native = false; - public array $SidecarService = []; + public bool $Native; + public array $SidecarService; public function isNative(): bool { diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 0fc59582..ee57fff7 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -67,16 +67,16 @@ class AgentServiceConnectProxyConfig extends AbstractModel 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 array $EnvoyExtensions; + public string $DestinationServiceName; + public string $DestinationServiceID; + public string $LocalServiceAddress; + public int $LocalServicePort; public ?FakeMap $Config = null; - public string $LocalServiceSocketPath = ''; - public string $Mode = ''; + public string $LocalServiceSocketPath; + public string $Mode; public ?TransparentProxyConfig $TransparentProxy = null; - public array $Upstreams = []; + public array $Upstreams; public MeshGatewayConfig $MeshGateway; public ExposeConfig $Expose; diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index f565821b..190abb59 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -95,14 +95,14 @@ class AgentServiceRegistration extends AbstractModel 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 string $Kind; + public string $ID; + public string $Name; + public int $Port; + public string $Address; + public array $TaggedAddresses; + public bool $EnableTagOverride; + public array $Meta; public ?AgentWeights $Weights = null; public ?AgentServiceCheck $Check = null; public AgentServiceChecks $Checks; diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index 4f95dba6..645b2800 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -24,7 +24,7 @@ class AgentToken extends AbstractModel { - public string $Token = ''; + public string $Token; public function getToken(): string { diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index 19dcb0b4..9fdb6d1c 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -24,8 +24,8 @@ class AgentWeights extends AbstractModel { - public int $Passing = 0; - public int $Warning = 0; + public int $Passing; + public int $Warning; public function getPassing(): int { diff --git a/src/Agent/EnvoyExtension.php b/src/Agent/EnvoyExtension.php index e433e843..d3983142 100644 --- a/src/Agent/EnvoyExtension.php +++ b/src/Agent/EnvoyExtension.php @@ -32,11 +32,11 @@ class EnvoyExtension extends AbstractModel private const FIELD_ARGUMENTS = 'Arguments'; - public string $Name = ''; - public bool $Required = false; + public string $Name; + public bool $Required; public FakeMap $Arguments; - public string $ConsulVersion = ''; - public string $EnvoyVersion = ''; + public string $ConsulVersion; + public string $EnvoyVersion; public function __construct(?array $data = []) { diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index e1ec1a6b..3df682e7 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -24,9 +24,9 @@ class GaugeValue extends AbstractModel { - public string $Name = ''; - public float $Value = 0.0; - public array $Labels = []; + public string $Name; + public float $Value; + public array $Labels; public function getName(): string { diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index b9b1e33a..df18ae7f 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -24,8 +24,8 @@ class MemberOpts extends AbstractModel { - public bool $WAN = false; - public string $Segment = ''; + public bool $WAN; + public string $Segment; public function isWAN(): bool { diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index d580ab99..cc036912 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -53,11 +53,11 @@ class MetricsInfo extends AbstractModel 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; + public array $Gauges; + public array $Points; + public array $Counters; + public array $Samples; public function getTimestamp(): string { diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 00cd83fa..40d5c1f1 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -24,8 +24,8 @@ class PointValue extends AbstractModel { - public string $Name = ''; - public array $Points = []; + public string $Name; + public array $Points; public function getName(): string { diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index 9c177c95..f7fc381a 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -24,14 +24,14 @@ class SampledValue extends AbstractModel { - 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; + public array $Labels; public function getName(): string { diff --git a/src/Agent/ServiceRegisterOpts.php b/src/Agent/ServiceRegisterOpts.php index f6fe773c..69cfe23d 100644 --- a/src/Agent/ServiceRegisterOpts.php +++ b/src/Agent/ServiceRegisterOpts.php @@ -24,7 +24,7 @@ class ServiceRegisterOpts extends AbstractModel { - public bool $ReplaceExistingChecks = false; + public bool $ReplaceExistingChecks; public function isReplaceExistingChecks(): bool { diff --git a/src/Agent/TransparentProxyConfig.php b/src/Agent/TransparentProxyConfig.php index eab35eb2..60244026 100644 --- a/src/Agent/TransparentProxyConfig.php +++ b/src/Agent/TransparentProxyConfig.php @@ -24,8 +24,8 @@ class TransparentProxyConfig extends AbstractModel { - public int $OutboundListenerPort = 0; - public bool $DialedDirectly = false; + public int $OutboundListenerPort; + public bool $DialedDirectly; public function getOutboundListenerPort(): int { diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 96672596..3e495c03 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -52,13 +52,13 @@ class Upstream extends AbstractModel 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 string $DestinationType; + public string $DestinationNamespace; + public string $DestinationName; + public string $Datacenter; + public string $LocalBindAddress; + public int $LocalBindPort; + public array $Config; public MeshGatewayConfig $MeshGatewayConfig; public function __construct(?array $data = []) diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index 1c6a1e1e..591a730e 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -21,95 +21,43 @@ */ use DCarbone\Go\Time; -use DCarbone\Go\Time\Duration; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Operator\ReadableDuration; -use DCarbone\PHPConsulAPI\Transcoding; class HealthCheckDefinition extends AbstractModel 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(); - } - - 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 - ); + public string $HTTP; + public array $Header; + public string $Method; + public string $Body; + public bool $TLSSkipVerify; + public string $TCP; + public Time\Duration $IntervalDuration; + public Time\Duration $TimeoutDuration; + public Time\Duration $DeregisterCriticalServiceAfterDuration; + + public function __construct( + null|array $data = null, + string $HTTP = '', + iterable $Header = [], + string $Method = '', + string $Body = '', + bool $TLSSkipVerify = false, + string $TCP = '', + 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->setIntervalDuration($IntervalDuration); + $this->setTimeoutDuration($TimeoutDuration); + $this->setDeregisterCriticalServiceAfterDuration($DeregisterCriticalServiceAfterDuration); + if (null !== $data && [] !== $data) { + static::jsonUnserialize((object)$data, $this); } } @@ -118,16 +66,34 @@ public function getHTTP(): string return $this->HTTP; } + public function setHTTP(string $HTTP): self + { + $this->HTTP = $HTTP; + return $this; + } + public function getHeader(): array { return $this->Header; } + public function setHeader(string ...$Header): self + { + $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 +110,91 @@ 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 getIntervalDuration(): Time\Duration { - return $this->TimeoutDuration; + return $this->IntervalDuration; } - public function getDeregisterCriticalServiceAfterDuration(): ?Duration - { - return $this->DeregisterCriticalServiceAfterDuration; + public function setIntervalDuration( + null|int|float|string|\DateInterval|Time\Duration $IntervalDuration + ): self { + $this->IntervalDuration = Time::Duration($IntervalDuration); + return $this; } - public function getInterval(): ?ReadableDuration + public function getTimeoutDuration(): Time\Duration { - return $this->Interval; + return $this->TimeoutDuration; } - public function getTimeout(): ?ReadableDuration - { - return $this->Timeout; + public function setTimeoutDuration( + null|int|float|string|\DateInterval|Time\Duration $TimeoutDuration + ): self { + $this->TimeoutDuration = Time::Duration($TimeoutDuration); + return $this; } - public function getDeregisterCriticalServiceAfter(): ?ReadableDuration + public function getDeregisterCriticalServiceAfterDuration(): Time\Duration { - return $this->DeregisterCriticalServiceAfter; + return $this->DeregisterCriticalServiceAfterDuration; } - public function jsonSerialize(): array - { - // 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, + public function setDeregisterCriticalServiceAfterDuration( + null|int|float|string|\DateInterval|Time\Duration $DeregisterCriticalServiceAfterDuration + ): self { + $this->DeregisterCriticalServiceAfterDuration = Time::Duration($DeregisterCriticalServiceAfterDuration); + 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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($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); + } else { + $n->{$k} = $v; + } } + return $n; + } - // handle per-field marshalling - $out = []; - foreach ($prep as $field => $value) { - $this->marshalField($out, $field, $value); + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; } - + $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->Interval = (string)$this->IntervalDuration; + $out->Timeout = (string)$this->TimeoutDuration; + $out->DeregisterCriticalServiceAfter = (string)$this->DeregisterCriticalServiceAfterDuration; return $out; } } diff --git a/src/Operator/ReadableDuration.php b/src/Operator/ReadableDuration.php deleted file mode 100644 index ccabca3f..00000000 --- a/src/Operator/ReadableDuration.php +++ /dev/null @@ -1,41 +0,0 @@ -{$field} = new self(\intval($value, 10)); - } - - public static function fromDuration(string $s): self - { - return new self(Time::ParseDuration($s)->Nanoseconds()); - } - - public function jsonSerialize(): string - { - return (string)$this; - } -} From 13784d3db796e19797dd3a6911f728ab76ecc438 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 11 Apr 2025 17:17:40 -0500 Subject: [PATCH 16/79] oops --- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentCheckRegistration.php | 2 +- src/Agent/AgentCheckUpdate.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 4f7fd201..f9c12dd4 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -38,7 +38,7 @@ class AgentCheck extends AbstractModel public string $Namespace; public function __construct( - null|array $data = null, + null|array $data = null, // Deprecated, will be removed. string $Node = '', string $CheckID = '', string $Name = '', diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 1fef04e2..1021d56d 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -27,10 +27,10 @@ class AgentCheckRegistration extends AgentServiceCheck public string $Namespace; public function __construct( + null|array $data = null, // Deprecated, will be removed. string $ID = '', string $ServiceID = '', string $Namespace = '', - null|array $data = null, ) { $this->ID = $ID; $this->ServiceID = $ServiceID; diff --git a/src/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php index 04cfcb6d..d534e849 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -28,7 +28,7 @@ final class AgentCheckUpdate extends AbstractModel public string $Output; public function __construct( - null|array $data = null, + null|array $data = null, // Deprecated, will be removed. string $Status = '', string $Output = '' ) { From f53867c957ce1e1134915e53d5425a543dcc451b Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 12 Apr 2025 22:52:21 -0500 Subject: [PATCH 17/79] lots of little work, long ways to go. --- src/ACL/ACLBindingRuleQueryResponse.php | 2 +- src/Agent/AgentCheck.php | 10 +- src/Agent/AgentChecksResponse.php | 2 +- src/Agent/AgentClient.php | 6 +- src/Agent/AgentHealthServiceResponse.php | 20 +- src/Agent/AgentHealthServicesResponse.php | 18 +- src/Agent/AgentMember.php | 83 +++++- src/Agent/AgentMembersResponse.php | 6 +- src/Agent/AgentService.php | 276 +++++++++++++----- src/Agent/AgentServiceCheck.php | 232 ++++++++++----- src/Agent/AgentServiceChecks.php | 64 +++- src/Agent/AgentServiceChecksInfo.php | 66 +++-- src/Agent/AgentServiceConnect.php | 55 +++- src/Agent/AgentServiceConnectProxyConfig.php | 214 +++++++++----- src/Agent/AgentServiceRegistration.php | 2 +- src/Agent/AgentWeights.php | 32 ++ src/Agent/MemberACLMode.php | 39 +++ src/Agent/ServiceKind.php | 54 ++++ src/Agent/UpstreamDestType.php | 31 ++ src/ConfigEntry/AccessLogsConfig.php | 155 ++++++++++ src/ConfigEntry/ConfigEntry.php | 13 +- src/ConfigEntry/LogSinkType.php | 29 ++ .../ProxyMode.php} | 13 +- src/Consul.php | 18 -- src/Peering/Locality.php | 77 +++++ 25 files changed, 1175 insertions(+), 342 deletions(-) create mode 100644 src/Agent/MemberACLMode.php create mode 100644 src/Agent/ServiceKind.php create mode 100644 src/Agent/UpstreamDestType.php create mode 100644 src/ConfigEntry/AccessLogsConfig.php create mode 100644 src/ConfigEntry/LogSinkType.php rename src/{HasStringTags.php => ConfigEntry/ProxyMode.php} (80%) create mode 100644 src/Peering/Locality.php diff --git a/src/ACL/ACLBindingRuleQueryResponse.php b/src/ACL/ACLBindingRuleQueryResponse.php index 6c3480fc..237d59f0 100644 --- a/src/ACL/ACLBindingRuleQueryResponse.php +++ b/src/ACL/ACLBindingRuleQueryResponse.php @@ -27,7 +27,7 @@ class ACLBindingRuleQueryResponse extends AbstractValuedQueryResponse implements { public null|ACLBindingRule $ACLBindingRule = null; - public function getValue(): ?ACLBindingRule + public function getValue(): null|ACLBindingRule { return $this->ACLBindingRule; } diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index f9c12dd4..dd519344 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -36,6 +36,7 @@ class AgentCheck extends AbstractModel public string $Type; public HealthCheckDefinition $Definition; public string $Namespace; + public string $Partition; public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -49,7 +50,8 @@ public function __construct( string $ServiceName = '', string $Type = '', null|HealthCheckDefinition $Definition = null, - string $Namespace = '' + string $Namespace = '', + string $Partition = '', ) { $this->Node = $Node; $this->CheckID = $CheckID; @@ -62,6 +64,7 @@ public function __construct( $this->Type = $Type; $this->Definition = $Definition ?? new HealthCheckDefinition(); $this->Namespace = $Namespace; + $this->Partition = $Partition; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -216,10 +219,13 @@ public function jsonSerialize(): \stdClass $out->ServiceID = $this->ServiceID; $out->ServiceName = $this->ServiceName; $out->Type = $this->Type; - $out->Definition = $this->Definition->jsonSerialize(); + $out->Definition = $this->Definition; if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; } + if ('' !== $this->Partition) { + $out->Partition = $this->Partition; + } return $out; } diff --git a/src/Agent/AgentChecksResponse.php b/src/Agent/AgentChecksResponse.php index 537feca8..95f72415 100644 --- a/src/Agent/AgentChecksResponse.php +++ b/src/Agent/AgentChecksResponse.php @@ -25,7 +25,7 @@ class AgentChecksResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public array $Checks = []; + public array $Checks; public function getValue(): ?array { diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index 52bda315..e79086c8 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -146,16 +146,16 @@ 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()) { diff --git a/src/Agent/AgentHealthServiceResponse.php b/src/Agent/AgentHealthServiceResponse.php index 35280160..5ada9735 100644 --- a/src/Agent/AgentHealthServiceResponse.php +++ b/src/Agent/AgentHealthServiceResponse.php @@ -29,14 +29,18 @@ class AgentHealthServiceResponse extends AbstractResponse use ErrorContainer; public string $AggregatedStatus; - public ?AgentServiceChecksInfo $AgentServiceChecksInfo = null; + 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 +49,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 a924c885..23caed23 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -29,16 +29,14 @@ class AgentHealthServicesResponse extends AbstractResponse use ErrorContainer; public string $AggregatedStatus; - public ?array $AgentServiceChecksInfos = null; + public array $AgentServiceChecksInfos; - public function __construct(string $aggregatedStatus, ?array $checkInfos, ?Error $err) + public function __construct(string $aggregatedStatus, array $checkInfos, ?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 +46,17 @@ public function getAggregatedStatus(): string return $this->AggregatedStatus; } - public function getAgentServiceChecksInfos(): ?array + 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 + 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 a0241db4..155d5d61 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -22,15 +22,23 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Consul; -use DCarbone\PHPConsulAPI\HasStringTags; class AgentMember extends AbstractModel { - use HasStringTags; - public string $Name; public string $Addr; public int $Port; + 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 string + */ public string $Status; public int $ProtocolMin; public int $ProtocolMax; @@ -39,6 +47,36 @@ class AgentMember extends AbstractModel public int $DelegateMax; public int $DelegateCur; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Name = '', + string $Addr = '', + int $Port = 0, + array $Tags = [], + string $Status = '', + 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 = $Tags; + $this->Status = $Status; + $this->ProtocolMin = $ProtocolMin; + $this->ProtocolMax = $ProtocolMax; + $this->ProtocolCur = $ProtocolCur; + $this->DelegateMin = $DelegateMin; + $this->DelegateMax = $DelegateMax; + $this->DelegateCur = $DelegateCur; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + public function getName(): string { return $this->Name; @@ -89,13 +127,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 +143,35 @@ public function IsConsulServer(): bool Consul::MemberTagValueRoleServer === $this->Tags[Consul::MemberTagKeyACLMode]; } + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..4e15bbd7 100644 --- a/src/Agent/AgentMembersResponse.php +++ b/src/Agent/AgentMembersResponse.php @@ -25,9 +25,9 @@ class AgentMembersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?array $Members = null; + public array $Members; - public function getValue(): ?array + public function getValue(): array { return $this->Members; } @@ -36,7 +36,7 @@ public function unmarshalValue(mixed $decodedData): void { $this->Members = []; foreach ($decodedData as $member) { - $this->Members[] = new AgentMember($member); + $this->Members[] = AgentMember::jsonUnserialize($member); } } } diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 6b59fec8..e079dfbc 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -22,83 +22,80 @@ 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; class AgentService extends AbstractModel { - 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 array $Tags; + public array $Meta; public int $Port; public string $Address; - public array $TaggedAddresses = []; + public string $SocketPath; + /** @var \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] */ + public array $TaggedAddresses; 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; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Kind = '', + string $ID = '', + string $Service = '', + string $SocketPath = '', + iterable $Tags = [], + array|\stdClass $Meta = [], + int $Port = 0, + string $Address = '', + iterable $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 = $Kind; + $this->ID = $ID; + $this->Service = $Service; + $this->Meta = $Meta instanceof \stdClass ? (array)$Meta : $Meta; + $this->Port = $Port; + $this->setTags(...$Tags); + $this->Address = $Address; + $this->SocketPath = $SocketPath; + $this->setTaggedAddresses(...$TaggedAddresses); + $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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } @@ -135,14 +132,25 @@ public function setService(string $Service): self return $this; } - public function getMeta(): FakeMap + public function getTags(): array + { + return $this->Tags; + } + + public function setTags(string ...$Tags): self + { + $this->Tags = $Tags; + return $this; + } + + public function getMeta(): array { return $this->Meta; } - public function setMeta(FakeMap $Meta): self + public function setMeta(array|\stdClass $Meta): self { - $this->Meta = $Meta; + $this->Meta = (array)$Meta; return $this; } @@ -173,7 +181,7 @@ public function getTaggedAddresses(): array return $this->TaggedAddresses; } - public function setTaggedAddresses(array $TaggedAddresses): self + public function setTaggedAddresses(ServiceAddress ...$TaggedAddresses): self { $this->TaggedAddresses = $TaggedAddresses; return $this; @@ -234,28 +242,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 +286,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 +307,98 @@ 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, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Tags' === $k) { + $n->setTags(...$v); + } elseif ('Meta' === $k) { + $n->setMeta($v); + } elseif ('Proxy' === $k) { + $n->Proxy = null === $v ? null : AgentServiceConnectProxyConfig::jsonUnserialize($v); + } elseif ('Weights' === $k) { + $n->Weights = AgentWeights::jsonUnserialize($v); + } elseif ('TaggedAddresses' === $k) { + foreach ($v as $vv) { + $n->TaggedAddresses[] = ServiceAddress::jsonUnserialize($vv); + } + } elseif ('Connect' === $k) { + $n->Connect = null === $v ? null : AgentServiceConnect::jsonUnserialize($v); + } elseif ('Locality' === $k) { + $n->Locality = null === $v ? null : Locality::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->Kind) { + $out->Kind = $this->Kind; + } + $out->ID = $this->ID; + $out->Service = $this->Service; + $out->Tags = $this->Tags; + $out->Meta = $this->Meta; + $out->Port = $this->Port; + $out->Address = $this->Address; + if ('' !== $this->SocketPath) { + $out->SocketPath = $this->SocketPath; + } + if ([] !== $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 75fc6431..b7a80066 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -21,68 +21,9 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class AgentServiceCheck extends AbstractModel { - 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; @@ -90,22 +31,75 @@ class AgentServiceCheck extends AbstractModel 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 $TTL; + public string $HTTP; + public array $Header; + public string $Method; + public string $TCP; + public string $Status; + public string $Notes; + public bool $TLSSkipVerify; + public string $GRPC; + public bool $GRPCUseTLS; + public string $AliasNode; + public string $AliasService; + public int $SuccessBeforePassing; + public int $FailuresBeforeCritical; + + public string $DeregisterCriticalServiceAfter; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $CheckID = '', + string $Name = '', + iterable $ScriptArgs = [], + string $DockerContainerID = '', + string $Shell = '', + string $Interval = '', + string $Timeout = '', + string $TTL = '', + string $HTTP = '', + iterable $Header = [], + string $Method = '', + string $TCP = '', + string $Status = '', + string $Notes = '', + bool $TLSSkipVerify = false, + string $GRPC = '', + bool $GRPCUseTLS = false, + string $AliasNode = '', + string $AliasService = '', + int $SuccessBeforePassing = 0, + int $FailuresBeforeCritical = 0, + string $DeregisterCriticalServiceAfter = '', + ) { + $this->CheckID = $CheckID; + $this->Name = $Name; + $this->ScriptArgs = []; + $this->setScriptArgs(...$ScriptArgs); + $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->AliasNode = $AliasNode; + $this->AliasService = $AliasService; + $this->SuccessBeforePassing = $SuccessBeforePassing; + $this->FailuresBeforeCritical = $FailuresBeforeCritical; + $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getCheckID(): string { @@ -134,7 +128,7 @@ public function getScriptArgs(): array return $this->ScriptArgs; } - public function setScriptArgs(array $args): self + public function setScriptArgs(string ...$args): self { $this->ScriptArgs = $args; return $this; @@ -211,7 +205,7 @@ public function getHeader(): array return $this->Header; } - public function setHeader(array $header): self + public function setHeader(mixed ...$header): self { $this->Header = $header; return $this; @@ -348,4 +342,88 @@ public function setDeregisterCriticalServiceAfter(string $deregisterCriticalServ $this->DeregisterCriticalServiceAfter = $deregisterCriticalServiceAfter; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->CheckID) { + $out->CheckID = $this->CheckID; + } + if ('' !== $this->Name) { + $out->Name = $this->Name; + } + if ([] !== $this->ScriptArgs) { + $out->ScriptArgs = $this->ScriptArgs; + } + 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 ([] !== $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 (false !== $this->TLSSkipVerify) { + $out->TLSSkipVerify = $this->TLSSkipVerify; + } + if ('' !== $this->GRPC) { + $out->GRPC = $this->GRPC; + } + if (false !== $this->GRPCUseTLS) { + $out->GRPCUseTLS = $this->GRPCUseTLS; + } + 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..1be51649 100644 --- a/src/Agent/AgentServiceChecks.php +++ b/src/Agent/AgentServiceChecks.php @@ -21,14 +21,68 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeSlice; -class AgentServiceChecks extends FakeSlice +class AgentServiceChecks implements \Countable, \ArrayAccess { - protected string $containedClass = AgentServiceCheck::class; + /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck[] */ + public array $Checks; - protected function newChild(array $data): AbstractModel + public function __construct( + iterable $Checks = [], + ) { + $this->setChecks(...$Checks); + } + + public function getChecks(): array + { + return $this->Checks; + } + + public function setChecks(AgentServiceCheck ...$Checks): self + { + $this->Checks = $Checks; + return $this; + } + + 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): mixed + { + 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 { - return new AgentServiceCheck($data); + unset($this->Checks[$offset]); } } diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 7c9201d7..1f0a5600 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -22,34 +22,24 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Health\HealthChecks; -use DCarbone\PHPConsulAPI\Transcoding; class AgentServiceChecksInfo extends AbstractModel { - 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 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( + null|array $data = null, // Deprecated, will be removed. + string $AggregatedStatus = '', + null|AgentService $Service = null, + null|HealthChecks $Checks = null, + ) { + $this->AggregatedStatus = $AggregatedStatus; + $this->Service = $Service; + $this->Checks = $Checks ?? new HealthChecks(); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } @@ -64,12 +54,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 +75,34 @@ public function setChecks(HealthChecks $Checks): self $this->Checks = $Checks; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 8f88adbf..1d333d8f 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -21,24 +21,23 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class AgentServiceConnect extends AbstractModel { - 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, - ], - ]; - - private const FIELD_NATIVE = 'Native'; - private const FIELD_SIDECAR_SERVICE = 'SidecarService'; - public bool $Native; - public array $SidecarService; + public null|AgentServiceRegistration $SidecarService; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + bool $Native = false, + null|AgentServiceRegistration $SidecarService = null, + ) { + $this->Native = $Native; + $this->SidecarService = $SidecarService; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function isNative(): bool { @@ -51,14 +50,38 @@ 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, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('SidecarService' === $k) { + $n->SidecarService = AgentServiceRegistration::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Native = $this->Native; + $out->SidecarService = $this->SidecarService; + return $out; + } } diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index ee57fff7..862e9f98 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -21,73 +21,59 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\ConfigEntry\AccessLogsConfig; use DCarbone\PHPConsulAPI\ConfigEntry\ExposeConfig; use DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\ConfigEntry\ProxyMode; class AgentServiceConnectProxyConfig extends AbstractModel { - 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; - public ?FakeMap $Config = null; public string $LocalServiceSocketPath; - public string $Mode; - public ?TransparentProxyConfig $TransparentProxy = null; + public ProxyMode $Mode; + public null|TransparentProxyConfig $TransparentProxy; + public array $Config; + /** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */ 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); + public null|MeshGatewayConfig $MeshGateway; + public null|ExposeConfig $Expose; + public null|AccessLogsConfig $AccessLogs; + + public function __construct( + null|array $data = [], // Deprecated, will be removed. + iterable $EnvoyExtensions = [], + string $DestinationServiceName = '', + string $DestinationServiceID = '', + string $LocalServiceAddress = '', + int $LocalServicePort = 0, + string $LocalServiceSocketPath = '', + string|ProxyMode $Mode = ProxyMode::Default, + null|TransparentProxyConfig $TransparentProxy = null, + null|array|\stdClass $Config = null, + 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->Config = null === $Config ? null : (array)$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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } @@ -102,7 +88,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,36 +149,36 @@ 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 + public function getConfig(): array { return $this->Config; } - public function setConfig(array|FakeMap|\stdClass|null $Config): self + public function setConfig(array|\stdClass $Config): self { - $this->Config = FakeMap::parse($Config); + $this->Config = (array)$Config; return $this; } @@ -201,31 +187,121 @@ 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, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($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 ('Config' === $k) { + $n->Config = (array)$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); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 ([] !== $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 190abb59..615ac575 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -108,7 +108,7 @@ class AgentServiceRegistration extends AbstractModel public AgentServiceChecks $Checks; public ?AgentServiceConnectProxyConfig $Proxy = null; public ?AgentServiceConnect $Connect = null; - public string $Namespace = ''; + public string $Namespace; public function __construct(?array $data = []) { diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index 9fdb6d1c..417df4cc 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -27,6 +27,18 @@ class AgentWeights extends AbstractModel public int $Passing; public int $Warning; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + int $Passing = 0, + int $Warning = 0, + ) { + $this->Passing = $Passing; + $this->Warning = $Warning; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getPassing(): int { return $this->Passing; @@ -36,4 +48,24 @@ public function getWarning(): int { return $this->Warning; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Passing = $this->Passing; + $out->Warning = $this->Warning; + return $out; + } } diff --git a/src/Agent/MemberACLMode.php b/src/Agent/MemberACLMode.php new file mode 100644 index 00000000..05bba7cf --- /dev/null +++ b/src/Agent/MemberACLMode.php @@ -0,0 +1,39 @@ +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 static(); + foreach ($decoded as $k => $v) { + if ('Type' === $k) { + $n->setType($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..2c809da6 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,13 @@ */ 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; + public function GetMeta(): array; public function GetCreateIndex(): int; diff --git a/src/ConfigEntry/LogSinkType.php b/src/ConfigEntry/LogSinkType.php new file mode 100644 index 00000000..099d032a --- /dev/null +++ b/src/ConfigEntry/LogSinkType.php @@ -0,0 +1,29 @@ +Tags; - } + case Default = ""; + case Transparent = "transparent"; + case Direct = "direct"; } diff --git a/src/Consul.php b/src/Consul.php index 0f1725fa..bdddea53 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -73,15 +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'; @@ -123,15 +114,6 @@ 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'; - // "private" constants public const _headerConsulPrefix = 'X-Consul-'; diff --git a/src/Peering/Locality.php b/src/Peering/Locality.php new file mode 100644 index 00000000..fe907135 --- /dev/null +++ b/src/Peering/Locality.php @@ -0,0 +1,77 @@ +Region = $Region; + $this->Zone = $Zone; + } + + public function getRegion(): string + { + return $this->Region; + } + + public function setRegion(string $Region): self + { + $this->Region = $Region; + return $this; + } + + public function getZone(): string + { + return $this->Zone; + } + + public function setZone(string $Zone): self + { + $this->Zone = $Zone; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Region = $this->Region; + $out->Zone = $this->Zone; + return $out; + } +} From 6e114297faab26de739194b749ed860399837f6f Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 13 Apr 2025 14:03:11 -0500 Subject: [PATCH 18/79] lots more work, need to go back and fix some things. --- src/ACL/ACLAuthMethod.php | 2 +- src/ACL/ACLAuthMethodListEntry.php | 2 +- .../ACLAuthMethodListEntryQueryResponse.php | 4 +- src/ACL/ACLAuthMethodNamespaceRule.php | 2 +- src/ACL/ACLAuthMethodQueryResponse.php | 6 +- src/ACL/ACLAuthMethodWriteResponse.php | 6 +- src/ACL/ACLBindingRule.php | 2 +- src/ACL/ACLBindingRuleQueryResponse.php | 6 +- src/ACL/ACLBindingRuleWriteResponse.php | 6 +- src/ACL/ACLBindingRulesQueryResponse.php | 4 +- src/ACL/ACLEntriesResponse.php | 4 +- src/ACL/ACLEntry.php | 2 +- src/ACL/ACLLink.php | 2 +- src/ACL/ACLLoginParams.php | 2 +- src/ACL/ACLNodeIdentity.php | 2 +- src/ACL/ACLOIDCAuthURLParams.php | 2 +- src/ACL/ACLOIDCCallbackParams.php | 2 +- src/ACL/ACLPolicy.php | 2 +- src/ACL/ACLPolicyListEntry.php | 2 +- src/ACL/ACLPolicyListEntryQueryResponse.php | 4 +- src/ACL/ACLPolicyQueryResponse.php | 6 +- src/ACL/ACLPolicyWriteResponse.php | 6 +- src/ACL/ACLReplicationStatus.php | 2 +- src/ACL/ACLReplicationStatusResponse.php | 6 +- src/ACL/ACLRole.php | 2 +- src/ACL/ACLRoleQueryResponse.php | 6 +- src/ACL/ACLRoleWriteResponse.php | 6 +- src/ACL/ACLRolesQueryResponse.php | 4 +- src/ACL/ACLServiceIdentity.php | 2 +- src/ACL/ACLToken.php | 2 +- src/ACL/ACLTokenListEntry.php | 2 +- src/ACL/ACLTokenListEntryQueryResponse.php | 4 +- src/ACL/ACLTokenQueryResponse.php | 6 +- src/ACL/ACLTokenWriteResponse.php | 6 +- src/ACL/KubernetesAuthMethodConfig.php | 2 +- src/ACL/OIDCAuthMethodConfig.php | 2 +- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentCheckRegistration.php | 70 ++++- src/Agent/AgentCheckUpdate.php | 4 +- src/Agent/AgentChecksResponse.php | 4 +- src/Agent/AgentHealthServicesResponse.php | 2 +- src/Agent/AgentMember.php | 2 +- src/Agent/AgentMembersResponse.php | 4 +- src/Agent/AgentService.php | 2 +- src/Agent/AgentServiceCheck.php | 50 ++- src/Agent/AgentServiceChecks.php | 9 + src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 10 +- src/Agent/AgentServiceConnectProxyConfig.php | 2 +- src/Agent/AgentServiceRegistration.php | 288 ++++++++++++------ src/Agent/AgentServiceResponse.php | 12 +- src/Agent/AgentServicesResponse.php | 4 +- src/Agent/AgentToken.php | 29 ++ src/Agent/AgentWeights.php | 2 +- src/Agent/EnvoyExtension.php | 63 ++-- src/Agent/GaugeValue.php | 43 ++- src/Agent/MemberOpts.php | 42 +++ src/Agent/MetricsInfo.php | 100 ++++-- src/Agent/MetricsInfoResponse.php | 12 +- src/Agent/PointValue.php | 34 ++- src/Agent/SampledValue.php | 58 +++- src/Agent/ServiceRegisterOpts.php | 44 +++ src/Catalog/CatalogDeregistration.php | 10 +- src/Catalog/CatalogNode.php | 2 +- src/Catalog/CatalogNodeResponse.php | 4 +- src/Catalog/CatalogNodeServiceList.php | 2 +- .../CatalogNodeServicesListResponse.php | 4 +- src/Catalog/CatalogRegistration.php | 10 +- src/Catalog/CatalogService.php | 34 +-- src/Catalog/CatalogServicesResponse.php | 4 +- src/Catalog/CompoundServiceName.php | 4 +- src/Catalog/GatewayService.php | 18 +- src/Catalog/GatewayServicesResponse.php | 4 +- src/Catalog/Node.php | 12 +- src/Catalog/NodesResponse.php | 4 +- src/Catalog/ServiceAddress.php | 36 ++- src/Catalog/Weights.php | 4 +- src/ConfigEntry/AccessLogsConfig.php | 2 +- .../CoordinateDatacentersResponse.php | 4 +- src/Coordinate/CoordinateEntriesResponse.php | 4 +- src/Event/UserEventResponse.php | 4 +- src/Event/UserEventsResponse.php | 4 +- src/HasSettableStringTags.php | 36 --- src/Health/HealthCheckDefinition.php | 2 +- src/Health/HealthChecksResponse.php | 4 +- src/Health/ServiceEntriesResponse.php | 4 +- src/KV/KVPairResponse.php | 4 +- src/KV/KVPairsResponse.php | 4 +- src/MapResponse.php | 6 +- src/Operator/AutopilotStateResponse.php | 4 +- src/Operator/OperatorAreaJoinResponse.php | 4 +- src/Operator/OperatorAreasResponse.php | 4 +- ...OperatorAutopilotConfigurationResponse.php | 4 +- src/Operator/OperatorHealthReplyResponse.php | 4 +- .../OperatorRaftConfigurationResponse.php | 4 +- src/Operator/OperatorSerfMembersResponse.php | 4 +- .../OperatorServerHealthsResponse.php | 4 +- src/Peering/Locality.php | 2 +- .../PreparedQueryDefinitionsResponse.php | 4 +- .../PreparedQueryExecuteResponseResponse.php | 4 +- src/QueryOptions.php | 2 +- src/ResponseValueBoolTrait.php | 12 +- src/ResponseValueStringTrait.php | 4 +- src/ResponseValueStringsTrait.php | 4 +- src/Session/SessionEntriesQueryResponse.php | 4 +- src/Session/SessionEntriesWriteResponse.php | 4 +- src/UnmarshalledResponseInterface.php | 2 +- src/WriteOptions.php | 2 +- 108 files changed, 917 insertions(+), 411 deletions(-) delete mode 100644 src/HasSettableStringTags.php diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 1c4ef290..ac43b1dc 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -206,7 +206,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 3259ace7..8228ea57 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -178,7 +178,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLAuthMethodListEntryQueryResponse.php b/src/ACL/ACLAuthMethodListEntryQueryResponse.php index 9d37f527..2b024782 100644 --- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php +++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php @@ -32,9 +32,9 @@ public function getValue(): array return $this->ACLAuthMethodListEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->ACLAuthMethodListEntries[] = ACLAuthMethodListEntry::jsonUnserialize($datum); } } diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 36a4664d..4252d82c 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -61,7 +61,7 @@ public function setBindNamespace(string $BindNamespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLAuthMethodQueryResponse.php b/src/ACL/ACLAuthMethodQueryResponse.php index 30b5c4fd..5c51602f 100644 --- a/src/ACL/ACLAuthMethodQueryResponse.php +++ b/src/ACL/ACLAuthMethodQueryResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLAuthMethod return $this->ACLAuthMethod; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLAuthMethod = null; return; } - $this->ACLAuthMethod = $this->ACLAuthMethod::jsonUnserialize($decodedData); + $this->ACLAuthMethod = $this->ACLAuthMethod::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLAuthMethodWriteResponse.php b/src/ACL/ACLAuthMethodWriteResponse.php index 44056647..61f17997 100644 --- a/src/ACL/ACLAuthMethodWriteResponse.php +++ b/src/ACL/ACLAuthMethodWriteResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLAuthMethod return $this->ACLAuthMethod; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLAuthMethod = null; return; } - $this->ACLAuthMethod = ACLAuthMethod::jsonUnserialize($decodedData); + $this->ACLAuthMethod = ACLAuthMethod::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 0e041aea..b9d62bd6 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -159,7 +159,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLBindingRuleQueryResponse.php b/src/ACL/ACLBindingRuleQueryResponse.php index 237d59f0..73381657 100644 --- a/src/ACL/ACLBindingRuleQueryResponse.php +++ b/src/ACL/ACLBindingRuleQueryResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLBindingRule return $this->ACLBindingRule; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLBindingRule = null; return; } - $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decodedData); + $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLBindingRuleWriteResponse.php b/src/ACL/ACLBindingRuleWriteResponse.php index 983da782..471cb66c 100644 --- a/src/ACL/ACLBindingRuleWriteResponse.php +++ b/src/ACL/ACLBindingRuleWriteResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLBindingRule return $this->ACLBindingRule; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLBindingRule = null; return; } - $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decodedData); + $this->ACLBindingRule = ACLBindingRule::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php index 4607e0fe..87c676eb 100644 --- a/src/ACL/ACLBindingRulesQueryResponse.php +++ b/src/ACL/ACLBindingRulesQueryResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $datum) { $this->ACLBindingRules[] = ACLBindingRule::jsonUnserialize($datum); } } diff --git a/src/ACL/ACLEntriesResponse.php b/src/ACL/ACLEntriesResponse.php index d26bacc3..2728a587 100644 --- a/src/ACL/ACLEntriesResponse.php +++ b/src/ACL/ACLEntriesResponse.php @@ -32,9 +32,9 @@ public function getValue(): array return $this->ACLEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - foreach ($decodedData as $entry) { + foreach ($decoded as $entry) { $this->ACLEntries[] = ACLEntry::jsonUnserialize($entry); } } diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index 97555cae..d27c8e53 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -117,7 +117,7 @@ public function setRules(string $rules): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index 8fe661cd..a8b638d1 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -61,7 +61,7 @@ public function setName(string $Name): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index 4a1221a5..1902aa27 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -78,7 +78,7 @@ public function setMeta(null|array|\stdClass $Meta): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 59820809..308b56fd 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -49,7 +49,7 @@ public function getDatacenter(): string return $this->Datacenter; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 39367264..93a026fd 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -93,7 +93,7 @@ public function setMeta(null|array|\stdClass $Meta): self } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 3beb692a..09ff38fb 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -89,7 +89,7 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 315d9d62..17d303d3 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -160,7 +160,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index 0651d313..78288acf 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -145,7 +145,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php index 131a8211..a40436a3 100644 --- a/src/ACL/ACLPolicyListEntryQueryResponse.php +++ b/src/ACL/ACLPolicyListEntryQueryResponse.php @@ -32,9 +32,9 @@ public function getValue(): array return $this->ACLPolicyListEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->ACLPolicyListEntries[] = ACLPolicyListEntry::jsonUnserialize($datum); } } diff --git a/src/ACL/ACLPolicyQueryResponse.php b/src/ACL/ACLPolicyQueryResponse.php index d5e0e05a..50895ba5 100644 --- a/src/ACL/ACLPolicyQueryResponse.php +++ b/src/ACL/ACLPolicyQueryResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLPolicy return $this->ACLPolicy; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLPolicy = null; return; } - $this->ACLPolicy = ACLPolicy::jsonUnserialize($decodedData); + $this->ACLPolicy = ACLPolicy::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLPolicyWriteResponse.php b/src/ACL/ACLPolicyWriteResponse.php index 74f6e693..a9b74b46 100644 --- a/src/ACL/ACLPolicyWriteResponse.php +++ b/src/ACL/ACLPolicyWriteResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLPolicy return $this->ACLPolicy; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLPolicy = null; return; } - $this->ACLPolicy = ACLPolicy::jsonUnserialize($decodedData); + $this->ACLPolicy = ACLPolicy::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 761fd96b..6da38a62 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -98,7 +98,7 @@ public function getLastError(): Time\Time return $this->LastError; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLReplicationStatusResponse.php b/src/ACL/ACLReplicationStatusResponse.php index f355ae90..51438d44 100644 --- a/src/ACL/ACLReplicationStatusResponse.php +++ b/src/ACL/ACLReplicationStatusResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLReplicationStatus return $this->ACLReplicationStatus; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLReplicationStatus = null; return; } - $this->ACLReplicationStatus = ACLReplicationStatus::jsonUnserialize($decodedData); + $this->ACLReplicationStatus = ACLReplicationStatus::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 9af96845..03ca9f86 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -173,7 +173,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLRoleQueryResponse.php b/src/ACL/ACLRoleQueryResponse.php index cc727773..9106283e 100644 --- a/src/ACL/ACLRoleQueryResponse.php +++ b/src/ACL/ACLRoleQueryResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLRole return $this->ACLRole; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLRole = null; return; } - $this->ACLRole = ACLRole::jsonUnserialize($decodedData); + $this->ACLRole = ACLRole::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLRoleWriteResponse.php b/src/ACL/ACLRoleWriteResponse.php index 62f747eb..0827b545 100644 --- a/src/ACL/ACLRoleWriteResponse.php +++ b/src/ACL/ACLRoleWriteResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLRole return $this->ACLRole; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLRole = null; return; } - $this->ACLRole = ACLRole::jsonUnserialize($decodedData); + $this->ACLRole = ACLRole::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php index 541421ef..1b66f2f7 100644 --- a/src/ACL/ACLRolesQueryResponse.php +++ b/src/ACL/ACLRolesQueryResponse.php @@ -32,9 +32,9 @@ public function getValue(): array return $this->ACLRoles; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->ACLRoles[] = ACLRole::jsonUnserialize($datum); } } diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 78ec9b63..9f730480 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -57,7 +57,7 @@ public function setDatacenters(string ...$datacenters): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index 8a5d90e3..4cfe9ef6 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -273,7 +273,7 @@ public function setRules(string $Rules): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index a57043d7..189f81da 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -244,7 +244,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php index bf08d930..0a0620b6 100644 --- a/src/ACL/ACLTokenListEntryQueryResponse.php +++ b/src/ACL/ACLTokenListEntryQueryResponse.php @@ -32,9 +32,9 @@ public function getValue(): array return $this->ACLTokenListEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->ACLTokenListEntries[] = ACLTokenListEntry::jsonUnserialize($datum); } } diff --git a/src/ACL/ACLTokenQueryResponse.php b/src/ACL/ACLTokenQueryResponse.php index 47ca20a6..c9d0c160 100644 --- a/src/ACL/ACLTokenQueryResponse.php +++ b/src/ACL/ACLTokenQueryResponse.php @@ -32,12 +32,12 @@ public function getValue(): null|ACLToken return $this->ACLToken; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLToken = null; return; } - $this->ACLToken = ACLToken::jsonUnserialize($decodedData); + $this->ACLToken = ACLToken::jsonUnserialize($decoded); } } diff --git a/src/ACL/ACLTokenWriteResponse.php b/src/ACL/ACLTokenWriteResponse.php index 291c4196..6a654d55 100644 --- a/src/ACL/ACLTokenWriteResponse.php +++ b/src/ACL/ACLTokenWriteResponse.php @@ -32,12 +32,12 @@ public function getValue(): ?ACLToken return $this->ACLToken; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->ACLToken = null; return; } - $this->ACLToken = ACLToken::jsonUnserialize($decodedData); + $this->ACLToken = ACLToken::jsonUnserialize($decoded); } } diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index a46c21da..9c81acdf 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -90,7 +90,7 @@ public function RenderToConfig(): array ]; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index a853af50..439c5d60 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -32,7 +32,7 @@ public function __construct( } } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index dd519344..45276866 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -191,7 +191,7 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 1021d56d..91c8fd7d 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -25,16 +25,69 @@ class AgentCheckRegistration extends AgentServiceCheck public string $ID; public string $ServiceID; public string $Namespace; + public string $Partition; public function __construct( null|array $data = null, // Deprecated, will be removed. string $ID = '', string $ServiceID = '', + string $CheckID = '', + string $Name = '', + iterable $ScriptArgs = [], + string $DockerContainerID = '', + string $Shell = '', + string $Interval = '', + string $Timeout = '', + string $TTL = '', + string $HTTP = '', + iterable $Header = [], + 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, + ScriptArgs: $ScriptArgs, + 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; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -73,9 +126,10 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self|AgentServiceCheck $into = null): static { $n = $into ?? new static(); + parent::jsonUnserialize($decoded, $n); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -84,10 +138,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = parent::jsonSerialize(); if ('' !== $this->ID) { $out->ID = $this->ID; } @@ -97,6 +148,15 @@ public function jsonSerialize(): \stdClass 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 d534e849..8e0bb063 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -22,7 +22,7 @@ use DCarbone\PHPConsulAPI\AbstractModel; -final class AgentCheckUpdate extends AbstractModel +class AgentCheckUpdate extends AbstractModel { public string $Status; public string $Output; @@ -61,7 +61,7 @@ public function setOutput(string $output): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new self(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentChecksResponse.php b/src/Agent/AgentChecksResponse.php index 95f72415..02b0c542 100644 --- a/src/Agent/AgentChecksResponse.php +++ b/src/Agent/AgentChecksResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->Checks; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->Checks = []; - foreach ($decodedData as $k => $v) { + foreach ($decoded as $k => $v) { $this->Checks[$k] = AgentCheck::jsonUnserialize($v); } } diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php index 23caed23..d5987797 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -31,7 +31,7 @@ class AgentHealthServicesResponse extends AbstractResponse public string $AggregatedStatus; public array $AgentServiceChecksInfos; - public function __construct(string $aggregatedStatus, array $checkInfos, ?Error $err) + public function __construct(string $aggregatedStatus, array $checkInfos, null|Error $err) { $this->AggregatedStatus = $aggregatedStatus; $this->AgentServiceChecksInfos = []; diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 155d5d61..61709714 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -143,7 +143,7 @@ public function IsConsulServer(): bool Consul::MemberTagValueRoleServer === $this->Tags[Consul::MemberTagKeyACLMode]; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentMembersResponse.php b/src/Agent/AgentMembersResponse.php index 4e15bbd7..f1f0f576 100644 --- a/src/Agent/AgentMembersResponse.php +++ b/src/Agent/AgentMembersResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $member) { $this->Members[] = AgentMember::jsonUnserialize($member); } } diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index e079dfbc..c47fbe0b 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -319,7 +319,7 @@ public function setLocality(null|Locality $Locality): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index b7a80066..b1189dc3 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -41,6 +41,8 @@ class AgentServiceCheck extends AbstractModel public bool $TLSSkipVerify; public string $GRPC; public bool $GRPCUseTLS; + public string $H2PING; + public bool $H2PINGUseTLS; public string $AliasNode; public string $AliasService; public int $SuccessBeforePassing; @@ -59,7 +61,7 @@ public function __construct( string $Timeout = '', string $TTL = '', string $HTTP = '', - iterable $Header = [], + array|\stdClass $Header = [], string $Method = '', string $TCP = '', string $Status = '', @@ -67,6 +69,8 @@ public function __construct( bool $TLSSkipVerify = false, string $GRPC = '', bool $GRPCUseTLS = false, + string $H2PING = '', + bool $H2PINGUseTLS = false, string $AliasNode = '', string $AliasService = '', int $SuccessBeforePassing = 0, @@ -83,7 +87,7 @@ public function __construct( $this->Timeout = $Timeout; $this->TTL = $TTL; $this->HTTP = $HTTP; - $this->setHeader(...$Header); + $this->setHeader($Header); $this->Method = $Method; $this->TCP = $TCP; $this->Status = $Status; @@ -91,6 +95,8 @@ public function __construct( $this->TLSSkipVerify = $TLSSkipVerify; $this->GRPC = $GRPC; $this->GRPCUseTLS = $GRPCUseTLS; + $this->H2PING = $H2PING; + $this->H2PINGUseTLS = $H2PINGUseTLS; $this->AliasNode = $AliasNode; $this->AliasService = $AliasService; $this->SuccessBeforePassing = $SuccessBeforePassing; @@ -128,7 +134,7 @@ public function getScriptArgs(): array return $this->ScriptArgs; } - public function setScriptArgs(string ...$args): self + public function setScriptArgs(string ...$args): self { $this->ScriptArgs = $args; return $this; @@ -205,9 +211,9 @@ public function getHeader(): array return $this->Header; } - public function setHeader(mixed ...$header): self + public function setHeader(array|\stdClass $Header): self { - $this->Header = $header; + $this->Header = (array)$Header; return $this; } @@ -282,6 +288,28 @@ public function isGRPCUseTLS(): bool return $this->GRPCUseTLS; } + public function getH2PING(): string + { + return $this->H2PING; + } + + public function setH2PING(string $H2PING): AgentServiceCheck + { + $this->H2PING = $H2PING; + return $this; + } + + public function isH2PINGUseTLS(): bool + { + return $this->H2PINGUseTLS; + } + + public function setH2PINGUseTLS(bool $H2PINGUseTLS): AgentServiceCheck + { + $this->H2PINGUseTLS = $H2PINGUseTLS; + return $this; + } + public function setGRPCUseTLS(bool $GRPCUseTLS): self { $this->GRPCUseTLS = $GRPCUseTLS; @@ -343,7 +371,7 @@ public function setDeregisterCriticalServiceAfter(string $deregisterCriticalServ return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { @@ -400,15 +428,21 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Notes) { $out->Notes = $this->Notes; } - if (false !== $this->TLSSkipVerify) { + if ($this->TLSSkipVerify) { $out->TLSSkipVerify = $this->TLSSkipVerify; } if ('' !== $this->GRPC) { $out->GRPC = $this->GRPC; } - if (false !== $this->GRPCUseTLS) { + 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; } diff --git a/src/Agent/AgentServiceChecks.php b/src/Agent/AgentServiceChecks.php index 1be51649..dfd574df 100644 --- a/src/Agent/AgentServiceChecks.php +++ b/src/Agent/AgentServiceChecks.php @@ -85,4 +85,13 @@ public function offsetUnset(mixed $offset): void { unset($this->Checks[$offset]); } + + public static function jsonUnserialize(array $decoded): static + { + $n = new static(); + foreach ($decoded as $v) { + $n->Checks[] = AgentServiceCheck::jsonUnserialize($v); + } + return $n; + } } diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 1f0a5600..81afd5ee 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -76,7 +76,7 @@ public function setChecks(HealthChecks $Checks): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 1d333d8f..8f479a03 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -61,7 +61,7 @@ public function setSidecarService(AgentServiceRegistration $SidecarService): sel return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { @@ -80,8 +80,12 @@ public function jsonSerialize(): \stdClass foreach ($this->_getDynamicFields() as $k => $v) { $out->{$k} = $v; } - $out->Native = $this->Native; - $out->SidecarService = $this->SidecarService; + 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 862e9f98..8cfb128c 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -226,7 +226,7 @@ public function setAccessLogs(null|AccessLogsConfig $AccessLogs): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 615ac575..3dba3cbf 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -22,110 +22,78 @@ 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; class AgentServiceRegistration extends AbstractModel { - 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 ServiceKind $Kind; public string $ID; public string $Name; + public array $Tags; public int $Port; public string $Address; public array $TaggedAddresses; public bool $EnableTagOverride; public array $Meta; - public ?AgentWeights $Weights = null; - public ?AgentServiceCheck $Check = null; + public null|AgentWeights $Weights; + public null|AgentServiceCheck $Check; public AgentServiceChecks $Checks; - public ?AgentServiceConnectProxyConfig $Proxy = null; - public ?AgentServiceConnect $Connect = null; + public null|AgentServiceConnectProxyConfig $Proxy; + public null|AgentServiceConnect $Connect; public string $Namespace; - - public function __construct(?array $data = []) - { - parent::__construct($data); - if (!isset($this->Checks)) { - $this->Checks = new AgentServiceChecks(null); + public string $Partition; + public null|Locality $Locality; + + public function __construct( + null|array $data = null, + string|ServiceKind $Kind = ServiceKind::Typical, + string $ID = '', + string $Name = '', + iterable $Tags = [], + int $Port = 0, + string $Address = '', + array|\stdClass $TaggedAddresses = [], + bool $EnableTagOverride = false, + array|\stdClass $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->setKind($Kind); + $this->ID = $ID; + $this->Name = $Name; + $this->setTags(...$Tags); + $this->Port = $Port; + $this->Address = $Address; + $this->setTaggedAddresses($TaggedAddresses); + $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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } - 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 +119,17 @@ public function setName(string $Name): self return $this; } + 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,14 +152,17 @@ public function setAddress(string $Address): self return $this; } - public function getTaggedAddresses(): ?array + public function getTaggedAddresses(): array { return $this->TaggedAddresses; } - public function setTaggedAddresses(array $TaggedAddresses): self + public function setTaggedAddresses(array|\stdClass $TaggedAddresses): self { - $this->TaggedAddresses = $TaggedAddresses; + $this->TaggedAddresses = []; + foreach ($TaggedAddresses as $k => $v) { + $this->TaggedAddresses[$k] = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize((object)$v); + } return $this; } @@ -195,34 +177,34 @@ public function setEnableTagOverride(bool $EnableTagOverride): self return $this; } - public function getMeta(): ?array + public function getMeta(): array { return $this->Meta; } - public function setMeta(array $Meta): self + public function setMeta(array|\stdClass $Meta): self { - $this->Meta = $Meta; + $this->Meta = (array)$Meta; 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 +221,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 +253,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(): ?Locality + { + return $this->Locality; + } + + public function setLocality(?Locality $Locality): self + { + $this->Locality = $Locality; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Kind' === $k) { + $n->setKind($v); + } elseif ('Tags' === $k) { + $n->setTags(...$v); + } elseif ('TaggedAddresses' === $k) { + $n->setTaggedAddresses($v); + } elseif ('Meta' === $k) { + $n->setMeta($v); + } 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); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 ([] !== $this->TaggedAddresses) { + $out->TaggedAddresses = $this->TaggedAddresses; + } + if ($this->EnableTagOverride) { + $out->EnableTagOverride = $this->EnableTagOverride; + } + if ([] !== $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..49d31f14 100644 --- a/src/Agent/AgentServiceResponse.php +++ b/src/Agent/AgentServiceResponse.php @@ -25,15 +25,19 @@ 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..14391dac 100644 --- a/src/Agent/AgentServicesResponse.php +++ b/src/Agent/AgentServicesResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->Services; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->Services = []; - foreach ($decodedData as $k => $service) { + foreach ($decoded as $k => $service) { $this->Services[$k] = new AgentService($service); } } diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index 645b2800..b0670c80 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -26,6 +26,16 @@ class AgentToken extends AbstractModel { public string $Token; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Token = '', + ) { + $this->Token = $Token; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getToken(): string { return $this->Token; @@ -36,4 +46,23 @@ public function setToken(string $Token): self $this->Token = $Token; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Token = $this->Token; + return $out; + } } diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index 417df4cc..8bd65d1b 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -49,7 +49,7 @@ public function getWarning(): int return $this->Warning; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Agent/EnvoyExtension.php b/src/Agent/EnvoyExtension.php index d3983142..45cb646f 100644 --- a/src/Agent/EnvoyExtension.php +++ b/src/Agent/EnvoyExtension.php @@ -21,28 +21,30 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; class EnvoyExtension extends AbstractModel { - protected const FIELDS = [ - self::FIELD_ARGUMENTS => Transcoding::MAP_FIELD, - ]; - - private const FIELD_ARGUMENTS = 'Arguments'; - public string $Name; public bool $Required; - public FakeMap $Arguments; + public array $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 __construct( + null|array $data = null, // Deprecated, will be removed. + string $Name = '', + bool $Required = false, + array|\stdClass $Arguments = [], + string $ConsulVersion = '', + string $EnvoyVersion = '', + ) { + $this->Name = $Name; + $this->Required = $Required; + $this->setArguments($Arguments); + $this->ConsulVersion = $ConsulVersion; + $this->EnvoyVersion = $EnvoyVersion; + if (null !== $data && [] !== $data) { + $this->jsonSerialize((object)$data, $this); } } @@ -68,14 +70,14 @@ public function setRequired(bool $Required): self return $this; } - public function getArguments(): ?FakeMap + public function getArguments(): array { return $this->Arguments; } - public function setArguments(array|FakeMap|\stdClass|null $Arguments): self + public function setArguments(array|\stdClass $Arguments): self { - $this->Arguments = FakeMap::parse($Arguments); + $this->Arguments = (array)$Arguments; return $this; } @@ -100,4 +102,31 @@ public function setEnvoyVersion(string $EnvoyVersion): self $this->EnvoyVersion = $EnvoyVersion; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Arguments' === $k) { + $n->setArguments($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Name = $this->Name; + $out->Required = $this->Required; + $out->Arguments = $this->Arguments; + $out->ConsulVersion = $this->ConsulVersion; + $out->EnvoyVersion = $this->EnvoyVersion; + return $out; + } } diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 3df682e7..986eb96d 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -28,6 +28,20 @@ class GaugeValue extends AbstractModel public float $Value; public array $Labels; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Name = '', + float $Value = 0.0, + array|\stdClass $Labels = [], + ) { + $this->Name = $Name; + $this->Value = $Value; + $this->setLabels($Labels); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getName(): string { return $this->Name; @@ -55,9 +69,34 @@ public function getLabels(): array return $this->Labels; } - public function setLabels(array $labels): self + public function setLabels(array|\stdClass $labels): self { - $this->Labels = $labels; + $this->Labels = (array)$labels; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Labels' === $k) { + $n->setLabels($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Name = $this->Name; + $out->Value = $this->Value; + $out->Labels = $this->Labels; + return $out; + } } diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index df18ae7f..4e66e592 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -26,6 +26,21 @@ class MemberOpts extends AbstractModel { public bool $WAN; public string $Segment; + public string $Filter; + + public function __construct( + null|array $data = null, + bool $WAN = false, + string $Segment = '', + string $Filter = '', + ) { + $this->WAN = $WAN; + $this->Segment = $Segment; + $this->Filter = $Filter; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function isWAN(): bool { @@ -48,4 +63,31 @@ public function setSegment(string $segment): self $this->Segment = $segment; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 cc036912..bc4805b8 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -21,44 +21,37 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class MetricsInfo extends AbstractModel { - 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; + /** @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; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Timestamp = '', + iterable $Gauges = [], + iterable $Points = [], + iterable $Counters = [], + iterable $Samples = [], + ) { + $this->Timestamp = $Timestamp; + $this->setGauges(...$Gauges); + $this->setPoints(...$Points); + $this->setCounters(...$Counters); + $this->setSamples(...$Samples); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getTimestamp(): string { return $this->Timestamp; @@ -75,7 +68,7 @@ public function getGauges(): array return $this->Gauges; } - public function setGauges(array $gauges): self + public function setGauges(GaugeValue ...$gauges): self { $this->Gauges = $gauges; return $this; @@ -86,7 +79,7 @@ public function getPoints(): array return $this->Points; } - public function setPoints(array $points): self + public function setPoints(PointValue ...$points): self { $this->Points = $points; return $this; @@ -97,7 +90,7 @@ public function getCounters(): array return $this->Counters; } - public function setCounters(array $counters): self + public function setCounters(SampledValue ...$counters): self { $this->Counters = $counters; return $this; @@ -108,9 +101,50 @@ 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, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Gauges' === $k) { + foreach ($v as $vv) { + $n->Gauges[] = GaugeValue::jsonUnserialize($vv); + } + } elseif ('Points' === $k) { + foreach ($v as $vv) { + $n->Points[] = PointValue::jsonUnserialize($vv); + } + } elseif ('Counters' === $k) { + foreach ($v as $vv) { + $n->Counters[] = SampledValue::jsonUnserialize($vv); + } + } elseif ('Samples' === $k) { + foreach ($v as $vv) { + $n->Samples[] = SampledValue::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..82fbe9f7 100644 --- a/src/Agent/MetricsInfoResponse.php +++ b/src/Agent/MetricsInfoResponse.php @@ -25,15 +25,19 @@ 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 40d5c1f1..29c9bca0 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -27,6 +27,18 @@ class PointValue extends AbstractModel public string $Name; public array $Points; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Name = '', + iterable $Points = [], + ) { + $this->Name = $Name; + $this->setPoints(...$Points); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getName(): string { return $this->Name; @@ -43,9 +55,29 @@ 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, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Name = $this->Name; + $out->Points = $this->Points; + return $out; + } } diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index f7fc381a..19e6a311 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -33,6 +33,30 @@ class SampledValue extends AbstractModel public float $Stddev; public array $Labels; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + 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|\stdClass $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); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + public function getName(): string { return $this->Name; @@ -115,9 +139,39 @@ public function getLabels(): array return $this->Labels; } - public function setLabels(array $labels): self + public function setLabels(array|\stdClass $labels): self { - $this->Labels = $labels; + $this->Labels = (array)$labels; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Labels' === $k) { + $n->setLabels($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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->Labels; + return $out; + } } diff --git a/src/Agent/ServiceRegisterOpts.php b/src/Agent/ServiceRegisterOpts.php index 69cfe23d..56f82c66 100644 --- a/src/Agent/ServiceRegisterOpts.php +++ b/src/Agent/ServiceRegisterOpts.php @@ -25,6 +25,19 @@ class ServiceRegisterOpts extends AbstractModel { public bool $ReplaceExistingChecks; + public string $Token; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + bool $ReplaceExistingChecks = false, + string $Token = '', + ) { + $this->ReplaceExistingChecks = $ReplaceExistingChecks; + $this->Token = $Token; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } public function isReplaceExistingChecks(): bool { @@ -36,4 +49,35 @@ public function setReplaceExistingChecks(bool $replaceExistingChecks): self $this->ReplaceExistingChecks = $replaceExistingChecks; return $this; } + + public function getToken(): string + { + return $this->Token; + } + + public function setToken(string $Token): ServiceRegisterOpts + { + $this->Token = $Token; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ReplaceExistingChecks = $this->ReplaceExistingChecks; + $out->Token = $this->Token; + return $out; + } } diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 139008fc..22ded7c4 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -33,11 +33,11 @@ class CatalogDeregistration extends AbstractModel 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 function getNode(): string { diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index 1f947d62..ac428358 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -42,7 +42,7 @@ class CatalogNode extends AbstractModel private const FIELD_SERVICES = 'Services'; public ?Node $Node = null; - public array $Services = []; + public array $Services; public function getNode(): ?Node { diff --git a/src/Catalog/CatalogNodeResponse.php b/src/Catalog/CatalogNodeResponse.php index b3095658..77d0c689 100644 --- a/src/Catalog/CatalogNodeResponse.php +++ b/src/Catalog/CatalogNodeResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?CatalogNode return $this->Node; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->Node = new CatalogNode((array)$decodedData); + $this->Node = new CatalogNode((array)$decoded); } } diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index abae0f3a..47f14a41 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -42,7 +42,7 @@ class CatalogNodeServiceList extends AbstractModel private const FIELD_SERVICES = 'Services'; public ?Node $Node = null; - public array $Services = []; + public array $Services; public function getNode(): ?Node { diff --git a/src/Catalog/CatalogNodeServicesListResponse.php b/src/Catalog/CatalogNodeServicesListResponse.php index d7f712fd..3c80714c 100644 --- a/src/Catalog/CatalogNodeServicesListResponse.php +++ b/src/Catalog/CatalogNodeServicesListResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?CatalogNodeServiceList return $this->CatalogNodeServiceList; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->CatalogNodeServiceList = new CatalogNodeServiceList((array)$decodedData); + $this->CatalogNodeServiceList = new CatalogNodeServiceList((array)$decoded); } } diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index 5175edc2..e3f2a320 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -52,16 +52,16 @@ class CatalogRegistration extends AbstractModel private const FIELD_CHECK = 'Check'; private const FIELD_CHECKS = 'Checks'; - public string $ID = ''; - public string $Node = ''; - public string $Address = ''; + public string $ID; + public string $Node; + public string $Address; public FakeMap $TaggedAddresses; public FakeMap $NodeMeta; - public string $Datacenter = ''; + public string $Datacenter; public ?AgentService $Service = null; public ?AgentCheck $Check = null; public HealthChecks $Checks; - public bool $SkipNodeUpdate = false; + public bool $SkipNodeUpdate; public function __construct(?array $data = []) { diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index deb51345..4895a509 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -55,25 +55,25 @@ class CatalogService extends AbstractModel 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; + 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; public Weights $ServiceWeights; - public bool $ServiceEnableTagOverride = false; - public int $CreateIndex = 0; + public bool $ServiceEnableTagOverride; + public int $CreateIndex; public ?AgentServiceConnectProxyConfig $ServiceProxy = null; - public int $ModifyIndex = 0; - public string $Namespace = ''; + public int $ModifyIndex; + public string $Namespace; public function getID(): string { diff --git a/src/Catalog/CatalogServicesResponse.php b/src/Catalog/CatalogServicesResponse.php index 6cbbc8f1..063048d8 100644 --- a/src/Catalog/CatalogServicesResponse.php +++ b/src/Catalog/CatalogServicesResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $node) { $this->Services[] = new CatalogService($node); } } diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 31d32162..34c3b4e5 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -31,8 +31,8 @@ class CompoundServiceName extends AbstractModel private const FIELD_NAMESPACE = 'Namespace'; - public string $Name = ''; - public string $Namespace = ''; + public string $Name; + public string $Namespace; public function getName(): string { diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 2a47bee2..f9850415 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -61,15 +61,15 @@ class GatewayService extends AbstractModel 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 string $GatewayKind; + public int $Port; + 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 = []) { diff --git a/src/Catalog/GatewayServicesResponse.php b/src/Catalog/GatewayServicesResponse.php index cbf9d620..e01c3028 100644 --- a/src/Catalog/GatewayServicesResponse.php +++ b/src/Catalog/GatewayServicesResponse.php @@ -32,10 +32,10 @@ public function getValue(): mixed return $this->GatewayServices; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->GatewayServices = []; - foreach ($decodedData as $service) { + foreach ($decoded as $service) { $this->GatewayServices[] = new GatewayService($service); } } diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 2a6d19fa..8f221ee7 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -34,14 +34,14 @@ class Node extends AbstractModel private const FIELD_TAGGED_ADDRESSES = 'TaggedAddresses'; private const FIELD_META = 'Meta'; - public string $ID = ''; - public string $Node = ''; - public string $Address = ''; - public string $Datacenter = ''; + 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 int $CreateIndex; + public int $ModifyIndex; public function __construct(?array $data = []) { diff --git a/src/Catalog/NodesResponse.php b/src/Catalog/NodesResponse.php index f38cddd9..59413281 100644 --- a/src/Catalog/NodesResponse.php +++ b/src/Catalog/NodesResponse.php @@ -32,10 +32,10 @@ public function getValue(): mixed return $this->Nodes; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->Nodes = []; - foreach ($decodedData as $node) { + foreach ($decoded as $node) { $this->Nodes[] = new Node($node); } } diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index 27d1fb6b..d3da820a 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -24,8 +24,20 @@ class ServiceAddress extends AbstractModel { - public string $Address = ''; - public int $Port = 0; + public string $Address; + public int $Port; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $address = '', + int $port = 0, + ) { + $this->Address = $address; + $this->Port = $port; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getAddress(): string { @@ -48,4 +60,24 @@ public function setPort(int $port): self $this->Port = $port; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Address = $this->Address; + $out->Port = $this->Port; + return $out; + } } diff --git a/src/Catalog/Weights.php b/src/Catalog/Weights.php index 08021e75..867f38ba 100644 --- a/src/Catalog/Weights.php +++ b/src/Catalog/Weights.php @@ -24,8 +24,8 @@ class Weights extends AbstractModel { - public int $Passing = 0; - public int $Warning = 0; + public int $Passing; + public int $Warning; public function getPassing(): int { diff --git a/src/ConfigEntry/AccessLogsConfig.php b/src/ConfigEntry/AccessLogsConfig.php index c94aec95..03563162 100644 --- a/src/ConfigEntry/AccessLogsConfig.php +++ b/src/ConfigEntry/AccessLogsConfig.php @@ -113,7 +113,7 @@ public function setTextFormat(string $TextFormat): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded): static { $n = new static(); foreach ($decoded as $k => $v) { diff --git a/src/Coordinate/CoordinateDatacentersResponse.php b/src/Coordinate/CoordinateDatacentersResponse.php index 7953d3b4..4fc83de5 100644 --- a/src/Coordinate/CoordinateDatacentersResponse.php +++ b/src/Coordinate/CoordinateDatacentersResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $item) { $this->DatacenterMap[] = new CoordinateDatacenterMap($item); } } diff --git a/src/Coordinate/CoordinateEntriesResponse.php b/src/Coordinate/CoordinateEntriesResponse.php index af95e426..c31d9f83 100644 --- a/src/Coordinate/CoordinateEntriesResponse.php +++ b/src/Coordinate/CoordinateEntriesResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $node) { $this->Nodes[] = new CoordinateEntry($node); } } diff --git a/src/Event/UserEventResponse.php b/src/Event/UserEventResponse.php index 1b854d71..40808bb9 100644 --- a/src/Event/UserEventResponse.php +++ b/src/Event/UserEventResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?UserEvent return $this->UserEvent; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->UserEvent = new UserEvent((array)$decodedData); + $this->UserEvent = new UserEvent((array)$decoded); } } diff --git a/src/Event/UserEventsResponse.php b/src/Event/UserEventsResponse.php index b9eb5f61..766d0d0b 100644 --- a/src/Event/UserEventsResponse.php +++ b/src/Event/UserEventsResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $datum) { $this->UserEvents[] = new UserEvent($datum); } } diff --git a/src/HasSettableStringTags.php b/src/HasSettableStringTags.php deleted file mode 100644 index c617b70d..00000000 --- a/src/HasSettableStringTags.php +++ /dev/null @@ -1,36 +0,0 @@ -Tags = $tags; - return $this; - } - - public function addTag(string $tag): static - { - $this->Tags[] = $tag; - return $this; - } -} diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index 591a730e..d9168d61 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -163,7 +163,7 @@ public function setDeregisterCriticalServiceAfterDuration( return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/Health/HealthChecksResponse.php b/src/Health/HealthChecksResponse.php index 54852a40..d8f2c3a0 100644 --- a/src/Health/HealthChecksResponse.php +++ b/src/Health/HealthChecksResponse.php @@ -32,8 +32,8 @@ 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); + $this->HealthChecks = new HealthChecks((array)$decoded); } } diff --git a/src/Health/ServiceEntriesResponse.php b/src/Health/ServiceEntriesResponse.php index 5ed674ea..f93c7f1b 100644 --- a/src/Health/ServiceEntriesResponse.php +++ b/src/Health/ServiceEntriesResponse.php @@ -32,10 +32,10 @@ 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) { + foreach ($decoded as $entry) { $this->ServiceEntries[] = new ServiceEntry($entry); } } diff --git a/src/KV/KVPairResponse.php b/src/KV/KVPairResponse.php index f6abca82..a8917b9a 100644 --- a/src/KV/KVPairResponse.php +++ b/src/KV/KVPairResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?KVPair return $this->KVPair; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->KVPair = new KVPair((array)$decodedData, true); + $this->KVPair = new KVPair((array)$decoded, true); } } diff --git a/src/KV/KVPairsResponse.php b/src/KV/KVPairsResponse.php index 2c5a1a65..621b1e40 100644 --- a/src/KV/KVPairsResponse.php +++ b/src/KV/KVPairsResponse.php @@ -32,8 +32,8 @@ 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); + $this->KVPairs = new KVPairs((array)$decoded); } } diff --git a/src/MapResponse.php b/src/MapResponse.php index 7887998f..7e805483 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -29,12 +29,12 @@ public function getValue(): null|array return $this->Map; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (null === $decodedData) { + if (null === $decoded) { $this->Map = null; return; } - $this->Map = (array)$decodedData; + $this->Map = (array)$decoded; } } diff --git a/src/Operator/AutopilotStateResponse.php b/src/Operator/AutopilotStateResponse.php index bf4add88..49ba9999 100644 --- a/src/Operator/AutopilotStateResponse.php +++ b/src/Operator/AutopilotStateResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?AutopilotState return $this->AutopilotState; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->AutopilotState = new AutopilotState($decodedData); + $this->AutopilotState = new AutopilotState($decoded); } } diff --git a/src/Operator/OperatorAreaJoinResponse.php b/src/Operator/OperatorAreaJoinResponse.php index b97836ae..ded7f19d 100644 --- a/src/Operator/OperatorAreaJoinResponse.php +++ b/src/Operator/OperatorAreaJoinResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->AreaJoinResponses; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->AreaJoinResponses = []; - foreach ($decodedData as $area) { + foreach ($decoded as $area) { $this->AreaJoinResponses[] = new AreaJoinResponse($area); } } diff --git a/src/Operator/OperatorAreasResponse.php b/src/Operator/OperatorAreasResponse.php index 9e7417a4..fd4e90e4 100644 --- a/src/Operator/OperatorAreasResponse.php +++ b/src/Operator/OperatorAreasResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->Areas; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->Areas = []; - foreach ($decodedData as $area) { + foreach ($decoded as $area) { $this->Areas[] = new Area($area); } } diff --git a/src/Operator/OperatorAutopilotConfigurationResponse.php b/src/Operator/OperatorAutopilotConfigurationResponse.php index 1bbe27ab..3175edfe 100644 --- a/src/Operator/OperatorAutopilotConfigurationResponse.php +++ b/src/Operator/OperatorAutopilotConfigurationResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?AutopilotConfiguration return $this->AutopilotConfiguration; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->AutopilotConfiguration = new AutopilotConfiguration((array)$decodedData); + $this->AutopilotConfiguration = new AutopilotConfiguration((array)$decoded); } } diff --git a/src/Operator/OperatorHealthReplyResponse.php b/src/Operator/OperatorHealthReplyResponse.php index 1a6446cc..1d08f4d2 100644 --- a/src/Operator/OperatorHealthReplyResponse.php +++ b/src/Operator/OperatorHealthReplyResponse.php @@ -32,8 +32,8 @@ public function getValue(): mixed return $this->OperatorHealthReply; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->OperatorHealthReply = new OperatorHealthReply((array)$decodedData); + $this->OperatorHealthReply = new OperatorHealthReply((array)$decoded); } } diff --git a/src/Operator/OperatorRaftConfigurationResponse.php b/src/Operator/OperatorRaftConfigurationResponse.php index 114410be..509c5a5e 100644 --- a/src/Operator/OperatorRaftConfigurationResponse.php +++ b/src/Operator/OperatorRaftConfigurationResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?RaftConfiguration return $this->RaftConfiguration; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->RaftConfiguration = new RaftConfiguration($decodedData); + $this->RaftConfiguration = new RaftConfiguration($decoded); } } diff --git a/src/Operator/OperatorSerfMembersResponse.php b/src/Operator/OperatorSerfMembersResponse.php index 5c875222..a18e45d4 100644 --- a/src/Operator/OperatorSerfMembersResponse.php +++ b/src/Operator/OperatorSerfMembersResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->SerfMembers; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->SerfMembers = []; - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->SerfMembers[] = new SerfMember($datum); } } diff --git a/src/Operator/OperatorServerHealthsResponse.php b/src/Operator/OperatorServerHealthsResponse.php index c1010a68..4c06dca1 100644 --- a/src/Operator/OperatorServerHealthsResponse.php +++ b/src/Operator/OperatorServerHealthsResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->ServerHealths; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->ServerHealths = []; - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->ServerHealths[] = new ServerHealth($datum); } } diff --git a/src/Peering/Locality.php b/src/Peering/Locality.php index fe907135..061487ff 100644 --- a/src/Peering/Locality.php +++ b/src/Peering/Locality.php @@ -55,7 +55,7 @@ public function setZone(string $Zone): self return $this; } - public static function jsonUnserialize(\stdClass $decoded): self + public static function jsonUnserialize(\stdClass $decoded): static { $n = new static(); foreach ($decoded as $k => $v) { diff --git a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php index eb04548e..6d6fab6b 100644 --- a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php +++ b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->PreparedQueryDefinitions; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->PreparedQueryDefinitions = []; - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->PreparedQueryDefinitions[] = new PreparedQueryDefinition($datum); } } diff --git a/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php b/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php index c5f66b20..3fe9b80c 100644 --- a/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php +++ b/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php @@ -32,8 +32,8 @@ public function getValue(): ?PreparedQueryExecuteResponse return $this->PreparedQueryExecuteResponse; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->PreparedQueryExecuteResponse = new PreparedQueryExecuteResponse((array)$decodedData); + $this->PreparedQueryExecuteResponse = new PreparedQueryExecuteResponse((array)$decoded); } } diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 80682718..b43709ff 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -360,7 +360,7 @@ public function apply(Request $r): void * @return self * @deprecated This is only here to support construction with map. It will be removed in a future version. */ - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { diff --git a/src/ResponseValueBoolTrait.php b/src/ResponseValueBoolTrait.php index e4a7c401..32cf416d 100644 --- a/src/ResponseValueBoolTrait.php +++ b/src/ResponseValueBoolTrait.php @@ -29,17 +29,17 @@ public function getValue(): bool return $this->Value; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - if (\is_bool($decodedData)) { - $this->Value = $decodedData; + if (\is_bool($decoded)) { + $this->Value = $decoded; return; } - if (\is_string($decodedData)) { - $this->Value = Transcoding::TRUE === strtolower(trim($decodedData)); + if (\is_string($decoded)) { + $this->Value = Transcoding::TRUE === strtolower(trim($decoded)); return; } - $this->Value = (bool)$decodedData; + $this->Value = (bool)$decoded; } public function __toString(): string diff --git a/src/ResponseValueStringTrait.php b/src/ResponseValueStringTrait.php index 804c3f74..bfdbf8ac 100644 --- a/src/ResponseValueStringTrait.php +++ b/src/ResponseValueStringTrait.php @@ -29,9 +29,9 @@ public function getValue(): string return $this->Value; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->Value = (string)$decodedData; + $this->Value = (string)$decoded; } public function __toString(): string diff --git a/src/ResponseValueStringsTrait.php b/src/ResponseValueStringsTrait.php index 83e78a96..f996b53c 100644 --- a/src/ResponseValueStringsTrait.php +++ b/src/ResponseValueStringsTrait.php @@ -29,8 +29,8 @@ public function getValue(): ?array return $this->Value; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { - $this->Value = (array)$decodedData; + $this->Value = (array)$decoded; } } diff --git a/src/Session/SessionEntriesQueryResponse.php b/src/Session/SessionEntriesQueryResponse.php index 6ebeda8b..a279a3a5 100644 --- a/src/Session/SessionEntriesQueryResponse.php +++ b/src/Session/SessionEntriesQueryResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->SessionEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->SessionEntries = []; - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->SessionEntries[] = new SessionEntry($datum); } } diff --git a/src/Session/SessionEntriesWriteResponse.php b/src/Session/SessionEntriesWriteResponse.php index b5ce2916..c9cec007 100644 --- a/src/Session/SessionEntriesWriteResponse.php +++ b/src/Session/SessionEntriesWriteResponse.php @@ -32,10 +32,10 @@ public function getValue(): ?array return $this->SessionEntries; } - public function unmarshalValue(mixed $decodedData): void + public function unmarshalValue(mixed $decoded): void { $this->SessionEntries = []; - foreach ($decodedData as $datum) { + foreach ($decoded as $datum) { $this->SessionEntries[] = new SessionEntry($datum); } } diff --git a/src/UnmarshalledResponseInterface.php b/src/UnmarshalledResponseInterface.php index 4c1e616d..c379cf6f 100644 --- a/src/UnmarshalledResponseInterface.php +++ b/src/UnmarshalledResponseInterface.php @@ -22,5 +22,5 @@ interface UnmarshalledResponseInterface { - public function unmarshalValue(mixed $decodedData): void; + public function unmarshalValue(mixed $decoded): void; } diff --git a/src/WriteOptions.php b/src/WriteOptions.php index ab29e899..672d74a7 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -126,7 +126,7 @@ public function apply(Request $r): void * @return self * @deprecated This is only here to support construction with map. It will be removed in a future version. */ - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($decoded as $k => $v) { From cbec949a5b0ece437afc920c2cc351554be44765 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 13 Apr 2025 14:05:09 -0500 Subject: [PATCH 19/79] missed one --- src/Agent/AgentServiceRegistration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 3dba3cbf..b5724580 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -265,12 +265,12 @@ public function setPartition(string $Partition): self return $this; } - public function getLocality(): ?Locality + public function getLocality(): null|Locality { return $this->Locality; } - public function setLocality(?Locality $Locality): self + public function setLocality(null|Locality $Locality): self { $this->Locality = $Locality; return $this; From af356ca3c523b688f68316f65496b2ef399fab5f Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 13 Apr 2025 21:03:01 -0500 Subject: [PATCH 20/79] maybe agent done? --- src/Agent/AgentServiceConnectProxyConfig.php | 2 + src/Agent/MemberACLMode.php | 24 ++- src/Agent/ServiceKind.php | 48 +++-- src/Agent/Upstream.php | 202 ++++++++++++++---- src/Agent/UpstreamDestType.php | 5 +- src/ConfigEntry/ConfigEntryTrait.php | 30 ++- src/{Agent => ConfigEntry}/EnvoyExtension.php | 4 +- src/ConfigEntry/ExposeConfig.php | 4 +- src/ConfigEntry/ExposePath.php | 10 +- src/ConfigEntry/MeshGatewayConfig.php | 45 +++- src/ConfigEntry/MeshGatewayMode.php | 46 ++++ .../MutualTLSMode.php} | 33 ++- src/ConfigEntry/PassiveHealthCheck.php | 2 +- src/ConfigEntry/ProxyConfigEntry.php | 2 +- src/ConfigEntry/ProxyMode.php | 25 ++- src/ConfigEntry/ServiceConfigEntry.php | 6 +- src/ConfigEntry/ServiceResolverFailover.php | 8 +- src/ConfigEntry/ServiceResolverRedirect.php | 8 +- src/ConfigEntry/ServiceResolverSubset.php | 4 +- src/ConfigEntry/ServiceRouteDestination.php | 14 +- src/ConfigEntry/ServiceRouteHTTPMatch.php | 12 +- .../ServiceRouteHTTPMatchHeader.php | 14 +- .../ServiceRouteHTTPMatchQueryParam.php | 8 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 2 +- src/ConfigEntry/ServiceSplit.php | 8 +- .../ServiceSplitterConfigEntry.php | 2 +- src/ConfigEntry/TransparentProxyConfig.php | 47 +++- src/ConfigEntry/UpstreamConfiguration.php | 12 +- 28 files changed, 441 insertions(+), 186 deletions(-) rename src/{Agent => ConfigEntry}/EnvoyExtension.php (97%) create mode 100644 src/ConfigEntry/MeshGatewayMode.php rename src/{Agent/TransparentProxyConfig.php => ConfigEntry/MutualTLSMode.php} (56%) diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 8cfb128c..203507b2 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -22,9 +22,11 @@ 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\ConfigEntry\ProxyMode; +use DCarbone\PHPConsulAPI\ConfigEntry\TransparentProxyConfig; class AgentServiceConnectProxyConfig extends AbstractModel { diff --git a/src/Agent/MemberACLMode.php b/src/Agent/MemberACLMode.php index 05bba7cf..0d0e9607 100644 --- a/src/Agent/MemberACLMode.php +++ b/src/Agent/MemberACLMode.php @@ -22,18 +22,26 @@ enum MemberACLMode: string { - // Disabled indicates that ACLs are disabled for this agent + /** + * Disabled indicates that ACLs are disabled for this agent + */ case Disabled = "0"; - // Enabled indicates that ACLs are enabled and operating in new ACL - // mode (v1.4.0+ ACLs) + /** + * Enabled indicates that ACLs are enabled and operating in new ACL + * mode (v1.4.0+ ACLs) + */ case Enabled = "1"; - // Legacy has been deprecated, and will be treated as ACLModeUnknown. + /** + * Legacy has been deprecated, and will be treated as ACLModeUnknown. + */ case Legacy = "2"; - // Unknown is used to indicate that the AgentMember.Tags didn't advertise - // an ACL mode at all. This is the case for Consul versions before v1.4.0 and - // should be treated the same as ACLModeLegacy. + /** + * Unknown is used to indicate that the AgentMember.Tags didn't advertise + * an ACL mode at all. This is the case for Consul versions before v1.4.0 and + * should be treated the same as ACLModeLegacy. + */ case Unknown = "3"; -} \ No newline at end of file +} diff --git a/src/Agent/ServiceKind.php b/src/Agent/ServiceKind.php index 9790215d..08c57c6c 100644 --- a/src/Agent/ServiceKind.php +++ b/src/Agent/ServiceKind.php @@ -22,33 +22,45 @@ enum ServiceKind: string { - // Typical is a typical, classic Consul service. This is - // represented by the absence of a value. This was chosen for ease of - // backwards compatibility: existing services in the catalog would - // default to the typical service. + /** + * Typical is a typical, classic Consul service. This is + * represented by the absence of a value. This was chosen for ease of + * backwards compatibility: existing services in the catalog would + * default to the typical service. + */ case Typical = ''; - // ConnectProxy is a proxy for the Connect feature. This - // service proxies another service within Consul and speaks the connect - // protocol. + /** + * ConnectProxy is a proxy for the Connect feature. This + * service proxies another service within Consul and speaks the connect + * protocol. + */ case ConnectProxy = 'connect-proxy'; - // MeshGateway is a Mesh Gateway for the Connect feature. This - // service will proxy connections based off the SNI header set by other - // connect proxies + /** + * MeshGateway is a Mesh Gateway for the Connect feature. This + * service will proxy connections based off the SNI header set by other + * connect proxies + */ case MeshGateway = 'mesh-gateway'; - // TerminatingGateway is a Terminating Gateway for the Connect - // feature. This service will proxy connections to services outside the mesh. + /** + * TerminatingGateway is a Terminating Gateway for the Connect + * feature. This service will proxy connections to services outside the mesh. + */ case TerminatingGateway = 'terminating-gateway'; - // IngressGateway is an Ingress Gateway for the Connect feature. - // This service will ingress connections based of configuration defined in - // the ingress-gateway config entry. + /** + * IngressGateway is an Ingress Gateway for the Connect feature. + * This service will ingress connections based of configuration defined in + * the ingress-gateway config entry. + */ case IngressGateway = 'ingress-gateway'; - // APIGateway is an API Gateway for the Connect feature. - // This service will ingress connections based of configuration defined in - // the api-gateway config entry. + /** + * APIGateway is an API Gateway for the Connect feature. + * This service will ingress connections based of configuration defined in + * the api-gateway config entry. + */ case APIGateway = 'api-gateway'; } diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 3e495c03..2d1ae88e 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -22,61 +22,76 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig; -use DCarbone\PHPConsulAPI\Transcoding; class Upstream extends AbstractModel { - 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 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; public array $Config; - public MeshGatewayConfig $MeshGatewayConfig; + public null|MeshGatewayConfig $MeshGateway; + public bool $CentrallyConfigured; - public function __construct(?array $data = []) - { - parent::__construct($data); - if (!isset($this->MeshGatewayConfig)) { - $this->MeshGatewayConfig = new MeshGatewayConfig(null); + public function __construct( + null|array $data = [], // Deprecated, will be removed. + 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|\stdClass $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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } - 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,6 +161,28 @@ public function setLocalBindPort(int $LocalBindPort): self return $this; } + 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; + } + public function getConfig(): array { return $this->Config; @@ -146,14 +194,86 @@ public function setConfig(array $Config): self return $this; } - public function getMeshGatewayConfig(): MeshGatewayConfig + public function getMeshGateway(): null|MeshGatewayConfig { - return $this->MeshGatewayConfig; + return $this->MeshGateway; } - public function setMeshGatewayConfig(MeshGatewayConfig $MeshGatewayConfig): self + public function setMeshGateway(null|MeshGatewayConfig $MeshGateway): self { - $this->MeshGatewayConfig = $MeshGatewayConfig; + $this->MeshGateway = $MeshGateway; return $this; } + + public function isCentrallyConfigured(): bool + { + return $this->CentrallyConfigured; + } + + public function setCentrallyConfigured(bool $CentrallyConfigured): self + { + $this->CentrallyConfigured = $CentrallyConfigured; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('DestinationType' === $k) { + $n->setDestinationType($v); + } elseif ('MeshGateway' === $k) { + $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 ([] !== $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/Agent/UpstreamDestType.php b/src/Agent/UpstreamDestType.php index fbb9a21e..856ccef2 100644 --- a/src/Agent/UpstreamDestType.php +++ b/src/Agent/UpstreamDestType.php @@ -28,4 +28,7 @@ enum UpstreamDestType: string // PreparedQuery discovers instances via prepared query // execution. case PreparedQuery = 'prepared_query'; -} \ No newline at end of file + + // Default case for when value is not set. + case UNDEFINED = ''; +} diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php index 3a302dc1..10834fb2 100644 --- a/src/ConfigEntry/ConfigEntryTrait.php +++ b/src/ConfigEntry/ConfigEntryTrait.php @@ -20,23 +20,21 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\FakeMap; - trait ConfigEntryTrait { - public string $Kind = ''; - public string $Name = ''; - public string $Namespace = ''; - public ?FakeMap $Meta = null; - public int $CreateIndex = 0; - public int $ModifyIndex = 0; + public string $Kind; + public string $Name; + public string $Namespace; + public array $Meta; + public int $CreateIndex; + public int $ModifyIndex; public function getKind(): string { return $this->Kind; } - public function setKind(string $Kind): ConfigEntry + public function setKind(string $Kind): self { $this->Kind = $Kind; return $this; @@ -47,7 +45,7 @@ public function getName(): string return $this->Name; } - public function setName(string $Name): ConfigEntry + public function setName(string $Name): self { $this->Name = $Name; return $this; @@ -58,20 +56,20 @@ 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 + public function getMeta(): array { return $this->Meta; } - public function setMeta(mixed $Meta): ProxyConfigEntry + public function setMeta(array|\stdClass $Meta): self { - $this->Meta = FakeMap::parse($Meta); + $this->Meta = (array)$Meta; return $this; } @@ -80,7 +78,7 @@ 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 +89,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/Agent/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php similarity index 97% rename from src/Agent/EnvoyExtension.php rename to src/ConfigEntry/EnvoyExtension.php index 45cb646f..d79df56a 100644 --- a/src/Agent/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI\Agent; +namespace DCarbone\PHPConsulAPI\ConfigEntry; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -44,7 +44,7 @@ public function __construct( $this->ConsulVersion = $ConsulVersion; $this->EnvoyVersion = $EnvoyVersion; if (null !== $data && [] !== $data) { - $this->jsonSerialize((object)$data, $this); + $this->jsonUnserialize((object)$data, $this); } } diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index de9d7867..5750ad49 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -38,8 +38,8 @@ class ExposeConfig extends AbstractModel private const FIELD_CHECKS = 'Checks'; private const FIELD_PATHS = 'Paths'; - public bool $Checks = false; - public array $Paths = []; + public bool $Checks; + public array $Paths; public function isChecks(): bool { diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index 78d0ddb4..5ead75f9 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -37,11 +37,11 @@ class ExposePath extends AbstractModel 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 getListenerPort(): int { diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 68074e57..41f386ff 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -21,26 +21,51 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class MeshGatewayConfig extends AbstractModel { - protected const FIELDS = [ - self::FIELD_MODE => Transcoding::OMITEMPTY_STRING_FIELD, - ]; + public MeshGatewayMode $Mode; - private const FIELD_MODE = 'Mode'; - - public string $Mode = ''; + public function __construct( + null|array $data = [], // Deprecated, will be removed. + string|MeshGatewayMode $mode = MeshGatewayMode::Default, + ) { + $this->setMode($mode); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } - 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, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ('Mode' === $k) { + $n->setMode($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 @@ +OutboundListenerPort; - } - - public function setOutboundListenerPort(int $OutboundListenerPort): TransparentProxyConfig - { - $this->OutboundListenerPort = $OutboundListenerPort; - return $this; - } + /** + * Default represents no specific mode and should + * be used to indicate that a different layer of the configuration + * chain should take precedence. + */ + case Default = ''; + /** + * Strict requires mTLS for incoming traffic. + */ + case Strict = 'strict'; + /** + * Permissive allows incoming non-mTLS traffic. + */ + case Permissive = 'permissive'; } diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index cec65118..686b00ed 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -36,7 +36,7 @@ class PassiveHealthCheck extends AbstractModel private const FIELD_INTERVAL = 'Interval'; public Time\Duration $Interval; - public int $MaxFailures = 0; + public int $MaxFailures; public function __construct(?array $data = []) { diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index d8896dd8..8d7c9d6e 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -55,7 +55,7 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry private const FIELD_MESH_GATEWAY = 'MeshGateway'; private const FIELD_EXPOSE = 'Expose'; - public string $Mode = ''; + public string $Mode; public ?TransparentProxyConfig $TransparentProxy = null; public ?FakeMap $Config = null; public MeshGatewayConfig $MeshGateway; diff --git a/src/ConfigEntry/ProxyMode.php b/src/ConfigEntry/ProxyMode.php index 743ba167..c416a423 100644 --- a/src/ConfigEntry/ProxyMode.php +++ b/src/ConfigEntry/ProxyMode.php @@ -7,14 +7,14 @@ /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) - Licensed under the Apache License, Version 2.0 (the "License"); + Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, + distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. @@ -22,7 +22,22 @@ enum ProxyMode: string { - case Default = ""; - case Transparent = "transparent"; - case Direct = "direct"; + /** + * Default represents no specific mode and should + * be used to indicate that a different layer of the configuration + * chain should take precedence + */ + case Default = ''; + + /** + * Transparent represents that inbound and outbound application + * traffic is being captured and redirected through the proxy. + */ + case Transparent = 'transparent'; + + /** + * Direct represents that the proxy's listeners must be dialed directly + * by the local application and other proxies. + */ + case Direct = 'direct'; } diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index 750fe4ce..1afd9799 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -63,12 +63,12 @@ class ServiceConfigEntry extends AbstractModel implements ConfigEntry private const FIELD_EXTERNAL_SNI = 'ExternalSNI'; private const FIELD_UPSTREAM_CONFIG = 'UpstreamConfig'; - public string $Protocol = ''; - public string $Mode = ''; + public string $Protocol; + public string $Mode; public ?TransparentProxyConfig $TransparentProxy = null; public MeshGatewayConfig $MeshGateway; public ExposeConfig $Expose; - public string $ExternalSNI = ''; + public string $ExternalSNI; public ?UpstreamConfiguration $UpstreamConfig = null; public function getProtocol(): string diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php index 54fad4ca..532a997a 100644 --- a/src/ConfigEntry/ServiceResolverFailover.php +++ b/src/ConfigEntry/ServiceResolverFailover.php @@ -37,10 +37,10 @@ class ServiceResolverFailover extends AbstractModel 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; + public array $Datacenters; public function getService(): string { diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php index a8410274..5e507e5d 100644 --- a/src/ConfigEntry/ServiceResolverRedirect.php +++ b/src/ConfigEntry/ServiceResolverRedirect.php @@ -37,10 +37,10 @@ class ServiceResolverRedirect extends AbstractModel 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 $Datacenter; public function getService(): string { diff --git a/src/ConfigEntry/ServiceResolverSubset.php b/src/ConfigEntry/ServiceResolverSubset.php index 7a1f8909..d399c403 100644 --- a/src/ConfigEntry/ServiceResolverSubset.php +++ b/src/ConfigEntry/ServiceResolverSubset.php @@ -33,8 +33,8 @@ class ServiceResolverSubset extends AbstractModel private const FIELD_FILTER = 'Filter'; private const FIELD_ONLY_PASSING = 'OnlyPassing'; - public string $Filter = ''; - public bool $OnlyPassing = false; + public string $Filter; + public bool $OnlyPassing; public function getFilter(): string { diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index 22db2b68..45e595e3 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -49,14 +49,14 @@ class ServiceRouteDestination extends AbstractModel 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 $PrefixRewrite; public Time\Duration $RequestTimeout; - public int $NumRetries = 0; - public bool $RetryOnConnectFailure = false; - public array $RetryOnStatusCodes = []; + public int $NumRetries; + public bool $RetryOnConnectFailure; + public array $RetryOnStatusCodes; public function getService(): string { diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php index 6e0e4211..169e8693 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -51,12 +51,12 @@ class ServiceRouteHTTPMatch extends AbstractModel 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 array $Header; + public array $QueryParam; + public array $Methods; public function getPathExact(): string { diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php index b7181eea..67e4e434 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -41,13 +41,13 @@ class ServiceRouteHTTPMatchHeader extends AbstractModel 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 getName(): string { diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php index 0063f23b..cfdcbdf0 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -35,10 +35,10 @@ class ServiceRouteHTTPMatchQueryParam extends AbstractModel 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 getName(): string { diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 5ae2d93c..86c3129f 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -38,7 +38,7 @@ class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry private const FIELD_ROUTES = 'Routes'; - public array $Routes = []; + public array $Routes; public function getRoutes(): array { diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php index 96319b07..0f320f19 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -35,10 +35,10 @@ class ServiceSplit extends AbstractModel 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 function getWeight(): float { diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index b821f2cb..afee7126 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -38,7 +38,7 @@ class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry private const FIELD_SPLITS = 'Splits'; - public array $Splits = []; + public array $Splits; public function getSplits(): array { diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index 0f6d5b30..b1a582e2 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -21,20 +21,23 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class TransparentProxyConfig extends AbstractModel { - 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( + null|array $data = [], // Deprecated, will be removed. + int $OutboundListenerPort = 0, + bool $DialedDirectly = false + ) { + $this->OutboundListenerPort = $OutboundListenerPort; + $this->DialedDirectly = $DialedDirectly; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getOutboundListenerPort(): int { @@ -57,4 +60,28 @@ public function setDialedDirectly(bool $DialedDirectly): self $this->DialedDirectly = $DialedDirectly; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (0 !== $this->OutboundListenerPort) { + $out->OutboundListenerPort = $this->OutboundListenerPort; + } + if ($this->DialedDirectly) { + $out->DialedDirectly = $this->DialedDirectly; + } + return $out; + } } diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php index 7aa0b584..858b03eb 100644 --- a/src/ConfigEntry/UpstreamConfiguration.php +++ b/src/ConfigEntry/UpstreamConfiguration.php @@ -62,12 +62,12 @@ class UpstreamConfiguration extends AbstractModel 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 string $Name; + public string $Namespace; + public string $EnvoyListenerJSON; + public string $EnvoyClusterJSON; + public string $Protocol; + public int $ConnectTimeoutMs; public ?UpstreamLimits $UpstreamLimits = null; public ?PassiveHealthCheck $PassiveHealthCheck = null; public ?MeshGatewayConfig $MeshGateway = null; From f047f4c9334c27ebb4aa529baac0d8e34c250290 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 13 Apr 2025 21:40:12 -0500 Subject: [PATCH 21/79] i dunno, sure. --- src/Config.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Config.php b/src/Config.php index 7cf39382..0acb2f5d 100644 --- a/src/Config.php +++ b/src/Config.php @@ -112,12 +112,7 @@ public function __construct( int $JSONDecodeOpts = 0, ) { $this->Address = self::_resolveValue($Address, Consul::HTTPAddrEnvName, self::DEFAULT_ADDRESS); - $scheme = strtolower(self::_resolveValue($Scheme, Consul::HTTPSSLEnvName, self::DEFAULT_SCHEME)); - $this->Scheme = match ($scheme) { - 'true' => 'https', - 'false' => 'http', - default => $scheme, - }; + $this->setScheme(self::_resolveValue($Scheme, Consul::HTTPSSLEnvName, self::DEFAULT_SCHEME)); $this->Datacenter = $Datacenter; $this->Namespace = $Namespace; $this->setHttpAuth(self::_resolveValue($HttpAuth, Consul::HTTPAuthEnvName, null)); @@ -229,7 +224,11 @@ public function getScheme(): string public function setScheme(bool|string $scheme): self { - $this->Scheme = $scheme; + $this->Scheme = match ($scheme) { + 'true', true => 'https', + 'false', false => 'http', + default => $scheme, + }; return $this; } From 2554c6680c067aaaa88b150e3c2b4458def02ae5 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 13 Apr 2025 22:26:19 -0500 Subject: [PATCH 22/79] ugh. --- src/Config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Config.php b/src/Config.php index 0acb2f5d..78bc515c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -224,9 +224,9 @@ public function getScheme(): string public function setScheme(bool|string $scheme): self { - $this->Scheme = match ($scheme) { - 'true', true => 'https', - 'false', false => 'http', + $this->Scheme = match (is_string($scheme) ? strtolower($scheme) : $scheme) { + true, 'true', '1' => 'https', + false, 'false', '0' => 'http', default => $scheme, }; return $this; From 4f1a05ce4397feb0bc55fb35bd954408c13cb5c3 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 19:56:13 -0500 Subject: [PATCH 23/79] ACL work. --- src/ACL/ACLClient.php | 24 +- src/ACL/ACLPolicy.php | 19 +- src/ACL/ACLPolicyListEntry.php | 17 + src/ACL/ACLRole.php | 58 +++- src/ACL/ACLServiceIdentity.php | 4 +- src/ACL/ACLTemplatedPolicy.php | 104 +++++++ src/ACL/ACLTemplatedPolicyVariables.php | 63 ++++ src/ACL/ACLToken.php | 274 +---------------- src/ACL/ACLTokenExpanded.php | 209 +++++++++++++ src/ACL/ACLTokenExpandedQueryResponse.php | 43 +++ src/ACL/ACLTokenFields.php | 358 ++++++++++++++++++++++ src/ACL/ACLTokenListEntry.php | 73 ++++- src/ACL/BindingRuleBindType.php | 30 ++ tests/Usage/ACL/ACLClientTest.php | 12 +- 14 files changed, 1000 insertions(+), 288 deletions(-) create mode 100644 src/ACL/ACLTemplatedPolicy.php create mode 100644 src/ACL/ACLTemplatedPolicyVariables.php create mode 100644 src/ACL/ACLTokenExpanded.php create mode 100644 src/ACL/ACLTokenExpandedQueryResponse.php create mode 100644 src/ACL/ACLTokenFields.php create mode 100644 src/ACL/BindingRuleBindType.php diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php index 72738c72..af9c7531 100644 --- a/src/ACL/ACLClient.php +++ b/src/ACL/ACLClient.php @@ -98,33 +98,43 @@ public function TokenUpdate(ACLToken $token, null|WriteOptions $opts = null): AC return $ret; } - public function TokenClone(string $tokenID, string $description, null|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, null|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, null|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 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)); diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 17d303d3..a5df92c9 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -33,6 +33,7 @@ class ACLPolicy extends AbstractModel public int $CreateIndex; public int $ModifyIndex; public string $Namespace; + public string $Partition; public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -44,7 +45,8 @@ public function __construct( string $Hash = '', int $CreateIndex = 0, int $ModifyIndex = 0, - string $Namespace = '' + string $Namespace = '', + string $Partition = '', ) { $this->ID = $ID; $this->Name = $Name; @@ -56,6 +58,7 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + $this->Partition = $Partition; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -160,6 +163,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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); @@ -190,6 +204,9 @@ public function jsonSerialize(): \stdClass 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 78288acf..c621df17 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -32,6 +32,7 @@ class ACLPolicyListEntry extends AbstractModel public int $CreateIndex; public int $ModifyIndex; public string $Namespace; + public string $Partition; public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -43,6 +44,7 @@ public function __construct( int $CreateIndex = 0, int $ModifyIndex = 0, string $Namespace = '', + string $Partition = '', ) { $this->ID = $ID; $this->Name = $Name; @@ -52,6 +54,7 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; + $this->Partition = $Partition; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -145,6 +148,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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); @@ -174,6 +188,9 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; } + if ('' !== $this->Partition) { + $out->Partition = $this->Partition; + } return $out; } } diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 03ca9f86..e348fa53 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -27,13 +27,19 @@ class ACLRole extends AbstractModel 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; public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -43,10 +49,12 @@ public function __construct( iterable $Policies = [], iterable $ServiceIdentities = [], iterable $NodeIdentities = [], + iterable $TemplatedPolicies = [], string $Hash = '', int $CreateIndex = 0, int $ModifyIndex = 0, - string $Namespace = '' + string $Namespace = '', + string $Partition = '', ) { $this->ID = $ID; $this->Name = $Name; @@ -54,10 +62,12 @@ public function __construct( $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; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -96,17 +106,23 @@ public function setDescription(string $Description): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[] + */ public function getPolicies(): array { return $this->Policies; } - public function setPolicies(ACLTokenPolicyLink ...$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; @@ -118,6 +134,9 @@ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] + */ public function getNodeIdentities(): array { return $this->NodeIdentities; @@ -129,6 +148,20 @@ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self 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; @@ -173,6 +206,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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); @@ -189,6 +233,10 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul foreach ($v as $vv) { $n->NodeIdentities[] = ACLNodeIdentity::jsonUnserialize($vv); } + } elseif ('TemplatedPolicies' === $k) { + foreach ($v as $vv) { + $n->TemplatedPolicies[] = ACLTemplatedPolicy::jsonUnserialize($vv); + } } else { $n->{$k} = $v; } @@ -215,11 +263,17 @@ public function jsonSerialize(): \stdClass 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/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 9f730480..044eb78f 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -24,8 +24,6 @@ class ACLServiceIdentity extends AbstractModel { - private const FIELD_DATACENTERS = 'Datacenters'; - public string $ServiceName; public array $Datacenters; @@ -35,7 +33,7 @@ public function __construct( iterable $Datacenters = [] ) { $this->ServiceName = $ServiceName; - $this->Datacenters = $Datacenters; + $this->setDatacenters(...$Datacenters); if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php new file mode 100644 index 00000000..1789dfa2 --- /dev/null +++ b/src/ACL/ACLTemplatedPolicy.php @@ -0,0 +1,104 @@ +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): ACLTemplatedPolicy + { + $this->TemplateVariables = $TemplateVariables; + return $this; + } + + public function getDatacenters(): array + { + return $this->Datacenters; + } + + public function setDatacenters(string ...$Datacenters): ACLTemplatedPolicy + { + $this->Datacenters = $Datacenters; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..d9f4eea9 --- /dev/null +++ b/src/ACL/ACLTemplatedPolicyVariables.php @@ -0,0 +1,63 @@ +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, null|self $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 4cfe9ef6..8f83f079 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -25,24 +25,7 @@ class ACLToken extends AbstractModel { - public int $CreateIndex; - public int $ModifyIndex; - public string $AccessorID; - public string $SecretID; - public string $Description; - public array $Policies; - public array $Roles; - public array $ServiceIdentities; - public array $NodeIdentities; - public bool $Local; - public string $AuthMethod; - public Time\Duration $ExpirationTTL; - public null|Time\Time $ExpirationTime = null; - public Time\Time $CreateTime; - public string $Hash; - public string $Namespace; - - public string $Rules; + use ACLTokenFields; public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -55,6 +38,7 @@ public function __construct( iterable $Roles = [], iterable $ServiceIdentities = [], iterable $NodeIdentities = [], + iterable $TemplatePolicies = [], bool $Local = false, string $AuthMethod = '', null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL = null, @@ -63,6 +47,8 @@ public function __construct( string $Hash = '', string $Namespace = '', string $Rules = '', + string $Partition = '', + string $AuthMethodNamespace = '', ) { $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; @@ -73,6 +59,7 @@ public function __construct( $this->setRoles(...$Roles); $this->setServiceIdentities(...$ServiceIdentities); $this->setNodeIdentities(...$NodeIdentities); + $this->setTemplatePolicies(...$TemplatePolicies); $this->Local = $Local; $this->AuthMethod = $AuthMethod; $this->setExpirationTTL($ExpirationTTL); @@ -81,225 +68,18 @@ public function __construct( $this->Hash = $Hash; $this->Namespace = $Namespace; $this->Rules = $Rules; + $this->Partition = $Partition; + $this->AuthMethodNamespace = $AuthMethodNamespace; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } } - 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; - } - - public function getPolicies(): array - { - return $this->Policies; - } - - public function setPolicies(ACLTokenPolicyLink ...$Policies): self - { - $this->Policies = $Policies; - return $this; - } - - public function getRoles(): array - { - return $this->Roles; - } - - public function setRoles(ACLTokenRoleLink ...$Roles): self - { - $this->Roles = $Roles; - return $this; - } - - public function getServiceIdentities(): array - { - return $this->ServiceIdentities; - } - - public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self - { - $this->ServiceIdentities = $ServiceIdentities; - return $this; - } - - public function getNodeIdentities(): array - { - return $this->NodeIdentities; - } - - public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self - { - $this->NodeIdentities = $NodeIdentities; - 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(): Time\Time - { - return $this->ExpirationTime; - } - - public function setExpirationTime(null|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->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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); foreach ($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 ('ExpirationTTL' === $k) { - $n->setExpirationTTL($v); - } elseif ('ExpirationTime' === $k) { - $n->ExpirationTime = (null === $v ? $v : Time\Time::createFromFormat(DATE_RFC3339, $v)); - } elseif ('CreateTime' === $k) { - $n->CreateTime = Time\Time::createFromFormat(DATE_RFC3339, $v); - } else { + if (!$n->_jsonUnserializeField($k, $v, $n)) { $n->{$k} = $v; } } @@ -312,43 +92,7 @@ public function jsonSerialize(): \stdClass foreach ($this->_getDynamicFields() as $k => $v) { $out->{$k} = $v; } - $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; - } - $out->Local = $this->Local; - if ('' !== $this->AuthMethod) { - $out->AuthMethod = $this->AuthMethod; - } - if (0 !== $this->ExpirationTTL->Nanoseconds()) { - $out->ExpirationTTL = (string)$this->ExpirationTTL; - } - if (null !== $this->ExpirationTime) { - $out->ExpirationTime = $this->ExpirationTime->format(DATE_RFC3339); - } - if (!$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; - } + $this->_jsonSerialize($out); return $out; } } diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php new file mode 100644 index 00000000..f995fdb2 --- /dev/null +++ b/src/ACL/ACLTokenExpanded.php @@ -0,0 +1,209 @@ +setExpandedPolicies(...$ExpandedPolicies); + $this->setExpandedRoles(...$ExpandedRoles); + $this->setNamespaceDefaultPolicyIDs(...$NamespaceDefaultPolicyIDs); + $this->setNamespaceDefaultRoleIDs(...$NamespaceDefaultRoleIDs); + $this->AgentACLDefaultPolicy = $AgentACLDefaultPolicy; + $this->AgentACLDownPolicy = $AgentACLDownPolicy; + $this->ResolvedByAgent = $ResolvedByAgent; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + + public function getExpandedPolicies(): array + { + return $this->ExpandedPolicies; + } + + public function setExpandedPolicies(ACLPolicy ...$ExpandedPolicies): self + { + $this->ExpandedPolicies = $ExpandedPolicies; + return $this; + } + + public function getExpandedRoles(): array + { + return $this->ExpandedRoles; + } + + public function setExpandedRoles(ACLRole ...$ExpandedRoles): self + { + $this->ExpandedRoles = $ExpandedRoles; + return $this; + } + + public function getNamespaceDefaultPolicyIDs(): array + { + return $this->NamespaceDefaultPolicyIDs; + } + + public function setNamespaceDefaultPolicyIDs(string ...$NamespaceDefaultPolicyIDs): self + { + $this->NamespaceDefaultPolicyIDs = $NamespaceDefaultPolicyIDs; + return $this; + } + + 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, null|ACLToken $into = null): static + { + $n = $into ?? new static(); + foreach ($decoded as $k => $v) { + if ($n->_jsonUnserializeField($k, $v, $n)) { + continue; + } elseif ('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 + { + return parent::jsonSerialize(); // TODO: Change the autogenerated stub + } +} diff --git a/src/ACL/ACLTokenExpandedQueryResponse.php b/src/ACL/ACLTokenExpandedQueryResponse.php new file mode 100644 index 00000000..09e6c9f6 --- /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..f663ff7e --- /dev/null +++ b/src/ACL/ACLTokenFields.php @@ -0,0 +1,358 @@ +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; + } + + public function getPolicies(): array + { + return $this->Policies; + } + + public function setPolicies(ACLTokenPolicyLink ...$Policies): self + { + $this->Policies = $Policies; + return $this; + } + + public function getRoles(): array + { + return $this->Roles; + } + + public function setRoles(ACLTokenRoleLink ...$Roles): self + { + $this->Roles = $Roles; + return $this; + } + + public function getServiceIdentities(): array + { + return $this->ServiceIdentities; + } + + public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): self + { + $this->ServiceIdentities = $ServiceIdentities; + return $this; + } + + public function getNodeIdentities(): array + { + return $this->NodeIdentities; + } + + public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self + { + $this->NodeIdentities = $NodeIdentities; + return $this; + } + + 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(): Time\Time + { + return $this->ExpirationTime; + } + + public function setExpirationTime(null|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->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; + } + + public 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 : Time\Time::createFromFormat(DATE_RFC3339, $v)); + } elseif ('CreateTime' === $k) { + $n->CreateTime = Time\Time::createFromFormat(DATE_RFC3339, $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 (!$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 189f81da..ac4f210c 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -28,11 +28,13 @@ class ACLTokenListEntry extends AbstractModel public int $CreateIndex; public int $ModifyIndex; public string $AccessorID; + public string $SecretID; public string $Description; public array $Policies; public array $Roles; public array $ServiceIdentities; public array $NodeIdentities; + public array $TemplatedPolicies; public bool $Local; public string $AuthMethod; public null|Time\Time $ExpirationTime = null; @@ -40,33 +42,41 @@ class ACLTokenListEntry extends AbstractModel public string $Hash; public bool $Legacy; public string $Namespace; + public string $Partition; + public string $AuthMethodNamespace; public function __construct( null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', + string $SecretID = '', string $Description = '', iterable $Policies = [], iterable $Roles = [], iterable $ServiceIdentities = [], iterable $NodeIdentities = [], + iterable $TemplatedPolicies = [], bool $Local = false, string $AuthMethod = '', null|Time\Time $ExpirationTime = null, null|Time\Time $CreateTime = null, string $Hash = '', bool $Legacy = false, - string $Namespace = '' + 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); @@ -74,6 +84,8 @@ public function __construct( $this->Hash = $Hash; $this->Legacy = $Legacy; $this->Namespace = $Namespace; + $this->Partition = $Partition; + $this->AuthMethodNamespace = $AuthMethodNamespace; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -112,6 +124,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; @@ -167,6 +190,17 @@ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self return $this; } + 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; @@ -244,6 +278,28 @@ 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 getAuthMethodNamespace(): string + { + return $this->AuthMethodNamespace; + } + + public function setAuthMethodNamespace(string $AuthMethodNamespace): self + { + $this->AuthMethodNamespace = $AuthMethodNamespace; + return $this; + } + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new static(); @@ -264,6 +320,10 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul 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 : Time\Time::createFromFormat(DATE_RFC3339, $v)); } elseif ('CreateTime' === $k) { @@ -284,6 +344,7 @@ public function jsonSerialize(): \stdClass $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; @@ -297,6 +358,9 @@ public function jsonSerialize(): \stdClass 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; @@ -306,10 +370,15 @@ public function jsonSerialize(): \stdClass } $out->CreateTime = $this->CreateTime->format(DATE_RFC3339); $out->Hash = $this->Hash; - $out->Legacy = $this->Legacy; 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/BindingRuleBindType.php b/src/ACL/BindingRuleBindType.php new file mode 100644 index 00000000..98103191 --- /dev/null +++ b/src/ACL/BindingRuleBindType.php @@ -0,0 +1,30 @@ +Info($aclID); - self::assertNull($err, 'ACL::info() return error: ' . $err); + self::assertNull($err, 'ACL::Info() return error: ' . $err); self::assertInstanceOf(QueryMeta::class, $qm); self::assertIsArray($acls); \var_dump($acls); From ec161b424502e1a35ce4b380a69690de8baf9738 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 21:57:18 -0500 Subject: [PATCH 24/79] some cleanup --- .../ACLAuthMethodListEntryQueryResponse.php | 1 + src/ACL/ACLBindingRulesQueryResponse.php | 1 + src/ACL/ACLEntriesResponse.php | 1 + src/ACL/ACLPolicy.php | 4 ++++ src/ACL/ACLPolicyListEntryQueryResponse.php | 1 + src/ACL/ACLRolesQueryResponse.php | 1 + src/ACL/ACLServiceIdentity.php | 4 ++++ src/ACL/ACLTemplatedPolicy.php | 4 ++++ src/ACL/ACLTokenExpanded.php | 12 +++++++++++ src/ACL/ACLTokenFields.php | 15 ++++++++++++++ src/ACL/ACLTokenListEntry.php | 20 +++++++++++++++++++ src/ACL/ACLTokenListEntryQueryResponse.php | 1 + src/Agent/AgentCheckRegistration.php | 10 ---------- src/Agent/AgentHealthServicesResponse.php | 8 ++++++++ src/Agent/AgentMembersResponse.php | 4 ++++ src/Agent/AgentService.php | 3 +++ src/Agent/AgentServiceCheck.php | 1 - src/Agent/AgentServiceChecks.php | 12 +++++++++-- src/Agent/AgentServiceConnectProxyConfig.php | 7 +++++++ src/Agent/AgentServiceRegistration.php | 3 +++ src/Agent/MetricsInfo.php | 12 +++++++++++ src/Agent/PointValue.php | 4 ++++ src/ErrorContainer.php | 4 ++-- 23 files changed, 118 insertions(+), 15 deletions(-) diff --git a/src/ACL/ACLAuthMethodListEntryQueryResponse.php b/src/ACL/ACLAuthMethodListEntryQueryResponse.php index 2b024782..4f9fe503 100644 --- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php +++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php @@ -25,6 +25,7 @@ class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry[] */ public array $ACLAuthMethodListEntries = []; public function getValue(): array diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php index 87c676eb..c8ebb512 100644 --- a/src/ACL/ACLBindingRulesQueryResponse.php +++ b/src/ACL/ACLBindingRulesQueryResponse.php @@ -25,6 +25,7 @@ class ACLBindingRulesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLBindingRule[] */ public array $ACLBindingRules = []; public function getValue(): array diff --git a/src/ACL/ACLEntriesResponse.php b/src/ACL/ACLEntriesResponse.php index 2728a587..2ef8aaff 100644 --- a/src/ACL/ACLEntriesResponse.php +++ b/src/ACL/ACLEntriesResponse.php @@ -25,6 +25,7 @@ class ACLEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLEntry[] */ public array $ACLEntries = []; public function getValue(): array diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index a5df92c9..730f8689 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -28,6 +28,7 @@ class ACLPolicy extends AbstractModel public string $Name; public string $Description; public string $Rules; + /** @var string[] */ public array $Datacenters; public string $Hash; public int $CreateIndex; @@ -108,6 +109,9 @@ public function setRules(string $Rules): self return $this; } + /** + * @return string[] + */ public function getDatacenters(): array { return $this->Datacenters; diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php index a40436a3..d24e9c47 100644 --- a/src/ACL/ACLPolicyListEntryQueryResponse.php +++ b/src/ACL/ACLPolicyListEntryQueryResponse.php @@ -25,6 +25,7 @@ class ACLPolicyListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLPolicyListEntry[] */ public array $ACLPolicyListEntries = []; public function getValue(): array diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php index 1b66f2f7..d6157583 100644 --- a/src/ACL/ACLRolesQueryResponse.php +++ b/src/ACL/ACLRolesQueryResponse.php @@ -25,6 +25,7 @@ class ACLRolesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLRole[] */ public array $ACLRoles = []; public function getValue(): array diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 044eb78f..7688c87a 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -25,6 +25,7 @@ class ACLServiceIdentity extends AbstractModel { public string $ServiceName; + /** @var string[] */ public array $Datacenters; public function __construct( @@ -44,6 +45,9 @@ public function getServiceName(): string return $this->ServiceName; } + /** + * @return string[] + */ public function getDatacenters(): array { return $this->Datacenters; diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php index 1789dfa2..089d0522 100644 --- a/src/ACL/ACLTemplatedPolicy.php +++ b/src/ACL/ACLTemplatedPolicy.php @@ -26,6 +26,7 @@ class ACLTemplatedPolicy extends AbstractModel { public string $TemplateName; public null|ACLTemplatedPolicyVariables $TemplateVariables; + /** @var string[] */ public array $Datacenters; public function __construct( @@ -60,6 +61,9 @@ public function setTemplateVariables(null|ACLTemplatedPolicyVariables $TemplateV return $this; } + /** + * @return string[] + */ public function getDatacenters(): array { return $this->Datacenters; diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index f995fdb2..c8b79446 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -100,6 +100,9 @@ public function __construct( } } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLPolicy[] + */ public function getExpandedPolicies(): array { return $this->ExpandedPolicies; @@ -111,6 +114,9 @@ public function setExpandedPolicies(ACLPolicy ...$ExpandedPolicies): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLRole[] + */ public function getExpandedRoles(): array { return $this->ExpandedRoles; @@ -122,6 +128,9 @@ public function setExpandedRoles(ACLRole ...$ExpandedRoles): self return $this; } + /** + * @return string[] + */ public function getNamespaceDefaultPolicyIDs(): array { return $this->NamespaceDefaultPolicyIDs; @@ -133,6 +142,9 @@ public function setNamespaceDefaultPolicyIDs(string ...$NamespaceDefaultPolicyID return $this; } + /** + * @return string[] + */ public function getNamespaceDefaultRoleIDs(): array { return $this->NamespaceDefaultRoleIDs; diff --git a/src/ACL/ACLTokenFields.php b/src/ACL/ACLTokenFields.php index f663ff7e..f37248d8 100644 --- a/src/ACL/ACLTokenFields.php +++ b/src/ACL/ACLTokenFields.php @@ -106,6 +106,9 @@ public function setDescription(string $Description): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[] + */ public function getPolicies(): array { return $this->Policies; @@ -117,6 +120,9 @@ public function setPolicies(ACLTokenPolicyLink ...$Policies): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink[] + */ public function getRoles(): array { return $this->Roles; @@ -128,6 +134,9 @@ public function setRoles(ACLTokenRoleLink ...$Roles): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[] + */ public function getServiceIdentities(): array { return $this->ServiceIdentities; @@ -139,6 +148,9 @@ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] + */ public function getNodeIdentities(): array { return $this->NodeIdentities; @@ -150,6 +162,9 @@ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[] + */ public function getTemplatePolicies(): array { return $this->TemplatePolicies; diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index ac4f210c..f6e11471 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -30,10 +30,15 @@ class ACLTokenListEntry extends AbstractModel public string $AccessorID; public string $SecretID; public string $Description; + /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[] */ public array $Policies; + /** @var \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[] */ public array $Roles; + /** @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 bool $Local; public string $AuthMethod; @@ -146,6 +151,9 @@ public function setDescription(string $Description): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[] + */ public function getPolicies(): array { return $this->Policies; @@ -157,6 +165,9 @@ public function setPolicies(ACLTokenPolicyLink ...$Policies): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[] + */ public function getRoles(): array { return $this->Roles; @@ -168,6 +179,9 @@ public function setRoles(ACLTokenRoleLink ...$Roles): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[] + */ public function getServiceIdentities(): array { return $this->ServiceIdentities; @@ -179,6 +193,9 @@ public function setServiceIdentities(ACLServiceIdentity ...$ServiceIdentities): return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] + */ public function getNodeIdentities(): array { return $this->NodeIdentities; @@ -190,6 +207,9 @@ public function setNodeIdentities(ACLNodeIdentity ...$NodeIdentities): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[] + */ public function getTemplatedPolicies(): array { return $this->TemplatedPolicies; diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php index 0a0620b6..5e896d91 100644 --- a/src/ACL/ACLTokenListEntryQueryResponse.php +++ b/src/ACL/ACLTokenListEntryQueryResponse.php @@ -25,6 +25,7 @@ class ACLTokenListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenListEntry[] */ public array $ACLTokenListEntries = []; public function getValue(): array diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 91c8fd7d..f5a6ab84 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -126,16 +126,6 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self|AgentServiceCheck $into = null): static - { - $n = $into ?? new static(); - parent::jsonUnserialize($decoded, $n); - foreach ($decoded as $k => $v) { - $n->{$k} = $v; - } - return $n; - } - public function jsonSerialize(): \stdClass { $out = parent::jsonSerialize(); diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php index d5987797..35be5641 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -29,6 +29,7 @@ class AgentHealthServicesResponse extends AbstractResponse use ErrorContainer; public string $AggregatedStatus; + /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[] */ public array $AgentServiceChecksInfos; public function __construct(string $aggregatedStatus, array $checkInfos, null|Error $err) @@ -46,6 +47,9 @@ public function getAggregatedStatus(): string return $this->AggregatedStatus; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[] + */ public function getAgentServiceChecksInfos(): array { return $this->AgentServiceChecksInfos; @@ -56,6 +60,10 @@ public function offsetExists(mixed $offset): bool return is_int($offset) && 0 <= $offset && $offset < 3; } + /** + * @param mixed $offset + * @return string|\DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[]|\DCarbone\PHPConsulAPI\Error|null + */ public function offsetGet(mixed $offset): string|array|Error|null { if (0 === $offset) { diff --git a/src/Agent/AgentMembersResponse.php b/src/Agent/AgentMembersResponse.php index f1f0f576..7223b729 100644 --- a/src/Agent/AgentMembersResponse.php +++ b/src/Agent/AgentMembersResponse.php @@ -25,8 +25,12 @@ class AgentMembersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { + /** @var \DCarbone\PHPConsulAPI\Agent\AgentMember[] */ public array $Members; + /** + * @return \DCarbone\PHPConsulAPI\Agent\AgentMember[] + */ public function getValue(): array { return $this->Members; diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index c47fbe0b..80a5af2e 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -176,6 +176,9 @@ public function setAddress(string $Address): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] + */ public function getTaggedAddresses(): array { return $this->TaggedAddresses; diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index b1189dc3..888ec698 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -47,7 +47,6 @@ class AgentServiceCheck extends AbstractModel public string $AliasService; public int $SuccessBeforePassing; public int $FailuresBeforeCritical; - public string $DeregisterCriticalServiceAfter; public function __construct( diff --git a/src/Agent/AgentServiceChecks.php b/src/Agent/AgentServiceChecks.php index dfd574df..78684b5d 100644 --- a/src/Agent/AgentServiceChecks.php +++ b/src/Agent/AgentServiceChecks.php @@ -22,7 +22,7 @@ use DCarbone\PHPConsulAPI\AbstractModel; -class AgentServiceChecks implements \Countable, \ArrayAccess +class AgentServiceChecks implements \JsonSerializable, \Countable, \ArrayAccess { /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck[] */ public array $Checks; @@ -33,6 +33,9 @@ public function __construct( $this->setChecks(...$Checks); } + /** + * @return \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck[] + */ public function getChecks(): array { return $this->Checks; @@ -62,7 +65,7 @@ public function offsetExists(mixed $offset): bool return isset($this->Checks[$offset]); } - public function offsetGet(mixed $offset): mixed + public function offsetGet(mixed $offset): null|AgentServiceCheck { return $this->Checks[$offset] ?? null; } @@ -94,4 +97,9 @@ public static function jsonUnserialize(array $decoded): static } return $n; } + + public function jsonSerialize(): array + { + return $this->Checks; + } } diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 203507b2..081e6fb4 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -30,6 +30,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel { + /** @var \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[] */ public array $EnvoyExtensions; public string $DestinationServiceName; public string $DestinationServiceID; @@ -79,6 +80,9 @@ public function __construct( } } + /** + * @return \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[] + */ public function getEnvoyExtensions(): array { return $this->EnvoyExtensions; @@ -184,6 +188,9 @@ public function setConfig(array|\stdClass $Config): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\Upstream[] + */ public function getUpstreams(): array { return $this->Upstreams; diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index b5724580..b96cc2ba 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -152,6 +152,9 @@ public function setAddress(string $Address): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] + */ public function getTaggedAddresses(): array { return $this->TaggedAddresses; diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index bc4805b8..1a4739c6 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -63,6 +63,9 @@ public function setTimestamp(string $timestamp): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\GaugeValue[] + */ public function getGauges(): array { return $this->Gauges; @@ -74,6 +77,9 @@ public function setGauges(GaugeValue ...$gauges): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\PointValue[] + */ public function getPoints(): array { return $this->Points; @@ -85,6 +91,9 @@ public function setPoints(PointValue ...$points): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\SampledValue[] + */ public function getCounters(): array { return $this->Counters; @@ -96,6 +105,9 @@ public function setCounters(SampledValue ...$counters): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\Agent\SampledValue[] + */ public function getSamples(): array { return $this->Samples; diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 29c9bca0..8104cc16 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -25,6 +25,7 @@ class PointValue extends AbstractModel { public string $Name; + /** @var float[] */ public array $Points; public function __construct( @@ -50,6 +51,9 @@ public function setName(string $name): self return $this; } + /** + * @return float[] + */ public function getPoints(): array { return $this->Points; diff --git a/src/ErrorContainer.php b/src/ErrorContainer.php index 0eb20750..bfd17fbf 100644 --- a/src/ErrorContainer.php +++ b/src/ErrorContainer.php @@ -22,9 +22,9 @@ trait ErrorContainer { - public ?Error $Err = null; + public null|Error $Err = null; - public function getErr(): ?Error + public function getErr(): null|Error { return $this->Err; } From e2f01673f8ac49528dbe503b177e2044919330d8 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 21:59:08 -0500 Subject: [PATCH 25/79] only acl & agent for now --- phpunit.xml | 42 +++++++++++------------ src/AbstractClient.php | 20 +++++------ src/Catalog/CatalogClient.php | 18 +++++----- src/Coordinate/CoordinateClient.php | 6 ++-- src/Event/EventClient.php | 4 +-- src/Health/HealthClient.php | 22 ++++++------ src/KV/KVClient.php | 24 ++++++------- src/Operator/OperatorClient.php | 28 +++++++-------- src/PreparedQuery/PreparedQueryClient.php | 12 +++---- src/QueryMetaContainer.php | 4 +-- src/Session/SessionClient.php | 18 +++++----- src/Status/StatusClient.php | 4 +-- src/WriteMetaContainer.php | 4 +-- 13 files changed, 103 insertions(+), 103 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 0699e390..1f865e50 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,31 +20,31 @@ ./tests/Usage/RequestUsageTest.php - - - + + ./tests/Usage/ACL + ./tests/Usage/Agent - - ./tests/Usage/Catalog - - - ./tests/Usage/Coordinate - - - ./tests/Usage/KV - - - ./tests/Usage/Operator - - - ./tests/Usage/Session - + + + + + + + + + + + + + + + - - ./tests/Usage/Random - + + + diff --git a/src/AbstractClient.php b/src/AbstractClient.php index 93327660..92da890c 100644 --- a/src/AbstractClient.php +++ b/src/AbstractClient.php @@ -92,12 +92,12 @@ protected function _newPutRequest(string $path, mixed $body, ?RequestOptions $op return $this->_newRequest(HTTP\MethodPut, $path, $body, $opts); } - protected function _newGetRequest(string $path, ?QueryOptions $opts): Request + protected function _newGetRequest(string $path, null|QueryOptions $opts): Request { return $this->_newRequest(HTTP\MethodGet, $path, null, $opts); } - protected function _newDeleteRequest(string $path, ?WriteOptions $opts): Request + protected function _newDeleteRequest(string $path, null|WriteOptions $opts): Request { return $this->_newRequest(HTTP\MethodDelete, $path, null, $opts); } @@ -195,7 +195,7 @@ protected function _requireNotFoundOrOK(RequestResponse $r): RequestResponse return $this->_requireStatus($r, HTTP\StatusOK, HTTP\StatusNotFound); } - protected function _doGet(string $path, ?QueryOptions $opts): RequestResponse + protected function _doGet(string $path, null|QueryOptions $opts): RequestResponse { return $this->_do($this->_newGetRequest($path, $opts)); } @@ -210,7 +210,7 @@ protected function _doPut(string $path, mixed $body, ?RequestOptions $opts): Req return $this->_do($this->_newPutRequest($path, $body, $opts)); } - protected function _doDelete(string $path, ?WriteOptions $opts): RequestResponse + protected function _doDelete(string $path, null|WriteOptions $opts): RequestResponse { return $this->_do($this->_newDeleteRequest($path, $opts)); } @@ -242,7 +242,7 @@ protected function _decodeBody(StreamInterface $body): DecodedBody ); } - protected function _executePut(string $path, mixed $body, ?WriteOptions $opts): WriteResponse + protected function _executePut(string $path, mixed $body, null|WriteOptions $opts): WriteResponse { $resp = $this->_requireOK($this->_doPut($path, $body, $opts)); $ret = new WriteResponse(); @@ -250,7 +250,7 @@ protected function _executePut(string $path, mixed $body, ?WriteOptions $opts): return $ret; } - protected function _executePost(string $path, mixed $body, ?WriteOptions $opts): WriteResponse + protected function _executePost(string $path, mixed $body, null|WriteOptions $opts): WriteResponse { $resp = $this->_requireOK($this->_doPost($path, $body, $opts)); $ret = new WriteResponse(); @@ -258,7 +258,7 @@ protected function _executePost(string $path, mixed $body, ?WriteOptions $opts): return $ret; } - protected function _executeDelete(string $path, ?WriteOptions $opts): WriteResponse + protected function _executeDelete(string $path, null|WriteOptions $opts): WriteResponse { $resp = $this->_requireOK($this->_doDelete($path, $opts)); $ret = new WriteResponse(); @@ -266,7 +266,7 @@ protected function _executeDelete(string $path, ?WriteOptions $opts): WriteRespo return $ret; } - protected function _executePutValuedStr(string $path, mixed $body, ?WriteOptions $opts): ValuedWriteStringResponse + protected function _executePutValuedStr(string $path, mixed $body, null|WriteOptions $opts): ValuedWriteStringResponse { $r = $this->_newPutRequest($path, $body, $opts); $resp = $this->_requireOK($this->_do($r)); @@ -275,7 +275,7 @@ protected function _executePutValuedStr(string $path, mixed $body, ?WriteOptions return $ret; } - protected function _executeGetValuedStr(string $path, ?QueryOptions $opts): ValuedQueryStringResponse + protected function _executeGetValuedStr(string $path, null|QueryOptions $opts): ValuedQueryStringResponse { $r = $this->_newGetRequest($path, $opts); $resp = $this->_requireOK($this->_do($r)); @@ -284,7 +284,7 @@ protected function _executeGetValuedStr(string $path, ?QueryOptions $opts): Valu return $ret; } - protected function _executeGetValuedStrs(string $path, ?QueryOptions $opts): ValuedQueryStringsResponse + protected function _executeGetValuedStrs(string $path, null|QueryOptions $opts): ValuedQueryStringsResponse { $r = $this->_newGetRequest($path, $opts); $resp = $this->_requireOK($this->_do($r)); diff --git a/src/Catalog/CatalogClient.php b/src/Catalog/CatalogClient.php index c778c499..8bce4c74 100644 --- a/src/Catalog/CatalogClient.php +++ b/src/Catalog/CatalogClient.php @@ -29,12 +29,12 @@ 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(); @@ -74,7 +74,7 @@ public function NodeServicesList(string $node, ?QueryOptions $opts = null): Cata 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 +86,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 +99,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/Coordinate/CoordinateClient.php b/src/Coordinate/CoordinateClient.php index 42aed10e..4a443303 100644 --- a/src/Coordinate/CoordinateClient.php +++ b/src/Coordinate/CoordinateClient.php @@ -36,7 +36,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 +44,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/Event/EventClient.php b/src/Event/EventClient.php index aa76bed0..c112e6ff 100644 --- a/src/Event/EventClient.php +++ b/src/Event/EventClient.php @@ -26,7 +26,7 @@ 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) { diff --git a/src/Health/HealthClient.php b/src/Health/HealthClient.php index b7ff2704..a2f118e1 100644 --- a/src/Health/HealthClient.php +++ b/src/Health/HealthClient.php @@ -30,12 +30,12 @@ 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); } @@ -44,7 +44,7 @@ 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,7 +53,7 @@ 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); } @@ -62,7 +62,7 @@ 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,7 +71,7 @@ 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); } @@ -80,7 +80,7 @@ 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,12 +89,12 @@ 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']; @@ -114,7 +114,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(); @@ -126,7 +126,7 @@ private function _getServiceEntries( string $service, array $tags, bool $passingOnly, - ?QueryOptions $opts, + null|QueryOptions $opts, string $healthType ): ServiceEntriesResponse { $uri = match ($healthType) { diff --git a/src/KV/KVClient.php b/src/KV/KVClient.php index 2fb51783..8adcd094 100644 --- a/src/KV/KVClient.php +++ b/src/KV/KVClient.php @@ -31,7 +31,7 @@ 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(); @@ -59,7 +59,7 @@ 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) { @@ -71,12 +71,12 @@ public function Put(KVPair $p, ?WriteOptions $opts = null): WriteResponse 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', ''); @@ -86,7 +86,7 @@ public function List(string $prefix = '', ?QueryOptions $opts = null): KVPairsRe 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', ''); @@ -96,7 +96,7 @@ public function Keys(string $prefix = '', ?QueryOptions $opts = null): ValuedQue 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); @@ -109,7 +109,7 @@ public function CAS(KVPair $p, ?WriteOptions $opts = null): ValuedWriteBoolRespo 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); @@ -122,7 +122,7 @@ public function Acquire(KVPair $p, ?WriteOptions $opts = null): WriteResponse 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; @@ -132,7 +132,7 @@ public function DeleteCAS(KVPair $p, ?WriteOptions $opts = null): ValuedWriteBoo 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,7 +145,7 @@ 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'] = ''; @@ -155,7 +155,7 @@ public function DeleteTree(string $prefix, ?WriteOptions $opts = null): WriteRes return $ret; } - public function Txn(KVTxnOps $txn, ?QueryOptions $opts = null): KVTxnAPIResponse + public function Txn(KVTxnOps $txn, null|QueryOptions $opts = null): KVTxnAPIResponse { $txnOps = new KVTxnOps(); foreach ($txn as $op) { @@ -206,7 +206,7 @@ public function Txn(KVTxnOps $txn, ?QueryOptions $opts = null): KVTxnAPIResponse * @var \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ - public function Tree(string $prefix = '', ?QueryOptions $opts = null): array + public function Tree(string $prefix = '', null|QueryOptions $opts = null): array { [$valueList, $_, $err] = $this->List($prefix, $opts); diff --git a/src/Operator/OperatorClient.php b/src/Operator/OperatorClient.php index f4ccf63c..3d477621 100644 --- a/src/Operator/OperatorClient.php +++ b/src/Operator/OperatorClient.php @@ -31,19 +31,19 @@ class OperatorClient extends AbstractClient { - public function AreaCreate(Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse + public function AreaCreate(Area $area, null|WriteOptions $opts = null): ValuedWriteStringResponse { return $this->_writeIDResponse($this->_requireOK($this->_doPost('v1/operator/area', $area, $opts))); } - public function AreaUpdate(string $areaID, Area $area, ?WriteOptions $opts = null): ValuedWriteStringResponse + public function AreaUpdate(string $areaID, Area $area, null|WriteOptions $opts = null): ValuedWriteStringResponse { return $this->_writeIDResponse( $this->_requireOK($this->_doPut(sprintf('v1/operator/area/%s', $areaID), $area, $opts)) ); } - public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAreasResponse + public function AreaGet(string $areaID, null|QueryOptions $opts = null): OperatorAreasResponse { $resp = $this->_requireOK($this->_doGet(sprintf('v1/operator/area/%s', urlencode($areaID)), $opts)); $ret = new OperatorAreasResponse(); @@ -51,7 +51,7 @@ public function AreaGet(string $areaID, ?QueryOptions $opts = null): OperatorAre return $ret; } - public function AreaList(?QueryOptions $opts = null): OperatorAreasResponse + public function AreaList(null|QueryOptions $opts = null): OperatorAreasResponse { $resp = $this->_requireOK($this->_doGet('v1/operator/area', $opts)); $ret = new OperatorAreasResponse(); @@ -59,12 +59,12 @@ public function AreaList(?QueryOptions $opts = null): OperatorAreasResponse return $ret; } - public function AreaDelete(string $areaID, ?WriteOptions $opts = null): WriteResponse + public function AreaDelete(string $areaID, null|WriteOptions $opts = null): WriteResponse { return $this->_executeDelete(sprintf('v1/operator/area/%s', $areaID), $opts); } - public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts = null): OperatorAreaJoinResponse + public function AreaJoin(string $areaID, array $addresses, null|WriteOptions $opts = null): OperatorAreaJoinResponse { $resp = $this->_requireOK($this->_doPut(sprintf('v1/operator/area/%s/join', $areaID), $addresses, $opts)); $ret = new OperatorAreaJoinResponse(); @@ -72,7 +72,7 @@ public function AreaJoin(string $areaID, array $addresses, ?WriteOptions $opts = return $ret; } - public function AreaMembers(string $areaID, ?QueryOptions $opts = null): OperatorSerfMembersResponse + public function AreaMembers(string $areaID, null|QueryOptions $opts = null): OperatorSerfMembersResponse { $resp = $this->_requireOK($this->_doGet(sprintf('v1/operator/area/%s/members', $areaID), $opts)); $ret = new OperatorSerfMembersResponse(); @@ -80,7 +80,7 @@ public function AreaMembers(string $areaID, ?QueryOptions $opts = null): Operato return $ret; } - public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorAutopilotConfigurationResponse + public function AutopilotGetConfiguration(null|QueryOptions $opts = null): OperatorAutopilotConfigurationResponse { $resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/configuration', $opts)); $ret = new OperatorAutopilotConfigurationResponse(); @@ -88,14 +88,14 @@ public function AutopilotGetConfiguration(?QueryOptions $opts = null): OperatorA return $ret; } - public function AutopilotSetConfiguration(AutopilotConfiguration $conf, ?WriteOptions $opts = null): ?Error + public function AutopilotSetConfiguration(AutopilotConfiguration $conf, null|WriteOptions $opts = null): ?Error { return $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts))->Err; } public function AutopilotCASConfiguration( AutopilotConfiguration $conf, - ?WriteOptions $opts = null + null|WriteOptions $opts = null ): ValuedBoolResponse { $resp = $this->_requireOK($this->_doPut('v1/operator/autopilot/configuration', $conf, $opts)); $ret = new ValuedBoolResponse(); @@ -103,7 +103,7 @@ public function AutopilotCASConfiguration( return $ret; } - public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorHealthReplyResponse + public function AutopilotServerHealth(null|QueryOptions $opts = null): OperatorHealthReplyResponse { $resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/health', $opts)); $ret = new OperatorHealthReplyResponse(); @@ -111,7 +111,7 @@ public function AutopilotServerHealth(?QueryOptions $opts = null): OperatorHealt return $ret; } - public function AutopilotState(?QueryOptions $opts = null): AutopilotStateResponse + public function AutopilotState(null|QueryOptions $opts = null): AutopilotStateResponse { $resp = $this->_requireOK($this->_doGet('v1/operator/autopilot/state', $opts)); $ret = new AutopilotStateResponse(); @@ -119,7 +119,7 @@ public function AutopilotState(?QueryOptions $opts = null): AutopilotStateRespon return $ret; } - public function RaftGetConfiguration(?QueryOptions $opts = null): OperatorRaftConfigurationResponse + public function RaftGetConfiguration(null|QueryOptions $opts = null): OperatorRaftConfigurationResponse { $resp = $this->_requireOK($this->_doGet('v1/operator/raft/configuration', $opts)); $ret = new OperatorRaftConfigurationResponse(); @@ -127,7 +127,7 @@ public function RaftGetConfiguration(?QueryOptions $opts = null): OperatorRaftCo return $ret; } - public function RaftRemovePeerByAddress(string $address, ?WriteOptions $opts = null): ?Error + public function RaftRemovePeerByAddress(string $address, null|WriteOptions $opts = null): ?Error { $r = $this->_newDeleteRequest('v1/operator/raft/peer', $opts); $r->applyOptions($opts); diff --git a/src/PreparedQuery/PreparedQueryClient.php b/src/PreparedQuery/PreparedQueryClient.php index e35585c7..27e3d187 100644 --- a/src/PreparedQuery/PreparedQueryClient.php +++ b/src/PreparedQuery/PreparedQueryClient.php @@ -28,7 +28,7 @@ class PreparedQueryClient extends AbstractClient { - public function Create(PreparedQueryDefinition $query, ?WriteOptions $opts = null): ValuedWriteStringResponse + public function Create(PreparedQueryDefinition $query, null|WriteOptions $opts = null): ValuedWriteStringResponse { $resp = $this->_requireOK($this->_doPost('v1/query', $query, $opts)); $ret = new ValuedWriteStringResponse(); @@ -36,12 +36,12 @@ public function Create(PreparedQueryDefinition $query, ?WriteOptions $opts = nul return $ret; } - public function Update(PreparedQueryDefinition $query, ?WriteOptions $opts = null): WriteResponse + public function Update(PreparedQueryDefinition $query, null|WriteOptions $opts = null): WriteResponse { return $this->_executePut('v1/query', $query, $opts); } - public function List(?QueryOptions $opts = null): PreparedQueryDefinitionsResponse + public function List(null|QueryOptions $opts = null): PreparedQueryDefinitionsResponse { $resp = $this->_doGet('v1/query', $opts); $ret = new PreparedQueryDefinitionsResponse(); @@ -49,7 +49,7 @@ public function List(?QueryOptions $opts = null): PreparedQueryDefinitionsRespon return $ret; } - public function Get(string $queryID, ?QueryOptions $opts = null): PreparedQueryDefinitionsResponse + public function Get(string $queryID, null|QueryOptions $opts = null): PreparedQueryDefinitionsResponse { $resp = $this->_doGet(sprintf('v1/query/%s', $queryID), $opts); $ret = new PreparedQueryDefinitionsResponse(); @@ -57,12 +57,12 @@ public function Get(string $queryID, ?QueryOptions $opts = null): PreparedQueryD return $ret; } - public function Delete(string $queryID, ?WriteOptions $opts = null): WriteResponse + public function Delete(string $queryID, null|WriteOptions $opts = null): WriteResponse { return $this->_executeDelete(sprintf('v1/query/%s', $queryID), $opts); } - public function Execute(string $queryIDOrName, ?QueryOptions $opts = null): PreparedQueryExecuteResponseResponse + public function Execute(string $queryIDOrName, null|QueryOptions $opts = null): PreparedQueryExecuteResponseResponse { $resp = $this->_doGet(sprintf('v1/query/%s/execute', $queryIDOrName), $opts); $ret = new PreparedQueryExecuteResponseResponse(); diff --git a/src/QueryMetaContainer.php b/src/QueryMetaContainer.php index 57bcc958..8c513435 100644 --- a/src/QueryMetaContainer.php +++ b/src/QueryMetaContainer.php @@ -22,9 +22,9 @@ trait QueryMetaContainer { - public ?QueryMeta $QueryMeta = null; + public null|QueryMeta $QueryMeta = null; - public function getQueryMeta(): ?QueryMeta + public function getQueryMeta(): null|QueryMeta { return $this->QueryMeta; } diff --git a/src/Session/SessionClient.php b/src/Session/SessionClient.php index 3c997a0c..00e51fe1 100644 --- a/src/Session/SessionClient.php +++ b/src/Session/SessionClient.php @@ -30,7 +30,7 @@ class SessionClient extends AbstractClient { - public function CreateNoChecks(?SessionEntry $sessionEntry = null, ?WriteOptions $opts = null): ValuedWriteStringResponse + public function CreateNoChecks(?SessionEntry $sessionEntry = null, null|WriteOptions $opts = null): ValuedWriteStringResponse { if (null === $sessionEntry) { $body = new SessionEntry(); @@ -45,17 +45,17 @@ public function CreateNoChecks(?SessionEntry $sessionEntry = null, ?WriteOptions return $this->_create('v1/session/create', $body, $opts); } - public function Create(?SessionEntry $sessionEntry = null, ?WriteOptions $opts = null): ValuedWriteStringResponse + public function Create(?SessionEntry $sessionEntry = null, null|WriteOptions $opts = null): ValuedWriteStringResponse { return $this->_create('v1/session/create', $sessionEntry, $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/session/destroy/%s', $id), null, $opts); } - public function Renew(string $id, ?WriteOptions $opts = null): SessionEntriesWriteResponse + public function Renew(string $id, null|WriteOptions $opts = null): SessionEntriesWriteResponse { $ret = new SessionEntriesWriteResponse(); @@ -87,22 +87,22 @@ public function Renew(string $id, ?WriteOptions $opts = null): SessionEntriesWri return $ret; } - public function Info(string $id, ?QueryOptions $opts = null): SessionEntriesQueryResponse + public function Info(string $id, null|QueryOptions $opts = null): SessionEntriesQueryResponse { return $this->_get(sprintf('v1/session/info/%s', $id), $opts); } - public function Node(string $node, ?QueryOptions $opts = null): SessionEntriesQueryResponse + public function Node(string $node, null|QueryOptions $opts = null): SessionEntriesQueryResponse { return $this->_get(sprintf('v1/session/node/%s', $node), $opts); } - public function List(?QueryOptions $opts = null): SessionEntriesQueryResponse + public function List(null|QueryOptions $opts = null): SessionEntriesQueryResponse { return $this->_get('v1/session/list', $opts); } - private function _get(string $path, ?QueryOptions $opts): SessionEntriesQueryResponse + private function _get(string $path, null|QueryOptions $opts): SessionEntriesQueryResponse { $resp = $this->_requireOK($this->_doGet($path, $opts)); $ret = new SessionEntriesQueryResponse(); @@ -110,7 +110,7 @@ private function _get(string $path, ?QueryOptions $opts): SessionEntriesQueryRes return $ret; } - private function _create(string $path, SessionEntry $entry, ?WriteOptions $opts): ValuedWriteStringResponse + private function _create(string $path, SessionEntry $entry, null|WriteOptions $opts): ValuedWriteStringResponse { $resp = $this->_requireOK($this->_doPut($path, $entry->_toAPIPayload(), $opts)); $ret = new ValuedWriteStringResponse(); diff --git a/src/Status/StatusClient.php b/src/Status/StatusClient.php index e66e6532..6659c958 100644 --- a/src/Status/StatusClient.php +++ b/src/Status/StatusClient.php @@ -27,7 +27,7 @@ class StatusClient extends AbstractClient { - public function LeaderWithQueryOptions(?QueryOptions $opts): ValuedStringResponse + public function LeaderWithQueryOptions(null|QueryOptions $opts): ValuedStringResponse { $resp = $this->_requireOK($this->_doGet('v1/status/leader', $opts)); $ret = new ValuedStringResponse(); @@ -40,7 +40,7 @@ public function Leader(): ValuedStringResponse return $this->LeaderWithQueryOptions(null); } - public function PeersWithQueryOptions(?QueryOptions $opts): ValuedStringsResponse + public function PeersWithQueryOptions(null|QueryOptions $opts): ValuedStringsResponse { $resp = $this->_requireOK($this->_doGet('v1/status/peers', $opts)); $ret = new ValuedStringsResponse(); diff --git a/src/WriteMetaContainer.php b/src/WriteMetaContainer.php index 76c5d857..0c13ba78 100644 --- a/src/WriteMetaContainer.php +++ b/src/WriteMetaContainer.php @@ -22,9 +22,9 @@ trait WriteMetaContainer { - public ?WriteMeta $WriteMeta = null; + public null|WriteMeta $WriteMeta = null; - public function getWriteMeta(): ?WriteMeta + public function getWriteMeta(): null|WriteMeta { return $this->WriteMeta; } From 7505b50138c161798fde75480807533d843bdf09 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:07:18 -0500 Subject: [PATCH 26/79] smidge test cleanup --- tests/Usage/Agent/AgentClientTest.php | 14 +++++++------- .../Agent/AgentServiceConnectProxyConfigTest.php | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/Usage/Agent/AgentClientTest.php b/tests/Usage/Agent/AgentClientTest.php index 40c8ce03..5926603f 100644 --- a/tests/Usage/Agent/AgentClientTest.php +++ b/tests/Usage/Agent/AgentClientTest.php @@ -132,9 +132,9 @@ public function testCanRegisterServiceWithOneCheck(): void ->setName(self::Service2Name) ->setAddress('127.0.0.1') ->setPort(4321) - ->setCheck(new AgentServiceCheck([ - 'TTL' => '5s', - ])); + ->setCheck(new AgentServiceCheck( + TTL: '5s', + )); $err = $client->ServiceRegister($svc); self::assertNull($err, \sprintf('AgentClient::serviceRegister returned error: %s', $err)); @@ -205,10 +205,10 @@ public function testCanRegisterServiceWithCheck(): void ->setName(self::Service1Name) ->setPort(1234) ->setAddress('127.0.0.1') - ->setCheck(new AgentServiceCheck([ - 'TCP' => '127.0.0.1', - 'Interval' => '30s', - ])); + ->setCheck(Check: new AgentServiceCheck( + Interval: '30s', + TCP: '127.0.0.1', + )); $err = $client->ServiceRegister($svc); self::assertNull($err, \sprintf('Error registering service with check: %s', $err)); diff --git a/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php b/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php index e0d5fea7..a2ca1640 100644 --- a/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php +++ b/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php @@ -20,7 +20,6 @@ */ use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig; -use DCarbone\PHPConsulAPI\FakeMap; use DCarbone\PHPConsulAPITests\Usage\AbstractUsageTests; class AgentServiceConnectProxyConfigTest extends AbstractUsageTests @@ -37,12 +36,12 @@ public function test_construct_givenConfig_willUnmarshalConfigValuesSuccessfully ], ]); - $this->assertEquals(new FakeMap([ + $this->assertEquals([ 'envoy_prometheus_bind_addr' => '0.0.0.0:12345', 'handshake_timeout_ms' => 10000, 'local_connect_timeout_ms' => 1000, 'local_request_timeout_ms' => 0, 'protocol' => 'http', - ]), $config->Config); + ], $config->Config); } } \ No newline at end of file From ca38b54cacab244bc6cc9455cd3b9fa3663c8409 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:11:33 -0500 Subject: [PATCH 27/79] who cares. --- src/AbstractClient.php | 10 +++--- src/AbstractValuedQueryResponse.php | 2 +- src/AbstractValuedResponse.php | 2 +- src/AbstractValuedWriteResponse.php | 2 +- src/Coordinate/Coordinate.php | 6 ++-- src/Coordinate/funcs.php | 2 +- src/Event/EventClient.php | 6 ++-- src/Health/HealthClient.php | 2 +- src/KV/KVTree.php | 10 +++--- src/Request.php | 2 +- src/ResponseValueBoolTrait.php | 4 +-- src/WriteResponse.php | 2 +- tests/ConsulManager.php | 16 ++++----- tests/Usage/ACL/ACLClientTest.php | 2 +- tests/Usage/Agent/AgentClientTest.php | 36 +++++++++---------- tests/Usage/Catalog/CatalogClientTest.php | 16 ++++----- .../Usage/Coordinate/CoordinateClientTest.php | 6 ++-- .../Usage/Coordinate/CoordinateUsageTest.php | 10 +++--- tests/Usage/KV/KVCRUDTest.php | 30 ++++++++-------- tests/Usage/KV/KVClientCASTest.php | 14 ++++---- tests/Usage/KV/KVClientLockTest.php | 6 ++-- .../Usage/Operator/OperatorAutopilotTest.php | 4 +-- tests/Usage/Operator/ReadableDurationTest.php | 4 +-- .../Usage/Session/SessionClientUsageTest.php | 10 +++--- tests/funcs.php | 2 +- 25 files changed, 103 insertions(+), 103 deletions(-) diff --git a/src/AbstractClient.php b/src/AbstractClient.php index 92da890c..99ebe77d 100644 --- a/src/AbstractClient.php +++ b/src/AbstractClient.php @@ -58,14 +58,14 @@ protected function _buildGuzzleRequestOptions(Request $r): array $opts[GuzzleRequestOptions::SSL_KEY] = $this->_config->KeyFile; } - if (null !== $r->timeout && 0 < ($ttl = \intval($r->timeout->Seconds(), 10))) { + if (null !== $r->timeout && 0 < ($ttl = intval($r->timeout->Seconds(), 10))) { $opts[GuzzleRequestOptions::TIMEOUT] = $ttl; } // todo: per-request content and accept value setting. $body = $r->getBody(); if (null !== $body) { - if (\is_scalar($body)) { + if (is_scalar($body)) { $opts[GuzzleRequestOptions::BODY] = $body; } else { $opts[GuzzleRequestOptions::JSON] = $body; @@ -132,7 +132,7 @@ protected function _do(Request $r): RequestResponse } // calculate execution time - $dur = new Time\Duration(\intval((microtime(true) - $start) * Time::Second, 10)); + $dur = new Time\Duration(intval((microtime(true) - $start) * Time::Second, 10)); return new RequestResponse($r->meta(), $dur, $response, $err); } @@ -155,7 +155,7 @@ protected function _requireStatus(RequestResponse $r, int ...$allowed): RequestR sprintf( '%s - Expected response to be instance of \\Psr\\Message\\ResponseInterface, %s seen.', static::class, - \is_object($r->Response) ? \get_class($r->Response) : \gettype($r->Response) + is_object($r->Response) ? get_class($r->Response) : gettype($r->Response) ) ); return $r; @@ -167,7 +167,7 @@ protected function _requireStatus(RequestResponse $r, int ...$allowed): RequestR $actualCode = $r->Response->getStatusCode(); // If response code is in allowed list, move right along - if (\in_array($actualCode, $allowed, true)) { + if (in_array($actualCode, $allowed, true)) { return $r; } diff --git a/src/AbstractValuedQueryResponse.php b/src/AbstractValuedQueryResponse.php index efb69211..a2ab90d9 100644 --- a/src/AbstractValuedQueryResponse.php +++ b/src/AbstractValuedQueryResponse.php @@ -27,7 +27,7 @@ abstract class AbstractValuedQueryResponse extends AbstractResponse implements Q 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 diff --git a/src/AbstractValuedResponse.php b/src/AbstractValuedResponse.php index 0d602a4b..1e8fc823 100644 --- a/src/AbstractValuedResponse.php +++ b/src/AbstractValuedResponse.php @@ -26,7 +26,7 @@ abstract class AbstractValuedResponse extends AbstractResponse implements Valued public function offsetExists(mixed $offset): bool { - return \is_int($offset) && 0 <= $offset && $offset < 2; + return is_int($offset) && 0 <= $offset && $offset < 2; } public function offsetGet(mixed $offset): mixed diff --git a/src/AbstractValuedWriteResponse.php b/src/AbstractValuedWriteResponse.php index 03e5a13e..c380bcd0 100644 --- a/src/AbstractValuedWriteResponse.php +++ b/src/AbstractValuedWriteResponse.php @@ -27,7 +27,7 @@ abstract class AbstractValuedWriteResponse extends AbstractResponse implements V 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 diff --git a/src/Coordinate/Coordinate.php b/src/Coordinate/Coordinate.php index 5ccb6a58..7898d6a3 100644 --- a/src/Coordinate/Coordinate.php +++ b/src/Coordinate/Coordinate.php @@ -37,7 +37,7 @@ class Coordinate extends AbstractModel public function __construct($data = []) { - if (\is_array($data)) { + if (is_array($data)) { parent::__construct($data); } elseif ($data instanceof CoordinateConfig) { $this->Vec = array_fill(0, $data->Dimensionality, 0.0); @@ -50,7 +50,7 @@ public function __construct($data = []) '%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) + is_object($data) ? get_class($data) : gettype($data) ) ); } @@ -98,7 +98,7 @@ public function IsValid(): bool 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 diff --git a/src/Coordinate/funcs.php b/src/Coordinate/funcs.php index 88d0eadd..9f0a90b2 100644 --- a/src/Coordinate/funcs.php +++ b/src/Coordinate/funcs.php @@ -48,7 +48,7 @@ function unitVectorAt(array $vec1, array $vec2): array return [mul($ret, 1.0 / $mag), 0.0]; } - $ret = array_fill(0, \count($ret), 0.0); + $ret = array_fill(0, count($ret), 0.0); $ret[0] = 1.0; return $ret; } diff --git a/src/Event/EventClient.php b/src/Event/EventClient.php index c112e6ff..aa322324 100644 --- a/src/Event/EventClient.php +++ b/src/Event/EventClient.php @@ -58,17 +58,17 @@ public function List(string $name = '', null|QueryOptions $opts = null): UserEve 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); + $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/Health/HealthClient.php b/src/Health/HealthClient.php index a2f118e1..82cf7370 100644 --- a/src/Health/HealthClient.php +++ b/src/Health/HealthClient.php @@ -98,7 +98,7 @@ public function State(string $state, null|QueryOptions $opts = null): HealthChec { 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( diff --git a/src/KV/KVTree.php b/src/KV/KVTree.php index ecfd21e9..ff493e58 100644 --- a/src/KV/KVTree.php +++ b/src/KV/KVTree.php @@ -79,12 +79,12 @@ public function getChildren(): \RecursiveIterator|KVTree|KVPair public function count(): int { - return \count($this->_children); + return count($this->_children); } public function offsetExists(mixed $offset): bool { - if (\is_string($offset)) { + if (is_string($offset)) { $subPath = str_replace($this->_prefix, '', $offset); $cnt = substr_count($subPath, '/'); @@ -96,12 +96,12 @@ public function offsetExists(mixed $offset): bool } } - return isset($this->_children[$offset]) || \array_key_exists($offset, $this->_children); + return isset($this->_children[$offset]) || array_key_exists($offset, $this->_children); } public function offsetGet(mixed $offset): KVTree|KVPair|null { - if (\is_string($offset)) { + if (is_string($offset)) { $subPath = str_replace($this->_prefix, '', $offset); $cnt = substr_count($subPath, '/'); if (1 < $cnt || (1 === $cnt && '/' !== substr($subPath, -1))) { @@ -130,7 +130,7 @@ public function offsetGet(mixed $offset): KVTree|KVPair|null public function offsetSet(mixed $offset, mixed $value): void { - if ('string' === \gettype($offset)) { + if ('string' === gettype($offset)) { $subPath = str_replace($this->_prefix, '', $offset); $cnt = substr_count($subPath, '/'); diff --git a/src/Request.php b/src/Request.php index bae97388..10c6e199 100644 --- a/src/Request.php +++ b/src/Request.php @@ -112,7 +112,7 @@ public function filterQuery(string $filter): void public function getUri(): UriInterface { $uri = "{$this->scheme}://{$this->address}/{$this->path}"; - if (0 < \count($this->params)) { + if (0 < count($this->params)) { $uri .= "?{$this->params}"; } return new Uri($uri); diff --git a/src/ResponseValueBoolTrait.php b/src/ResponseValueBoolTrait.php index 32cf416d..a38c9dfc 100644 --- a/src/ResponseValueBoolTrait.php +++ b/src/ResponseValueBoolTrait.php @@ -31,11 +31,11 @@ public function getValue(): bool public function unmarshalValue(mixed $decoded): void { - if (\is_bool($decoded)) { + if (is_bool($decoded)) { $this->Value = $decoded; return; } - if (\is_string($decoded)) { + if (is_string($decoded)) { $this->Value = Transcoding::TRUE === strtolower(trim($decoded)); return; } diff --git a/src/WriteResponse.php b/src/WriteResponse.php index 82145329..592e7586 100644 --- a/src/WriteResponse.php +++ b/src/WriteResponse.php @@ -27,7 +27,7 @@ class WriteResponse extends AbstractResponse implements WriteResponseInterface public function offsetExists(mixed $offset): bool { - return \is_int($offset) && 0 <= $offset && $offset < 2; + return is_int($offset) && 0 <= $offset && $offset < 2; } public function offsetGet(mixed $offset): Error|null|WriteMeta diff --git a/tests/ConsulManager.php b/tests/ConsulManager.php index f34ebb03..bc315102 100644 --- a/tests/ConsulManager.php +++ b/tests/ConsulManager.php @@ -40,14 +40,14 @@ final class ConsulManager */ public static function startSingle(string $flags): void { - if (\file_exists(self::PID_FILE)) { + if (file_exists(self::PID_FILE)) { self::stopSingle(); } - \shell_exec(self::START_SINGLE_CMD . " {$flags}"); + shell_exec(self::START_SINGLE_CMD . " {$flags}"); // sleep to allow consul to setup - \sleep(3); + sleep(3); } /** @@ -63,12 +63,12 @@ public static function startSingleDev(): void */ public static function stopSingle(): void { - if (\file_exists(self::PID_FILE)) { - \shell_exec(self::STOP_SINGLE_CMD); - if (\file_exists(self::PID_FILE)) { - \unlink(self::PID_FILE); + if (file_exists(self::PID_FILE)) { + shell_exec(self::STOP_SINGLE_CMD); + if (file_exists(self::PID_FILE)) { + unlink(self::PID_FILE); } - \sleep(1); + sleep(1); } } diff --git a/tests/Usage/ACL/ACLClientTest.php b/tests/Usage/ACL/ACLClientTest.php index e427ea4c..5cb48d94 100644 --- a/tests/Usage/ACL/ACLClientTest.php +++ b/tests/Usage/ACL/ACLClientTest.php @@ -59,6 +59,6 @@ public function testCanGetBootstrappedACL(string $aclID): void self::assertNull($err, 'ACL::Info() return error: ' . $err); self::assertInstanceOf(QueryMeta::class, $qm); self::assertIsArray($acls); - \var_dump($acls); + var_dump($acls); } } diff --git a/tests/Usage/Agent/AgentClientTest.php b/tests/Usage/Agent/AgentClientTest.php index 5926603f..dd7fa486 100644 --- a/tests/Usage/Agent/AgentClientTest.php +++ b/tests/Usage/Agent/AgentClientTest.php @@ -56,9 +56,9 @@ public function testCanGetSelf(): void self::assertNull($err); self::assertIsArray( $self, - \sprintf( + sprintf( 'Expected AgentClient::self to return array, saw "%s"', - \gettype($self) + gettype($self) ) ); } @@ -70,7 +70,7 @@ public function testCanReloadSelf(): void { $client = new AgentClient(ConsulManager::testConfig()); $err = $client->Reload(); - self::assertNull($err, \sprintf('AgentClient::reload returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::reload returned error: %s', $err)); } /** @@ -81,10 +81,10 @@ public function testCanGetNodeName(): void $client = new AgentClient(ConsulManager::testConfig()); [$nodeName, $err] = $client->NodeName(); - self::assertNull($err, \sprintf('Unable to get agent node name: %s', $err)); + self::assertNull($err, sprintf('Unable to get agent node name: %s', $err)); self::assertIsString( $nodeName, - \sprintf('node name expected to be string, %s seen', \gettype($nodeName)) + sprintf('node name expected to be string, %s seen', gettype($nodeName)) ); self::assertNotEmpty($nodeName, 'NodeName was empty!'); } @@ -97,7 +97,7 @@ public function testCanGeMembers(): void $client = new AgentClient(ConsulManager::testConfig()); [$members, $err] = $client->Members(); - self::assertNull($err, \sprintf('AgentClient::members returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::members returned error: %s', $err)); self::assertIsArray($members); self::assertContainsOnlyInstancesOf(AgentMember::class, $members); self::assertCount(1, $members); @@ -117,7 +117,7 @@ public function testCanRegisterServiceNoChecks(): void ->setPort(1234); $err = $client->ServiceRegister($svc); - self::assertNull($err, \sprintf('AgentClient::serviceRegister returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::serviceRegister returned error: %s', $err)); } /** @@ -137,7 +137,7 @@ public function testCanRegisterServiceWithOneCheck(): void )); $err = $client->ServiceRegister($svc); - self::assertNull($err, \sprintf('AgentClient::serviceRegister returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::serviceRegister returned error: %s', $err)); } /** @@ -152,7 +152,7 @@ public function testCanGetServiceList(): void [$svcs, $err] = $client->Services(); try { - self::assertNull($err, \sprintf('AgentClient::services return error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::services return error: %s', $err)); self::assertIsArray($svcs); self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); @@ -160,7 +160,7 @@ public function testCanGetServiceList(): void self::assertCount(2, $svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; - \var_dump($svcs); + var_dump($svcs); echo "\n"; throw $e; @@ -175,18 +175,18 @@ public function testCanDeregisterService(): void $client = new AgentClient(ConsulManager::testConfig()); $err = $client->ServiceDeregister(self::Service1Name); - self::assertNull($err, \sprintf('AgentClient::serviceDeregister returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::serviceDeregister returned error: %s', $err)); [$svcs, $err] = $client->Services(); try { - self::assertNull($err, \sprintf('AgentClient::services returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::services returned error: %s', $err)); self::assertIsArray($svcs); self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); self::assertCount(1, $svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; - \var_dump($svcs); + var_dump($svcs); echo "\n"; throw $e; @@ -211,26 +211,26 @@ public function testCanRegisterServiceWithCheck(): void )); $err = $client->ServiceRegister($svc); - self::assertNull($err, \sprintf('Error registering service with check: %s', $err)); + self::assertNull($err, sprintf('Error registering service with check: %s', $err)); - \sleep(2); + sleep(2); [$svcs, $err] = $client->Services(); try { - self::assertNull($err, \sprintf('AgentClient::services returned error: %s', $err)); + self::assertNull($err, sprintf('AgentClient::services returned error: %s', $err)); self::assertIsArray($svcs); self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); self::assertCount(2, $svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; - \var_dump($svcs); + var_dump($svcs); echo "\n"; throw $e; } $err = $client->ServiceDeregister(self::Service1Name); - self::assertNull($err, \sprintf('Error deregistering service: %s', $err)); + self::assertNull($err, sprintf('Error deregistering service: %s', $err)); } } diff --git a/tests/Usage/Catalog/CatalogClientTest.php b/tests/Usage/Catalog/CatalogClientTest.php index e0111b9a..47cbd31f 100644 --- a/tests/Usage/Catalog/CatalogClientTest.php +++ b/tests/Usage/Catalog/CatalogClientTest.php @@ -89,7 +89,7 @@ public function testCanGetService(): void self::assertInstanceOf(QueryMeta::class, $qm); self::assertIsArray($service); self::assertCount(1, $service); - self::assertInstanceOf(CatalogService::class, \reset($service)); + self::assertInstanceOf(CatalogService::class, reset($service)); } /** @@ -132,7 +132,7 @@ public function testCanGetListOfService(): void self::assertInstanceOf(CatalogService::class, $s); } } catch (AssertionFailedError $e) { - \var_dump($service); + var_dump($service); throw $e; } } @@ -153,7 +153,7 @@ public function testCanGetListOfServices(): void self::assertCount(2, $services); self::assertContainsOnly('array', $services); } catch (AssertionFailedError $e) { - \var_dump($services); + var_dump($services); throw $e; } } @@ -176,7 +176,7 @@ public function testCanDeregisterService(): void self::assertNull($err, 'CatalogClient::service returned error: ' . $err); self::assertInstanceOf(QueryMeta::class, $qm); self::assertCount(1, $service); - self::assertInstanceOf(CatalogService::class, \reset($service)); + self::assertInstanceOf(CatalogService::class, reset($service)); } /** @@ -196,7 +196,7 @@ public function testCanGetDatacenters(): void self::assertCount(1, $dcs); self::assertSame('dc1', $dcs[0]); } catch (AssertionFailedError $e) { - \var_dump($dcs); + var_dump($dcs); throw $e; } } @@ -217,7 +217,7 @@ public function testCanGetListOfNodes(): void self::assertCount(2, $nodes); self::assertContainsOnlyInstancesOf(Node::class, $nodes); } catch (AssertionFailedError $e) { - \var_dump($nodes); + var_dump($nodes); throw $e; } } @@ -245,7 +245,7 @@ public function testCanGetNode(): void self::assertNotNull($id, 'Unable to get node with ID'); } catch (AssertionFailedError $e) { - \var_dump($nodes); + var_dump($nodes); throw $e; } @@ -255,7 +255,7 @@ public function testCanGetNode(): void self::assertInstanceOf(QueryMeta::class, $qm); self::assertInstanceOf(CatalogNode::class, $node); } catch (AssertionFailedError $e) { - \var_dump($node); + var_dump($node); throw $e; } } diff --git a/tests/Usage/Coordinate/CoordinateClientTest.php b/tests/Usage/Coordinate/CoordinateClientTest.php index 1d615539..2440e5fa 100644 --- a/tests/Usage/Coordinate/CoordinateClientTest.php +++ b/tests/Usage/Coordinate/CoordinateClientTest.php @@ -47,9 +47,9 @@ public function testDatacenters(): void $client = new CoordinateClient(ConsulManager::testConfig()); [$dcs, $err] = $client->Datacenters(); - self::assertNull($err, \sprintf('CoordinateClient::datacenters() - %s', $err)); + self::assertNull($err, sprintf('CoordinateClient::datacenters() - %s', $err)); self::assertIsArray($dcs); - self::assertGreaterThan(0, \count($dcs), 'Expected at least 1 datacenter'); + self::assertGreaterThan(0, count($dcs), 'Expected at least 1 datacenter'); } /** @@ -60,7 +60,7 @@ public function testNodes(): void $client = new CoordinateClient(ConsulManager::testConfig()); [$nodes, $qm, $err] = $client->Nodes(); - self::assertNull($err, \sprintf('CoordinateClient::nodes() - %s', $err)); + self::assertNull($err, sprintf('CoordinateClient::nodes() - %s', $err)); self::assertInstanceOf(QueryMeta::class, $qm); self::assertIsArray($nodes); } diff --git a/tests/Usage/Coordinate/CoordinateUsageTest.php b/tests/Usage/Coordinate/CoordinateUsageTest.php index 0ed2b1a5..b4c91268 100644 --- a/tests/Usage/Coordinate/CoordinateUsageTest.php +++ b/tests/Usage/Coordinate/CoordinateUsageTest.php @@ -178,7 +178,7 @@ public function testApplyForce(): void $this->verifyEqualFloats($c->Height, $config->HeightMin); $bad = clone $c; - $bad->Vec = \array_fill(0, \count($c->Vec) + 1, 0.0); + $bad->Vec = array_fill(0, count($c->Vec) + 1, 0.0); $c->ApplyForce($config, 1.0, $bad); } @@ -212,7 +212,7 @@ public function testDistanceTo(): void $this->verifyEqualFloats($c1->DistanceTo($c2)->Seconds(), 4.104875150354758 + 0.3 + 0.8); $bad = clone $c1; - $bad->Vec = \array_fill(0, \count($c1->Vec) + 1, 0.0); + $bad->Vec = array_fill(0, count($c1->Vec) + 1, 0.0); $c1->DistanceTo($bad); } @@ -224,8 +224,8 @@ protected function verifyEqualFloats(float $f1, float $f2): void { self::assertLessThanOrEqual( self::ZeroThreshold, - \abs($f1 - $f2), - \sprintf('equal assertion fail, %.6f != %.6f', $f1, $f2) + abs($f1 - $f2), + sprintf('equal assertion fail, %.6f != %.6f', $f1, $f2) ); } @@ -241,7 +241,7 @@ protected function verifyEqualVectors(array $vec1, array $vec2): void $this->verifyEqualFloats($v, $vec2[$k]); } } catch (AssertionFailedError $e) { - \var_dump($vec1, $vec2); + var_dump($vec1, $vec2); throw $e; } } diff --git a/tests/Usage/KV/KVCRUDTest.php b/tests/Usage/KV/KVCRUDTest.php index ae1cebd9..4c038b47 100644 --- a/tests/Usage/KV/KVCRUDTest.php +++ b/tests/Usage/KV/KVCRUDTest.php @@ -55,7 +55,7 @@ public function testCanPutKey(): void $client = new KVClient(ConsulManager::testConfig()); [$wm, $err] = $client->Put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1])); - self::assertNull($err, \sprintf('Unable to set kvp: %s', (string)$err)); + self::assertNull($err, sprintf('Unable to set kvp: %s', (string)$err)); self::assertInstanceOf(WriteMeta::class, $wm); } @@ -68,7 +68,7 @@ public function testCanGetKey(): void $client->Put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1])); [$kv, $qm, $err] = $client->Get(self::KVKey1); - self::assertNull($err, \sprintf('KV::get returned error: %s', (string)$err)); + self::assertNull($err, sprintf('KV::get returned error: %s', (string)$err)); self::assertInstanceOf(QueryMeta::class, $qm); self::assertInstanceOf(KVPair::class, $kv); self::assertSame(self::KVKey1, $kv->Key); @@ -84,14 +84,14 @@ public function testCanDeleteKey(): void $client->Put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1])); [$wm, $err] = $client->Delete(self::KVKey1); - self::assertNull($err, \sprintf('KV::delete returned error: %s', $err)); + self::assertNull($err, sprintf('KV::delete returned error: %s', $err)); self::assertInstanceOf( WriteMeta::class, $wm, - \sprintf( + sprintf( 'expected "%s", saw "%s"', WriteMeta::class, - \is_object($wm) ? \get_class($wm) : \gettype($wm) + is_object($wm) ? get_class($wm) : gettype($wm) ) ); } @@ -103,10 +103,10 @@ public function testListReturnsErrorWithInvalidPrefix(): void self::assertInstanceOf( Error::class, $err, - \sprintf( + sprintf( 'Expected $err to be instanceof "%s", saw "%s"', Error::class, - \is_object($err) ? \get_class($err) : \gettype($err) + is_object($err) ? get_class($err) : gettype($err) ) ); } @@ -126,7 +126,7 @@ public function testCanGetNoPrefixList(): void /** @noinspection PhpUnhandledExceptionInspection */ [$list, $qm, $err] = $client->List(); - self::assertNull($err, \sprintf('KV::valueList returned error: %s', $err)); + self::assertNull($err, sprintf('KV::valueList returned error: %s', $err)); try { self::assertInstanceOf(KVPairs::class, $list); @@ -152,7 +152,7 @@ public function testCanGetNoPrefixList(): void self::assertTrue($key3found, 'Key3 not found in list!'); } catch (AssertionFailedError $e) { echo "\nno prefix \$list value:\n"; - \var_dump($list); + var_dump($list); echo "\n"; throw $e; @@ -173,7 +173,7 @@ public function testCanGetPrefixList(): void $client->Put(new KVPair(['Key' => self::KVPrefix . '/' . self::KVKey3, 'Value' => self::KVValue3])); [$list, $qm, $err] = $client->List(self::KVPrefix); - self::assertNull($err, \sprintf('KV::valueList returned error: %s', $err)); + self::assertNull($err, sprintf('KV::valueList returned error: %s', $err)); self::assertInstanceOf(QueryMeta::class, $qm); try { @@ -200,7 +200,7 @@ public function testCanGetPrefixList(): void self::assertTrue($key3found, 'Key3 not found in list!'); } catch (AssertionFailedError $e) { echo "\nprefix \$list value:\n"; - \var_dump($list); + var_dump($list); echo "\n"; throw $e; @@ -214,10 +214,10 @@ public function testKeysReturnsErrorWithInvalidPrefix(): void self::assertInstanceOf( Error::class, $err, - \sprintf( + sprintf( 'Expected $err to be "%s", saw "%s"', Error::class, - \is_object($err) ? \get_class($err) : \gettype($err) + is_object($err) ? get_class($err) : gettype($err) ) ); } @@ -236,7 +236,7 @@ public function testCanGetNoPrefixKeys(): void $client->Put(new KVPair(['Key' => self::KVKey3, 'Value' => self::KVValue3])); [$list, $qm, $err] = $client->Keys(); - self::assertNull($err, \sprintf('KV::keys returned error: %s', $err)); + self::assertNull($err, sprintf('KV::keys returned error: %s', $err)); self::assertInstanceOf(QueryMeta::class, $qm); try { @@ -263,7 +263,7 @@ public function testCanGetNoPrefixKeys(): void self::assertTrue($key3found, 'Key3 not found in list!'); } catch (AssertionFailedError $e) { echo "\nprefix \$list value:\n"; - \var_dump($list); + var_dump($list); echo "\n"; throw $e; diff --git a/tests/Usage/KV/KVClientCASTest.php b/tests/Usage/KV/KVClientCASTest.php index d212e6c2..ecfc4a5c 100644 --- a/tests/Usage/KV/KVClientCASTest.php +++ b/tests/Usage/KV/KVClientCASTest.php @@ -29,10 +29,10 @@ public function testKVWithCAS(): void $client = new KVClient(ConsulManager::testConfig()); [$_, $err] = $client->Put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVOriginalValue])); - self::assertNull($err, \sprintf('Unable to put KV: %s', $err)); + self::assertNull($err, sprintf('Unable to put KV: %s', $err)); [$kv, $_, $err] = $client->Get(self::KVKey1); - self::assertNull($err, \sprintf('Unable to get KV: %s', $err)); + self::assertNull($err, sprintf('Unable to get KV: %s', $err)); self::assertInstanceOf(KVPair::class, $kv); self::assertSame(self::KVOriginalValue, $kv->Value); @@ -41,27 +41,27 @@ public function testKVWithCAS(): void $kv->Value = self::KVUpdatedValue; [$ok, $_, $err] = $client->CAS($kv); - self::assertNull($err, \sprintf('Unable to update kv value: %s', $err)); + self::assertNull($err, sprintf('Unable to update kv value: %s', $err)); self::assertTrue($ok); $kv->Value = self::KVUpdatedValue2; [$ok, $_, $err] = $client->CAS($kv); - self::assertNull($err, \sprintf('Error updating kv with old cas: %s', $err)); + self::assertNull($err, sprintf('Error updating kv with old cas: %s', $err)); self::assertFalse($ok, 'Expected false when trying to update key with old cas'); [$ok, $_, $err] = $client->DeleteCAS($kv); - self::assertNull($err, \sprintf('Error deleting kv with old cas: %s', $err)); + self::assertNull($err, sprintf('Error deleting kv with old cas: %s', $err)); self::assertFalse($ok, 'Expected false when trying to delete key with old cas'); [$kv, $_, $err] = $client->Get(self::KVKey1); - self::assertNull($err, \sprintf('Error retrieving updated key: %s', $err)); + self::assertNull($err, sprintf('Error retrieving updated key: %s', $err)); self::assertInstanceOf(KVPair::class, $kv); self::assertNotSame($omi, $kv->ModifyIndex, 'Expected ModifyIndex to be different'); self::assertSame(self::KVUpdatedValue, $kv->Value, 'KV Value was not actually updated'); [$ok, $_, $err] = $client->DeleteCAS($kv); - self::assertNull($err, \sprintf('Error deleting key: %s', $err)); + self::assertNull($err, sprintf('Error deleting key: %s', $err)); self::assertTrue($ok, 'Expected true when deleting key with updated cas'); } } diff --git a/tests/Usage/KV/KVClientLockTest.php b/tests/Usage/KV/KVClientLockTest.php index 615455d2..2d5abfbd 100644 --- a/tests/Usage/KV/KVClientLockTest.php +++ b/tests/Usage/KV/KVClientLockTest.php @@ -41,15 +41,15 @@ public function testAcquireAndRelease(): void ] ) ); - self::assertNull($err, \sprintf('Error creating session: %s', $err)); + self::assertNull($err, sprintf('Error creating session: %s', $err)); $kv = new KVPair(['Key' => $key, 'Value' => 'whatever', 'Session' => $id]); [$wm, $err] = $kvClient->Acquire($kv); - self::assertNull($err, \sprintf('Error acquiring lock: %s', $err)); + self::assertNull($err, sprintf('Error acquiring lock: %s', $err)); self::assertInstanceOf(WriteMeta::class, $wm); [$kv, $_, $err] = $kvClient->Get($key); - self::assertNull($err, \sprintf('Error retrieving key: %s', $err)); + self::assertNull($err, sprintf('Error retrieving key: %s', $err)); self::assertInstanceOf(KVPair::class, $kv); self::assertSame($id, $kv->Session); self::assertSame('whatever', $kv->Value); diff --git a/tests/Usage/Operator/OperatorAutopilotTest.php b/tests/Usage/Operator/OperatorAutopilotTest.php index e77a82fb..6fd456ac 100644 --- a/tests/Usage/Operator/OperatorAutopilotTest.php +++ b/tests/Usage/Operator/OperatorAutopilotTest.php @@ -39,11 +39,11 @@ public function testCanGetAutopilotConfiguration(): void $client = new OperatorClient(ConsulManager::testConfig()); [$conf, $err] = $client->AutopilotGetConfiguration(); - self::assertNull($err, \sprintf('Unable to list autopilot configuration: %s', $err)); + self::assertNull($err, sprintf('Unable to list autopilot configuration: %s', $err)); self::assertInstanceOf( AutopilotConfiguration::class, $conf, - \sprintf('Expected instance of %s, saw: %s', AutopilotConfiguration::class, \json_encode($conf)) + sprintf('Expected instance of %s, saw: %s', AutopilotConfiguration::class, json_encode($conf)) ); } diff --git a/tests/Usage/Operator/ReadableDurationTest.php b/tests/Usage/Operator/ReadableDurationTest.php index 53db8ae9..c6abb929 100644 --- a/tests/Usage/Operator/ReadableDurationTest.php +++ b/tests/Usage/Operator/ReadableDurationTest.php @@ -31,7 +31,7 @@ final class ReadableDurationTest extends TestCase { public function testReadableJsonEncoding(): void { - $rd = new ReadableDuration(\time() * Time::Second); - self::assertSame('"' . (string)$rd . '"', \json_encode($rd)); + $rd = new ReadableDuration(time() * Time::Second); + self::assertSame('"' . (string)$rd . '"', json_encode($rd)); } } diff --git a/tests/Usage/Session/SessionClientUsageTest.php b/tests/Usage/Session/SessionClientUsageTest.php index 47cdeca3..f51d07ea 100644 --- a/tests/Usage/Session/SessionClientUsageTest.php +++ b/tests/Usage/Session/SessionClientUsageTest.php @@ -36,12 +36,12 @@ public function testNoChecksLifecycle(): void 'Behavior' => Consul::SessionBehaviorDelete, 'TTL' => $ttl, ])); - self::assertNull($err, \sprintf('Error creating session: %s', $err)); + self::assertNull($err, sprintf('Error creating session: %s', $err)); self::assertInstanceOf(WriteMeta::class, $wm); self::assertIsString($id, 'Expected ID to be string'); [$sessions, $qm, $err] = $client->Info($id); - self::assertNull($err, \sprintf('Error getting %s info: %s', $id, $err)); + self::assertNull($err, sprintf('Error getting %s info: %s', $id, $err)); self::assertInstanceOf(QueryMeta::class, $qm); self::assertIsArray($sessions); self::assertCount(1, $sessions); @@ -58,17 +58,17 @@ public function testNoChecksLifecycle(): void self::assertSame(15 * Time::Second, $session->LockDelay->Nanoseconds()); [$sessions, $wm, $err] = $client->Renew($id); - self::assertNull($err, \sprintf('Error renewing session: %s', $err)); + self::assertNull($err, sprintf('Error renewing session: %s', $err)); self::assertInstanceOf(WriteMeta::class, $wm); self::assertIsArray($sessions); self::assertCount(1, $sessions); self::assertContainsOnlyInstancesOf(SessionEntry::class, $sessions); [$_, $err] = $client->Destroy($id); - self::assertNull($err, \sprintf('Error destroying session: %s', $err)); + self::assertNull($err, sprintf('Error destroying session: %s', $err)); [$sessions, $_, $err] = $client->Info($id); - self::assertNull($err, \sprintf('Error getting list after expected expiration: %s', $err)); + self::assertNull($err, sprintf('Error getting list after expected expiration: %s', $err)); self::assertIsArray($sessions, 'Expected $sessions to be an array'); self::assertCount(0, $sessions, 'Expected $sessions to be empty'); } diff --git a/tests/funcs.php b/tests/funcs.php index a7102800..83429fff 100644 --- a/tests/funcs.php +++ b/tests/funcs.php @@ -50,7 +50,7 @@ function determine_param_hint(Compound $compoundHint): array $others[] = $hint; } } - if (1 === \count($others)) { + if (1 === count($others)) { $out[1] = $others[0]; } return $out; From 33a8236603e387c584d33568145565a8eb7c86e2 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:24:44 -0500 Subject: [PATCH 28/79] php-cs-fixer fixes, prolly add stan --- tools/php-cs-fixer/php-consul-api-rules.php_cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/php-cs-fixer/php-consul-api-rules.php_cs b/tools/php-cs-fixer/php-consul-api-rules.php_cs index 1db0153f..854b38db 100644 --- a/tools/php-cs-fixer/php-consul-api-rules.php_cs +++ b/tools/php-cs-fixer/php-consul-api-rules.php_cs @@ -1,17 +1,17 @@ -setUsingCache(false) - ->setRiskyAllowed(true) +// ->setRiskyAllowed(true) ->setLineEnding("\n") ->setIndent(' ') ->registerCustomFixers( @@ -20,9 +20,10 @@ $config ] ) ->setRules( - (new PSR12Set())->getRules() + - (new PSR12RiskySet())->getRules() + [ + '@PSR12' => true, +// 'PSR12Risky', + // custom rules 'AdamWojs/phpdoc_force_fqcn_fixer' => true, From 648bc95da5c2d305c604abf8bf3d3f068ff4b217 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:41:09 -0500 Subject: [PATCH 29/79] phpstan, going to be a little bit of a rabbit hole... --- composer.json | 3 +- composer.lock | 60 +++++++++++++++++++- phpstan.neon | 5 ++ src/ACL/ACLAuthMethod.php | 36 ++++++++++-- src/ACL/ACLAuthMethodListEntry.php | 2 +- src/ACL/ACLAuthMethodNamespaceRule.php | 2 +- src/ACL/ACLBindingRule.php | 2 +- src/ACL/ACLEntry.php | 2 +- src/ACL/ACLLink.php | 2 +- src/ACL/ACLLoginParams.php | 2 +- src/ACL/ACLNodeIdentity.php | 2 +- src/ACL/ACLOIDCAuthURLParams.php | 2 +- src/ACL/ACLOIDCCallbackParams.php | 2 +- src/ACL/ACLPolicy.php | 2 +- src/ACL/ACLPolicyListEntry.php | 2 +- src/ACL/ACLReplicationStatus.php | 2 +- src/ACL/ACLRole.php | 2 +- src/ACL/ACLServiceIdentity.php | 2 +- src/ACL/ACLTemplatedPolicy.php | 2 +- src/ACL/ACLTemplatedPolicyVariables.php | 2 +- src/ACL/ACLToken.php | 2 +- src/ACL/ACLTokenExpanded.php | 2 +- src/ACL/ACLTokenListEntry.php | 2 +- src/ACL/KubernetesAuthMethodConfig.php | 2 +- src/ACL/OIDCAuthMethodConfig.php | 2 +- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentMember.php | 2 +- src/Agent/AgentService.php | 2 +- src/Agent/AgentServiceCheck.php | 2 +- src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 2 +- src/Agent/AgentServiceConnectProxyConfig.php | 2 +- src/Agent/AgentServiceRegistration.php | 2 +- src/Agent/AgentToken.php | 2 +- src/Agent/AgentWeights.php | 2 +- src/Agent/GaugeValue.php | 2 +- src/Agent/MemberOpts.php | 2 +- src/Agent/MetricsInfo.php | 2 +- src/Agent/PointValue.php | 2 +- src/Agent/SampledValue.php | 2 +- src/Agent/ServiceRegisterOpts.php | 2 +- src/Agent/Upstream.php | 2 +- src/Catalog/ServiceAddress.php | 2 +- src/ConfigEntry/EnvoyExtension.php | 2 +- src/ConfigEntry/MeshGatewayConfig.php | 2 +- src/ConfigEntry/TransparentProxyConfig.php | 2 +- src/Health/HealthCheckDefinition.php | 2 +- src/QueryOptions.php | 2 +- src/WriteOptions.php | 2 +- 49 files changed, 143 insertions(+), 51 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index abff10c1..b106011d 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ } }, "require-dev": { - "phpunit/phpunit": "^10.5 || ^11.0" + "phpunit/phpunit": "^10.5 || ^11.0", + "phpstan/phpstan": "~2.1.11" }, "autoload-dev": { "files": [ diff --git a/composer.lock b/composer.lock index ec3229c1..74de3870 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", @@ -941,6 +941,64 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.1.11", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30", + "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30", + "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-03-24T13:45:00+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.16", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..e05e39d2 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 6 + paths: + - src + - tests \ No newline at end of file diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index ac43b1dc..f7225134 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -32,21 +32,39 @@ class ACLAuthMethod extends AbstractModel public string $Description; public Time\Duration $MaxTokenTTL; 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; + /** + * @param array|null $data + * @param string $ID + * @param string $Name + * @param string $Type + * @param string $DisplayName + * @param string $Description + * @param int|float|string|\DateInterval|\DCarbone\Go\Time\Duration|null $MaxTokenTTL + * @param string $TokenLocality + * @param array|\stdClass $Config + * @param int $CreateIndex + * @param int $ModifyIndex + * @param iterable<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules + * @param string $Namespace + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Type = '', string $DisplayName = '', - string $Description = '', + string $Description = '', null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null, string $TokenLocality = '', + array|\stdClass $Config = [], int $CreateIndex = 0, int $ModifyIndex = 0, iterable $NamespaceRules = [], @@ -59,6 +77,7 @@ public function __construct( $this->Description = $Description; $this->setMaxTokenTTL($MaxTokenTTL); $this->TokenLocality = $TokenLocality; + $this->setConfig($Config); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->setNamespaceRules(...$NamespaceRules); @@ -145,14 +164,20 @@ public function setTokenLocality(string $TokenLocality): self return $this; } + /** + * @return array + */ public function getConfig(): array { return $this->config; } - public function setConfig(array $config): self + /** + * @param array|\stdClass $Config + */ + public function setConfig(array|\stdClass $Config): self { - $this->config = $config; + $this->config = (array)$Config; return $this; } @@ -178,6 +203,9 @@ public function setModifyIndex(int $ModifyIndex): self return $this; } + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule[] + */ public function getNamespaceRules(): array { return $this->NamespaceRules; @@ -208,7 +236,7 @@ public function setNamespace(string $Namespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { switch ($k) { case 'MaxTokenTTL': diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 8228ea57..a868f1cb 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -180,7 +180,7 @@ public function setNamespace(string $Namespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if (null === $v) { continue; diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 4252d82c..18e85591 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -63,7 +63,7 @@ public function setBindNamespace(string $BindNamespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index b9d62bd6..37e9f6b0 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -161,7 +161,7 @@ public function setNamespace(string $Namespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index d27c8e53..423a5fcc 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -119,7 +119,7 @@ public function setRules(string $rules): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index a8b638d1..a6d76c03 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -63,7 +63,7 @@ public function setName(string $Name): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index 1902aa27..ddd9dce2 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -80,7 +80,7 @@ public function setMeta(null|array|\stdClass $Meta): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 308b56fd..e894a411 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -51,7 +51,7 @@ public function getDatacenter(): string public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 93a026fd..28ba045a 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -95,7 +95,7 @@ public function setMeta(null|array|\stdClass $Meta): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 09ff38fb..438d4d19 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -91,7 +91,7 @@ public function setClientNonce(string $ClientNonce): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 730f8689..e5a3a62a 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -180,7 +180,7 @@ public function setPartition(string $Partition): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index c621df17..92d2fce0 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -161,7 +161,7 @@ public function setPartition(string $Partition): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 6da38a62..9981f0f5 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -100,7 +100,7 @@ public function getLastError(): Time\Time public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('LastSuccess' === $k) { $n->LastSuccess = Time\Time::createFromFormat(DATE_RFC3339, $v); diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index e348fa53..8f8eed27 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -219,7 +219,7 @@ public function setPartition(string $Partition): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 7688c87a..afde704a 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -61,7 +61,7 @@ public function setDatacenters(string ...$datacenters): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php index 089d0522..6db39783 100644 --- a/src/ACL/ACLTemplatedPolicy.php +++ b/src/ACL/ACLTemplatedPolicy.php @@ -77,7 +77,7 @@ public function setDatacenters(string ...$Datacenters): ACLTemplatedPolicy public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('TemplateVariables' === $k) { $n->setTemplateVariables($v); diff --git a/src/ACL/ACLTemplatedPolicyVariables.php b/src/ACL/ACLTemplatedPolicyVariables.php index d9f4eea9..c36c7cf2 100644 --- a/src/ACL/ACLTemplatedPolicyVariables.php +++ b/src/ACL/ACLTemplatedPolicyVariables.php @@ -44,7 +44,7 @@ public function setName(string $Name): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index 8f83f079..ee9ae18f 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -77,7 +77,7 @@ public function __construct( public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if (!$n->_jsonUnserializeField($k, $v, $n)) { $n->{$k} = $v; diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index c8b79446..d5bc981a 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -191,7 +191,7 @@ public function setResolvedByAgent(string $ResolvedByAgent): self public static function jsonUnserialize(\stdClass $decoded, null|ACLToken $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ($n->_jsonUnserializeField($k, $v, $n)) { continue; diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index f6e11471..e19bdc02 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -322,7 +322,7 @@ public function setAuthMethodNamespace(string $AuthMethodNamespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 9c81acdf..b65f54b4 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -92,7 +92,7 @@ public function RenderToConfig(): array public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index 439c5d60..601e4cd9 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -34,7 +34,7 @@ public function __construct( public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 45276866..79ec6341 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -193,7 +193,7 @@ public function setNamespace(string $Namespace): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Definition' === $k) { $n->Definition = HealthCheckDefinition::jsonUnserialize($v); diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 61709714..93ec5dea 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -145,7 +145,7 @@ public function IsConsulServer(): bool public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 80a5af2e..e4cb84a0 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -324,7 +324,7 @@ public function setLocality(null|Locality $Locality): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Tags' === $k) { $n->setTags(...$v); diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 888ec698..bf4e3a16 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -372,7 +372,7 @@ public function setDeregisterCriticalServiceAfter(string $deregisterCriticalServ public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 81afd5ee..88528352 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -78,7 +78,7 @@ public function setChecks(HealthChecks $Checks): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Checks' === $k) { $n->Checks = HealthChecks::jsonUnserialize($v); diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 8f479a03..94232c42 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -63,7 +63,7 @@ public function setSidecarService(AgentServiceRegistration $SidecarService): sel public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('SidecarService' === $k) { $n->SidecarService = AgentServiceRegistration::jsonUnserialize($v); diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 081e6fb4..22601ba2 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -237,7 +237,7 @@ public function setAccessLogs(null|AccessLogsConfig $AccessLogs): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('EnvoyExtensions' === $k) { foreach ($v as $vv) { diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index b96cc2ba..e5d0ab3d 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -281,7 +281,7 @@ public function setLocality(null|Locality $Locality): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Kind' === $k) { $n->setKind($v); diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index b0670c80..c5a5e837 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -49,7 +49,7 @@ public function setToken(string $Token): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index 8bd65d1b..ed2ed79e 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -51,7 +51,7 @@ public function getWarning(): int public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 986eb96d..7880cef0 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -77,7 +77,7 @@ public function setLabels(array|\stdClass $labels): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Labels' === $k) { $n->setLabels($v); diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index 4e66e592..2b820ff2 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -66,7 +66,7 @@ public function setSegment(string $segment): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index 1a4739c6..b13e5ddd 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -121,7 +121,7 @@ public function setSamples(SampledValue ...$samples): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Gauges' === $k) { foreach ($v as $vv) { diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 8104cc16..3cf026a3 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -67,7 +67,7 @@ public function setPoints(float ...$points): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index 19e6a311..7c6cc505 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -147,7 +147,7 @@ public function setLabels(array|\stdClass $labels): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Labels' === $k) { $n->setLabels($v); diff --git a/src/Agent/ServiceRegisterOpts.php b/src/Agent/ServiceRegisterOpts.php index 56f82c66..65d092f2 100644 --- a/src/Agent/ServiceRegisterOpts.php +++ b/src/Agent/ServiceRegisterOpts.php @@ -63,7 +63,7 @@ public function setToken(string $Token): ServiceRegisterOpts public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 2d1ae88e..6eb28314 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -218,7 +218,7 @@ public function setCentrallyConfigured(bool $CentrallyConfigured): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('DestinationType' === $k) { $n->setDestinationType($v); diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index d3da820a..3351e5fe 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -63,7 +63,7 @@ public function setPort(int $port): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index d79df56a..7c214962 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -105,7 +105,7 @@ public function setEnvoyVersion(string $EnvoyVersion): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Arguments' === $k) { $n->setArguments($v); diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 41f386ff..df1d8939 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -49,7 +49,7 @@ public function setMode(string|MeshGatewayMode $Mode): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Mode' === $k) { $n->setMode($v); diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index b1a582e2..3d25817e 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -63,7 +63,7 @@ public function setDialedDirectly(bool $DialedDirectly): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index d9168d61..75983ca4 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -165,7 +165,7 @@ public function setDeregisterCriticalServiceAfterDuration( public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Interval' === $k || 'IntervalDuration' === $k) { $n->IntervalDuration = Time::Duration($v); diff --git a/src/QueryOptions.php b/src/QueryOptions.php index b43709ff..11ffb3b0 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -362,7 +362,7 @@ public function apply(Request $r): void */ public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('MaxAge' === $k) { $n->MaxAge = Time::Duration($v); diff --git a/src/WriteOptions.php b/src/WriteOptions.php index 672d74a7..41c63840 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -128,7 +128,7 @@ public function apply(Request $r): void */ public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { - $n = $into ?? new static(); + $n = $into ?? new self(); foreach ($decoded as $k => $v) { if ('Timeout' === $k) { $n->Timeout = Time::Duration($v); From 47c6b15fc1daf284f72fe625242356f04dabbbb0 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:43:33 -0500 Subject: [PATCH 30/79] its late. --- phpunit.xml | 6 +++--- src/ACL/ACLAuthMethodListEntryQueryResponse.php | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 1f865e50..7b8e50b3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,9 +16,9 @@ ./tests/Usage/ConfigUsageTest.php - - ./tests/Usage/RequestUsageTest.php - + + + ./tests/Usage/ACL diff --git a/src/ACL/ACLAuthMethodListEntryQueryResponse.php b/src/ACL/ACLAuthMethodListEntryQueryResponse.php index 4f9fe503..268e6554 100644 --- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php +++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php @@ -28,6 +28,9 @@ class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse im /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry[] */ public array $ACLAuthMethodListEntries = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodListEntry[] + */ public function getValue(): array { return $this->ACLAuthMethodListEntries; From aaeba9044400494e93fca0aaaf6f122c4e8b8a22 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 14 Apr 2025 22:47:55 -0500 Subject: [PATCH 31/79] gotta fix acl with dev --- phpunit.xml | 6 +++--- tests/consul.hcl | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/consul.hcl diff --git a/phpunit.xml b/phpunit.xml index 7b8e50b3..4aeef048 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -20,9 +20,9 @@ - - ./tests/Usage/ACL - + + + ./tests/Usage/Agent diff --git a/tests/consul.hcl b/tests/consul.hcl new file mode 100644 index 00000000..a348735d --- /dev/null +++ b/tests/consul.hcl @@ -0,0 +1,7 @@ +acl { + enabled = true + default_policy = "allow" + tokens { + default = "123456" + } +} \ No newline at end of file From 040ae392a9e440120f8471d0a730424b8c59d920 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:28:51 -0500 Subject: [PATCH 32/79] stdclass are a pain to work with, but faster than fussing around with another FakeMap impl. --- src/ACL/ACLAuthMethod.php | 83 +++++----- src/Agent/AgentMember.php | 18 +- src/Agent/AgentService.php | 69 +++++--- src/Agent/AgentServiceCheck.php | 45 ++++- src/Agent/AgentServiceConnectProxyConfig.php | 32 +++- src/Agent/AgentServiceRegistration.php | 61 ++++--- src/Agent/ConnectProxyConfig.php | 164 +++++++++++++++++++ src/Agent/GaugeValue.php | 26 +-- src/Agent/SampledValue.php | 35 ++-- src/Agent/Upstream.php | 12 +- src/MapResponse.php | 4 + 11 files changed, 415 insertions(+), 134 deletions(-) create mode 100644 src/Agent/ConnectProxyConfig.php diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index f7225134..2780fe6e 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -25,79 +25,67 @@ class ACLAuthMethod extends AbstractModel { - public string $ID; public string $Name; public string $Type; public string $DisplayName; public string $Description; public Time\Duration $MaxTokenTTL; public string $TokenLocality; - /** @var array */ - public array $config; + public null|\stdClass $Config; public int $CreateIndex; public int $ModifyIndex; /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule[] */ public array $NamespaceRules; public string $Namespace; + public string $Partition; /** - * @param array|null $data - * @param string $ID + * @param array|null $data Deprecated, will be removed. * @param string $Name * @param string $Type * @param string $DisplayName * @param string $Description * @param int|float|string|\DateInterval|\DCarbone\Go\Time\Duration|null $MaxTokenTTL * @param string $TokenLocality - * @param array|\stdClass $Config + * @param null|\stdClass $Config * @param int $CreateIndex * @param int $ModifyIndex * @param iterable<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules * @param string $Namespace + * @param string $Partition */ public function __construct( null|array $data = null, // Deprecated, will be removed. - string $ID = '', string $Name = '', string $Type = '', string $DisplayName = '', string $Description = '', null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null, string $TokenLocality = '', - array|\stdClass $Config = [], + null|\stdClass $Config = null, int $CreateIndex = 0, int $ModifyIndex = 0, iterable $NamespaceRules = [], - string $Namespace = '' + string $Namespace = '', + string $Partition = '', ) { - $this->ID = $ID; $this->Name = $Name; $this->Type = $Type; $this->DisplayName = $DisplayName; $this->Description = $Description; $this->setMaxTokenTTL($MaxTokenTTL); $this->TokenLocality = $TokenLocality; - $this->setConfig($Config); + $this->Config = $Config; $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->setNamespaceRules(...$NamespaceRules); $this->Namespace = $Namespace; + $this->Partition = $Partition; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } } - public function getID(): string - { - return $this->ID; - } - - public function setID(string $ID): ACLAuthMethod - { - $this->ID = $ID; - return $this; - } - public function getName(): string { return $this->Name; @@ -164,20 +152,14 @@ public function setTokenLocality(string $TokenLocality): self return $this; } - /** - * @return array - */ - public function getConfig(): array + public function getConfig(): null|\stdClass { - return $this->config; + return $this->Config; } - /** - * @param array|\stdClass $Config - */ - public function setConfig(array|\stdClass $Config): self + public function setConfig(null|\stdClass $Config): self { - $this->config = (array)$Config; + $this->Config = $Config; return $this; } @@ -234,22 +216,30 @@ 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 static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static { $n = $into ?? new self(); foreach ($decoded as $k => $v) { - switch ($k) { - case 'MaxTokenTTL': - $n->setMaxTokenTTL($v); - break; - case 'NamespaceRules': - foreach ($v as $vv) { - $n->addNamespaceRule(ACLAuthMethodNamespaceRule::jsonUnserialize($vv)); - } - break; - - default: - $n->{$k} = $v; + if ('MaxTokenTTL' === $k) { + $n->setMaxTokenTTL($v); + } elseif ('NamespaceRules' === $k) { + $n->NamespaceRules = []; + foreach ($v as $vv) { + $n->NamespaceRules[] = ACLAuthMethodNamespaceRule::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; } } return $n; @@ -261,7 +251,6 @@ public function jsonSerialize(): \stdClass foreach ($this->_getDynamicFields() as $k => $v) { $out->{$k} = $v; } - $out->ID = $this->ID; $out->Name = $this->Name; if ('' !== $this->DisplayName) { $out->DisplayName = $this->DisplayName; @@ -275,6 +264,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->TokenLocality) { $out->TokenLocality = $this->TokenLocality; } + $out->Config = $this->Config; $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; if ([] !== $this->NamespaceRules) { @@ -283,6 +273,9 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; } + if ('' !== $this->Partition) { + $out->Partition = $this->Partition; + } return $out; } } diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 93ec5dea..95d29c69 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -28,7 +28,7 @@ class AgentMember extends AbstractModel public string $Name; public string $Addr; public int $Port; - public array $Tags; + public null|\stdClass $Tags; /** * Status of the Member which corresponds to github.com/hashicorp/serf/serf.MemberStatus * Value is one of: @@ -47,12 +47,26 @@ class AgentMember extends AbstractModel public int $DelegateMax; public int $DelegateCur; + /** + * @param array|null $data // Deprecated, will be removed. + * @param string $Name + * @param string $Addr + * @param int $Port + * @param \stdClass|null $Tags + * @param string $Status + * @param int $ProtocolMin + * @param int $ProtocolMax + * @param int $ProtocolCur + * @param int $DelegateMin + * @param int $DelegateMax + * @param int $DelegateCur + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Addr = '', int $Port = 0, - array $Tags = [], + null|\stdClass $Tags = null, string $Status = '', int $ProtocolMin = 0, int $ProtocolMax = 0, diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index e4cb84a0..52436cd9 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -29,13 +29,13 @@ class AgentService extends AbstractModel public string $Kind; public string $ID; public string $Service; + /** @var array */ public array $Tags; - public array $Meta; + public null|\stdClass $Meta; public int $Port; public string $Address; public string $SocketPath; - /** @var \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] */ - public array $TaggedAddresses; + public null|\stdClass $TaggedAddresses; public AgentWeights $Weights; public bool $EnableTagOverride; public int $CreateIndex; @@ -49,6 +49,30 @@ class AgentService extends AbstractModel public string $Datacenter; public null|Locality $Locality; + /** + * @param array |null $data Deprecated, will be removed. + * @param string $Kind + * @param string $ID + * @param string $Service + * @param string $SocketPath + * @param iterable $Tags + * @param \stdClass|null $Meta + * @param int $Port + * @param string $Address + * @param \stdClass|null $TaggedAddresses + * @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights + * @param bool $EnableTagOverride + * @param int $CreateIndex + * @param int $ModifyIndex + * @param string $ContentHash + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig|null $Proxy + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnect|null $Connect + * @param string $PeerName + * @param string $Namespace + * @param string $Partition + * @param string $Datacenter + * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Kind = '', @@ -56,10 +80,10 @@ public function __construct( string $Service = '', string $SocketPath = '', iterable $Tags = [], - array|\stdClass $Meta = [], + null|\stdClass $Meta = null, int $Port = 0, string $Address = '', - iterable $TaggedAddresses = [], + null|\stdClass $TaggedAddresses = null, null|AgentWeights $Weights = null, bool $EnableTagOverride = false, int $CreateIndex = 0, @@ -76,12 +100,12 @@ public function __construct( $this->Kind = $Kind; $this->ID = $ID; $this->Service = $Service; - $this->Meta = $Meta instanceof \stdClass ? (array)$Meta : $Meta; + $this->Meta = $Meta; $this->Port = $Port; $this->setTags(...$Tags); $this->Address = $Address; $this->SocketPath = $SocketPath; - $this->setTaggedAddresses(...$TaggedAddresses); + $this->setTaggedAddresses($TaggedAddresses); $this->Weights = $Weights ?? new AgentWeights(); $this->EnableTagOverride = $EnableTagOverride; $this->CreateIndex = $CreateIndex; @@ -132,6 +156,9 @@ public function setService(string $Service): self return $this; } + /** + * @return array + */ public function getTags(): array { return $this->Tags; @@ -143,14 +170,14 @@ public function setTags(string ...$Tags): self return $this; } - public function getMeta(): array + public function getMeta(): null|\stdClass { return $this->Meta; } - public function setMeta(array|\stdClass $Meta): self + public function setMeta(null|\stdClass $Meta): self { - $this->Meta = (array)$Meta; + $this->Meta = $Meta; return $this; } @@ -176,17 +203,21 @@ public function setAddress(string $Address): self return $this; } - /** - * @return \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] - */ - public function getTaggedAddresses(): array + public function getTaggedAddresses(): null|\stdClass { return $this->TaggedAddresses; } - public function setTaggedAddresses(ServiceAddress ...$TaggedAddresses): self + public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self { - $this->TaggedAddresses = $TaggedAddresses; + if (null === $TaggedAddresses) { + $this->TaggedAddresses = null; + return $this; + } + $this->TaggedAddresses = new \stdClass(); + foreacH($TaggedAddresses as $k => $v) { + $this->TaggedAddresses->{$k} = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize($v); + } return $this; } @@ -335,9 +366,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul } elseif ('Weights' === $k) { $n->Weights = AgentWeights::jsonUnserialize($v); } elseif ('TaggedAddresses' === $k) { - foreach ($v as $vv) { - $n->TaggedAddresses[] = ServiceAddress::jsonUnserialize($vv); - } + $n->settaggedAddresses($v); } elseif ('Connect' === $k) { $n->Connect = null === $v ? null : AgentServiceConnect::jsonUnserialize($v); } elseif ('Locality' === $k) { @@ -367,7 +396,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->SocketPath) { $out->SocketPath = $this->SocketPath; } - if ([] !== $this->TaggedAddresses) { + if (null !== $this->TaggedAddresses) { $out->TaggedAddresses = $this->TaggedAddresses; } $out->Weights = $this->Weights; diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index bf4e3a16..1640430d 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -26,6 +26,7 @@ class AgentServiceCheck extends AbstractModel { public string $CheckID; public string $Name; + /** @var string[] */ public array $ScriptArgs; public string $DockerContainerID; public string $Shell; @@ -33,7 +34,7 @@ class AgentServiceCheck extends AbstractModel public string $Timeout; public string $TTL; public string $HTTP; - public array $Header; + public null|\stdClass $Header; public string $Method; public string $TCP; public string $Status; @@ -49,6 +50,33 @@ class AgentServiceCheck extends AbstractModel public int $FailuresBeforeCritical; public string $DeregisterCriticalServiceAfter; + /** + * @param array|null $data // Deprecated, will be removed. + * @param string $CheckID + * @param string $Name + * @param iterable $ScriptArgs + * @param string $DockerContainerID + * @param string $Shell + * @param string $Interval + * @param string $Timeout + * @param string $TTL + * @param string $HTTP + * @param \stdClass|null $Header + * @param string $Method + * @param string $TCP + * @param string $Status + * @param string $Notes + * @param bool $TLSSkipVerify + * @param string $GRPC + * @param bool $GRPCUseTLS + * @param string $H2PING + * @param bool $H2PINGUseTLS + * @param string $AliasNode + * @param string $AliasService + * @param int $SuccessBeforePassing + * @param int $FailuresBeforeCritical + * @param string $DeregisterCriticalServiceAfter + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $CheckID = '', @@ -60,7 +88,7 @@ public function __construct( string $Timeout = '', string $TTL = '', string $HTTP = '', - array|\stdClass $Header = [], + null|\stdClass $Header = null, string $Method = '', string $TCP = '', string $Status = '', @@ -86,7 +114,7 @@ public function __construct( $this->Timeout = $Timeout; $this->TTL = $TTL; $this->HTTP = $HTTP; - $this->setHeader($Header); + $this->Header = $Header; $this->Method = $Method; $this->TCP = $TCP; $this->Status = $Status; @@ -128,6 +156,9 @@ public function setName(string $name): self return $this; } + /** + * @return array + */ public function getScriptArgs(): array { return $this->ScriptArgs; @@ -205,14 +236,14 @@ public function setHTTP(string $http): self return $this; } - public function getHeader(): array + public function getHeader(): null|\stdClass { return $this->Header; } - public function setHeader(array|\stdClass $Header): self + public function setHeader(null|\stdClass $Header): self { - $this->Header = (array)$Header; + $this->Header = $Header; return $this; } @@ -412,7 +443,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->HTTP) { $out->HTTP = $this->HTTP; } - if ([] !== $this->Header) { + if (null !== $this->Header) { $out->Header = $this->Header; } if ('' !== $this->Method) { diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 22601ba2..83a5d757 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -39,13 +39,29 @@ class AgentServiceConnectProxyConfig extends AbstractModel public string $LocalServiceSocketPath; public ProxyMode $Mode; public null|TransparentProxyConfig $TransparentProxy; - public array $Config; + public null|\stdClass $Config; /** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */ public array $Upstreams; public null|MeshGatewayConfig $MeshGateway; public null|ExposeConfig $Expose; public null|AccessLogsConfig $AccessLogs; + /** + * @param array|null $data + * @param iterable<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions + * @param string $DestinationServiceName + * @param string $DestinationServiceID + * @param string $LocalServiceAddress + * @param int $LocalServicePort + * @param string $LocalServiceSocketPath + * @param string|\DCarbone\PHPConsulAPI\ConfigEntry\ProxyMode $Mode + * @param \DCarbone\PHPConsulAPI\ConfigEntry\TransparentProxyConfig|null $TransparentProxy + * @param null|\stdClass $Config + * @param iterable<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams + * @param \DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig|null $MeshGateway + * @param \DCarbone\PHPConsulAPI\ConfigEntry\ExposeConfig|null $Expose + * @param \DCarbone\PHPConsulAPI\ConfigEntry\AccessLogsConfig|null $AccessLogs + */ public function __construct( null|array $data = [], // Deprecated, will be removed. iterable $EnvoyExtensions = [], @@ -56,7 +72,7 @@ public function __construct( string $LocalServiceSocketPath = '', string|ProxyMode $Mode = ProxyMode::Default, null|TransparentProxyConfig $TransparentProxy = null, - null|array|\stdClass $Config = null, + null|\stdClass $Config = null, iterable $Upstreams = [], null|MeshGatewayConfig $MeshGateway = null, null|ExposeConfig $Expose = null, @@ -67,7 +83,7 @@ public function __construct( $this->DestinationServiceID = $DestinationServiceID; $this->LocalServiceAddress = $LocalServiceAddress; $this->LocalServicePort = $LocalServicePort; - $this->Config = null === $Config ? null : (array)$Config; + $this->Config = $Config; $this->LocalServiceSocketPath = $LocalServiceSocketPath; $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode); $this->TransparentProxy = $TransparentProxy; @@ -177,14 +193,14 @@ public function setTransparentProxy(null|TransparentProxyConfig $TransparentProx return $this; } - public function getConfig(): array + public function getConfig(): null|\stdClass { return $this->Config; } - public function setConfig(array|\stdClass $Config): self + public function setConfig(null|\stdClass $Config): self { - $this->Config = (array)$Config; + $this->Config = $Config; return $this; } @@ -247,8 +263,6 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul $n->setMode($v); } elseif ('TransparentProxy' === $k) { $n->TransparentProxy = TransparentProxyConfig::jsonUnserialize($v); - } elseif ('Config' === $k) { - $n->Config = (array)$v; } elseif ('Upstreams' === $k) { foreach ($v as $vv) { $n->Upstreams[] = Upstream::jsonUnserialize($vv); @@ -287,7 +301,7 @@ public function jsonSerialize(): \stdClass if (0 !== $this->LocalServicePort) { $out->LocalServicePort = $this->LocalServicePort; } - if ([] !== $this->Config) { + if (null !== $this->Config) { $out->Config = $this->Config; } if ('' !== $this->LocalServiceSocketPath) { diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index e5d0ab3d..4ba46dbd 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -29,12 +29,13 @@ class AgentServiceRegistration extends AbstractModel public ServiceKind $Kind; public string $ID; public string $Name; + /** @var string[] */ public array $Tags; public int $Port; public string $Address; - public array $TaggedAddresses; + public null|\stdClass $TaggedAddresses; public bool $EnableTagOverride; - public array $Meta; + public null|\stdClass $Meta; public null|AgentWeights $Weights; public null|AgentServiceCheck $Check; public AgentServiceChecks $Checks; @@ -44,6 +45,26 @@ class AgentServiceRegistration extends AbstractModel public string $Partition; public null|Locality $Locality; + /** + * @param array|null $data + * @param string|\DCarbone\PHPConsulAPI\Agent\ServiceKind $Kind + * @param string $ID + * @param string $Name + * @param iterable $Tags + * @param int $Port + * @param string $Address + * @param \stdClass|null $TaggedAddresses + * @param bool $EnableTagOverride + * @param \stdClass|null $Meta + * @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck|null $Check + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceChecks|null $Checks + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig|null $Proxy + * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnect|null $Connect + * @param string $Namespace + * @param string $Partition + * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality + */ public function __construct( null|array $data = null, string|ServiceKind $Kind = ServiceKind::Typical, @@ -52,9 +73,9 @@ public function __construct( iterable $Tags = [], int $Port = 0, string $Address = '', - array|\stdClass $TaggedAddresses = [], + null|\stdClass $TaggedAddresses = null, bool $EnableTagOverride = false, - array|\stdClass $Meta = [], + null|\stdClass $Meta = null, null|AgentWeights $Weights = null, null|AgentServiceCheck $Check = null, null|AgentServiceChecks $Checks = null, @@ -72,7 +93,7 @@ public function __construct( $this->Address = $Address; $this->setTaggedAddresses($TaggedAddresses); $this->EnableTagOverride = $EnableTagOverride; - $this->setMeta($Meta); + $this->Meta = $Meta; $this->Weights = $Weights; $this->Check = $Check; $this->Checks = $Checks ?? new AgentServiceChecks(); @@ -119,6 +140,9 @@ public function setName(string $Name): self return $this; } + /** + * @return string[] + */ public function getTags(): array { return $this->Tags; @@ -152,19 +176,20 @@ public function setAddress(string $Address): self return $this; } - /** - * @return \DCarbone\PHPConsulAPI\Catalog\ServiceAddress[] - */ - public function getTaggedAddresses(): array + public function getTaggedAddresses(): \stdClass { return $this->TaggedAddresses; } - public function setTaggedAddresses(array|\stdClass $TaggedAddresses): self + public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self { - $this->TaggedAddresses = []; + if (null === $TaggedAddresses) { + $this->TaggedAddresses = null; + return $this; + } + $this->TaggedAddresses = new \stdClass(); foreach ($TaggedAddresses as $k => $v) { - $this->TaggedAddresses[$k] = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize((object)$v); + $this->TaggedAddresses->{$k} = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize((object)$v); } return $this; } @@ -180,14 +205,14 @@ public function setEnableTagOverride(bool $EnableTagOverride): self return $this; } - public function getMeta(): array + public function getMeta(): null|\stdClass { return $this->Meta; } - public function setMeta(array|\stdClass $Meta): self + public function setMeta(null|\stdClass $Meta): self { - $this->Meta = (array)$Meta; + $this->Meta = $Meta; return $this; } @@ -289,8 +314,6 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul $n->setTags(...$v); } elseif ('TaggedAddresses' === $k) { $n->setTaggedAddresses($v); - } elseif ('Meta' === $k) { - $n->setMeta($v); } elseif ('Weights' === $k) { $n->Weights = AgentWeights::jsonUnserialize($v); } elseif ('Check' === $k) { @@ -334,13 +357,13 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Address) { $out->Address = $this->Address; } - if ([] !== $this->TaggedAddresses) { + if (null !== $this->TaggedAddresses) { $out->TaggedAddresses = $this->TaggedAddresses; } if ($this->EnableTagOverride) { $out->EnableTagOverride = $this->EnableTagOverride; } - if ([] !== $this->Meta) { + if (null !== $this->Meta) { $out->Meta = $this->Meta; } if (null !== $this->Weights) { diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php new file mode 100644 index 00000000..37430db4 --- /dev/null +++ b/src/Agent/ConnectProxyConfig.php @@ -0,0 +1,164 @@ + */ + public array $Upstreams; + + /** + * @param array|null $data // Deprecated, will be removed. + * @param string $ProxyServiceID + * @param string $TargetServiceID + * @param string $TargetServiceName + * @param string $ContentHash + * @param \stdClass|null $Config + * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $ProxyServiceID = '', + string $TargetServiceID = '', + string $TargetServiceName = '', + string $ContentHash = '', + null|\stdClass $Config = null, + array $Upstreams = [], + ) { + $this->ProxyServiceID = $ProxyServiceID; + $this->TargetServiceID = $TargetServiceID; + $this->TargetServiceName = $TargetServiceName; + $this->ContentHash = $ContentHash; + $this->Config = $Config; + $this->setUpstreams(...$Upstreams); + + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + + 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; + } + + public function getConfig(): null|\stdClass + { + return $this->Config; + } + + public function setConfig(?\stdClass $Config): self + { + $this->Config = $Config; + 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Upstreams' === $k) { + $n->Upstreams = []; + foreach ($v as $vv) { + $n->Upstreams[] = Upstream::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ProxyServiceID = $this->ProxyServiceID; + $out->TargetServiceID = $this->TargetServiceID; + $out->TargetServiceName = $this->TargetServiceName; + $out->ContentHash = $this->ContentHash; + $out->Config = $this->Config; + $out->Upstreams = $this->Upstreams; + return $out; + } +} diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 7880cef0..25513169 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -26,17 +26,23 @@ class GaugeValue extends AbstractModel { public string $Name; public float $Value; - public array $Labels; - + public null|\stdClass $Labels; + + /** + * @param array|null $data + * @param string $Name + * @param float $Value + * @param \stdClass|null $Labels + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Name = '', float $Value = 0.0, - array|\stdClass $Labels = [], + null|\stdClass $Labels = null, ) { $this->Name = $Name; $this->Value = $Value; - $this->setLabels($Labels); + $this->Labels = $Labels; if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -64,14 +70,14 @@ public function setValue(float $value): self return $this; } - public function getLabels(): array + public function getLabels(): null|\stdClass { return $this->Labels; } - public function setLabels(array|\stdClass $labels): self + public function setLabels(null|\stdClass $Labels): self { - $this->Labels = (array)$labels; + $this->Labels = $Labels; return $this; } @@ -79,11 +85,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul { $n = $into ?? new self(); foreach ($decoded as $k => $v) { - if ('Labels' === $k) { - $n->setLabels($v); - } else { - $n->{$k} = $v; - } + $n->{$k} = $v; } return $n; } diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index 7c6cc505..0373c302 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -31,8 +31,19 @@ class SampledValue extends AbstractModel public float $Max; public float $Mean; public float $Stddev; - public array $Labels; - + public null|\stdClass $Labels; + + /** + * @param array|null $data Deprecated, will be removed. + * @param string $Name + * @param int $Count + * @param float $Sum + * @param float $Min + * @param float $Max + * @param float $Mean + * @param float $Stddev + * @param \stdClass|null $Labels + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Name = '', @@ -42,7 +53,7 @@ public function __construct( float $Max = 0.0, float $Mean = 0.0, float $Stddev = 0.0, - array|\stdClass $Labels = [], + null|\stdClass $Labels = null, ) { $this->Name = $Name; $this->Count = $Count; @@ -51,7 +62,7 @@ public function __construct( $this->Max = $Max; $this->Mean = $Mean; $this->Stddev = $Stddev; - $this->setLabels($Labels); + $this->Labels = $Labels ?? new \stdClass(); if (null !== $data && [] !== $data) { $this->jsonUnserialize((object)$data, $this); } @@ -128,20 +139,20 @@ public function getStddev(): float return $this->Stddev; } - public function setStddev(float $Stddev): self + public function setStddev(float $stddev): self { - $this->Stddev = $Stddev; + $this->Stddev = $stddev; return $this; } - public function getLabels(): array + public function getLabels(): null|\stdClass { return $this->Labels; } - public function setLabels(array|\stdClass $labels): self + public function setLabels(null|\stdClass $labels): self { - $this->Labels = (array)$labels; + $this->Labels = $labels ?? new \stdClass(); return $this; } @@ -149,11 +160,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul { $n = $into ?? new self(); foreach ($decoded as $k => $v) { - if ('Labels' === $k) { - $n->setLabels($v); - } else { - $n->{$k} = $v; - } + $n->{$k} = $v; } return $n; } diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 6eb28314..cbe48a63 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -35,7 +35,7 @@ class Upstream extends AbstractModel public int $LocalBindPort; public string $LocalBindSocketPath; public string $LocalBindSocketMode; - public array $Config; + public null|\stdClass $Config; public null|MeshGatewayConfig $MeshGateway; public bool $CentrallyConfigured; @@ -51,7 +51,7 @@ public function __construct( int $LocalBindPort = 0, string $LocalBindSocketPath = '', string $LocalBindSocketMode = '', - array|\stdClass $Config = [], + null|\stdClass $Config = null, null|MeshGatewayConfig $MeshGateway = null, bool $CentrallyConfigured = false, ) { @@ -65,7 +65,7 @@ public function __construct( $this->LocalBindPort = $LocalBindPort; $this->LocalBindSocketPath = $LocalBindSocketPath; $this->LocalBindSocketMode = $LocalBindSocketMode; - $this->setConfig($Config); + $this->Config = $Config; $this->MeshGateway = $MeshGateway; $this->CentrallyConfigured = $CentrallyConfigured; if (null !== $data && [] !== $data) { @@ -183,12 +183,12 @@ public function setLocalBindSocketMode(string $LocalBindSocketMode): self return $this; } - public function getConfig(): array + public function getConfig(): null|\stdClass { return $this->Config; } - public function setConfig(array $Config): self + public function setConfig(null|\stdClass $Config): self { $this->Config = $Config; return $this; @@ -265,7 +265,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->LocalBindSocketMode) { $out->LocalBindSocketMode = $this->LocalBindSocketMode; } - if ([] !== $this->Config) { + if (null !== $this->Config) { $out->Config = $this->Config; } if (null !== $this->MeshGateway) { diff --git a/src/MapResponse.php b/src/MapResponse.php index 7e805483..05b45a3e 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -22,8 +22,12 @@ class MapResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { + /** @var array|null */ public null|array $Map = null; + /** + * @return array|null + */ public function getValue(): null|array { return $this->Map; From 2be67f0fa53d659452a9e89822a3e9870dc15b24 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:35:08 -0500 Subject: [PATCH 33/79] objects --- src/Agent/AgentClient.php | 4 ++-- src/MapResponse.php | 14 +++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index e79086c8..2bc90f40 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -76,8 +76,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, $self->Map->Config->NodeName)) { + $ret->Value = $self->Map->Config->NodeName; } return $ret; } diff --git a/src/MapResponse.php b/src/MapResponse.php index 05b45a3e..4425a4f1 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -22,23 +22,15 @@ class MapResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - /** @var array|null */ - public null|array $Map = null; + public null|\stdClass $Map = null; - /** - * @return array|null - */ - public function getValue(): null|array + public function getValue(): null|\stdClass { return $this->Map; } public function unmarshalValue(mixed $decoded): void { - if (null === $decoded) { - $this->Map = null; - return; - } - $this->Map = (array)$decoded; + $this->Map = $decoded; } } From 5a5cbd829abea4e982acbd0f838e92299fab1345 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:38:21 -0500 Subject: [PATCH 34/79] more werk --- src/Agent/AgentServicesResponse.php | 14 +++++++++----- tests/Usage/Agent/AgentClientTest.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Agent/AgentServicesResponse.php b/src/Agent/AgentServicesResponse.php index 14391dac..852a88bb 100644 --- a/src/Agent/AgentServicesResponse.php +++ b/src/Agent/AgentServicesResponse.php @@ -25,18 +25,22 @@ class AgentServicesResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?array $Services = null; + public null|\stdClass $Services = null; - public function getValue(): ?array + public function getValue(): null|\stdClass { return $this->Services; } public function unmarshalValue(mixed $decoded): void { - $this->Services = []; - foreach ($decoded as $k => $service) { - $this->Services[$k] = new AgentService($service); + if (null === $decoded) { + $this->Services = null; + return; + } + $this->Services = new \stdClass(); + foreach ($decoded as $k => $v) { + $this->Services->{$k} = AgentService::jsonUnserialize($v); } } } diff --git a/tests/Usage/Agent/AgentClientTest.php b/tests/Usage/Agent/AgentClientTest.php index dd7fa486..1ff636b8 100644 --- a/tests/Usage/Agent/AgentClientTest.php +++ b/tests/Usage/Agent/AgentClientTest.php @@ -54,7 +54,7 @@ public function testCanGetSelf(): void [$self, $err] = $client->Self(); self::assertNull($err); - self::assertIsArray( + self::assertIsObject( $self, sprintf( 'Expected AgentClient::self to return array, saw "%s"', From 6dfbd9bc5b21f261100f4d66ea62a6165f7bece1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:39:33 -0500 Subject: [PATCH 35/79] test fixups --- tests/Usage/Agent/AgentClientTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Usage/Agent/AgentClientTest.php b/tests/Usage/Agent/AgentClientTest.php index 1ff636b8..a7040052 100644 --- a/tests/Usage/Agent/AgentClientTest.php +++ b/tests/Usage/Agent/AgentClientTest.php @@ -153,11 +153,11 @@ public function testCanGetServiceList(): void try { self::assertNull($err, sprintf('AgentClient::services return error: %s', $err)); - self::assertIsArray($svcs); - self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); + self::assertIsObject($svcs); + self::assertContainsOnlyInstancesOf(AgentService::class, (array)$svcs); // NOTE: will always contain "consul" service - self::assertCount(2, $svcs); + self::assertCount(2, (array)$svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; var_dump($svcs); @@ -181,9 +181,9 @@ public function testCanDeregisterService(): void try { self::assertNull($err, sprintf('AgentClient::services returned error: %s', $err)); - self::assertIsArray($svcs); - self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); - self::assertCount(1, $svcs); + self::assertIsObject($svcs); + self::assertContainsOnlyInstancesOf(AgentService::class, (array)$svcs); + self::assertCount(1, (array)$svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; var_dump($svcs); @@ -219,9 +219,9 @@ public function testCanRegisterServiceWithCheck(): void try { self::assertNull($err, sprintf('AgentClient::services returned error: %s', $err)); - self::assertIsArray($svcs); - self::assertContainsOnlyInstancesOf(AgentService::class, $svcs); - self::assertCount(2, $svcs); + self::assertIsObject($svcs); + self::assertContainsOnlyInstancesOf(AgentService::class, (array)$svcs); + self::assertCount(2, (array)$svcs); } catch (AssertionFailedError $e) { echo "\nservices list:\n"; var_dump($svcs); From 6c437e46ae4d692f62ba310111a3cd95cbffaeab Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:42:27 -0500 Subject: [PATCH 36/79] AgentMember fixes --- src/Agent/AgentMember.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 95d29c69..8f53b40b 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -37,9 +37,9 @@ class AgentMember extends AbstractModel * AgentMemberLeaving = 2 * AgentMemberLeft = 3 * AgentMemberFailed = 4 - * @var string + * @var int */ - public string $Status; + public int $Status; public int $ProtocolMin; public int $ProtocolMax; public int $ProtocolCur; @@ -53,7 +53,7 @@ class AgentMember extends AbstractModel * @param string $Addr * @param int $Port * @param \stdClass|null $Tags - * @param string $Status + * @param int $Status * @param int $ProtocolMin * @param int $ProtocolMax * @param int $ProtocolCur @@ -67,7 +67,7 @@ public function __construct( string $Addr = '', int $Port = 0, null|\stdClass $Tags = null, - string $Status = '', + int $Status = 0, int $ProtocolMin = 0, int $ProtocolMax = 0, int $ProtocolCur = 0, @@ -106,7 +106,7 @@ public function getPort(): int return $this->Port; } - public function getStatus(): string + public function getStatus(): int { return $this->Status; } From 707ce4062741445d520767e159a09d59bcfa182f Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 15 Apr 2025 20:48:23 -0500 Subject: [PATCH 37/79] bleh... --- tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php b/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php index a2ca1640..89f38180 100644 --- a/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php +++ b/tests/Usage/Agent/AgentServiceConnectProxyConfigTest.php @@ -26,17 +26,17 @@ class AgentServiceConnectProxyConfigTest extends AbstractUsageTests { public function test_construct_givenConfig_willUnmarshalConfigValuesSuccessfully() { - $config = new AgentServiceConnectProxyConfig([ - 'Config' => [ + $config = new AgentServiceConnectProxyConfig( + Config: (object)[ 'envoy_prometheus_bind_addr' => '0.0.0.0:12345', 'handshake_timeout_ms' => 10000, 'local_connect_timeout_ms' => 1000, 'local_request_timeout_ms' => 0, 'protocol' => 'http', ], - ]); + ); - $this->assertEquals([ + $this->assertEquals((object)[ 'envoy_prometheus_bind_addr' => '0.0.0.0:12345', 'handshake_timeout_ms' => 10000, 'local_connect_timeout_ms' => 1000, From a170dab52d986e3d5efb2e1c00c3239c539ca7a1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 16 Apr 2025 20:48:46 -0500 Subject: [PATCH 38/79] less stupid, but its still stupid. --- src/HttpAuth.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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; } } From 1394fb5712706cbde67027a7fdecc992d43717e2 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 16 Apr 2025 20:54:45 -0500 Subject: [PATCH 39/79] small cleanup --- src/QueryOptions.php | 29 ++++++++++++----------------- src/ResponseValueBoolTrait.php | 4 ++-- src/Values.php | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 11ffb3b0..ab7bd1ac 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -47,7 +47,7 @@ class QueryOptions implements RequestOptions public bool $Pretty; public function __construct( - array $data = [], // Deprecated do not use. + null|array $data = null, // Deprecated do not use. string $Namespace = '', string $Datacenter = '', bool $AllowStale = false, @@ -68,10 +68,6 @@ public function __construct( null|int|float|string|\DateInterval|Time\Duration $Timeout = null, bool $Pretty = false, ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Namespace = $Namespace; $this->Datacenter = $Datacenter; $this->AllowStale = $AllowStale; @@ -91,6 +87,9 @@ public function __construct( $this->Connect = $Connect; $this->Timeout = Time::Duration($Timeout); $this->Pretty = $Pretty; + if (null !== $data && [] !== $data) { + $this->_fromMap((object)$data); + } } public function getNamespace(): string @@ -355,27 +354,23 @@ public function apply(Request $r): void } /** - * @param \stdClass $decoded - * @param \DCarbone\PHPConsulAPI\QueryOptions|null $into - * @return self + * @param \stdClass $data * @deprecated This is only here to support construction with map. It will be removed in a future version. */ - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + private function _fromMap(\stdClass $data): void { - $n = $into ?? new self(); - foreach ($decoded as $k => $v) { + foreach ($data as $k => $v) { if ('MaxAge' === $k) { - $n->MaxAge = Time::Duration($v); + $this->MaxAge = Time::Duration($v); } elseif ('StaleIfError' === $k) { - $n->StaleIfError = Time::Duration($v); + $this->StaleIfError = Time::Duration($v); } elseif ('WaitTime' === $k) { - $n->WaitTime = Time::Duration($v); + $this->WaitTime = Time::Duration($v); } elseif ('Timeout' === $k) { - $n->Timeout = Time::Duration($v); + $this->Timeout = Time::Duration($v); } else { - $n->{$k} = $v; + $this->{$k} = $v; } } - return $n; } } diff --git a/src/ResponseValueBoolTrait.php b/src/ResponseValueBoolTrait.php index a38c9dfc..8741df78 100644 --- a/src/ResponseValueBoolTrait.php +++ b/src/ResponseValueBoolTrait.php @@ -36,7 +36,7 @@ public function unmarshalValue(mixed $decoded): void return; } if (is_string($decoded)) { - $this->Value = Transcoding::TRUE === strtolower(trim($decoded)); + $this->Value = 'true' === strtolower(trim($decoded)); return; } $this->Value = (bool)$decoded; @@ -44,6 +44,6 @@ public function unmarshalValue(mixed $decoded): void public function __toString(): string { - return $this->Value ? Transcoding::TRUE : Transcoding::FALSE; + return $this->Value ? 'true' : 'false'; } } diff --git a/src/Values.php b/src/Values.php index 23e382f8..3d2b60fb 100644 --- a/src/Values.php +++ b/src/Values.php @@ -120,7 +120,7 @@ public function __toString(): string if ('' === $v) { $str .= $k; } else { - $str .= sprintf('%s=%s', $k, $this->encode($v)); + $str .= "{$k}={$this->encode($v)}"; } } } From c68166b848945389495c5153ce386305b14a364d Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 16 Apr 2025 21:16:29 -0500 Subject: [PATCH 40/79] more cleanup --- README.md | 4 +++- src/QueryMeta.php | 4 ++-- src/QueryOptions.php | 10 +++++----- src/WriteOptions.php | 25 ++++++++++--------------- tests/Usage/RequestUsageTest.php | 4 ++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b87b90f7..e815ef66 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,9 @@ There are a couple breaking changes between v2 and v3: 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 `Config` class may no longer be constructed with a map. You must use constructor parameters. +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) diff --git a/src/QueryMeta.php b/src/QueryMeta.php index 97d4ccb3..96d3760b 100644 --- a/src/QueryMeta.php +++ b/src/QueryMeta.php @@ -36,14 +36,14 @@ class QueryMeta public function __construct( string $RequestUrl, - null|int|float|string|\DateInterval|Time\Duration $RequestTime, + null|Time\Duration $RequestTime, int $LastIndex = 0, string $LastContentHash = '', int $LastContact = 0, bool $KnownLeader = false, bool $AddressTranslationEnabled = false, bool $CacheHit = false, - null|int|float|string|\DateInterval|Time\Duration $CacheAge = null + null|Time\Duration $CacheAge = null ) { $this->RequestUrl = $RequestUrl; $this->RequestTime = Time::Duration($RequestTime); diff --git a/src/QueryOptions.php b/src/QueryOptions.php index ab7bd1ac..7360de01 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -37,7 +37,7 @@ class QueryOptions implements RequestOptions public string $Token; public string $Near; public string $Filter; - public array $NodeMeta; + public null|\stdClass $NodeMeta; public int $RelayFactor; public bool $LocalOnly; public bool $Connect; @@ -61,7 +61,7 @@ public function __construct( string $Token = '', string $Near = '', string $Filter = '', - array $NodeMeta = [], + null|\stdClass $NodeMeta = null, int $RelayFactor = 0, bool $LocalOnly = false, bool $Connect = false, @@ -222,12 +222,12 @@ public function setFilter(string $filter): void $this->Filter = $filter; } - public function getNodeMeta(): array + public function getNodeMeta(): null|\stdClass { return $this->NodeMeta; } - public function setNodeMeta(array $nodeMeta): void + public function setNodeMeta(null|\stdClass $nodeMeta): void { $this->NodeMeta = $nodeMeta; } @@ -314,7 +314,7 @@ public function apply(Request $r): void if ('' !== $this->Filter) { $r->params->set('filter', $this->Filter); } - if ([] !== $this->NodeMeta) { + if (null !== $this->NodeMeta) { foreach ($this->NodeMeta as $k => $v) { $r->params->add('node-meta', "{$k}:{$v}"); } diff --git a/src/WriteOptions.php b/src/WriteOptions.php index 41c63840..f659b0ad 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -32,22 +32,21 @@ class WriteOptions implements RequestOptions public Time\Duration $Timeout; public function __construct( - array $data = [], // Deprecated do not use. + null|array $data = null, // Deprecated do not use. string $Namespace = '', string $Datacenter = '', string $Token = '', int $RelayFactor = 0, null|int|float|string|\DateInterval|Time\Duration $Timeout = null, ) { - if ([] !== $data) { - $this->jsonUnserialize((object)$data, $this); - return; - } $this->Namespace = $Namespace; $this->Datacenter = $Datacenter; $this->Token = $Token; $this->RelayFactor = $RelayFactor; $this->Timeout = Time::Duration($Timeout); + if (null !== $data && [] !== $data) { + $this->_fromMap((object)$data); + } } public function getNamespace(): string @@ -112,7 +111,7 @@ public function apply(Request $r): void $r->header->set('X-Consul-Token', $this->Token); } if (0 !== $this->RelayFactor) { - $r->params->set('relay-factor', (string) $this->RelayFactor); + $r->params->set('relay-factor', (string)$this->RelayFactor); } if (0 < $this->Timeout->Nanoseconds()) { @@ -121,21 +120,17 @@ public function apply(Request $r): void } /** - * @param \stdClass $decoded - * @param \DCarbone\PHPConsulAPI\WriteOptions|null $into - * @return self + * @param \stdClass $data * @deprecated This is only here to support construction with map. It will be removed in a future version. */ - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + private function _fromMap(\stdClass $data): void { - $n = $into ?? new self(); - foreach ($decoded as $k => $v) { + foreach ($data as $k => $v) { if ('Timeout' === $k) { - $n->Timeout = Time::Duration($v); + $this->Timeout = Time::Duration($v); } else { - $n->{$k} = $v; + $this->{$k} = $v; } } - return $n; } } diff --git a/tests/Usage/RequestUsageTest.php b/tests/Usage/RequestUsageTest.php index 2e0bc48a..35c04223 100644 --- a/tests/Usage/RequestUsageTest.php +++ b/tests/Usage/RequestUsageTest.php @@ -79,7 +79,7 @@ public function testCanCreatePsr7Request(): void public function testCanSetQueryOptions(): void { $r = new Request('GET', 'kv', ConsulManager::testConfig(), null); - $r->applyOptions(new QueryOptions(['Pretty' => true])); + $r->applyOptions(new QueryOptions(Pretty: true)); $psr7 = $r->toPsrRequest(); $uri = $psr7->getUri(); @@ -92,7 +92,7 @@ public function testCanSetQueryOptions(): void public function testCanSetWriteOptions(): void { $r = new Request('GET', 'kv', ConsulManager::testConfig(), null); - $r->applyOptions(new WriteOptions(['Datacenter' => 'dc1'])); + $r->applyOptions(new WriteOptions(Datacenter: 'dc1')); $psr7 = $r->toPsrRequest(); $uri = $psr7->getUri(); From 4f289c01b243568aeb07d210be5a5dc930294d8c Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 16 Apr 2025 21:29:06 -0500 Subject: [PATCH 41/79] some enums and cleanup --- src/Consul.php | 28 --------------------- src/DecodedBody.php | 2 +- src/Error.php | 7 ++---- src/Operator/AutopilotServerStatus.php | 30 ++++++++++++++++++++++ src/Operator/AutopilotServerType.php | 30 ++++++++++++++++++++++ src/Operator/AutopilotUpgradeStatus.php | 33 +++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 src/Operator/AutopilotServerStatus.php create mode 100644 src/Operator/AutopilotServerType.php create mode 100644 src/Operator/AutopilotUpgradeStatus.php diff --git a/src/Consul.php b/src/Consul.php index bdddea53..e82d8de2 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -73,34 +73,6 @@ class Consul public const SessionBehaviorRelease = 'release'; public const SessionBehaviorDelete = 'delete'; - 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'; diff --git a/src/DecodedBody.php b/src/DecodedBody.php index da120b52..068a2ac0 100644 --- a/src/DecodedBody.php +++ b/src/DecodedBody.php @@ -26,7 +26,7 @@ final class DecodedBody public mixed $Decoded = null; - public function __construct(mixed $decoded, ?Error $err) + public function __construct(mixed $decoded, null|Error $err) { $this->Decoded = $decoded; $this->Err = $err; diff --git a/src/Error.php b/src/Error.php index ce2cd9d8..d84620aa 100644 --- a/src/Error.php +++ b/src/Error.php @@ -29,9 +29,6 @@ */ class Error implements \JsonSerializable { - private const FIELD_MESSAGE = 'message'; - private const FIELD_TIMESTAMP = 'timestamp'; - private Time\Time $time; private string $message; @@ -67,8 +64,8 @@ public function getMessage(): string public function jsonSerialize(): array { return [ - self::FIELD_MESSAGE => $this->message, - self::FIELD_TIMESTAMP => $this->time, + 'message' => $this->message, + 'timestamp' => $this->time, ]; } diff --git a/src/Operator/AutopilotServerStatus.php b/src/Operator/AutopilotServerStatus.php new file mode 100644 index 00000000..b732d9e3 --- /dev/null +++ b/src/Operator/AutopilotServerStatus.php @@ -0,0 +1,30 @@ + Date: Wed, 16 Apr 2025 21:52:42 -0500 Subject: [PATCH 42/79] starting on catalog... --- src/Catalog/CatalogDeregistration.php | 96 +++++++++++++++++-- src/Catalog/CatalogNode.php | 76 +++++++++++---- src/Catalog/CatalogNodeResponse.php | 10 +- src/Catalog/CatalogNodeServiceList.php | 74 ++++++++++---- .../CatalogNodeServicesListResponse.php | 10 +- 5 files changed, 210 insertions(+), 56 deletions(-) diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 22ded7c4..0996cfd1 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -21,23 +21,48 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class CatalogDeregistration extends AbstractModel { - 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 $Namespace; + public string $Partition; + + /** + * @param array|null $data + * @param string $Node + * @param string $Address + * @param string $Datacenter + * @param string $ServiceID + * @param string $CheckID + * @param string $Namespace + * @param string $Partition + */ + public function __construct( + null|array $data = null, // Deprecated, do not use + 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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getNode(): string { @@ -93,4 +118,57 @@ 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->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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 ac428358..47e6d6f1 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -22,29 +22,30 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Agent\AgentService; -use DCarbone\PHPConsulAPI\Transcoding; class CatalogNode extends AbstractModel { - 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; + public null|\stdClass $Services; - private const FIELD_NODE = 'Node'; - private const FIELD_SERVICES = 'Services'; - - public ?Node $Node = null; - public array $Services; + /** + * @param array|null $data + * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node + * @param null|\stdClass $Services + */ + public function __construct( + null|array $data = null, // Deprecated, do not use, + null|Node $Node = null, + null|\stdClass $Services = null + ) { + $this->Node = $Node; + $this->setServices($Services); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } - public function getNode(): ?Node + public function getNode(): null|Node { return $this->Node; } @@ -55,14 +56,47 @@ public function setNode(?Node $Node): self return $this; } - public function getServices(): array + public function getServices(): null|\stdClass { return $this->Services; } - public function setServices(array $Services): self + public function setServices(null|\stdClass $Services): self { - $this->Services = $Services; + if (null === $Services) { + $this->Services = null; + return $this; + } + $this->Services = new \stdClass(); + foreach ($Services as $k => $v) { + $this->Services->{$k} = $v instanceof AgentService ? $v : AgentService::jsonUnserialize($v); + } return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Node' === $k) { + $n->Node = null === $v ? null : Node::jsonUnserialize($v); + } elseif ('Services' === $k) { + $n->setServices($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Node = $this->Node; + $out->Services = $this->Services; + return $out; + } } diff --git a/src/Catalog/CatalogNodeResponse.php b/src/Catalog/CatalogNodeResponse.php index 77d0c689..362f38e0 100644 --- a/src/Catalog/CatalogNodeResponse.php +++ b/src/Catalog/CatalogNodeResponse.php @@ -25,15 +25,19 @@ 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 $decoded): void { - $this->Node = new CatalogNode((array)$decoded); + 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 47f14a41..97b315dc 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -22,47 +22,81 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Agent\AgentService; -use DCarbone\PHPConsulAPI\Transcoding; class CatalogNodeServiceList extends AbstractModel { - 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, - ], - ]; - - private const FIELD_NODE = 'Node'; - private const FIELD_SERVICES = 'Services'; - - public ?Node $Node = null; + public null|Node $Node; + /** @var array<\DCarbone\PHPConsulAPI\Agent\AgentService> */ public array $Services; - public function getNode(): ?Node + /** + * @param array|null $data + * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node + * @param array<\DCarbone\PHPConsulAPI\Agent\AgentService> $Services + */ + public function __construct( + null|array $data = null, + null|Node $Node = null, + array $Services = [] + ) { + $this->Node = $Node; + $this->setServices(...$Services); + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } + + 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Node = $this->Node; + $out->Services = $this->Services; + return $out; + } } diff --git a/src/Catalog/CatalogNodeServicesListResponse.php b/src/Catalog/CatalogNodeServicesListResponse.php index 3c80714c..30126820 100644 --- a/src/Catalog/CatalogNodeServicesListResponse.php +++ b/src/Catalog/CatalogNodeServicesListResponse.php @@ -25,15 +25,19 @@ 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 $decoded): void { - $this->CatalogNodeServiceList = new CatalogNodeServiceList((array)$decoded); + if (null === $decoded) { + $this->CatalogNodeServiceList = null; + return; + } + $this->CatalogNodeServiceList = CatalogNodeServiceList::jsonUnserialize($decoded); } } From 0f895ac3834e68b2bc65d0d9993bff3f7495cd94 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 19 Apr 2025 14:34:41 -0500 Subject: [PATCH 43/79] small thing --- src/Catalog/CatalogRegistration.php | 167 ++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 45 deletions(-) diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index e3f2a320..adbd131c 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -23,57 +23,68 @@ 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; class CatalogRegistration extends AbstractModel { - 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 null|\stdClass $TaggedAddresses; + public null|\stdClass $NodeMeta; public string $Datacenter; - public ?AgentService $Service = null; - public ?AgentCheck $Check = null; - public HealthChecks $Checks; + public null|AgentService $Service; + public null|AgentCheck $Check; + public null|HealthChecks $Checks; public bool $SkipNodeUpdate; + public string $Partition; + public null|Locality $Locality; - 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); + /** + * @param array|null $data + * @param string $ID + * @param string $Node + * @param string $Address + * @param \stdClass|null $TaggedAddresses + * @param \stdClass|null $NodeMeta + * @param string $Datacenter + * @param \DCarbone\PHPConsulAPI\Agent\AgentService|null $Service + * @param \DCarbone\PHPConsulAPI\Agent\AgentCheck|null $Check + * @param \DCarbone\PHPConsulAPI\Health\HealthChecks|null $Checks + * @param bool $SkipNodeUpdate + * @param string $Partition + * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality + */ + public function __construct( + null|array $data = null, + string $ID = '', + string $Node = '', + string $Address = '', + null|\stdClass $TaggedAddresses = null, + null|\stdClass $NodeMeta = null, + 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->TaggedAddresses = $TaggedAddresses; + $this->NodeMeta = $NodeMeta; + $this->Datacenter = $Datacenter; + $this->Service = $Service; + $this->Check = $Check; + $this->Checks = $Checks; + $this->SkipNodeUpdate = $SkipNodeUpdate; + $this->Partition = $Partition; + $this->Locality = $Locality; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); } } @@ -110,23 +121,23 @@ public function setAddress(string $Address): self return $this; } - public function getTaggedAddresses(): FakeMap + public function getTaggedAddresses(): null|\stdClass { return $this->TaggedAddresses; } - public function setTaggedAddresses(FakeMap $TaggedAddresses): self + public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self { $this->TaggedAddresses = $TaggedAddresses; return $this; } - public function getNodeMeta(): FakeMap + public function getNodeMeta(): null|\stdClass { return $this->NodeMeta; } - public function setNodeMeta(FakeMap $NodeMeta): self + public function setNodeMeta(null|\stdClass $NodeMeta): self { $this->NodeMeta = $NodeMeta; return $this; @@ -186,4 +197,70 @@ 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('TaggedAddresses' === $k) { + $n->TaggedAddresses = null === $v ? null : (object)$v; + } elseif ('NodeMeta' === $k) { + $n->NodeMeta = null === $v ? null : (object)$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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ID = $this->ID; + $out->Node = $this->Node; + $out->Address = $this->Address; + $out->TaggedAddresses = $this->TaggedAddresses; + $out->NodeMeta = $this->NodeMeta; + $out->Datacenter = $this->Datacenter; + $out->Service = $this->Service; + $out->Check = $this->Check; + $out->Checks = $this->Checks; + $out->SkipNodeUpdate = $this->SkipNodeUpdate; + $out->Partition = $this->Partition; + $out->Locality = $this->Locality; + return $out; + } } From e7ba5ddda36863e5637e1fd3c3b3bf69c181ad01 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 6 May 2025 19:06:04 -0500 Subject: [PATCH 44/79] more bits of work --- src/ACL/ACLBindingRulesQueryResponse.php | 3 + src/ACL/ACLEntriesResponse.php | 4 + src/ACL/ACLPolicyListEntryQueryResponse.php | 4 + src/ACL/ACLRolesQueryResponse.php | 4 + src/ACL/ACLTokenListEntryQueryResponse.php | 4 + src/Agent/AgentChecksResponse.php | 6 +- src/Agent/AgentHealthServicesResponse.php | 5 + src/Agent/AgentMembersResponse.php | 2 +- src/Catalog/CatalogService.php | 250 ++++++++++++++---- src/Catalog/CatalogServicesResponse.php | 10 +- src/Catalog/GatewayServicesResponse.php | 8 +- src/Catalog/NodesResponse.php | 10 +- .../CoordinateDatacentersResponse.php | 10 +- src/Coordinate/CoordinateEntriesResponse.php | 10 +- src/Event/UserEventResponse.php | 10 +- src/Event/UserEventsResponse.php | 10 +- src/Health/HealthChecksResponse.php | 15 +- src/Health/ServiceEntriesResponse.php | 10 +- src/KV/KVPairResponse.php | 10 +- src/KV/KVPairsResponse.php | 15 +- src/KV/KVTxnAPIResponse.php | 4 +- src/Operator/AutopilotStateResponse.php | 6 +- src/Operator/OperatorAreaJoinResponse.php | 10 +- src/Operator/OperatorAreasResponse.php | 10 +- ...OperatorAutopilotConfigurationResponse.php | 6 +- src/Operator/OperatorHealthReplyResponse.php | 6 +- .../OperatorRaftConfigurationResponse.php | 6 +- src/Operator/OperatorSerfMembersResponse.php | 10 +- .../OperatorServerHealthsResponse.php | 10 +- .../PreparedQueryDefinitionsResponse.php | 10 +- src/Session/SessionEntriesQueryResponse.php | 10 +- src/Session/SessionEntriesWriteResponse.php | 10 +- 32 files changed, 378 insertions(+), 120 deletions(-) diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php index c8ebb512..cf6d7d59 100644 --- a/src/ACL/ACLBindingRulesQueryResponse.php +++ b/src/ACL/ACLBindingRulesQueryResponse.php @@ -28,6 +28,9 @@ class ACLBindingRulesQueryResponse extends AbstractValuedQueryResponse implement /** @var \DCarbone\PHPConsulAPI\ACL\ACLBindingRule[] */ public array $ACLBindingRules = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLBindingRule[] + */ public function getValue(): array { return $this->ACLBindingRules; diff --git a/src/ACL/ACLEntriesResponse.php b/src/ACL/ACLEntriesResponse.php index 2ef8aaff..e4bd298a 100644 --- a/src/ACL/ACLEntriesResponse.php +++ b/src/ACL/ACLEntriesResponse.php @@ -28,6 +28,9 @@ class ACLEntriesResponse extends AbstractValuedQueryResponse implements Unmarsha /** @var \DCarbone\PHPConsulAPI\ACL\ACLEntry[] */ public array $ACLEntries = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLEntry[] + */ public function getValue(): array { return $this->ACLEntries; @@ -35,6 +38,7 @@ public function getValue(): array public function unmarshalValue(mixed $decoded): void { + $this->ACLEntries = []; foreach ($decoded as $entry) { $this->ACLEntries[] = ACLEntry::jsonUnserialize($entry); } diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php index d24e9c47..0fd2ac10 100644 --- a/src/ACL/ACLPolicyListEntryQueryResponse.php +++ b/src/ACL/ACLPolicyListEntryQueryResponse.php @@ -28,6 +28,9 @@ class ACLPolicyListEntryQueryResponse extends AbstractValuedQueryResponse implem /** @var \DCarbone\PHPConsulAPI\ACL\ACLPolicyListEntry[] */ public array $ACLPolicyListEntries = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLPolicyListEntry[] + */ public function getValue(): array { return $this->ACLPolicyListEntries; @@ -35,6 +38,7 @@ public function getValue(): array public function unmarshalValue(mixed $decoded): void { + $this->ACLPolicyListEntries = []; foreach ($decoded as $datum) { $this->ACLPolicyListEntries[] = ACLPolicyListEntry::jsonUnserialize($datum); } diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php index d6157583..d07d6036 100644 --- a/src/ACL/ACLRolesQueryResponse.php +++ b/src/ACL/ACLRolesQueryResponse.php @@ -28,6 +28,9 @@ class ACLRolesQueryResponse extends AbstractValuedQueryResponse implements Unmar /** @var \DCarbone\PHPConsulAPI\ACL\ACLRole[] */ public array $ACLRoles = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLRole[] + */ public function getValue(): array { return $this->ACLRoles; @@ -35,6 +38,7 @@ public function getValue(): array public function unmarshalValue(mixed $decoded): void { + $this->ACLRoles = []; foreach ($decoded as $datum) { $this->ACLRoles[] = ACLRole::jsonUnserialize($datum); } diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php index 5e896d91..350bf618 100644 --- a/src/ACL/ACLTokenListEntryQueryResponse.php +++ b/src/ACL/ACLTokenListEntryQueryResponse.php @@ -28,6 +28,9 @@ class ACLTokenListEntryQueryResponse extends AbstractValuedQueryResponse impleme /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenListEntry[] */ public array $ACLTokenListEntries = []; + /** + * @return \DCarbone\PHPConsulAPI\ACL\ACLTokenListEntry[] + */ public function getValue(): array { return $this->ACLTokenListEntries; @@ -35,6 +38,7 @@ public function getValue(): array public function unmarshalValue(mixed $decoded): void { + $this->ACLTokenListEntries = []; foreach ($decoded as $datum) { $this->ACLTokenListEntries[] = ACLTokenListEntry::jsonUnserialize($datum); } diff --git a/src/Agent/AgentChecksResponse.php b/src/Agent/AgentChecksResponse.php index 02b0c542..dc4bdc67 100644 --- a/src/Agent/AgentChecksResponse.php +++ b/src/Agent/AgentChecksResponse.php @@ -25,8 +25,12 @@ class AgentChecksResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public array $Checks; + /** @var \DCarbone\PHPConsulAPI\Agent\AgentCheck[] */ + public array $Checks = []; + /** + * @return \DCarbone\PHPConsulAPI\Agent\AgentCheck[]|null + */ public function getValue(): ?array { return $this->Checks; diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php index 35be5641..f529be51 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -32,6 +32,11 @@ class AgentHealthServicesResponse extends AbstractResponse /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[] */ public array $AgentServiceChecksInfos; + /** + * @param string $aggregatedStatus + * @param \stdClass[] $checkInfos + * @param \DCarbone\PHPConsulAPI\Error|null $err + */ public function __construct(string $aggregatedStatus, array $checkInfos, null|Error $err) { $this->AggregatedStatus = $aggregatedStatus; diff --git a/src/Agent/AgentMembersResponse.php b/src/Agent/AgentMembersResponse.php index 7223b729..6005c021 100644 --- a/src/Agent/AgentMembersResponse.php +++ b/src/Agent/AgentMembersResponse.php @@ -26,7 +26,7 @@ class AgentMembersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Agent\AgentMember[] */ - public array $Members; + public array $Members = []; /** * @return \DCarbone\PHPConsulAPI\Agent\AgentMember[] diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 4895a509..8c866db0 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -23,57 +23,90 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig; use DCarbone\PHPConsulAPI\Health\HealthChecks; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\Peering\Locality; class CatalogService extends AbstractModel { - 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 null|\stdClass $TaggedAddresses; + public null|\stdClass $NodeMeta; public string $ServiceID; public string $ServiceName; public string $ServiceAddress; - public array $ServiceTaggedAddresses; + public null|\stdClass $ServiceTaggedAddresses; + /** @var array */ public array $ServiceTags; - public array $ServiceMeta; + public null|\stdClass $ServiceMeta; public int $ServicePort; public Weights $ServiceWeights; public bool $ServiceEnableTagOverride; + public null|AgentServiceConnectProxyConfig $ServiceProxy; + public null|Locality $ServiceLocality; public int $CreateIndex; - public ?AgentServiceConnectProxyConfig $ServiceProxy = null; + public HealthChecks $Checks; public int $ModifyIndex; public string $Namespace; + public string $Partition; + + /** + * @param array|null $data + * @param array $ServiceTags + */ + public function __construct( + null|array $data = null, // Deprecated, do not use. + string $ID = '', + string $Node = '', + string $Address = '', + string $Datacenter = '', + null|\stdclass $TaggedAddresses = null, + null|\stdclass $NodeMeta = null, + string $ServiceID = '', + string $ServiceName = '', + string $ServiceAddress = '', + null|\stdclass $ServiceTaggedAddresses = null, + array $ServiceTags = [], + null|\stdclass $ServiceMeta = null, + 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->TaggedAddresses = $TaggedAddresses; + $this->NodeMeta = $NodeMeta; + $this->ServiceID = $ServiceID; + $this->ServiceName = $ServiceName; + $this->ServiceAddress = $ServiceAddress; + $this->ServiceTaggedAddresses = $ServiceTaggedAddresses; + $this->setServiceTags(...$ServiceTags); + $this->setServiceTaggedAddresses($ServiceTaggedAddresses); + $this->ServiceMeta = $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; + if (null !== $data && [] !== $data) { + $this->jsonUnserialize((object)$data, $this); + } + } public function getID(): string { @@ -119,23 +152,23 @@ public function setDatacenter(string $Datacenter): self return $this; } - public function getTaggedAddresses(): array + public function getTaggedAddresses(): null|\stdClass { return $this->TaggedAddresses; } - public function setTaggedAddresses(array $TaggedAddresses): self + public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self { $this->TaggedAddresses = $TaggedAddresses; return $this; } - public function getNodeMeta(): array + public function getNodeMeta(): \stdClass { return $this->NodeMeta; } - public function setNodeMeta(array $NodeMeta): self + public function setNodeMeta(null|\stdClass $NodeMeta): self { $this->NodeMeta = $NodeMeta; return $this; @@ -174,34 +207,48 @@ public function setServiceAddress(string $ServiceAddress): self return $this; } - public function getServiceTaggedAddresses(): array + public function getServiceTaggedAddresses(): \stdClass { return $this->ServiceTaggedAddresses; } - public function setServiceTaggedAddresses(array $ServiceTaggedAddresses): self - { - $this->ServiceTaggedAddresses = $ServiceTaggedAddresses; + public function setServiceTaggedAddresses(null|\stdClass $ServiceTaggedAddresses): self + { + if (null === $ServiceTaggedAddresses) { + $this->ServiceTaggedAddresses = null; + return $this; + } + $this->ServiceTaggedAddresses = new \stdClass(); + foreach ($ServiceTaggedAddresses as $k => $v) { + if ($v instanceof ServiceAddress) { + $this->ServiceTaggedAddresses->{$k} = $v; + } else { + $this->ServiceTaggedAddresses->{$k} = ServiceAddress::jsonUnserialize((object)$v); + } + } return $this; } + /** + * @return string[] + */ public function getServiceTags(): array { return $this->ServiceTags; } - public function setServiceTags(array $ServiceTags): self + public function setServiceTags(string ...$ServiceTags): self { $this->ServiceTags = $ServiceTags; return $this; } - public function getServiceMeta(): array + public function getServiceMeta(): \stdClass { return $this->ServiceMeta; } - public function setServiceMeta(array $ServiceMeta): self + public function setServiceMeta(null|\stdClass $ServiceMeta): self { $this->ServiceMeta = $ServiceMeta; return $this; @@ -240,6 +287,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 +320,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 +342,93 @@ 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('TaggedAddresses' === $k) { + $n->settaggedAddresses($v); + } elseif ('NodeMeta' === $k) { + $n->setnodemeta($v); + } elseif ('ServiceTaggedAddresses' === $k) { + $n->setservicetaggedaddresses($v); + } elseif ('Weights' === $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); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ID = $this->ID; + $out->Node = $this->Node; + $out->Address = $this->Address; + $out->Datacenter = $this->Datacenter; + $out->TaggedAddresses = $this->TaggedAddresses; + $out->NodeMeta = $this->NodeMeta; + $out->ServiceID = $this->ServiceID; + $out->ServiceName = $this->ServiceName; + $out->ServiceAddress = $this->ServiceAddress; + $out->ServiceTaggedAddresses = $this->ServiceTaggedAddresses; + $out->ServiceTags = $this->ServiceTags; + $out->ServiceMeta = $this->ServiceMeta; + $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 063048d8..fdeaf4d1 100644 --- a/src/Catalog/CatalogServicesResponse.php +++ b/src/Catalog/CatalogServicesResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->Services = []; foreach ($decoded as $node) { - $this->Services[] = new CatalogService($node); + $this->Services[] = CatalogService::jsonUnserialize($node); } } } diff --git a/src/Catalog/GatewayServicesResponse.php b/src/Catalog/GatewayServicesResponse.php index e01c3028..b470ea96 100644 --- a/src/Catalog/GatewayServicesResponse.php +++ b/src/Catalog/GatewayServicesResponse.php @@ -25,9 +25,13 @@ 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; } diff --git a/src/Catalog/NodesResponse.php b/src/Catalog/NodesResponse.php index 59413281..a56b77bb 100644 --- a/src/Catalog/NodesResponse.php +++ b/src/Catalog/NodesResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->Nodes = []; foreach ($decoded as $node) { - $this->Nodes[] = new Node($node); + $this->Nodes[] = Node::jsonUnserialize($node); } } } diff --git a/src/Coordinate/CoordinateDatacentersResponse.php b/src/Coordinate/CoordinateDatacentersResponse.php index 4fc83de5..031fc260 100644 --- a/src/Coordinate/CoordinateDatacentersResponse.php +++ b/src/Coordinate/CoordinateDatacentersResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->DatacenterMap = []; foreach ($decoded as $item) { - $this->DatacenterMap[] = new CoordinateDatacenterMap($item); + $this->DatacenterMap[] = CoordinateDatacenterMap::jsonUnserialize($item); } } } diff --git a/src/Coordinate/CoordinateEntriesResponse.php b/src/Coordinate/CoordinateEntriesResponse.php index c31d9f83..8ecefa28 100644 --- a/src/Coordinate/CoordinateEntriesResponse.php +++ b/src/Coordinate/CoordinateEntriesResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->Nodes = []; foreach ($decoded as $node) { - $this->Nodes[] = new CoordinateEntry($node); + $this->Nodes[] = CoordinateEntry::jsonUnserialize($node); } } } diff --git a/src/Event/UserEventResponse.php b/src/Event/UserEventResponse.php index 40808bb9..a71a354e 100644 --- a/src/Event/UserEventResponse.php +++ b/src/Event/UserEventResponse.php @@ -25,15 +25,19 @@ 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 $decoded): void { - $this->UserEvent = new UserEvent((array)$decoded); + 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 766d0d0b..d3c56eca 100644 --- a/src/Event/UserEventsResponse.php +++ b/src/Event/UserEventsResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->UserEvents = []; foreach ($decoded as $datum) { - $this->UserEvents[] = new UserEvent($datum); + $this->UserEvents[] = UserEvent::jsonUnserialize($datum); } } } diff --git a/src/Health/HealthChecksResponse.php b/src/Health/HealthChecksResponse.php index d8f2c3a0..14081f1e 100644 --- a/src/Health/HealthChecksResponse.php +++ b/src/Health/HealthChecksResponse.php @@ -25,15 +25,24 @@ 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 $decoded): void { - $this->HealthChecks = new HealthChecks((array)$decoded); + if (null === $decoded) { + $this->HealthChecks = new HealthChecks(); + return; + } + $this->HealthChecks = HealthChecks::jsonUnserialize($decoded); } } diff --git a/src/Health/ServiceEntriesResponse.php b/src/Health/ServiceEntriesResponse.php index f93c7f1b..9223803b 100644 --- a/src/Health/ServiceEntriesResponse.php +++ b/src/Health/ServiceEntriesResponse.php @@ -25,9 +25,13 @@ 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; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->ServiceEntries = []; foreach ($decoded as $entry) { - $this->ServiceEntries[] = new ServiceEntry($entry); + $this->ServiceEntries[] = ServiceEntry::jsonUnserialize($entry); } } } diff --git a/src/KV/KVPairResponse.php b/src/KV/KVPairResponse.php index a8917b9a..89d95eb9 100644 --- a/src/KV/KVPairResponse.php +++ b/src/KV/KVPairResponse.php @@ -25,15 +25,19 @@ 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 $decoded): void { - $this->KVPair = new KVPair((array)$decoded, true); + if (null === $decoded) { + $this->KVPair = null; + return; + } + $this->KVPair = KVPair::jsonUnserialize($decoded); } } diff --git a/src/KV/KVPairsResponse.php b/src/KV/KVPairsResponse.php index 621b1e40..ddd34cdb 100644 --- a/src/KV/KVPairsResponse.php +++ b/src/KV/KVPairsResponse.php @@ -25,15 +25,24 @@ 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(): null|KVPairs { return $this->KVPairs; } public function unmarshalValue(mixed $decoded): void { - $this->KVPairs = new KVPairs((array)$decoded); + if (null === $decoded) { + $this->KVPairs = new KVPairs(); + return; + } + $this->KVPairs = KVPairs::jsonUnserialize($decoded); } } diff --git a/src/KV/KVTxnAPIResponse.php b/src/KV/KVTxnAPIResponse.php index d64b2515..05221fe1 100644 --- a/src/KV/KVTxnAPIResponse.php +++ b/src/KV/KVTxnAPIResponse.php @@ -29,14 +29,14 @@ class KVTxnAPIResponse use ErrorContainer; public bool $OK = false; - public ?KVTxnResponse $KVTxnResponse = null; + public null|KVTxnResponse $KVTxnResponse = null; public function isOK(): bool { return $this->OK; } - public function getKVTxnResponse(): ?KVTxnResponse + public function getKVTxnResponse(): null|KVTxnResponse { return $this->KVTxnResponse; } diff --git a/src/Operator/AutopilotStateResponse.php b/src/Operator/AutopilotStateResponse.php index 49ba9999..9e54d9c7 100644 --- a/src/Operator/AutopilotStateResponse.php +++ b/src/Operator/AutopilotStateResponse.php @@ -25,15 +25,15 @@ class AutopilotStateResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?AutopilotState $AutopilotState = null; + public null|AutopilotState $AutopilotState = null; - public function getValue(): ?AutopilotState + public function getValue(): null|AutopilotState { return $this->AutopilotState; } public function unmarshalValue(mixed $decoded): void { - $this->AutopilotState = new AutopilotState($decoded); + $this->AutopilotState = AutopilotState::jsonUnserialize($decoded); } } diff --git a/src/Operator/OperatorAreaJoinResponse.php b/src/Operator/OperatorAreaJoinResponse.php index ded7f19d..88fe7404 100644 --- a/src/Operator/OperatorAreaJoinResponse.php +++ b/src/Operator/OperatorAreaJoinResponse.php @@ -25,9 +25,13 @@ class OperatorAreaJoinResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { - public ?array $AreaJoinResponses = null; + /** @var \DCarbone\PHPConsulAPI\Operator\AreaJoinResponse[] */ + public array $AreaJoinResponses = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Operator\AreaJoinResponse[] + */ + public function getValue(): array { return $this->AreaJoinResponses; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->AreaJoinResponses = []; foreach ($decoded as $area) { - $this->AreaJoinResponses[] = new AreaJoinResponse($area); + $this->AreaJoinResponses[] = AreaJoinResponse::jsonUnserialize($area); } } } diff --git a/src/Operator/OperatorAreasResponse.php b/src/Operator/OperatorAreasResponse.php index fd4e90e4..928e3fba 100644 --- a/src/Operator/OperatorAreasResponse.php +++ b/src/Operator/OperatorAreasResponse.php @@ -25,9 +25,13 @@ class OperatorAreasResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $Areas = null; + /** @var \DCarbone\PHPConsulAPI\Operator\Area[] */ + public array $Areas = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Operator\Area[] + */ + public function getValue(): array { return $this->Areas; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->Areas = []; foreach ($decoded as $area) { - $this->Areas[] = new Area($area); + $this->Areas[] = Area::jsonUnserialize($area); } } } diff --git a/src/Operator/OperatorAutopilotConfigurationResponse.php b/src/Operator/OperatorAutopilotConfigurationResponse.php index 3175edfe..30ad276a 100644 --- a/src/Operator/OperatorAutopilotConfigurationResponse.php +++ b/src/Operator/OperatorAutopilotConfigurationResponse.php @@ -25,15 +25,15 @@ class OperatorAutopilotConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?AutopilotConfiguration $AutopilotConfiguration = null; + public null|AutopilotConfiguration $AutopilotConfiguration = null; - public function getValue(): ?AutopilotConfiguration + public function getValue(): null|AutopilotConfiguration { return $this->AutopilotConfiguration; } public function unmarshalValue(mixed $decoded): void { - $this->AutopilotConfiguration = new AutopilotConfiguration((array)$decoded); + $this->AutopilotConfiguration = AutopilotConfiguration::jsonUnserialize($decoded); } } diff --git a/src/Operator/OperatorHealthReplyResponse.php b/src/Operator/OperatorHealthReplyResponse.php index 1d08f4d2..deccc502 100644 --- a/src/Operator/OperatorHealthReplyResponse.php +++ b/src/Operator/OperatorHealthReplyResponse.php @@ -25,15 +25,15 @@ class OperatorHealthReplyResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?OperatorHealthReply $OperatorHealthReply = null; + public null|OperatorHealthReply $OperatorHealthReply = null; - public function getValue(): mixed + public function getValue(): null|OperatorHealthReply { return $this->OperatorHealthReply; } public function unmarshalValue(mixed $decoded): void { - $this->OperatorHealthReply = new OperatorHealthReply((array)$decoded); + $this->OperatorHealthReply = OperatorHealthReply::jsonUnserialize($decoded); } } diff --git a/src/Operator/OperatorRaftConfigurationResponse.php b/src/Operator/OperatorRaftConfigurationResponse.php index 509c5a5e..89b700df 100644 --- a/src/Operator/OperatorRaftConfigurationResponse.php +++ b/src/Operator/OperatorRaftConfigurationResponse.php @@ -25,15 +25,15 @@ class OperatorRaftConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?RaftConfiguration $RaftConfiguration = null; + public null|RaftConfiguration $RaftConfiguration = null; - public function getValue(): ?RaftConfiguration + public function getValue(): null|RaftConfiguration { return $this->RaftConfiguration; } public function unmarshalValue(mixed $decoded): void { - $this->RaftConfiguration = new RaftConfiguration($decoded); + $this->RaftConfiguration = RaftConfiguration::jsonUnserialize($decoded); } } diff --git a/src/Operator/OperatorSerfMembersResponse.php b/src/Operator/OperatorSerfMembersResponse.php index a18e45d4..33688ac6 100644 --- a/src/Operator/OperatorSerfMembersResponse.php +++ b/src/Operator/OperatorSerfMembersResponse.php @@ -25,9 +25,13 @@ class OperatorSerfMembersResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $SerfMembers = null; + /** @var \DCarbone\PHPConsulAPI\Operator\SerfMember[] */ + public array $SerfMembers = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Operator\SerfMember[] + */ + public function getValue(): array { return $this->SerfMembers; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->SerfMembers = []; foreach ($decoded as $datum) { - $this->SerfMembers[] = new SerfMember($datum); + $this->SerfMembers[] = SerfMember::jsonUnserialize($datum); } } } diff --git a/src/Operator/OperatorServerHealthsResponse.php b/src/Operator/OperatorServerHealthsResponse.php index 4c06dca1..9c1fdc21 100644 --- a/src/Operator/OperatorServerHealthsResponse.php +++ b/src/Operator/OperatorServerHealthsResponse.php @@ -25,9 +25,13 @@ class OperatorServerHealthsResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public ?array $ServerHealths = null; + /** @var \DCarbone\PHPConsulAPI\Operator\ServerHealth[] */ + public array $ServerHealths = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Operator\ServerHealth[] + */ + public function getValue(): array { return $this->ServerHealths; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->ServerHealths = []; foreach ($decoded as $datum) { - $this->ServerHealths[] = new ServerHealth($datum); + $this->ServerHealths[] = ServerHealth::jsonUnserialize($datum); } } } diff --git a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php index 6d6fab6b..595e93f6 100644 --- a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php +++ b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php @@ -25,9 +25,13 @@ class PreparedQueryDefinitionsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $PreparedQueryDefinitions = null; + /** @var \DCarbone\PHPConsulAPI\PreparedQuery\PreparedQueryDefinition[] */ + public array $PreparedQueryDefinitions = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\PreparedQuery\PreparedQueryDefinition[] + */ + public function getValue(): array { return $this->PreparedQueryDefinitions; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->PreparedQueryDefinitions = []; foreach ($decoded as $datum) { - $this->PreparedQueryDefinitions[] = new PreparedQueryDefinition($datum); + $this->PreparedQueryDefinitions[] = PreparedQueryDefinition::jsonUnserialize($datum); } } } diff --git a/src/Session/SessionEntriesQueryResponse.php b/src/Session/SessionEntriesQueryResponse.php index a279a3a5..08a25a10 100644 --- a/src/Session/SessionEntriesQueryResponse.php +++ b/src/Session/SessionEntriesQueryResponse.php @@ -25,9 +25,13 @@ class SessionEntriesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - public ?array $SessionEntries = []; + /** @var \DCarbone\PHPConsulAPI\Session\SessionEntry[] */ + public array $SessionEntries = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Session\SessionEntry[] + */ + public function getValue(): array { return $this->SessionEntries; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->SessionEntries = []; foreach ($decoded as $datum) { - $this->SessionEntries[] = new SessionEntry($datum); + $this->SessionEntries[] = SessionEntry::jsonUnserialize($datum); } } } diff --git a/src/Session/SessionEntriesWriteResponse.php b/src/Session/SessionEntriesWriteResponse.php index c9cec007..4e7f13a9 100644 --- a/src/Session/SessionEntriesWriteResponse.php +++ b/src/Session/SessionEntriesWriteResponse.php @@ -25,9 +25,13 @@ class SessionEntriesWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { - public ?array $SessionEntries = null; + /** @var \DCarbone\PHPConsulAPI\Session\SessionEntry[] */ + public array $SessionEntries = []; - public function getValue(): ?array + /** + * @return \DCarbone\PHPConsulAPI\Session\SessionEntry[] + */ + public function getValue(): array { return $this->SessionEntries; } @@ -36,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->SessionEntries = []; foreach ($decoded as $datum) { - $this->SessionEntries[] = new SessionEntry($datum); + $this->SessionEntries[] = SessionEntry::jsonUnserialize($datum); } } } From d9df71e1bfbc71957289f77b1bd06b99275110ab Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 24 May 2025 22:56:08 -0500 Subject: [PATCH 45/79] small stuff --- src/ACL/ACLAuthMethod.php | 2 +- src/ACL/ACLAuthMethodListEntry.php | 2 +- src/ACL/ACLAuthMethodNamespaceRule.php | 2 +- src/ACL/ACLBindingRule.php | 2 +- src/ACL/ACLEntry.php | 2 +- src/ACL/ACLLink.php | 2 +- src/ACL/ACLLoginParams.php | 2 +- src/ACL/ACLNodeIdentity.php | 2 +- src/ACL/ACLOIDCAuthURLParams.php | 2 +- src/ACL/ACLOIDCCallbackParams.php | 2 +- src/ACL/ACLPolicy.php | 2 +- src/ACL/ACLPolicyListEntry.php | 2 +- src/ACL/ACLReplicationStatus.php | 2 +- src/ACL/ACLRole.php | 2 +- src/ACL/ACLServiceIdentity.php | 2 +- src/ACL/ACLToken.php | 2 +- src/ACL/ACLTokenExpanded.php | 2 +- src/ACL/ACLTokenListEntry.php | 2 +- src/ACL/KubernetesAuthMethodConfig.php | 2 +- src/ACL/OIDCAuthMethodConfig.php | 2 +- src/Agent/AgentCheck.php | 2 +- src/Agent/AgentCheckRegistration.php | 2 +- src/Agent/AgentService.php | 2 +- src/Agent/AgentServiceCheck.php | 2 +- src/Agent/AgentServiceChecksInfo.php | 2 +- src/Agent/AgentServiceConnect.php | 2 +- src/Agent/AgentServiceConnectProxyConfig.php | 2 +- src/Agent/AgentServiceRegistration.php | 2 +- src/Agent/AgentToken.php | 2 +- src/Agent/AgentWeights.php | 2 +- src/Agent/ConnectProxyConfig.php | 2 +- src/Agent/GaugeValue.php | 2 +- src/Agent/MemberOpts.php | 2 +- src/Agent/MetricsInfo.php | 2 +- src/Agent/PointValue.php | 2 +- src/Agent/SampledValue.php | 2 +- src/Agent/Upstream.php | 2 +- src/Catalog/CatalogDeregistration.php | 2 +- src/Catalog/CatalogNode.php | 2 +- src/Catalog/CatalogNodeServiceList.php | 2 +- src/Catalog/CatalogRegistration.php | 2 +- src/Catalog/CatalogService.php | 2 +- src/Catalog/CatalogServicesResponse.php | 2 +- src/Catalog/CompoundServiceName.php | 60 +++++++- src/Catalog/GatewayService.php | 140 ++++++++++++------- src/Catalog/GatewayServicesResponse.php | 2 +- src/Catalog/Node.php | 131 ++++++++++++++--- src/Catalog/ServiceAddress.php | 2 +- src/ConfigEntry/EnvoyExtension.php | 2 +- src/ConfigEntry/MeshGatewayConfig.php | 2 +- src/ConfigEntry/TransparentProxyConfig.php | 2 +- 51 files changed, 304 insertions(+), 123 deletions(-) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 2780fe6e..3cdd2661 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -82,7 +82,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index a868f1cb..ae35c351 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -62,7 +62,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 18e85591..23b3b773 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -35,7 +35,7 @@ public function __construct( $this->Selector = $Selector; $this->BindNamespace = $BindNamespace; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 37e9f6b0..0be0e60a 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -56,7 +56,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index 423a5fcc..1ed8c060 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -47,7 +47,7 @@ public function __construct( $this->Type = $Type; $this->Rules = $Rules; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index a6d76c03..42324c08 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -35,7 +35,7 @@ public function __construct( $this->ID = $ID; $this->Name = $Name; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index ddd9dce2..d4df6b65 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -38,7 +38,7 @@ public function __construct( $this->BearerToken = $BearerToken; $this->setMeta($Meta); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index e894a411..7dee2ad8 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -35,7 +35,7 @@ public function __construct( $this->NodeName = $NodeName; $this->Datacenter = $Datacenter; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 28ba045a..bb996202 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -41,7 +41,7 @@ public function __construct( $this->ClientNonce = $ClientNonce; $this->setMeta($Meta); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 438d4d19..ea0995be 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -41,7 +41,7 @@ public function __construct( $this->Code = $Code; $this->ClientNonce = $ClientNonce; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index e5a3a62a..f025ba4e 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -61,7 +61,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index 92d2fce0..ec329888 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -56,7 +56,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 9981f0f5..a147ce55 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -54,7 +54,7 @@ public function __construct( $this->LastSuccess = $LastSuccess ?? Time::New(); $this->LastError = $LastError ?? Time::New(); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 8f8eed27..d88c50e9 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -69,7 +69,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index afde704a..f93681d0 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -36,7 +36,7 @@ public function __construct( $this->ServiceName = $ServiceName; $this->setDatacenters(...$Datacenters); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index ee9ae18f..a09aebe4 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -71,7 +71,7 @@ public function __construct( $this->Partition = $Partition; $this->AuthMethodNamespace = $AuthMethodNamespace; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index d5bc981a..4713b067 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -96,7 +96,7 @@ public function __construct( $this->AgentACLDownPolicy = $AgentACLDownPolicy; $this->ResolvedByAgent = $ResolvedByAgent; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index e19bdc02..f1a707df 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -92,7 +92,7 @@ public function __construct( $this->Partition = $Partition; $this->AuthMethodNamespace = $AuthMethodNamespace; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index b65f54b4..958c8081 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -38,7 +38,7 @@ public function __construct( $this->CACert = $CACert; $this->ServiceAccountJWT = $ServiceAccountJWT; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index 601e4cd9..f2ea6528 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -28,7 +28,7 @@ public function __construct( null|array $data = null, // Deprecated, will be removed. ) { if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 79ec6341..62b82292 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -66,7 +66,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index f5a6ab84..4fa4bebe 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -89,7 +89,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 52436cd9..c7506c32 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -119,7 +119,7 @@ public function __construct( $this->Datacenter = $Datacenter; $this->Locality = $Locality; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 1640430d..0f85b602 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -130,7 +130,7 @@ public function __construct( $this->FailuresBeforeCritical = $FailuresBeforeCritical; $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 88528352..99c377a2 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -39,7 +39,7 @@ public function __construct( $this->Service = $Service; $this->Checks = $Checks ?? new HealthChecks(); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 94232c42..adce2dfd 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -35,7 +35,7 @@ public function __construct( $this->Native = $Native; $this->SidecarService = $SidecarService; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 83a5d757..c237081a 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -92,7 +92,7 @@ public function __construct( $this->Expose = $Expose; $this->AccessLogs = $AccessLogs; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 4ba46dbd..e5d9772b 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -103,7 +103,7 @@ public function __construct( $this->Partition = $Partition; $this->Locality = $Locality; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index c5a5e837..b151fc35 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -32,7 +32,7 @@ public function __construct( ) { $this->Token = $Token; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index ed2ed79e..ecf7d2d9 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -35,7 +35,7 @@ public function __construct( $this->Passing = $Passing; $this->Warning = $Warning; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php index 37430db4..786ecd2b 100644 --- a/src/Agent/ConnectProxyConfig.php +++ b/src/Agent/ConnectProxyConfig.php @@ -58,7 +58,7 @@ public function __construct( $this->setUpstreams(...$Upstreams); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 25513169..89ce37d0 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -44,7 +44,7 @@ public function __construct( $this->Value = $Value; $this->Labels = $Labels; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index 2b820ff2..af44f68e 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -38,7 +38,7 @@ public function __construct( $this->Segment = $Segment; $this->Filter = $Filter; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index b13e5ddd..b65eecaa 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -48,7 +48,7 @@ public function __construct( $this->setCounters(...$Counters); $this->setSamples(...$Samples); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 3cf026a3..2b1d8948 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -36,7 +36,7 @@ public function __construct( $this->Name = $Name; $this->setPoints(...$Points); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index 0373c302..2e02725e 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -64,7 +64,7 @@ public function __construct( $this->Stddev = $Stddev; $this->Labels = $Labels ?? new \stdClass(); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index cbe48a63..122cfd53 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -69,7 +69,7 @@ public function __construct( $this->MeshGateway = $MeshGateway; $this->CentrallyConfigured = $CentrallyConfigured; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 0996cfd1..42f51931 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -60,7 +60,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index 47e6d6f1..e5259866 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -41,7 +41,7 @@ public function __construct( $this->Node = $Node; $this->setServices($Services); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index 97b315dc..dc9c1398 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -42,7 +42,7 @@ public function __construct( $this->Node = $Node; $this->setServices(...$Services); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index adbd131c..a48c86cd 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -84,7 +84,7 @@ public function __construct( $this->Partition = $Partition; $this->Locality = $Locality; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 8c866db0..1fcb4ac5 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -104,7 +104,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/Catalog/CatalogServicesResponse.php b/src/Catalog/CatalogServicesResponse.php index fdeaf4d1..6758043e 100644 --- a/src/Catalog/CatalogServicesResponse.php +++ b/src/Catalog/CatalogServicesResponse.php @@ -26,7 +26,7 @@ class CatalogServicesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { /** @var array<\DCarbone\PHPConsulAPI\Catalog\CatalogService> */ - public array $Services; + public array $Services = []; /** * @return array<\DCarbone\PHPConsulAPI\Catalog\CatalogService> diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 34c3b4e5..6992637f 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -21,18 +21,27 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class CompoundServiceName extends AbstractModel { - protected const FIELDS = [ - self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, - ]; - - private const FIELD_NAMESPACE = 'Namespace'; - public string $Name; public string $Namespace; + public string $Partition; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Name = '', + string $Namespace = '', + string $Partition = '', + ) + { + $this->Name = $Name; + $this->Namespace = $Namespace; + $this->Partition = $Partition; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } public function getName(): string { @@ -55,4 +64,41 @@ 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 f9850415..569b509b 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -21,49 +21,16 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\Agent\ServiceKind; class GatewayService extends AbstractModel { - 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 ServiceKind $GatewayKind; public int $Port; public string $Protocol; + /** @var array */ public array $Hosts; public string $CAFile; public string $CertFile; @@ -71,14 +38,34 @@ class GatewayService extends AbstractModel 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 function __construct( + null|array $data = [], // Deprecated, will be removed. + 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; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); } } @@ -104,12 +91,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 +124,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 +192,60 @@ public function setFromWildCard(string $FromWildCard): self $this->FromWildCard = $FromWildCard; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Gateway' === $k) { + $n->Gateway = CompoundServiceName::jsonUnserialize($v); + } else if ('Service' === $k) { + $n->Service = CompoundServiceName::jsonUnserialize($v); + } else if ('GatewayKind' === $k) { + $n->GatewayKind = ServiceKind::from($v); + } else if ('Hosts' === $k) { + $n->setHosts(...$v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 b470ea96..127a92b9 100644 --- a/src/Catalog/GatewayServicesResponse.php +++ b/src/Catalog/GatewayServicesResponse.php @@ -40,7 +40,7 @@ public function unmarshalValue(mixed $decoded): void { $this->GatewayServices = []; foreach ($decoded as $service) { - $this->GatewayServices[] = new GatewayService($service); + $this->GatewayServices[] = GatewayService::jsonUnserialize($service); } } } diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 8f221ee7..2832db77 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -21,33 +21,50 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\Peering\Locality; class Node extends AbstractModel { - 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 null|\stdClass $TaggedAddresses; + public null|\stdClass $Meta; public int $CreateIndex; public int $ModifyIndex; - - public function __construct(?array $data = []) + public string $Partition; + public string $PeerName; + public null|Locality $Locality; + + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $ID = '', + string $Node = '', + string $Address = '', + string $Datacenter = '', + null|\stdClass $TaggedAddresses = null, + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $Partition = '', + string $PeerName = '', + null|Locality $Locality = null + ) { - parent::__construct($data); - if (!isset($this->Meta)) { - $this->Meta = new FakeMap(null); + $this->ID = $ID; + $this->Node = $Node; + $this->Address = $Address; + $this->Datacenter = $Datacenter; + $this->TaggedAddresses = $TaggedAddresses ?? new \stdClass(); + $this->Meta = $Meta ?? new \stdClass(); + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->Partition = $Partition; + $this->PeerName = $PeerName; + $this->Locality = $Locality; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); } } @@ -95,23 +112,23 @@ public function setDatacenter(string $Datacenter): self return $this; } - public function getTaggedAddresses(): FakeMap + public function getTaggedAddresses(): null|\stdClass { return $this->TaggedAddresses; } - public function setTaggedAddresses(FakeMap $TaggedAddresses): self + public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self { $this->TaggedAddresses = $TaggedAddresses; return $this; } - public function getMeta(): FakeMap + public function getMeta(): null|\stdClass { return $this->Meta; } - public function setMeta(FakeMap $Meta): self + public function setMeta(null|\stdClass $Meta): self { $this->Meta = $Meta; return $this; @@ -138,4 +155,76 @@ public function setModifyIndex(int $ModifyIndex): self $this->ModifyIndex = $ModifyIndex; return $this; } + + public function getPartition(): string + { + return $this->Partition; + } + + public function setPartition(string $Partition): self + { + $this->Partition = $Partition; + return $this; + } + + public function getPeerName(): string + { + return $this->PeerName; + } + + public function setPeerName(string $PeerName): self + { + $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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Locality' === $k) { + $n->Locality = Locality::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->ID = $this->ID; + $out->Node = $this->Node; + $out->Address = $this->Address; + $out->Datacenter = $this->Datacenter; + $out->TaggedAddresses = $this->TaggedAddresses; + $out->Meta = $this->Meta; + $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/ServiceAddress.php b/src/Catalog/ServiceAddress.php index 3351e5fe..444c0809 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -35,7 +35,7 @@ public function __construct( $this->Address = $address; $this->Port = $port; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 7c214962..20d88c04 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -44,7 +44,7 @@ public function __construct( $this->ConsulVersion = $ConsulVersion; $this->EnvoyVersion = $EnvoyVersion; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index df1d8939..94302e0d 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -32,7 +32,7 @@ public function __construct( ) { $this->setMode($mode); if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index 3d25817e..cdb83f22 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -35,7 +35,7 @@ public function __construct( $this->OutboundListenerPort = $OutboundListenerPort; $this->DialedDirectly = $DialedDirectly; if (null !== $data && [] !== $data) { - $this->jsonUnserialize((object)$data, $this); + self::jsonUnserialize((object)$data, $this); } } From 2727a446d90107397dbc5ae72747800b217b3cc1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 25 May 2025 21:27:12 -0500 Subject: [PATCH 46/79] more little bits of work --- src/AbstractModel.php | 8 ++- src/Catalog/CatalogService.php | 2 +- src/Catalog/CompoundServiceName.php | 1 - src/Catalog/Node.php | 6 ++- src/Catalog/ServiceAddress.php | 3 ++ src/Catalog/Weights.php | 35 ++++++++++++ src/ConfigEntry/ConfigEntry.php | 2 +- src/ConfigEntry/ConfigEntryTrait.php | 8 +-- src/ConfigEntry/EnvoyExtension.php | 18 +++---- src/Health/HealthChecks.php | 81 +++++++++++++++++++++++++--- 10 files changed, 135 insertions(+), 29 deletions(-) diff --git a/src/AbstractModel.php b/src/AbstractModel.php index e566be2c..61225a70 100644 --- a/src/AbstractModel.php +++ b/src/AbstractModel.php @@ -22,14 +22,15 @@ abstract class AbstractModel implements \JsonSerializable { + /** @var array */ private array $_dyn = []; - public function __set(string $field, $value): void + public function __set(string $field, mixed $value): void { $this->_dyn[$field] = $value; } - public function &__get(string $field) + public function &__get(string $field): mixed { if (!array_key_exists($field, $this->_dyn)) { $this->_dyn[$field] = null; @@ -42,6 +43,9 @@ public function __unset(string $field): void unset($this->_dyn[$field]); } + /** + * @return array + */ public function _getDynamicFields(): array { return $this->_dyn; diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 1fcb4ac5..a5b0f741 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -52,7 +52,7 @@ class CatalogService extends AbstractModel public string $Partition; /** - * @param array|null $data + * @param array|null $data * @param array $ServiceTags */ public function __construct( diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 6992637f..b2f45c98 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -85,7 +85,6 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul return $n; } - public function jsonSerialize(): \stdClass { $out = new \stdClass(); diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 2832db77..4f6968f1 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -37,6 +37,9 @@ class Node extends AbstractModel public string $PeerName; public null|Locality $Locality; + /** + * @param array|null $data + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $ID = '', @@ -50,8 +53,7 @@ public function __construct( string $Partition = '', string $PeerName = '', null|Locality $Locality = null - ) - { + ) { $this->ID = $ID; $this->Node = $Node; $this->Address = $Address; diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index 444c0809..cf02e047 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -27,6 +27,9 @@ class ServiceAddress extends AbstractModel public string $Address; public int $Port; + /** + * @param array|null $data + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $address = '', diff --git a/src/Catalog/Weights.php b/src/Catalog/Weights.php index 867f38ba..0a237e98 100644 --- a/src/Catalog/Weights.php +++ b/src/Catalog/Weights.php @@ -27,6 +27,21 @@ class Weights extends AbstractModel public int $Passing; public int $Warning; + /** + * @param array|null $data + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + int $Passing = 0, + int $Warning = 0 + ) { + $this->Passing = $Passing; + $this->Warning = $Warning; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + public function getPassing(): int { return $this->Passing; @@ -48,4 +63,24 @@ public function setWarning(int $Warning): self $this->Warning = $Warning; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Passing = $this->Passing; + $out->Warning = $this->Warning; + return $out; + } } diff --git a/src/ConfigEntry/ConfigEntry.php b/src/ConfigEntry/ConfigEntry.php index 2c809da6..a8332bea 100644 --- a/src/ConfigEntry/ConfigEntry.php +++ b/src/ConfigEntry/ConfigEntry.php @@ -34,7 +34,7 @@ public function GetName(): string; public function GetNamespace(): string; - public function GetMeta(): array; + public function GetMeta(): \stdClass; public function GetCreateIndex(): int; diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php index 10834fb2..7d0125b9 100644 --- a/src/ConfigEntry/ConfigEntryTrait.php +++ b/src/ConfigEntry/ConfigEntryTrait.php @@ -25,7 +25,7 @@ trait ConfigEntryTrait public string $Kind; public string $Name; public string $Namespace; - public array $Meta; + public null|\stdClass $Meta; public int $CreateIndex; public int $ModifyIndex; @@ -62,14 +62,14 @@ public function setNamespace(string $Namespace): self return $this; } - public function getMeta(): array + public function getMeta(): null|\stdClass { return $this->Meta; } - public function setMeta(array|\stdClass $Meta): self + public function setMeta(null|\stdClass $Meta): self { - $this->Meta = (array)$Meta; + $this->Meta = $Meta; return $this; } diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 20d88c04..3747ccad 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -26,7 +26,7 @@ class EnvoyExtension extends AbstractModel { public string $Name; public bool $Required; - public array $Arguments; + public null|\stdClass $Arguments; public string $ConsulVersion; public string $EnvoyVersion; @@ -34,13 +34,13 @@ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Name = '', bool $Required = false, - array|\stdClass $Arguments = [], + null|\stdClass $Arguments = null, string $ConsulVersion = '', string $EnvoyVersion = '', ) { $this->Name = $Name; $this->Required = $Required; - $this->setArguments($Arguments); + $this->Arguments = $Arguments; $this->ConsulVersion = $ConsulVersion; $this->EnvoyVersion = $EnvoyVersion; if (null !== $data && [] !== $data) { @@ -70,14 +70,14 @@ public function setRequired(bool $Required): self return $this; } - public function getArguments(): array + public function getArguments(): null|\stdClass { return $this->Arguments; } - public function setArguments(array|\stdClass $Arguments): self + public function setArguments(null|\stdClass $Arguments): self { - $this->Arguments = (array)$Arguments; + $this->Arguments = $Arguments; return $this; } @@ -107,11 +107,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul { $n = $into ?? new self(); foreach ($decoded as $k => $v) { - if ('Arguments' === $k) { - $n->setArguments($v); - } else { - $n->{$k} = $v; - } + $n->{$k} = $v; } return $n; } diff --git a/src/Health/HealthChecks.php b/src/Health/HealthChecks.php index f764dd26..e60860c4 100644 --- a/src/Health/HealthChecks.php +++ b/src/Health/HealthChecks.php @@ -22,17 +22,26 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Consul; -use DCarbone\PHPConsulAPI\FakeSlice; -class HealthChecks extends FakeSlice +/** + * @implements \ArrayAccess + * @implements \IteratorAggregate + */ +class HealthChecks extends AbstractModel 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,66 @@ 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->Checks[$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; + } else { + if (!is_int($offset)) { + throw new \InvalidArgumentException('Offset must be an integer'); + } + $this->Checks[$offset] = $value; + } + } + + public function offsetUnset($offset): void + { + unset($this->Checks[$offset]); + } + + /** + * @param array<\stdClass> $decoded + */ + public static function jsonUnserialize(array $decoded, null|self $into = null): static + { + $n = $into ?? 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; } } From fc4176bab5cbdac8c9260e0774ee2c36778f3156 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 27 May 2025 17:53:29 -0500 Subject: [PATCH 47/79] smidge more work --- src/ConfigEntry/ConfigEntryTrait.php | 24 ---- src/ConfigEntry/EnvoyExtension.php | 3 + src/ConfigEntry/ExposeConfig.php | 65 ++++++++--- src/ConfigEntry/ExposePath.php | 73 +++++++++--- src/ConfigEntry/MeshConfigEntry.php | 55 +++++++-- src/ConfigEntry/MeshDirectionalTLSConfig.php | 115 +++++++++++++++++++ src/ConfigEntry/MeshHTTPConfig.php | 63 ++++++++++ src/ConfigEntry/MeshTLSConfig.php | 88 ++++++++++++++ src/ConfigEntry/PeeringMeshConfig.php | 63 ++++++++++ src/Consul.php | 22 ++++ 10 files changed, 508 insertions(+), 63 deletions(-) create mode 100644 src/ConfigEntry/MeshDirectionalTLSConfig.php create mode 100644 src/ConfigEntry/MeshHTTPConfig.php create mode 100644 src/ConfigEntry/MeshTLSConfig.php create mode 100644 src/ConfigEntry/PeeringMeshConfig.php diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php index 7d0125b9..85b6c4f7 100644 --- a/src/ConfigEntry/ConfigEntryTrait.php +++ b/src/ConfigEntry/ConfigEntryTrait.php @@ -22,35 +22,11 @@ trait ConfigEntryTrait { - public string $Kind; - public string $Name; public string $Namespace; public null|\stdClass $Meta; public int $CreateIndex; public int $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 getNamespace(): string { return $this->Namespace; diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 3747ccad..1af3ec01 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -30,6 +30,9 @@ class EnvoyExtension extends AbstractModel public string $ConsulVersion; public string $EnvoyVersion; + /** + * @param array|null $data + */ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Name = '', diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index 5750ad49..9d05a783 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -21,26 +21,28 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ExposeConfig extends AbstractModel { - 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, - ], - ]; - - private const FIELD_CHECKS = 'Checks'; - private const FIELD_PATHS = 'Paths'; - public bool $Checks; + /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> */ public array $Paths; + /** + * @param array|null $data + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + bool $Checks = false, + array $Paths = [], + ) { + $this->Checks = $Checks; + $this->setPaths(...$Paths); + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + public function isChecks(): bool { return $this->Checks; @@ -52,14 +54,47 @@ 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): static + { + $n = $n ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 5ead75f9..a60fdd6f 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -21,28 +21,36 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ExposePath extends AbstractModel { - 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; public string $Path; public int $LocalPathPort; public string $Protocol; public bool $ParsedFromCheck; + /** + * @param array|null $data + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + 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; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + public function getListenerPort(): int { return $this->ListenerPort; @@ -97,4 +105,43 @@ public function setParsedFromCheck(bool $ParsedFromCheck): self $this->ParsedFromCheck = $ParsedFromCheck; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): static + { + $n = $n ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (0 !== $this->ListenerPort) { + $out->listener_port = $this->ListenerPort; + } + if ('' !== $this->Path) { + $out->Path = $this->Path; + } + if (0 !== $this->LocalPathPort) { + $out->local_path_port = $this->LocalPathPort; + } + if ('' !== $this->Protocol) { + $out->Protocol = $this->Protocol; + } + if ($this->ParsedFromCheck) { + $out->ParsedFromCheck = true; + } + return $out; + } } diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 27414433..6fcfea57 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -21,24 +21,57 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\Consul; class MeshConfigEntry extends AbstractModel 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 TransparentProxyConfig $TransparentProxy; + public bool $AllowEnablingPermissiveMutualTLS; + public null|MeshTLSConfig $TLS; + public null|MeshHTTPConfig $HTTP; + public null|PeeringMeshConfig $Peering; - private const FIELD_TRANSPARENT_PROXY = 'TransparentProxy'; + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Partition = '', + string $Namespace = '', + null|TransparentProxyConfig $TransparentProxy = null, + bool $AllowEnablingPermissiveMutualTLS = false, + null|MeshTLSConfig $TLS = null, + null|MeshHTTPConfig $HTTP = null, + null|PeeringMeshConfig $Peering = null, + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0 + ) { + $this->Partition = $Partition; + $this->Namespace = $Namespace; + $this->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + $this->TransparentProxy = $TransparentProxy; + $this->AllowEnablingPermissiveMutualTLS = $AllowEnablingPermissiveMutualTLS; + $this->TLS = $TLS; + $this->HTTP = $HTTP; + $this->Peering = $Peering; - public TransparentProxyConfig $TransparentProxy; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + + public function getKind(): string + { + return Consul::MeshConfig; + } + + public function getName(): string + { + return Consul::MeshConfigMesh; + } public function getTransparentProxy(): TransparentProxyConfig { diff --git a/src/ConfigEntry/MeshDirectionalTLSConfig.php b/src/ConfigEntry/MeshDirectionalTLSConfig.php new file mode 100644 index 00000000..32e31311 --- /dev/null +++ b/src/ConfigEntry/MeshDirectionalTLSConfig.php @@ -0,0 +1,115 @@ + */ + 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 ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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/MeshHTTPConfig.php b/src/ConfigEntry/MeshHTTPConfig.php new file mode 100644 index 00000000..ece4e585 --- /dev/null +++ b/src/ConfigEntry/MeshHTTPConfig.php @@ -0,0 +1,63 @@ +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 ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->SanitizeXForwardClientCert = $this->SanitizeXForwardClientCert; + return $out; + } +} diff --git a/src/ConfigEntry/MeshTLSConfig.php b/src/ConfigEntry/MeshTLSConfig.php new file mode 100644 index 00000000..881a5131 --- /dev/null +++ b/src/ConfigEntry/MeshTLSConfig.php @@ -0,0 +1,88 @@ +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 ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (null !== $this->Incoming) { + $out->Incoming = $this->Incoming; + } + if (null !== $this->Outgoing) { + $out->Outgoing = $this->Outgoing; + } + return $out; + } +} diff --git a/src/ConfigEntry/PeeringMeshConfig.php b/src/ConfigEntry/PeeringMeshConfig.php new file mode 100644 index 00000000..252679ad --- /dev/null +++ b/src/ConfigEntry/PeeringMeshConfig.php @@ -0,0 +1,63 @@ +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 ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->PeerThroughMeshGateways = $this->PeerThroughMeshGateways; + return $out; + } +} diff --git a/src/Consul.php b/src/Consul.php index e82d8de2..361ca0e9 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -86,6 +86,28 @@ class Consul public const MemberTagKeyReadReplica = 'read_replica'; public const MemberTagValueReadReplica = '1'; + // 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 public const _headerConsulPrefix = 'X-Consul-'; From 3b2e565933e6f85946425943450b97f829a0505c Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 28 May 2025 20:34:38 -0500 Subject: [PATCH 48/79] more work. --- src/ConfigEntry/MeshConfigEntry.php | 104 +++++++++++++++++- .../TransparentProxyMeshConfig.php | 64 +++++++++++ 2 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 src/ConfigEntry/TransparentProxyMeshConfig.php diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 6fcfea57..58eb4c9f 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -28,7 +28,7 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry use ConfigEntryTrait; public string $Partition; - public TransparentProxyConfig $TransparentProxy; + public TransparentProxyMeshConfig $TransparentProxy; public bool $AllowEnablingPermissiveMutualTLS; public null|MeshTLSConfig $TLS; public null|MeshHTTPConfig $HTTP; @@ -38,7 +38,7 @@ public function __construct( null|array $data = null, // Deprecated, will be removed. string $Partition = '', string $Namespace = '', - null|TransparentProxyConfig $TransparentProxy = null, + null|TransparentProxyMeshConfig $TransparentProxy = null, bool $AllowEnablingPermissiveMutualTLS = false, null|MeshTLSConfig $TLS = null, null|MeshHTTPConfig $HTTP = null, @@ -73,14 +73,110 @@ 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 ($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; + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Kind = Consul::MeshConfigMesh; + if ('' !== $this->Partition) { + $out->Partition = $this->Partition; + } + $out->TransparentProxy = $this->TransparentProxy; + if ($this->AllowEnablingPermissiveMutualTLS) { + $out->allow_enabling_permissive_mutual_tls = 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/TransparentProxyMeshConfig.php b/src/ConfigEntry/TransparentProxyMeshConfig.php new file mode 100644 index 00000000..9b1901eb --- /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 ($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; + } +} From beaaf364c6de0f3cc3f728a6690c554c46a7e236 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 9 Jun 2025 08:39:02 -0500 Subject: [PATCH 49/79] more little bits of work --- src/ConfigEntry/ExposeConfig.php | 1 + src/ConfigEntry/PassiveHealthCheck.php | 110 +++++++-- src/ConfigEntry/ProxyConfigEntry.php | 215 ++++++++++++++---- .../ServiceResolverFailoverPolicy.php | 88 +++++++ .../ServiceResolverPrioritizeByLocality.php | 65 ++++++ 5 files changed, 426 insertions(+), 53 deletions(-) create mode 100644 src/ConfigEntry/ServiceResolverFailoverPolicy.php create mode 100644 src/ConfigEntry/ServiceResolverPrioritizeByLocality.php diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index 9d05a783..358ec5e4 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -30,6 +30,7 @@ class ExposeConfig extends AbstractModel /** * @param array|null $data + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> $Paths */ public function __construct( null|array $data = null, // Deprecated, will be removed. diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index 686b00ed..e346e27c 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -26,23 +26,29 @@ class PassiveHealthCheck extends AbstractModel { - protected const FIELDS = [ - self::FIELD_INTERVAL => [ - Transcoding::FIELD_UNMARSHAL_CALLBACK => Transcoding::UNMARSHAL_DURATION, - Transcoding::FIELD_OMITEMPTY => true, - ], - ]; - - private const FIELD_INTERVAL = 'Interval'; - public Time\Duration $Interval; public int $MaxFailures; - public function __construct(?array $data = []) - { - parent::__construct($data); - if (!isset($this->Interval)) { - $this->Interval = new Time\Duration(); + public null|int $EnforcingConsecutive5xx; + public null|int $MaxEjectionPercent; + + public null|Time\Duration $BaseEjectionTime; + + public function __construct( + null|array $data = [], // Deprecated, will be removed. + null|Time\Duration $Interval = null, + int $MaxFailures = 0, + null|int $EnforcingConsecutive5xx = null, + null|int $MaxEjectionPercent = null, + null|Time\Duration $BaseEjectionTime = null, + ) { + $this->Interval = $Interval ?? Time::Duration(0); + $this->MaxFailures = $MaxFailures; + $this->EnforcingConsecutive5xx = $EnforcingConsecutive5xx; + $this->MaxEjectionPercent = $MaxEjectionPercent; + $this->BaseEjectionTime = $BaseEjectionTime; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); } } @@ -67,4 +73,80 @@ 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(): ?Time\Duration + { + return $this->BaseEjectionTime; + } + + public function setBaseEjectionTime(?Time\Duration $BaseEjectionTime): self + { + $this->BaseEjectionTime = $BaseEjectionTime; + return $this; + } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index 8d7c9d6e..b6b48dfc 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -21,76 +21,147 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\FakeMap; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\Consul; class ProxyConfigEntry extends AbstractModel 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; + public null|\stdClass $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 __construct( + array|null $data = null, // Deprecated, will be removed. + string $Kind = '', + string $Name = '', + string $Partition = '', + string|ProxyMode $Mode = ProxyMode::Default, + null|TransparentProxyConfig $TransparentProxy = null, + string|MutualTLSMode $MutualTLSMode = MutualTLSMode::Default, + null|\stdClass $Config = null, + null|MeshGatewayConfig $MeshGateway = null, + null|ExposeConfig $Expose = null, + null|AccessLogsConfig $AccessLogs = null, + array $EnvoyExtensions = [], + null|ServiceResolverFailoverPolicy $FailoverPolicy = null, + null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null, + string $Namespace = '', + null|\stdClass $Meta = null, + 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->Config = $Config; + $this->MeshGateway = $MeshGateway ?? new MeshGatewayConfig(); + $this->Expose = $Expose ?? new ExposeConfig(); + $this->AccessLogs = $AccessLogs; + $this->EnvoyExtensions = $this->setEnvoyExtensions(...$EnvoyExtensions); + $this->FailoverPolicy = $FailoverPolicy; + $this->PrioritizeByLocality = $PrioritizeByLocality; + $this->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + } + + 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 getMode(): string + 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; + } + + public function getConfig(): null|\stdClass { return $this->Config; } - public function setConfig(mixed $Config): self + public function setConfig(null|\stdClass $Config): self { - $this->Config = FakeMap::parse($Config); + $this->Config = $Config; return $this; } @@ -115,4 +186,70 @@ 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } } diff --git a/src/ConfigEntry/ServiceResolverFailoverPolicy.php b/src/ConfigEntry/ServiceResolverFailoverPolicy.php new file mode 100644 index 00000000..97b40ea7 --- /dev/null +++ b/src/ConfigEntry/ServiceResolverFailoverPolicy.php @@ -0,0 +1,88 @@ + */ + 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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/ServiceResolverPrioritizeByLocality.php b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php new file mode 100644 index 00000000..2e88cf9a --- /dev/null +++ b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php @@ -0,0 +1,65 @@ +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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->Mode) { + $out->Mode = $this->Mode; + } + return $out; + } +} \ No newline at end of file From d60ec93a3ea29967f35b1eef62f0608553c5bd4e Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 10 Jun 2025 18:18:57 -0500 Subject: [PATCH 50/79] lazy --- src/ConfigEntry/ProxyConfigEntry.php | 67 +++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index b6b48dfc..e87f4e53 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -75,7 +75,7 @@ public function __construct( $this->MeshGateway = $MeshGateway ?? new MeshGatewayConfig(); $this->Expose = $Expose ?? new ExposeConfig(); $this->AccessLogs = $AccessLogs; - $this->EnvoyExtensions = $this->setEnvoyExtensions(...$EnvoyExtensions); + $this->setEnvoyExtensions(...$EnvoyExtensions); $this->FailoverPolicy = $FailoverPolicy; $this->PrioritizeByLocality = $PrioritizeByLocality; $this->Meta = $Meta; @@ -241,7 +241,29 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul { $n = $into ?? new self(); foreach ($decoded as $k => $v) { - $n->{$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); + } else { + $n->{$k} = $v; + } } return $n; } @@ -252,4 +274,45 @@ public function jsonSerialize(): \stdClass foreach ($this->_getDynamicFields() as $k => $v) { $out->{$k} = $v; } + $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->jsonSerialize(); + } + if (MutualTLSMode::Default !== $this->MutualTLSMode) { + $out->MutualTLSMode = $this->MutualTLSMode->value; + } + if (null !== $this->Config) { + $out->Config = $this->Config; + } + $out->MeshGateway = $this->MeshGateway; + $out->Expose = $this->Expose; + if (null !== $this->AccessLogs) { + $out->AccessLogs = $this->AccessLogs->jsonSerialize(); + } + if ([] !== $this->EnvoyExtensions) { + $out->EnvoyExtensions = $this->EnvoyExtensions; + } + if (null !== $this->FailoverPolicy) { + $out->FailoverPolicy = $this->FailoverPolicy->jsonSerialize(); + } + if (null !== $this->PrioritizeByLocality) { + $out->PrioritizeByLocality = $this->PrioritizeByLocality->jsonSerialize(); + } + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + if (null !== $this->Meta) { + $out->Meta = $this->Meta; + } + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + return $out; + } } From 75a4fc4a8d9db66f51c96f3d8be8c3388e437d93 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 14 Jun 2025 16:15:45 -0500 Subject: [PATCH 51/79] smidge more work --- src/ConfigEntry/CookieConfig.php | 105 +++++++++++++ src/ConfigEntry/HashPolicy.php | 142 ++++++++++++++++++ src/ConfigEntry/LeastRequestConfig.php | 69 +++++++++ src/ConfigEntry/LoadBalancer.php | 32 ++++ src/ConfigEntry/ProxyConfigEntry.php | 20 ++- src/ConfigEntry/RingHashConfig.php | 66 +++++++- .../ServiceResolverConfigEntry.php | 20 ++- src/Consul.php | 2 +- src/funcs.php | 15 +- 9 files changed, 448 insertions(+), 23 deletions(-) create mode 100644 src/ConfigEntry/CookieConfig.php create mode 100644 src/ConfigEntry/HashPolicy.php create mode 100644 src/ConfigEntry/LeastRequestConfig.php create mode 100644 src/ConfigEntry/LoadBalancer.php diff --git a/src/ConfigEntry/CookieConfig.php b/src/ConfigEntry/CookieConfig.php new file mode 100644 index 00000000..f7298456 --- /dev/null +++ b/src/ConfigEntry/CookieConfig.php @@ -0,0 +1,105 @@ +Session = $Session; + $this->TTL = $TTL ?? new Time\Duration(); + $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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('TTL' === $k) { + $n->TTL = Time::Duration($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ($this->Session) { + $out->Session = $this->Session; + } + if (($v = $this->TTL->Nanoseconds()) && 0 !== $v) { + $out->TTL = $v; + } + if ('' !== $this->Path) { + $out->Path = $this->Path; + } + return $out; + } +} \ No newline at end of file diff --git a/src/ConfigEntry/HashPolicy.php b/src/ConfigEntry/HashPolicy.php new file mode 100644 index 00000000..28ea517b --- /dev/null +++ b/src/ConfigEntry/HashPolicy.php @@ -0,0 +1,142 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('field_value' === $k) { + $n->FieldValue = $v; + } elseif ('cookie_config' === $k) { + $n->CookieConfig = CookieConfig::jsonUnserialize($v); + } elseif ('source_ip' === $k) { + $n->SourceIP = (bool)$v; + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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/LeastRequestConfig.php b/src/ConfigEntry/LeastRequestConfig.php new file mode 100644 index 00000000..c8af7ffd --- /dev/null +++ b/src/ConfigEntry/LeastRequestConfig.php @@ -0,0 +1,69 @@ +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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('choice_count' === $k) { + $n->ChoiceCount = $v; + } else { + $n->{$k}= $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (0 !== $this->ChoiceCount) { + $out->ChoiceCount = $this->ChoiceCount; + } + return $out; + } +} \ No newline at end of file diff --git a/src/ConfigEntry/LoadBalancer.php b/src/ConfigEntry/LoadBalancer.php new file mode 100644 index 00000000..55824e60 --- /dev/null +++ b/src/ConfigEntry/LoadBalancer.php @@ -0,0 +1,32 @@ +|null $data + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions + */ public function __construct( array|null $data = null, // Deprecated, will be removed. string $Kind = '', @@ -283,7 +288,7 @@ public function jsonSerialize(): \stdClass $out->ProxyMode = $this->Mode->value; } if (null !== $this->TransparentProxy) { - $out->TransparentProxy = $this->TransparentProxy->jsonSerialize(); + $out->TransparentProxy = $this->TransparentProxy; } if (MutualTLSMode::Default !== $this->MutualTLSMode) { $out->MutualTLSMode = $this->MutualTLSMode->value; @@ -291,19 +296,18 @@ public function jsonSerialize(): \stdClass if (null !== $this->Config) { $out->Config = $this->Config; } - $out->MeshGateway = $this->MeshGateway; - $out->Expose = $this->Expose; + _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway); + _enc_obj_if_valued($out, 'Expose', $this->Expose); if (null !== $this->AccessLogs) { - $out->AccessLogs = $this->AccessLogs->jsonSerialize(); - } - if ([] !== $this->EnvoyExtensions) { + $out->AccessLogs = $this->AccessLogs; + } if ([] !== $this->EnvoyExtensions) { $out->EnvoyExtensions = $this->EnvoyExtensions; } if (null !== $this->FailoverPolicy) { - $out->FailoverPolicy = $this->FailoverPolicy->jsonSerialize(); + $out->FailoverPolicy = $this->FailoverPolicy; } if (null !== $this->PrioritizeByLocality) { - $out->PrioritizeByLocality = $this->PrioritizeByLocality->jsonSerialize(); + $out->PrioritizeByLocality = $this->PrioritizeByLocality; } if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php index 6b7fad97..039a6485 100644 --- a/src/ConfigEntry/RingHashConfig.php +++ b/src/ConfigEntry/RingHashConfig.php @@ -21,15 +21,67 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class RingHashConfig extends AbstractModel { - 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, null|self $into = null): static + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (0 !== $this->MinimumRingSize) { + $out->MinimumRingSize = $this->MinimumRingSize; + } + if (0 !== $this->MaximumRingSize) { + $out->MaximumRingSize = $this->MaximumRingSize; + } + return $out; + } } diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index 7766fbd2..8afc7929 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -21,15 +21,23 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\Go\Time; class ServiceResolverConfigEntry extends AbstractModel 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 $DefaultSubnet; + public \stdClass $Subsets; + public null|ServiceResolverRedirect $Redirect; + public \stdClass $Failover; + public Time\Duration $ConnectTimeout; + public Time\Duration $RequestTimeout; + public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; + public null|LoadBalancer $LoadBalancer; + + } diff --git a/src/Consul.php b/src/Consul.php index 361ca0e9..f7cccf5c 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -99,7 +99,7 @@ class Consul 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"; diff --git a/src/funcs.php b/src/funcs.php index 8d088c0f..ad8a1bb0 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -31,5 +31,18 @@ function dur_to_millisecond(Time\Duration $dur): string $ms = 1; } - return sprintf('%dms', $ms); + return "${ms}ms"; +} + +$_zeroObject = new \stdclass(); + +function _enc_obj_if_valued(\stdClass &$out, string $field, \stdClass | \JsonSerializable $obj): void +{ + global $_zeroObject; + if ($obj instanceof \JsonSerializable) { + $obj = $obj->jsonSerialize(); + } + if ($obj != $_zeroObject) { + $out->{$field} = $obj; + } } From 2e3954d8a044f4f64cefd9167b3abba2f1af07cd Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 14 Jun 2025 19:43:38 -0500 Subject: [PATCH 52/79] little bit more --- src/ConfigEntry/HashPolicy.php | 4 +- src/ConfigEntry/LoadBalancer.php | 107 +++++++- .../ServiceResolverConfigEntry.php | 257 +++++++++++++++++- 3 files changed, 362 insertions(+), 6 deletions(-) diff --git a/src/ConfigEntry/HashPolicy.php b/src/ConfigEntry/HashPolicy.php index 28ea517b..1437fde5 100644 --- a/src/ConfigEntry/HashPolicy.php +++ b/src/ConfigEntry/HashPolicy.php @@ -105,10 +105,10 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul foreach ($decoded as $k => $v) { if ('field_value' === $k) { $n->FieldValue = $v; - } elseif ('cookie_config' === $k) { + } elseif ('CookieConfig' === $k || 'cookie_config' === $k) { $n->CookieConfig = CookieConfig::jsonUnserialize($v); } elseif ('source_ip' === $k) { - $n->SourceIP = (bool)$v; + $n->SourceIP = $v; } else { $n->{$k} = $v; } diff --git a/src/ConfigEntry/LoadBalancer.php b/src/ConfigEntry/LoadBalancer.php index 55824e60..e23ef711 100644 --- a/src/ConfigEntry/LoadBalancer.php +++ b/src/ConfigEntry/LoadBalancer.php @@ -27,6 +27,111 @@ class LoadBalancer extends AbstractModel public string $Policy; public null|RingHashConfig $RingHashConfig; public null|LeastRequestConfig $LeastRequestConfig; - + /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\HashPolicy> */ public array $HashPolicies; + + /** + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\HashPolicy> $HashPolicies + */ + public function __construct( + string $Policy = '', + null|RingHashConfig $RingHashConfig = null, + null|LeastRequestConfig $LeastRequestConfig = null, + array $HashPolicies = [] + ) { + $this->Policy = $Policy; + $this->RingHashConfig = $RingHashConfig; + $this->LeastRequestConfig = $LeastRequestConfig; + $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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach($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) { + foreach ($v as $hp) { + $n->HashPolicies[] = HashPolicy::jsonUnserialize($hp); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->Policy) { + $out->Policy = $this->Policy; + } + if (null !== $this->RingHashConfig) { + $out->RingHashConfig = $this->RingHashConfig; + } + if (null !== $this->LeastRequestConfig) { + $out->LeastRequestConfig = $this->LeastRequestConfig; + } + if ([] !== $this->HashPolicies) { + $out->HashPolicies = $this->HashPolicies; + } + return $out; + } } \ No newline at end of file diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index 8afc7929..3cbd76fe 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -22,6 +22,8 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\Go\Time; +use stdClass; +use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry { @@ -30,14 +32,263 @@ class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry public string $Kind; public string $Name; public string $Partition; - public string $DefaultSubnet; - public \stdClass $Subsets; + public string $DefaultSubset; + public null|\stdClass $Subsets; public null|ServiceResolverRedirect $Redirect; - public \stdClass $Failover; + public null|\stdClass $Failover; public Time\Duration $ConnectTimeout; public Time\Duration $RequestTimeout; public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; public null|LoadBalancer $LoadBalancer; + public function __construct( + string $Kind = '', + string $Name = '', + string $Partition = '', + string $Namespace = '', + string $DefaultSubnet = '', + null|\stdClass $Subsets = null, + null|ServiceResolverRedirect $Redirect = null, + null|\stdClass $Failover = null, + null|Time\Duration $ConnectTimeout = null, + null|Time\Duration $RequestTimeout = null, + null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null, + null|LoadBalancer $LoadBalancer = null, + null|\stdClass $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 = $ConnectTimeout ?? new Time\Duration(0); + $this->RequestTimeout = $RequestTimeout ?? new Time\Duration(0); + $this->PrioritizeByLocality = $PrioritizeByLocality; + $this->LoadBalancer = $LoadBalancer; + $this->Meta = $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; + } + + public function getSubsets(): null|\stdClass + { + return $this->Subsets; + } + + public function setSubsetKey(string $key, ServiceResolverSubset $subset): self + { + if (!isset($this->Subsets)) { + $this->Subsets = new \stdClass(); + } + $this->Subsets->{$key} = $subset; + return $this; + } + + public function setSubsets(\stdClass $subsets): self + { + unset($this->Subsets); + 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; + } + + public function getFailover(): null|\stdClass + { + return $this->Failover; + } + + public function setFailoverKey(string $key, ServiceResolverFailover $failover): self + { + if (!isset($this->Failover)) { + $this->Failover = new \stdClass(); + } + $this->Failover->{$key} = $failover; + return $this; + } + + public function setFailover(\stdClass $failover): self + { + unset($this->Failover); + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach($decoded as $k => $v) { + if ('default_subset' === $k) { + $n->DefaultSubset = $v; + } elseif ('Subsets' === $k) { + foreach($v as $k => $ss) { + $n->setSubsetKey($k, ServiceResolverSubset::jsonUnserialize($ss)); + } + } else if ('Redirect' === $k) { + $n->Redirect = ServiceResolverRedirect::jsonUnserialize($v); + } elseif ('Failover' === $k) { + foreach($v as $k => $fo) { + $n->setFailoverKey($k, ServiceResolverFailover::jsonUnserialize($fo)); + } + } 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); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new stdClass(); + foreach($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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->default_subset = $this->DefaultSubset; + } + _enc_obj_if_valued($out, 'Subsets', $this->Subsets); + if (null !== $this->Redirect) { + $out->Redirect = $this->Redirect; + } + _enc_obj_if_valued($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; + } + _enc_obj_if_valued($out, 'Meta', $this->Meta); + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + return $out; + } } From 499467c6668e86359c51fecbdeb0ef964fe1a7a0 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 17 Jun 2025 15:32:52 -0500 Subject: [PATCH 53/79] bit more done. --- src/ConfigEntry/DestinationConfig.php | 88 +++++ src/ConfigEntry/InstanceLevelRateLimits.php | 109 ++++++ .../InstanceLevelRouteRateLimits.php | 136 +++++++ src/ConfigEntry/RateLimits.php | 67 ++++ src/ConfigEntry/ServiceConfigEntry.php | 350 +++++++++++++++--- 5 files changed, 704 insertions(+), 46 deletions(-) create mode 100644 src/ConfigEntry/DestinationConfig.php create mode 100644 src/ConfigEntry/InstanceLevelRateLimits.php create mode 100644 src/ConfigEntry/InstanceLevelRouteRateLimits.php create mode 100644 src/ConfigEntry/RateLimits.php diff --git a/src/ConfigEntry/DestinationConfig.php b/src/ConfigEntry/DestinationConfig.php new file mode 100644 index 00000000..69cd0153 --- /dev/null +++ b/src/ConfigEntry/DestinationConfig.php @@ -0,0 +1,88 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ([] !== $this->Addresses) { + $out->Addresses = $this->Addresses; + } + if (0 !== $this->Port) { + $out->Port = $this->Port; + } + return $out; + } +} diff --git a/src/ConfigEntry/InstanceLevelRateLimits.php b/src/ConfigEntry/InstanceLevelRateLimits.php new file mode 100644 index 00000000..880f6a66 --- /dev/null +++ b/src/ConfigEntry/InstanceLevelRateLimits.php @@ -0,0 +1,109 @@ + */ + public array $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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..32d41890 --- /dev/null +++ b/src/ConfigEntry/InstanceLevelRouteRateLimits.php @@ -0,0 +1,136 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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/ConfigEntry/RateLimits.php b/src/ConfigEntry/RateLimits.php new file mode 100644 index 00000000..7d0e0f05 --- /dev/null +++ b/src/ConfigEntry/RateLimits.php @@ -0,0 +1,67 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->InstanceLevel = $this->InstanceLevel; + return $out; + } +} diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index 1afd9799..c20b9ea9 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -21,55 +21,120 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; +use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class ServiceConfigEntry extends AbstractModel 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 $Kind; + public string $Name; + public string $Partition; public string $Protocol; - public string $Mode; - public ?TransparentProxyConfig $TransparentProxy = null; + public ProxyMode $Mode; + public null|TransparentProxyConfig $TransparentProxy; + + public MutualTLSMode $MutualTLSMode; public MeshGatewayConfig $MeshGateway; public ExposeConfig $Expose; public string $ExternalSNI; - public ?UpstreamConfiguration $UpstreamConfig = null; + public null|UpstreamConfiguration $UpstreamConfig; + public null|DestinationConfig $Destination; + public int $MaxInboundConnections; + public int $LocalConnectTimeoutMs; + public int $LocalRequestTimeoutMs; + public string $BalanceInboundConnections; + public null|RateLimits $RateLimits; + public array $EnvoyExtensions; + + /** + * @param array|null $data + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + 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 = [], + null|\stdClass $Meta = null, + 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->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)$data, $this); + } + } + + 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 +147,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 +213,196 @@ 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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->external_sni = $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; + } + _enc_obj_if_valued($out, 'Meta', $this->Meta); + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + return $out; + } } From 90bffb1966312232b276475c108939a88e29022f Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 17 Jun 2025 20:35:04 -0500 Subject: [PATCH 54/79] cleanup around duration setting --- src/ACL/ACLAuthMethod.php | 13 +------------ src/ConfigEntry/CookieConfig.php | 4 ++-- src/ConfigEntry/PassiveHealthCheck.php | 19 +++++++++++-------- .../ServiceResolverConfigEntry.php | 8 ++++---- src/ConfigEntry/ServiceRouteDestination.php | 4 ++-- src/Health/HealthCheckDefinition.php | 6 +++--- src/Operator/SerfMember.php | 4 ++-- src/QueryMeta.php | 4 ++-- src/QueryOptions.php | 3 +++ src/Request.php | 4 ++-- src/RequestResponse.php | 4 ++-- src/Session/SessionEntry.php | 4 ++-- src/WriteMeta.php | 4 ++-- src/WriteOptions.php | 5 ++++- 14 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 3cdd2661..2b630e00 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -41,18 +41,7 @@ class ACLAuthMethod extends AbstractModel /** * @param array|null $data Deprecated, will be removed. - * @param string $Name - * @param string $Type - * @param string $DisplayName - * @param string $Description - * @param int|float|string|\DateInterval|\DCarbone\Go\Time\Duration|null $MaxTokenTTL - * @param string $TokenLocality - * @param null|\stdClass $Config - * @param int $CreateIndex - * @param int $ModifyIndex * @param iterable<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules - * @param string $Namespace - * @param string $Partition */ public function __construct( null|array $data = null, // Deprecated, will be removed. @@ -73,7 +62,7 @@ public function __construct( $this->Type = $Type; $this->DisplayName = $DisplayName; $this->Description = $Description; - $this->setMaxTokenTTL($MaxTokenTTL); + $this->MaxTokenTTL = Time::Duration($MaxTokenTTL); $this->TokenLocality = $TokenLocality; $this->Config = $Config; $this->CreateIndex = $CreateIndex; diff --git a/src/ConfigEntry/CookieConfig.php b/src/ConfigEntry/CookieConfig.php index f7298456..4487c373 100644 --- a/src/ConfigEntry/CookieConfig.php +++ b/src/ConfigEntry/CookieConfig.php @@ -31,11 +31,11 @@ class CookieConfig extends AbstractModel public function __construct( bool $Session = false, - null|Time\Duration $TTL = null, + null|string|int|float|\DateInterval|Time\Duration $TTL = null, string $Path = '' ) { $this->Session = $Session; - $this->TTL = $TTL ?? new Time\Duration(); + $this->TTL = Time::Duration($TTL); $this->Path = $Path; } diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index e346e27c..e55a8fa6 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -34,19 +34,22 @@ class PassiveHealthCheck extends AbstractModel public null|Time\Duration $BaseEjectionTime; + /** + * @param array|null $data + */ public function __construct( null|array $data = [], // Deprecated, will be removed. - null|Time\Duration $Interval = null, + null|string|int|float|\DateInterval|Time\Duration $Interval = null, int $MaxFailures = 0, null|int $EnforcingConsecutive5xx = null, null|int $MaxEjectionPercent = null, - null|Time\Duration $BaseEjectionTime = null, + null|string|int|float|\DateInterval|Time\Duration $BaseEjectionTime = null, ) { - $this->Interval = $Interval ?? Time::Duration(0); + $this->Interval = Time::Duration($Interval); $this->MaxFailures = $MaxFailures; $this->EnforcingConsecutive5xx = $EnforcingConsecutive5xx; $this->MaxEjectionPercent = $MaxEjectionPercent; - $this->BaseEjectionTime = $BaseEjectionTime; + $this->BaseEjectionTime = Time::Duration($BaseEjectionTime); if (null !== $data && [] !== $data) { self::jsonUnserialize((object)$data, $this); } @@ -57,9 +60,9 @@ 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; } @@ -96,12 +99,12 @@ public function setMaxEjectionPercent(null|int $MaxEjectionPercent): self return $this; } - public function getBaseEjectionTime(): ?Time\Duration + public function getBaseEjectionTime(): null|Time\Duration { return $this->BaseEjectionTime; } - public function setBaseEjectionTime(?Time\Duration $BaseEjectionTime): self + public function setBaseEjectionTime(null|Time\Duration $BaseEjectionTime): self { $this->BaseEjectionTime = $BaseEjectionTime; return $this; diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index 3cbd76fe..9e1aa755 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -50,8 +50,8 @@ public function __construct( null|\stdClass $Subsets = null, null|ServiceResolverRedirect $Redirect = null, null|\stdClass $Failover = null, - null|Time\Duration $ConnectTimeout = null, - null|Time\Duration $RequestTimeout = 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|\stdClass $Meta = null, @@ -66,8 +66,8 @@ public function __construct( $this->setSubsets($Subsets); $this->Redirect = $Redirect; $this->setFailover($Failover); - $this->ConnectTimeout = $ConnectTimeout ?? new Time\Duration(0); - $this->RequestTimeout = $RequestTimeout ?? new Time\Duration(0); + $this->ConnectTimeout = Time::Duration($ConnectTimeout); + $this->RequestTimeout = Time::Duration($RequestTimeout); $this->PrioritizeByLocality = $PrioritizeByLocality; $this->LoadBalancer = $LoadBalancer; $this->Meta = $Meta; diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index 45e595e3..db7329f5 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -107,9 +107,9 @@ 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 = $RequestTimeout; + $this->RequestTimeout = Time::Duration($RequestTimeout); return $this; } diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index 75983ca4..a8dad9bc 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -53,9 +53,9 @@ public function __construct( $this->Body = $Body; $this->TLSSkipVerify = $TLSSkipVerify; $this->TCP = $TCP; - $this->setIntervalDuration($IntervalDuration); - $this->setTimeoutDuration($TimeoutDuration); - $this->setDeregisterCriticalServiceAfterDuration($DeregisterCriticalServiceAfterDuration); + $this->IntervalDuration = Time::Duration($IntervalDuration); + $this->TimeoutDuration = Time::Duration($TimeoutDuration); + $this->DeregisterCriticalServiceAfterDuration = Time::Duration($DeregisterCriticalServiceAfterDuration); if (null !== $data && [] !== $data) { static::jsonUnserialize((object)$data, $this); } diff --git a/src/Operator/SerfMember.php b/src/Operator/SerfMember.php index 3c22bf53..3ce951ba 100644 --- a/src/Operator/SerfMember.php +++ b/src/Operator/SerfMember.php @@ -157,9 +157,9 @@ public function getRTT(): Time\Duration return $this->RTT; } - public function setRTT(Time\Duration $RTT): self + public function setRTT(null|string|int|float|\DateInterval|Time\Duration $RTT): self { - $this->RTT = $RTT; + $this->RTT = Time::Duration($RTT); return $this; } } diff --git a/src/QueryMeta.php b/src/QueryMeta.php index 96d3760b..d130d152 100644 --- a/src/QueryMeta.php +++ b/src/QueryMeta.php @@ -36,14 +36,14 @@ class QueryMeta public function __construct( string $RequestUrl, - null|Time\Duration $RequestTime, + null|string|int|float|\DateInterval|Time\Duration $RequestTime, int $LastIndex = 0, string $LastContentHash = '', int $LastContact = 0, bool $KnownLeader = false, bool $AddressTranslationEnabled = false, bool $CacheHit = false, - null|Time\Duration $CacheAge = null + null|string|int|float|\DateInterval|Time\Duration $CacheAge = null ) { $this->RequestUrl = $RequestUrl; $this->RequestTime = Time::Duration($RequestTime); diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 7360de01..4172a2ac 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -46,6 +46,9 @@ class QueryOptions implements RequestOptions public bool $Pretty; + /** + * @param array|null $data + */ public function __construct( null|array $data = null, // Deprecated do not use. string $Namespace = '', diff --git a/src/Request.php b/src/Request.php index 10c6e199..06540d40 100644 --- a/src/Request.php +++ b/src/Request.php @@ -31,7 +31,7 @@ class Request public Values $header; public Params $params; - public ?Time\Duration $timeout = null; + public null|Time\Duration $timeout = null; private string $scheme; private string $address; @@ -93,7 +93,7 @@ public function getBody(): mixed return $this->body; } - public function applyOptions(?RequestOptions $opts): void + public function applyOptions(null|RequestOptions $opts): void { if (null === $opts) { return; diff --git a/src/RequestResponse.php b/src/RequestResponse.php index 29dfe33e..3a954f99 100644 --- a/src/RequestResponse.php +++ b/src/RequestResponse.php @@ -30,10 +30,10 @@ final class RequestResponse public null|ResponseInterface $Response; public null|Error $Err; - public function __construct(RequestMeta $meta, Time\Duration $dur, null|ResponseInterface $resp, null|Error $err) + public function __construct(RequestMeta $meta, null|string|int|float|\DateInterval|Time\Duration $dur, null|ResponseInterface $resp, null|Error $err) { $this->RequestMeta = $meta; - $this->Duration = $dur; + $this->Duration = Time::Duration($dur); $this->Response = $resp; $this->Err = $err; } diff --git a/src/Session/SessionEntry.php b/src/Session/SessionEntry.php index e269c2b1..fe6490e7 100644 --- a/src/Session/SessionEntry.php +++ b/src/Session/SessionEntry.php @@ -119,9 +119,9 @@ public function getLockDelay(): Time\Duration return $this->LockDelay; } - public function setLockDelay(Time\Duration $LockDelay): self + public function setLockDelay(null|string|int|float|\DateInterval|Time\Duration $LockDelay): self { - $this->LockDelay = $LockDelay; + $this->LockDelay = Time::Duration($LockDelay); return $this; } diff --git a/src/WriteMeta.php b/src/WriteMeta.php index d911ecca..c92c3ffa 100644 --- a/src/WriteMeta.php +++ b/src/WriteMeta.php @@ -26,9 +26,9 @@ class WriteMeta { public Time\Duration $RequestTime; - public function __construct(Time\Duration $RequestTime) + public function __construct(null|string|int|float|\DateInterval|Time\Duration $RequestTime) { - $this->RequestTime = $RequestTime; + $this->RequestTime = Time::Duration($RequestTime); } public function getRequestTime(): Time\Duration diff --git a/src/WriteOptions.php b/src/WriteOptions.php index f659b0ad..4f4232b8 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -31,6 +31,9 @@ class WriteOptions implements RequestOptions public Time\Duration $Timeout; + /** + * @param array|null $data + */ public function __construct( null|array $data = null, // Deprecated do not use. string $Namespace = '', @@ -89,7 +92,7 @@ public function setRelayFactor(int $relayFactor): void $this->RelayFactor = $relayFactor; } - public function getTimeout(): ?Time\Duration + public function getTimeout(): null|Time\Duration { return $this->Timeout; } From e930027cfe3c69b0fab0053f84a6c7a01214cc5c Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 17 Jun 2025 20:58:14 -0500 Subject: [PATCH 55/79] little bit more work --- src/ConfigEntry/GatewayServiceTLSConfig.php | 69 ++++++++ src/ConfigEntry/GatewayTLSConfig.php | 149 ++++++++++++++++++ src/ConfigEntry/GatewayTLSSDSConfig.php | 89 +++++++++++ src/ConfigEntry/IngressGatewayConfigEntry.php | 33 ++++ src/ConfigEntry/InstanceLevelRateLimits.php | 3 + src/funcs.php | 23 +++ 6 files changed, 366 insertions(+) create mode 100644 src/ConfigEntry/GatewayServiceTLSConfig.php create mode 100644 src/ConfigEntry/GatewayTLSConfig.php create mode 100644 src/ConfigEntry/GatewayTLSSDSConfig.php create mode 100644 src/ConfigEntry/IngressGatewayConfigEntry.php diff --git a/src/ConfigEntry/GatewayServiceTLSConfig.php b/src/ConfigEntry/GatewayServiceTLSConfig.php new file mode 100644 index 00000000..aba5c070 --- /dev/null +++ b/src/ConfigEntry/GatewayServiceTLSConfig.php @@ -0,0 +1,69 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach($decoded as $k => $v) { + if ('SDS' === $k) { + $n->SDS = GatewayTLSSDSConfig::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..ab4cda34 --- /dev/null +++ b/src/ConfigEntry/GatewayTLSConfig.php @@ -0,0 +1,149 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 $into; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..5739c1de --- /dev/null +++ b/src/ConfigEntry/GatewayTLSSDSConfig.php @@ -0,0 +1,89 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->ClusterName) { + $out->ClusterName = $this->ClusterName; + } + if ('' !== $this->CertResource) { + $out->CertResource = $this->CertResource; + } + return $out; + } +} diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php new file mode 100644 index 00000000..d84a8578 --- /dev/null +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -0,0 +1,33 @@ + */ public array $Routes; + /** + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\InstanceLevelRouteRateLimits> $Routes + */ public function __construct( int $RequestsPerSecond = 0, int $RequestsMaxBurst = 0, diff --git a/src/funcs.php b/src/funcs.php index ad8a1bb0..cbeffc2f 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -21,6 +21,7 @@ */ use DCarbone\Go\Time; +use DCarbone\PHPConsulAPI\ConfigEntry; function dur_to_millisecond(Time\Duration $dur): string { @@ -46,3 +47,25 @@ function _enc_obj_if_valued(\stdClass &$out, string $field, \stdClass | \JsonSer $out->{$field} = $obj; } } + +function MakeConfigEntry(string $kind, string $name): ConfigEntry\ConfigEntry +{ + switch ($kind) { + case Consul::ServiceDefaults: + return new ConfigEntry\ServiceConfigEntry(kind: $kind, name: $name); + case Consul::ProxyDefaults: + return new ConfigEntry\ProxyConfigEntry(kind: $kind, name: $name); + case Consul::ServiceRouter: + return new ConfigEntry\ServiceRouterConfigEntry(kind: $kind, name: $name); + case Consul::ServiceSplitter: + return new ConfigEntry\ServiceSplitterConfigEntry(kind: $kind, name: $name); + case Consul::ServiceResolver: + return new ConfigEntry\ServiceResolverConfigEntry(kind: $kind, name: $name); + case Consul::IngressGateway: + return new ConfigEntry\IngressGatewayConfigEntry(kind: $kind, name: $name); + + + default: + throw new \InvalidArgumentException(sprintf('Unknown kind "%s"', $kind)); + } +} From e066d7cfd076c2cd8c4fb80fc22165478db21afd Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 17 Jun 2025 22:15:14 -0500 Subject: [PATCH 56/79] few more small bits of work --- src/ConfigEntry/HTTPHeaderModifiers.php | 121 ++++++++++++ src/ConfigEntry/IngressListener.php | 128 ++++++++++++ src/ConfigEntry/IngressService.php | 247 ++++++++++++++++++++++++ 3 files changed, 496 insertions(+) create mode 100644 src/ConfigEntry/HTTPHeaderModifiers.php create mode 100644 src/ConfigEntry/IngressListener.php create mode 100644 src/ConfigEntry/IngressService.php diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php new file mode 100644 index 00000000..3c13e207 --- /dev/null +++ b/src/ConfigEntry/HTTPHeaderModifiers.php @@ -0,0 +1,121 @@ + */ + public array $Remove; + + /** + * @param array $Remove + */ + public function __construct( + null|\stdClass $Add = null, + null|\stdClass $Set = null, + array $Remove = [] + ) { + $this->Add = $Add ?? new \stdClass(); + $this->Set = $Set ?? new \stdClass(); + $this->setRemove(...$Remove); + } + + public function getAdd(): \stdClass + { + return $this->Add; + } + + public function setAddKey(string $key, string $value): self + { + $this->Add->{$key} = $value; + return $this; + } + + public function setAdd(\stdClass $Add): self + { + foreach ($Add as $k => $v) { + $this->setaddKey($k, $v); + } + return $this; + } + + public function getSet(): \stdClass + { + return $this->Set; + } + + public function setSetKey(string $key, string $value): self + { + $this->Set->{$key} = $value; + return $this; + } + + public function setSet(\stdClass $Set): self + { + foreach ($Set as $k => $v) { + $this->setSetKey($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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + _enc_obj_if_valued($out, 'Add', $this->Add); + _enc_obj_if_valued($out, 'Set', $this->Set); + if ([] !== $this->Remove) { + $out->Remove = $this->Remove; + } + return $out; + } +} diff --git a/src/ConfigEntry/IngressListener.php b/src/ConfigEntry/IngressListener.php new file mode 100644 index 00000000..0ffbe2f8 --- /dev/null +++ b/src/ConfigEntry/IngressListener.php @@ -0,0 +1,128 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 $into; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..1464c877 --- /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; + + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach($decoded as $k => $v) { + if ('RequestHeaders' === $k || 'request_headers' === $k) { + $n->RequestHeaders = HTTPHeaderModifiers::jsonUnserialize($v, $n->RequestHeaders); + } elseif ('ResponseHeaders' === $k || 'response_headers' === $k) { + $n->ResponseHeaders = HTTPHeaderModifiers::jsonUnserialize($v, $n->ResponseHeaders); + } elseif ('TLS' === $k) { + $n->TLS = GatewayServiceTLSConfig::jsonUnserialize($v, $n->TLS); + } elseif ('PassiveHealthCheck' === $k || 'passive_health_check' === $k) { + $n->PassiveHealthCheck = PassiveHealthCheck::jsonUnserialize($v, $n->PassiveHealthCheck); + } else { + $n->{$k} = $v; + } + } + return $into; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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; + } +} From 2e8e9ae7f5bb460ff00cdd773c3bb238cc4cd383 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 18 Jun 2025 19:26:15 -0500 Subject: [PATCH 57/79] more config entry stuff --- src/ConfigEntry/IngressGatewayConfigEntry.php | 152 ++++++++++++++++- src/ConfigEntry/IngressServiceConfig.php | 115 +++++++++++++ src/ConfigEntry/LinkedService.php | 159 +++++++++++++++++ src/ConfigEntry/PassiveHealthCheck.php | 1 - src/ConfigEntry/ServiceConfigEntry.php | 5 +- .../ServiceResolverConfigEntry.php | 19 ++- .../TerminatingGatewayConfigEntry.php | 161 ++++++++++++++++++ src/funcs.php | 2 + 8 files changed, 603 insertions(+), 11 deletions(-) create mode 100644 src/ConfigEntry/IngressServiceConfig.php create mode 100644 src/ConfigEntry/LinkedService.php create mode 100644 src/ConfigEntry/TerminatingGatewayConfigEntry.php diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index d84a8578..1f76fd5d 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -21,6 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry { @@ -30,4 +31,153 @@ class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry public string $Name; public string $Partition; public GatewayTLSConfig $TLS; -} \ No newline at end of file + /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener> */ + public array $Listeners; + public null|IngressServiceConfig $Defaults; + + /** + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener> $Listeners + */ + public function __construct( + string $Kind = '', + string $Name = '', + string $Partition = '', + string $Namespace = '', + null|GatewayTLSConfig $TLS = null, + array $Listeners = [], + null|\stdClass $Meta = null, + 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->Meta = $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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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->jsonSerialize(); + } + $out->CreateIndex = $this->CreateIndex; + $out->ModifyIndex = $this->ModifyIndex; + return $out; + } +} diff --git a/src/ConfigEntry/IngressServiceConfig.php b/src/ConfigEntry/IngressServiceConfig.php new file mode 100644 index 00000000..72788854 --- /dev/null +++ b/src/ConfigEntry/IngressServiceConfig.php @@ -0,0 +1,115 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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/LinkedService.php b/src/ConfigEntry/LinkedService.php new file mode 100644 index 00000000..45404705 --- /dev/null +++ b/src/ConfigEntry/LinkedService.php @@ -0,0 +1,159 @@ +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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if ('' !== $this->Namespace) { + $out->Namespace = $this->Namespace; + } + if ('' !== $this->Name) { + $out->Name = $this->Name; + } + if ('' !== $this->CAFile) { + $out->ca_file = $this->CAFile; + } + if ('' !== $this->CertFile) { + $out->cert_file = $this->CertFile; + } + if ('' !== $this->KeyFile) { + $out->key_file = $this->KeyFile; + } + if ('' !== $this->SNI) { + $out->sni = $this->SNI; + } + return $out; + } +} diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index e55a8fa6..fa4ae803 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -22,7 +22,6 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class PassiveHealthCheck extends AbstractModel { diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index c20b9ea9..b390e894 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -21,6 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; + use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class ServiceConfigEntry extends AbstractModel implements ConfigEntry @@ -400,7 +401,9 @@ public function jsonSerialize(): \stdClass if ([] !== $this->EnvoyExtensions) { $out->EnvoyExtensions = $this->EnvoyExtensions; } - _enc_obj_if_valued($out, 'Meta', $this->Meta); + 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 9e1aa755..ce5ba167 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -23,6 +23,7 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\Go\Time; use stdClass; + use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry @@ -224,18 +225,18 @@ public function setLoadBalancer(null|LoadBalancer $LoadBalancer): self public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self { $n = $into ?? new self(); - foreach($decoded as $k => $v) { + foreach ($decoded as $k => $v) { if ('default_subset' === $k) { $n->DefaultSubset = $v; } elseif ('Subsets' === $k) { - foreach($v as $k => $ss) { - $n->setSubsetKey($k, ServiceResolverSubset::jsonUnserialize($ss)); + foreach ($v as $kk => $vv) { + $n->setSubsetKey($kk, ServiceResolverSubset::jsonUnserialize($vv)); } - } else if ('Redirect' === $k) { + } elseif ('Redirect' === $k) { $n->Redirect = ServiceResolverRedirect::jsonUnserialize($v); } elseif ('Failover' === $k) { - foreach($v as $k => $fo) { - $n->setFailoverKey($k, ServiceResolverFailover::jsonUnserialize($fo)); + foreach ($v as $kk => $vv) { + $n->setFailoverKey($kk, ServiceResolverFailover::jsonUnserialize($vv)); } } elseif ('ConnectTimeout' === $k || 'connect_timeout' === $k) { $n->ConnectTimeout = Time::ParseDuration($v); @@ -255,7 +256,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { $out = new stdClass(); - foreach($this->_getDynamicFields() as $k => $v) { + foreach ($this->_getDynamicFields() as $k => $v) { $out->{$k} = $v; } $out->Kind = $this->Kind; @@ -286,7 +287,9 @@ public function jsonSerialize(): \stdClass if (null !== $this->LoadBalancer) { $out->LoadBalancer = $this->LoadBalancer; } - _enc_obj_if_valued($out, 'Meta', $this->Meta); + if (null !== $this->Meta) { + $out->Meta = $this->Meta; + } $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; return $out; diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php new file mode 100644 index 00000000..fd02ba33 --- /dev/null +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -0,0 +1,161 @@ + */ + public array $Services; + public string $Partition; + + /** + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\LinkedService> $Services + */ + public function __construct( + string $Kind = '', + string $Name = '', + array $Services = [], + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, + string $Partition = '', + string $Namespace = '', + ) { + $this->Kind = $Kind; + $this->Name = $Name; + $this->setServices(...$Services); + $this->Meta = $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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Services' === $k) { + $n->Services = []; + foreach ($v as $vv) { + $n->Services[] = LinkedService::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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/funcs.php b/src/funcs.php index cbeffc2f..84f5cbcc 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -63,6 +63,8 @@ function MakeConfigEntry(string $kind, string $name): ConfigEntry\ConfigEntry return new ConfigEntry\ServiceResolverConfigEntry(kind: $kind, name: $name); case Consul::IngressGateway: return new ConfigEntry\IngressGatewayConfigEntry(kind: $kind, name: $name); + case Consul::TerminatingGateway: + return new ConfigEntry\TerminatingGatewayConfigEntry(kind: $kind, name: $name); default: From 11f58f08bda5a922febfd3ee796c6037e2aa5f96 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 18 Jun 2025 21:41:28 -0500 Subject: [PATCH 58/79] lotsa work --- src/ConfigEntry/ExposePath.php | 6 +- src/ConfigEntry/IngressGatewayConfigEntry.php | 1 - src/ConfigEntry/IntentionAction.php | 30 ++ .../IntentionHTTPHeaderPermission.php | 160 +++++++++ src/ConfigEntry/IntentionHTTPPermission.php | 159 +++++++++ .../IntentionJWTClaimVerification.php | 82 +++++ src/ConfigEntry/IntentionJWTRequirement.php | 95 ++++++ src/ConfigEntry/IntentionMatchType.php | 30 ++ src/ConfigEntry/IntentionPermission.php | 106 ++++++ src/ConfigEntry/IntentionSourceType.php | 29 ++ src/ConfigEntry/LinkedService.php | 8 +- src/ConfigEntry/MeshConfigEntry.php | 2 +- src/ConfigEntry/ServiceConfigEntry.php | 2 +- .../ServiceIntentionsConfigEntry.php | 159 +++++++++ .../ServiceResolverConfigEntry.php | 2 +- src/ConfigEntry/ServiceRoute.php | 64 +++- src/ConfigEntry/ServiceRouteDestination.php | 207 ++++++++++-- src/ConfigEntry/ServiceRouteHTTPMatch.php | 128 ++++++-- .../ServiceRouteHTTPMatchHeader.php | 76 +++-- .../ServiceRouteHTTPMatchQueryParam.php | 51 ++- src/ConfigEntry/ServiceRouteMatch.php | 46 ++- src/ConfigEntry/ServiceRouterConfigEntry.php | 116 ++++++- src/ConfigEntry/ServiceSplit.php | 110 ++++++- .../ServiceSplitterConfigEntry.php | 116 ++++++- src/ConfigEntry/SourceIntention.php | 310 ++++++++++++++++++ .../TerminatingGatewayConfigEntry.php | 2 +- src/SimpleJsonUnserializeTrait.php | 33 ++ src/funcs.php | 4 +- 28 files changed, 1983 insertions(+), 151 deletions(-) create mode 100644 src/ConfigEntry/IntentionAction.php create mode 100644 src/ConfigEntry/IntentionHTTPHeaderPermission.php create mode 100644 src/ConfigEntry/IntentionHTTPPermission.php create mode 100644 src/ConfigEntry/IntentionJWTClaimVerification.php create mode 100644 src/ConfigEntry/IntentionJWTRequirement.php create mode 100644 src/ConfigEntry/IntentionMatchType.php create mode 100644 src/ConfigEntry/IntentionPermission.php create mode 100644 src/ConfigEntry/IntentionSourceType.php create mode 100644 src/ConfigEntry/ServiceIntentionsConfigEntry.php create mode 100644 src/ConfigEntry/SourceIntention.php create mode 100644 src/SimpleJsonUnserializeTrait.php diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index a60fdd6f..0576fc76 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -106,7 +106,7 @@ public function setParsedFromCheck(bool $ParsedFromCheck): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): static + public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): self { $n = $n ?? new self(); foreach ($decoded as $k => $v) { @@ -128,13 +128,13 @@ public function jsonSerialize(): \stdClass $out->{$k} = $v; } if (0 !== $this->ListenerPort) { - $out->listener_port = $this->ListenerPort; + $out->ListenerPort = $this->ListenerPort; } if ('' !== $this->Path) { $out->Path = $this->Path; } if (0 !== $this->LocalPathPort) { - $out->local_path_port = $this->LocalPathPort; + $out->LocalPathPort = $this->LocalPathPort; } if ('' !== $this->Protocol) { $out->Protocol = $this->Protocol; diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index 1f76fd5d..d385eb5d 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -21,7 +21,6 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry { diff --git a/src/ConfigEntry/IntentionAction.php b/src/ConfigEntry/IntentionAction.php new file mode 100644 index 00000000..e97f19d8 --- /dev/null +++ b/src/ConfigEntry/IntentionAction.php @@ -0,0 +1,30 @@ +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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..25f9097e --- /dev/null +++ b/src/ConfigEntry/IntentionHTTPPermission.php @@ -0,0 +1,159 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..455da4ad --- /dev/null +++ b/src/ConfigEntry/IntentionJWTClaimVerification.php @@ -0,0 +1,82 @@ + */ + 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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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..633bf534 --- /dev/null +++ b/src/ConfigEntry/IntentionJWTRequirement.php @@ -0,0 +1,95 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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/ConfigEntry/IntentionSourceType.php b/src/ConfigEntry/IntentionSourceType.php new file mode 100644 index 00000000..69dca2a1 --- /dev/null +++ b/src/ConfigEntry/IntentionSourceType.php @@ -0,0 +1,29 @@ +Name = $this->Name; } if ('' !== $this->CAFile) { - $out->ca_file = $this->CAFile; + $out->CAFile = $this->CAFile; } if ('' !== $this->CertFile) { - $out->cert_file = $this->CertFile; + $out->CertFile = $this->CertFile; } if ('' !== $this->KeyFile) { - $out->key_file = $this->KeyFile; + $out->KeyFile = $this->KeyFile; } if ('' !== $this->SNI) { - $out->sni = $this->SNI; + $out->SNI = $this->SNI; } return $out; } diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 58eb4c9f..37d645a0 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -161,7 +161,7 @@ public function jsonSerialize(): \stdClass } $out->TransparentProxy = $this->TransparentProxy; if ($this->AllowEnablingPermissiveMutualTLS) { - $out->allow_enabling_permissive_mutual_tls = true; + $out->AllowEnablingPermissiveMutualTLS = true; } if (null !== $this->TLS) { $out->TLS = $this->TLS; diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index b390e894..bb5dc804 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -375,7 +375,7 @@ public function jsonSerialize(): \stdClass _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway); _enc_obj_if_valued($out, 'Expose', $this->Expose); if ('' !== $this->ExternalSNI) { - $out->external_sni = $this->ExternalSNI; + $out->ExternalSNI = $this->ExternalSNI; } if (null !== $this->UpstreamConfig) { $out->UpstreamConfig = $this->UpstreamConfig; diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php new file mode 100644 index 00000000..abad027b --- /dev/null +++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php @@ -0,0 +1,159 @@ + */ + public array $Sources; + public null|IntentionJWTRequirement $JWT; + + /** + * @param array $Sources + */ + public function __construct( + string $Kind = '', + string $name = '', + string $Partition = '', + string $Namespace = '', + array $Sources = [], + null|IntentionJWTRequirement $JWT = null, + null|\stdClass $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->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + } + + public function getKind(): string + { + return $this->Kind; + } + + 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; + } + + /** + * @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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 ce5ba167..3a19b416 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -268,7 +268,7 @@ public function jsonSerialize(): \stdClass $out->Namespace = $this->Namespace; } if ('' !== $this->DefaultSubset) { - $out->default_subset = $this->DefaultSubset; + $out->DefaultSubset = $this->DefaultSubset; } _enc_obj_if_valued($out, 'Subsets', $this->Subsets); if (null !== $this->Redirect) { diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php index c8c60400..7aad16b5 100644 --- a/src/ConfigEntry/ServiceRoute.php +++ b/src/ConfigEntry/ServiceRoute.php @@ -24,8 +24,66 @@ class ServiceRoute extends AbstractModel { - 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 db7329f5..7bdb6b30 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -22,41 +22,58 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouteDestination extends AbstractModel { - 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 $Partition; public string $PrefixRewrite; public Time\Duration $RequestTimeout; + 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; @@ -113,6 +141,17 @@ public function setRequestTimeout(null|string|int|float|\DateInterval|Time\Durat return $this; } + public function getIdleTimeout(): Time\Duration + { + return $this->IdleTimeout; + } + + public function setIdleTimeout(null|string|int|float|\DateInterval|Time\Duration $IdleTimeout): self + { + $this->IdleTimeout = Time::Duration($IdleTimeout); + return $this; + } + public function getNumRetries(): int { return $this->NumRetries; @@ -135,14 +174,132 @@ 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 169e8693..84d7e778 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -21,43 +21,43 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouteHTTPMatch extends AbstractModel { - 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 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 { return $this->PathExact; @@ -91,36 +91,104 @@ 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + 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 67e4e434..2ef4866c 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -21,26 +21,9 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouteHTTPMatchHeader extends AbstractModel { - 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; public string $Exact; @@ -49,6 +32,24 @@ class ServiceRouteHTTPMatchHeader extends AbstractModel 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 { return $this->Name; @@ -115,14 +116,51 @@ 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): static { $this->Invert = $Invert; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 cfdcbdf0..0b854236 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -21,25 +21,26 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouteHTTPMatchQueryParam extends AbstractModel { - 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; 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 { return $this->Name; @@ -83,4 +84,32 @@ public function setRegex(string $Regex): self $this->Regex = $Regex; return $this; } + + public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..1f21b33f 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -21,31 +21,49 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouteMatch extends AbstractModel { - 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) + { + $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, null|self $into = null): self + { + $n = $into ?? new self(null); + foreach ($decoded as $k => $v) { + if ('HTTP' === $k) { + $n->HTTP = ServiceRouteHTTPMatch::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + if (null !== $this->HTTP) { + $out->HTTP = $this->HTTP; + } + return $out; + } } diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 86c3129f..10533aa8 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -21,33 +21,125 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceRouterConfigEntry extends AbstractModel 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 + */ + public function __construct( + string $Kind = '', + string $Name = '', + string $Partition = '', + string $Namespace = '', + array $Routes = [], + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, + ) { + $this->Kind = $Kind; + $this->Name = $Name; + $this->Partition = $Partition; + $this->Namespace = $Namespace; + $this->setRoutes(...$Routes); + $this->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + } - public array $Routes; + 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; + } + + /** + * @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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Routes' === $k) { + $n->Routes = []; + foreach ($v as $vv) { + $n->Routes[] = ServiceRoute::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 0f320f19..8875650a 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -21,24 +21,34 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceSplit extends AbstractModel { - 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; 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,82 @@ 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(): ?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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 afee7126..ba5f435f 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -21,33 +21,125 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceSplitterConfigEntry extends AbstractModel 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 + */ + public function __construct( + string $Kind = '', + string $Name = '', + string $Partition = '', + string $Namespace = '', + array $Splits = [], + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, + ) { + $this->Kind = $Kind; + $this->Name = $Name; + $this->Partition = $Partition; + $this->Namespace = $Namespace; + $this->setSplits(...$Splits); + $this->Meta = $Meta; + $this->CreateIndex = $CreateIndex; + $this->ModifyIndex = $ModifyIndex; + } - public array $Splits; + 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; + } + + /** + * @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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Splits' === $k) { + $n->Splits = []; + foreach ($v as $vv) { + $n->Splits[] = ServiceSplit::jsonUnserialize($vv); + } + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..ce6a54bf --- /dev/null +++ b/src/ConfigEntry/SourceIntention.php @@ -0,0 +1,310 @@ + */ + 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 : Time\Time::createFromFormat(DATE_RFC3339, $v); + } elseif ('legacy_update_time' === $k) { + $n->LegacyUpdateTime = null === $v ? null : Time\Time::createFromFormat(DATE_RFC3339, $v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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 index fd02ba33..64b8a8bc 100644 --- a/src/ConfigEntry/TerminatingGatewayConfigEntry.php +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -146,7 +146,7 @@ public function jsonSerialize(): \stdClass $out->Services = $this->Services; } if (null !== $this->Meta) { - $out->meta = $this->Meta; + $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; diff --git a/src/SimpleJsonUnserializeTrait.php b/src/SimpleJsonUnserializeTrait.php new file mode 100644 index 00000000..92561ed2 --- /dev/null +++ b/src/SimpleJsonUnserializeTrait.php @@ -0,0 +1,33 @@ + $v) { + $n->{$k} = $v; + } + return $n; + } +} \ No newline at end of file diff --git a/src/funcs.php b/src/funcs.php index 84f5cbcc..7db3a63c 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -21,7 +21,6 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\ConfigEntry; function dur_to_millisecond(Time\Duration $dur): string { @@ -65,7 +64,8 @@ function MakeConfigEntry(string $kind, string $name): ConfigEntry\ConfigEntry return new ConfigEntry\IngressGatewayConfigEntry(kind: $kind, name: $name); case Consul::TerminatingGateway: return new ConfigEntry\TerminatingGatewayConfigEntry(kind: $kind, name: $name); - + case Consul::ServiceIntentions: + return new ConfigEntry\ServiceIntentionsConfigEntry(kind: $kind, name: $name); default: throw new \InvalidArgumentException(sprintf('Unknown kind "%s"', $kind)); From ed0c336c0b9f02c289096e5806b1facdb4451827 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 30 Jun 2025 20:10:04 -0500 Subject: [PATCH 59/79] cleaning up coordinate --- composer.json | 2 - src/Coordinate/Coordinate.php | 203 +++++++++++++++++---- src/Coordinate/CoordinateConfig.php | 115 +++++++++--- src/Coordinate/CoordinateDatacenterMap.php | 69 +++++-- src/Coordinate/CoordinateEntry.php | 80 ++++++-- src/Coordinate/CoordinateUnitVectorAt.php | 64 +++++++ src/Coordinate/funcs.php | 100 ---------- src/Metrics/Label.php | 77 ++++++++ 8 files changed, 520 insertions(+), 190 deletions(-) create mode 100644 src/Coordinate/CoordinateUnitVectorAt.php delete mode 100644 src/Coordinate/funcs.php create mode 100644 src/Metrics/Label.php diff --git a/composer.json b/composer.json index b106011d..57c8434c 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ }, "autoload": { "files": [ - "src/Coordinate/funcs.php", "src/funcs.php" ], "psr-4": { @@ -38,7 +37,6 @@ }, "autoload-dev": { "files": [ - "src/Coordinate/funcs.php", "tests/funcs.php" ], "psr-4": { diff --git a/src/Coordinate/Coordinate.php b/src/Coordinate/Coordinate.php index 7898d6a3..73bec637 100644 --- a/src/Coordinate/Coordinate.php +++ b/src/Coordinate/Coordinate.php @@ -30,37 +30,57 @@ */ class Coordinate extends AbstractModel { - 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|null $data + * @param array $Vec + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + 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; + } + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)($data), $this); } } + /** + * @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; @@ -76,12 +96,7 @@ 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 Clone(): self { return clone $this; } @@ -89,11 +104,13 @@ 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 @@ -107,11 +124,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 +136,130 @@ 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 + */ + private 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 + */ + private 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 + */ + private 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 + */ + private 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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($decoded as $k => $v) { + if ('Vec' === $k) { + $n->Vec = (array)$v; + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Vec = $this->Vec; + $out->Error = $this->Error; + $out->Adjustment = $this->Adjustment; + $out->Height = $this->Height; + return $out; } } diff --git a/src/Coordinate/CoordinateConfig.php b/src/Coordinate/CoordinateConfig.php index 9ec4d450..4b1902dd 100644 --- a/src/Coordinate/CoordinateConfig.php +++ b/src/Coordinate/CoordinateConfig.php @@ -21,6 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\Metrics\Label; class CoordinateConfig extends AbstractModel { @@ -33,29 +34,53 @@ 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 @@ -145,4 +170,52 @@ public function setGravityRho(float $gravityRho): self $this->GravityRho = $gravityRho; return $this; } + + /** + * @return array<\DCarbone\PHPConsulAPI\Metrics\Label> + */ + public function getMetricsLabels(): array + { + 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 ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..e1152b49 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -21,23 +21,31 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class CoordinateDatacenterMap extends AbstractModel { - protected const FIELDS = [ - self::FIELD_COORDINATES => [ - Transcoding::FIELD_TYPE => Transcoding::ARRAY, - Transcoding::FIELD_CLASS => Coordinate::class, - Transcoding::FIELD_ARRAY_TYPE => Transcoding::OBJECT, - ], - ]; - - private const FIELD_COORDINATES = 'Coordinates'; - public string $Datacenter = ''; public string $AreaID = ''; - public array $Coordinates = []; + /** @var array<\DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry> */ + public array $Coordinates; + + /** + * @param array|null $data + * @param array<\DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry> $Coordinates + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Datacenter = '', + string $AreaID = '', + array $Coordinates = [], + ) { + $this->Datacenter = $Datacenter; + $this->AreaID = $AreaID; + $this->setCoordinates(...$Coordinates); + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)($data), $this); + } + } public function getDatacenter(): string { @@ -49,8 +57,45 @@ public function getAreaID(): string return $this->AreaID; } + /** + * @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, null|self $into = null): self + { + $n = $into ?? new self(); + foreach ($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 = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Datacenter = $this->Datacenter; + $out->AreaID = $this->AreaID; + $out->Coordinates = $this->Coordinates; + return $out; + } } diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index d6503694..0925bf94 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -21,23 +21,32 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class CoordinateEntry extends AbstractModel { - 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; + + /** + * @param array|null $data + */ + public function __construct( + null|array $data = null, // Deprecated, will be removed. + string $Node = '', + string $Segment = '', + string $Partition = '', + null|Coordinate $Coord = null, + ) { + $this->Node = $Node; + $this->Segment = $Segment; + $this->Partition = $Partition; + $this->Coord = $Coord; + if (null !== $data && [] !== $data) { + self::jsonUnserialize((object)($data), $this); + } + } public function getNode(): string { @@ -61,14 +70,53 @@ 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, null | self $into = null): self + { + $n = $into ?? new self(); + foreach($decoded as $k => $v) { + if ('Coord' === $k) { + $n->Coord = Coordinate::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $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..0beaf425 --- /dev/null +++ b/src/Coordinate/CoordinateUnitVectorAt.php @@ -0,0 +1,64 @@ + */ + 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 9f0a90b2..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/Metrics/Label.php b/src/Metrics/Label.php new file mode 100644 index 00000000..7020a158 --- /dev/null +++ b/src/Metrics/Label.php @@ -0,0 +1,77 @@ +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 ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } + + public function jsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + $out->Name = $this->Name; + $out->Value = $this->Value; + return $out; + } +} From b940734879f59d62b6df8df238a3007806456cb5 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 30 Jun 2025 20:18:46 -0500 Subject: [PATCH 60/79] composer update --- composer.lock | 70 ++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/composer.lock b/composer.lock index 74de3870..dbea1932 100644 --- a/composer.lock +++ b/composer.lock @@ -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", @@ -943,16 +943,16 @@ }, { "name": "phpstan/phpstan", - "version": "2.1.11", + "version": "2.1.17", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30" + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30", - "reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/89b5ef665716fa2a52ecd2633f21007a6a349053", + "reference": "89b5ef665716fa2a52ecd2633f21007a6a349053", "shasum": "" }, "require": { @@ -997,7 +997,7 @@ "type": "github" } ], - "time": "2025-03-24T13:45:00+00:00" + "time": "2025-05-21T20:55:28+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1322,16 +1322,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.45", + "version": "10.5.47", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "bd68a781d8e30348bc297449f5234b3458267ae8" + "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bd68a781d8e30348bc297449f5234b3458267ae8", - "reference": "bd68a781d8e30348bc297449f5234b3458267ae8", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3", + "reference": "3637b3e50d32ab3a0d1a33b3b6177169ec3d95a3", "shasum": "" }, "require": { @@ -1341,7 +1341,7 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.12.1", + "myclabs/deep-copy": "^1.13.1", "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.1", @@ -1403,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/10.5.45" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.47" }, "funding": [ { @@ -1414,12 +1414,20 @@ "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-02-06T16:08:12+00:00" + "time": "2025-06-20T11:29:11+00:00" }, { "name": "sebastian/cli-parser", From 149ca6ce08df4dd7bd0441f871384849c4c5d471 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 1 Jul 2025 22:20:44 -0500 Subject: [PATCH 61/79] lots more to do. --- src/ACL/ACLAuthMethod.php | 16 +- src/ACL/ACLAuthMethodListEntry.php | 15 +- src/ACL/ACLAuthMethodNamespaceRule.php | 15 +- src/ACL/ACLBindingRule.php | 15 +- src/ACL/ACLEntry.php | 15 +- src/ACL/ACLLink.php | 15 +- src/ACL/ACLLoginParams.php | 15 +- src/ACL/ACLNodeIdentity.php | 15 +- src/ACL/ACLOIDCAuthURLParams.php | 32 +-- src/ACL/ACLOIDCCallbackParams.php | 15 +- src/ACL/ACLPolicy.php | 15 +- src/ACL/ACLPolicyListEntry.php | 15 +- src/ACL/ACLReplicationStatus.php | 15 +- src/ACL/ACLRole.php | 15 +- src/ACL/ACLServiceIdentity.php | 15 +- src/ACL/ACLTemplatedPolicy.php | 9 +- src/ACL/ACLTemplatedPolicyVariables.php | 9 +- src/ACL/ACLToken.php | 15 +- src/ACL/ACLTokenExpanded.php | 37 ++- src/ACL/ACLTokenListEntry.php | 15 +- src/ACL/KubernetesAuthMethodConfig.php | 15 +- src/ACL/OIDCAuthMethodConfig.php | 15 +- src/AbstractModel.php | 9 + src/Agent/AgentCheck.php | 15 +- src/Agent/AgentCheckRegistration.php | 6 +- src/Agent/AgentCheckUpdate.php | 15 +- src/Agent/AgentMember.php | 16 +- src/Agent/AgentService.php | 16 +- src/Agent/AgentServiceCheck.php | 16 +- src/Agent/AgentServiceChecksInfo.php | 15 +- src/Agent/AgentServiceConnect.php | 15 +- src/Agent/AgentServiceConnectProxyConfig.php | 15 +- src/Agent/AgentServiceRegistration.php | 16 +- src/Agent/AgentToken.php | 15 +- src/Agent/AgentWeights.php | 15 +- src/Agent/ConnectProxyConfig.php | 17 +- src/Agent/GaugeValue.php | 16 +- src/Agent/MemberOpts.php | 15 +- src/Agent/MetricsInfo.php | 15 +- src/Agent/PointValue.php | 15 +- src/Agent/SampledValue.php | 16 +- src/Agent/ServiceRegisterOpts.php | 15 +- src/Agent/Upstream.php | 14 +- src/Catalog/CatalogDeregistration.php | 16 +- src/Catalog/CatalogNode.php | 16 +- src/Catalog/CatalogNodeServiceList.php | 16 +- src/Catalog/CatalogRegistration.php | 16 +- src/Catalog/CatalogService.php | 16 +- src/Catalog/CompoundServiceName.php | 15 +- src/Catalog/GatewayService.php | 14 +- src/Catalog/Node.php | 15 +- src/Catalog/ServiceAddress.php | 15 +- src/Catalog/Weights.php | 15 +- src/ConfigEntry/AccessLogsConfig.php | 5 +- src/ConfigEntry/CookieConfig.php | 9 +- src/ConfigEntry/DestinationConfig.php | 9 +- src/ConfigEntry/EnvoyExtension.php | 15 +- src/ConfigEntry/ExposeConfig.php | 12 +- src/ConfigEntry/ExposePath.php | 11 +- src/ConfigEntry/GatewayServiceTLSConfig.php | 4 +- src/ConfigEntry/GatewayTLSConfig.php | 9 +- src/ConfigEntry/GatewayTLSSDSConfig.php | 9 +- src/ConfigEntry/HTTPHeaderModifiers.php | 9 +- src/ConfigEntry/HashPolicy.php | 9 +- src/ConfigEntry/IngressGatewayConfigEntry.php | 9 +- src/ConfigEntry/IngressListener.php | 9 +- src/ConfigEntry/IngressService.php | 9 +- src/ConfigEntry/IngressServiceConfig.php | 9 +- src/ConfigEntry/InstanceLevelRateLimits.php | 9 +- .../InstanceLevelRouteRateLimits.php | 9 +- .../IntentionHTTPHeaderPermission.php | 5 +- src/ConfigEntry/IntentionHTTPPermission.php | 9 +- .../IntentionJWTClaimVerification.php | 5 +- src/ConfigEntry/IntentionJWTRequirement.php | 9 +- src/ConfigEntry/IntentionPermission.php | 9 +- src/ConfigEntry/LeastRequestConfig.php | 4 +- src/ConfigEntry/LinkedService.php | 9 +- src/ConfigEntry/LoadBalancer.php | 9 +- src/ConfigEntry/MeshConfigEntry.php | 12 +- src/ConfigEntry/MeshDirectionalTLSConfig.php | 5 +- src/ConfigEntry/MeshGatewayConfig.php | 14 +- src/ConfigEntry/MeshHTTPConfig.php | 5 +- src/ConfigEntry/MeshTLSConfig.php | 5 +- src/ConfigEntry/PassiveHealthCheck.php | 14 +- src/ConfigEntry/PeeringMeshConfig.php | 5 +- src/ConfigEntry/ProxyConfigEntry.php | 16 +- src/ConfigEntry/RateLimits.php | 9 +- src/ConfigEntry/RingHashConfig.php | 9 +- src/ConfigEntry/ServiceConfigEntry.php | 57 ++--- .../ServiceIntentionsConfigEntry.php | 9 +- .../ServiceResolverConfigEntry.php | 4 +- .../ServiceResolverFailoverPolicy.php | 9 +- .../ServiceResolverPrioritizeByLocality.php | 9 +- src/ConfigEntry/ServiceRoute.php | 9 +- src/ConfigEntry/ServiceRouteDestination.php | 9 +- src/ConfigEntry/ServiceRouteHTTPMatch.php | 9 +- .../ServiceRouteHTTPMatchHeader.php | 9 +- .../ServiceRouteHTTPMatchQueryParam.php | 9 +- src/ConfigEntry/ServiceRouteMatch.php | 7 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 9 +- src/ConfigEntry/ServiceSplit.php | 9 +- .../ServiceSplitterConfigEntry.php | 9 +- src/ConfigEntry/SourceIntention.php | 9 +- .../TerminatingGatewayConfigEntry.php | 9 +- src/ConfigEntry/TransparentProxyConfig.php | 14 +- src/ConfigEntry/UpstreamConfig.php | 228 ++++++++++++++++++ src/ConfigEntry/UpstreamConfiguration.php | 179 ++++---------- src/Consul.php | 16 ++ src/Coordinate/Coordinate.php | 11 +- src/Coordinate/CoordinateConfig.php | 5 +- src/Coordinate/CoordinateDatacenterMap.php | 11 +- src/Coordinate/CoordinateEntry.php | 8 +- src/Event/UserEvent.php | 1 - src/Health/HealthCheckDefinition.php | 10 +- src/Health/HealthChecks.php | 4 +- src/KV/KVPair.php | 1 - src/KV/KVTxnOp.php | 1 - src/Metrics/Label.php | 5 +- src/Peering/Locality.php | 5 +- src/QueryOptions.php | 1 - src/SimpleJsonUnserializeTrait.php | 4 +- src/WriteOptions.php | 23 -- src/funcs.php | 25 -- 123 files changed, 721 insertions(+), 1143 deletions(-) create mode 100644 src/ConfigEntry/UpstreamConfig.php diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 2b630e00..d978df8e 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -40,11 +40,9 @@ class ACLAuthMethod extends AbstractModel public string $Partition; /** - * @param array|null $data Deprecated, will be removed. * @param iterable<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Type = '', string $DisplayName = '', @@ -70,10 +68,7 @@ public function __construct( $this->setNamespaceRules(...$NamespaceRules); $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -216,9 +211,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('MaxTokenTTL' === $k) { $n->setMaxTokenTTL($v); @@ -236,10 +231,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ('' !== $this->DisplayName) { $out->DisplayName = $this->DisplayName; diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index ae35c351..6d7871e9 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -41,7 +41,6 @@ class ACLAuthMethodListEntry extends AbstractModel public string $Namespace; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Type = '', string $DisplayName = '', @@ -61,10 +60,7 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -178,9 +174,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if (null === $v) { continue; @@ -196,10 +192,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Type = $this->Type; if ('' !== $this->DisplayName) { diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 23b3b773..a69bc613 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -28,16 +28,12 @@ class ACLAuthMethodNamespaceRule extends AbstractModel public string $BindNamespace; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Selector = '', string $BindNamespace = '', ) { $this->Selector = $Selector; $this->BindNamespace = $BindNamespace; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getSelector(): string { @@ -61,9 +57,9 @@ public function setBindNamespace(string $BindNamespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -72,10 +68,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Selector) { $out->Selector = $this->Selector; } diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 0be0e60a..a4c9e421 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -35,7 +35,6 @@ class ACLBindingRule extends AbstractModel public string $Namespace; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Description = '', string $AuthMethod = '', @@ -55,10 +54,7 @@ public function __construct( $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -159,9 +155,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -170,10 +166,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Description = $this->Description; $out->AuthMethod = $this->AuthMethod; diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index 1ed8c060..dd55e409 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -32,7 +32,6 @@ class ACLEntry extends AbstractModel public string $Rules; public function __construct( - null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $ID = '', @@ -46,10 +45,7 @@ public function __construct( $this->Name = $Name; $this->Type = $Type; $this->Rules = $Rules; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getCreateIndex(): int { @@ -117,9 +113,9 @@ public function setRules(string $rules): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -128,10 +124,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; $out->ID = $this->ID; diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index 42324c08..925ff716 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -28,16 +28,12 @@ class ACLLink extends AbstractModel public string $Name; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', ) { $this->ID = $ID; $this->Name = $Name; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -61,9 +57,9 @@ public function setName(string $Name): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -72,10 +68,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 d4df6b65..1d83cace 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -29,7 +29,6 @@ class ACLLoginParams extends AbstractModel public null|array $Meta; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $BearerToken = '', null|array|\stdClass $Meta = null, @@ -37,10 +36,7 @@ public function __construct( $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; $this->setMeta($Meta); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getAuthMethod(): string { @@ -78,9 +74,9 @@ public function setMeta(null|array|\stdClass $Meta): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); @@ -93,10 +89,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->AuthMethod = $this->AuthMethod; $out->BearerToken = $this->BearerToken; if (null !== $this->Meta && [] !== $this->Meta) { diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 7dee2ad8..f0e0cbf5 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -28,16 +28,12 @@ class ACLNodeIdentity extends AbstractModel public string $Datacenter; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $NodeName = '', string $Datacenter = '' ) { $this->NodeName = $NodeName; $this->Datacenter = $Datacenter; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getNodeName(): string { @@ -49,9 +45,9 @@ public function getDatacenter(): string return $this->Datacenter; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -60,10 +56,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 bb996202..a8afbec1 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -27,23 +27,19 @@ class ACLOIDCAuthURLParams extends AbstractModel public string $AuthMethod; public string $RedirectURI; public string $ClientNonce; - public null|array $Meta; + public null|\stdClass $Meta; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $RedirectURI = '', string $ClientNonce = '', - null|array|\stdClass $Meta = null + null|\stdClass $Meta = null ) { $this->AuthMethod = $AuthMethod; $this->RedirectURI = $RedirectURI; $this->ClientNonce = $ClientNonce; - $this->setMeta($Meta); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } + $this->Meta = $Meta; +} public function getAuthMethod(): string { @@ -78,24 +74,21 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public function getMeta(): null|array + public function getMeta(): null|\stdClass { return $this->Meta; } - public function setMeta(null|array|\stdClass $Meta): self + public function setMeta(null|\stdClass $Meta): self { - $this->Meta = match($Meta) { - null => null, - default => (array)$Meta, - }; + $this->Meta = $Meta; return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Meta' === $k) { $n->setMeta($v); @@ -108,14 +101,11 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->AuthMethod = $this->AuthMethod; $out->RedirectURI = $this->RedirectURI; $out->ClientNonce = $this->ClientNonce; - if (null !== $this->Meta && [] !== $this->Meta) { + if (null !== $this->Meta) { $out->Meta = $this->Meta; } return $out; diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index ea0995be..8242fa7a 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -30,7 +30,6 @@ class ACLOIDCCallbackParams extends AbstractModel public string $ClientNonce; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $AuthMethod = '', string $State = '', string $Code = '', @@ -40,10 +39,7 @@ public function __construct( $this->State = $State; $this->Code = $Code; $this->ClientNonce = $ClientNonce; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getAuthMethod(): string { @@ -89,9 +85,9 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -100,10 +96,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->AuthMethod = $this->AuthMethod; $out->State = $this->State; $out->Code = $this->Code; diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index f025ba4e..1fbcd8cb 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -37,7 +37,6 @@ class ACLPolicy extends AbstractModel public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -60,10 +59,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -178,9 +174,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); @@ -193,10 +189,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Name = $this->Name; $out->Description = $this->Description; diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index ec329888..c9fc82b3 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -35,7 +35,6 @@ class ACLPolicyListEntry extends AbstractModel public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -55,10 +54,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -159,9 +155,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); @@ -174,10 +170,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Name = $this->Name; $out->Description = $this->Description; diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index a147ce55..6a8b82d4 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -35,7 +35,6 @@ class ACLReplicationStatus extends AbstractModel public Time\Time $LastError; public function __construct( - null|array $data = null, // Deprecated, will be removed. bool $Enabled = false, bool $Running = false, string $SourceDatacenter = '', @@ -53,10 +52,7 @@ public function __construct( $this->ReplicatedTokenIndex = $ReplicatedTokenIndex; $this->LastSuccess = $LastSuccess ?? Time::New(); $this->LastError = $LastError ?? Time::New(); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function isEnabled(): bool { @@ -98,9 +94,9 @@ public function getLastError(): Time\Time return $this->LastError; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('LastSuccess' === $k) { $n->LastSuccess = Time\Time::createFromFormat(DATE_RFC3339, $v); @@ -115,10 +111,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Enabled = $this->Enabled; $out->Running = $this->Running; $out->SourceDatacenter = $this->SourceDatacenter; diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index d88c50e9..fd89e695 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -42,7 +42,6 @@ class ACLRole extends AbstractModel public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Name = '', string $Description = '', @@ -68,10 +67,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -217,9 +213,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { @@ -246,10 +242,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Name = $this->Name; $out->Description = $this->Description; diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index f93681d0..6da2fd0d 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -29,16 +29,12 @@ class ACLServiceIdentity extends AbstractModel public array $Datacenters; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ServiceName = '', iterable $Datacenters = [] ) { $this->ServiceName = $ServiceName; $this->setDatacenters(...$Datacenters); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getServiceName(): string { @@ -59,9 +55,9 @@ public function setDatacenters(string ...$datacenters): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Datacenters' === $k) { $n->setDatacenters(...$v); @@ -74,10 +70,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ServiceName = $this->ServiceName; if ([] !== $this->Datacenters) { $out->Datacenters = $this->Datacenters; diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php index 6db39783..fba2bccb 100644 --- a/src/ACL/ACLTemplatedPolicy.php +++ b/src/ACL/ACLTemplatedPolicy.php @@ -75,9 +75,9 @@ public function setDatacenters(string ...$Datacenters): ACLTemplatedPolicy return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('TemplateVariables' === $k) { $n->setTemplateVariables($v); @@ -92,10 +92,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->TemplateName = $this->TemplateName; if (null !== $this->TemplateVariables) { $out->TemplateVariables = $this->TemplateVariables; diff --git a/src/ACL/ACLTemplatedPolicyVariables.php b/src/ACL/ACLTemplatedPolicyVariables.php index c36c7cf2..3e43c433 100644 --- a/src/ACL/ACLTemplatedPolicyVariables.php +++ b/src/ACL/ACLTemplatedPolicyVariables.php @@ -42,9 +42,9 @@ public function setName(string $Name): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -53,10 +53,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; return $out; } diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index a09aebe4..5da848c7 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -28,7 +28,6 @@ class ACLToken extends AbstractModel use ACLTokenFields; public function __construct( - null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -70,14 +69,11 @@ public function __construct( $this->Rules = $Rules; $this->Partition = $Partition; $this->AuthMethodNamespace = $AuthMethodNamespace; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if (!$n->_jsonUnserializeField($k, $v, $n)) { $n->{$k} = $v; @@ -88,10 +84,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $this->_jsonSerialize($out); return $out; } diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index 4713b067..f73f0e6b 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -36,8 +36,36 @@ class ACLTokenExpanded extends ACLToken public string $AgentACLDownPolicy; public string $ResolvedByAgent; + /** + * @param iterable $ExpandedPolicies + * @param iterable $ExpandedRoles + * @param iterable $NamespaceDefaultPolicyIDs + * @param iterable $NamespaceDefaultRoleIDs + * @param string $AgentACLDefaultPolicy + * @param string $AgentACLDownPolicy + * @param string $ResolvedByAgent + * @param int $CreateIndex + * @param int $ModifyIndex + * @param string $AccessorID + * @param string $SecretID + * @param string $Description + * @param iterable $Policies + * @param iterable $Roles + * @param iterable $ServiceIdentities + * @param iterable $NodeIdentities + * @param iterable $TemplatePolicies + * @param bool $Local + * @param string $AuthMethod + * @param \DateInterval|float|int|string|\DCarbone\Go\Time\Duration|null $ExpirationTTL + * @param \DCarbone\Go\Time\Time|null $ExpirationTime + * @param \DCarbone\Go\Time\Time|null $CreateTime + * @param string $Hash + * @param string $Namespace + * @param string $Rules + * @param string $Partition + * @param string $AuthMethodNamespace + */ public function __construct( - null|array $data = null, iterable $ExpandedPolicies = [], iterable $ExpandedRoles = [], iterable $NamespaceDefaultPolicyIDs = [], @@ -95,10 +123,7 @@ public function __construct( $this->AgentACLDefaultPolicy = $AgentACLDefaultPolicy; $this->AgentACLDownPolicy = $AgentACLDownPolicy; $this->ResolvedByAgent = $ResolvedByAgent; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} /** * @return \DCarbone\PHPConsulAPI\ACL\ACLPolicy[] @@ -191,7 +216,7 @@ public function setResolvedByAgent(string $ResolvedByAgent): self public static function jsonUnserialize(\stdClass $decoded, null|ACLToken $into = null): static { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ($n->_jsonUnserializeField($k, $v, $n)) { continue; diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index f1a707df..913b2701 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -51,7 +51,6 @@ class ACLTokenListEntry extends AbstractModel public string $AuthMethodNamespace; public function __construct( - null|array $data = null, // Deprecated, will be removed. int $CreateIndex = 0, int $ModifyIndex = 0, string $AccessorID = '', @@ -91,10 +90,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; $this->AuthMethodNamespace = $AuthMethodNamespace; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getCreateIndex(): int { @@ -320,9 +316,9 @@ public function setAuthMethodNamespace(string $AuthMethodNamespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { foreach ($v as $vv) { @@ -357,10 +353,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; $out->AccessorID = $this->AccessorID; diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 958c8081..2280ef6c 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -29,7 +29,6 @@ class KubernetesAuthMethodConfig extends AbstractModel public string $ServiceAccountJWT; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Host = '', string $CACert = '', string $ServiceAccountJWT = '' @@ -37,10 +36,7 @@ public function __construct( $this->Host = $Host; $this->CACert = $CACert; $this->ServiceAccountJWT = $ServiceAccountJWT; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getHost(): string { @@ -90,9 +86,9 @@ public function RenderToConfig(): array ]; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -101,10 +97,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Host) { $out->Host = $this->Host; } diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index f2ea6528..f47a1825 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -25,16 +25,12 @@ class OIDCAuthMethodConfig extends AbstractModel { public function __construct( - null|array $data = null, // Deprecated, will be removed. ) { - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -43,10 +39,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); return $out; } } diff --git a/src/AbstractModel.php b/src/AbstractModel.php index 61225a70..55c85808 100644 --- a/src/AbstractModel.php +++ b/src/AbstractModel.php @@ -55,4 +55,13 @@ public function __toString(): string { return static::class; } + + protected function _startJsonSerialize(): \stdClass + { + $out = new \stdClass(); + foreach ($this->_getDynamicFields() as $k => $v) { + $out->{$k} = $v; + } + return $out; + } } diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 62b82292..847cfd79 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -39,7 +39,6 @@ class AgentCheck extends AbstractModel public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Node = '', string $CheckID = '', string $Name = '', @@ -65,10 +64,7 @@ public function __construct( $this->Definition = $Definition ?? new HealthCheckDefinition(); $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getNode(): string { @@ -191,9 +187,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Definition' === $k) { $n->Definition = HealthCheckDefinition::jsonUnserialize($v); @@ -206,10 +202,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Node = $this->Node; $out->CheckID = $this->CheckID; $out->Name = $this->Name; diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 4fa4bebe..40543d9c 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -28,7 +28,6 @@ class AgentCheckRegistration extends AgentServiceCheck public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $ServiceID = '', string $CheckID = '', @@ -88,10 +87,7 @@ public function __construct( $this->ServiceID = $ServiceID; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { diff --git a/src/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php index 8e0bb063..0dfeebeb 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -28,16 +28,12 @@ class AgentCheckUpdate extends AbstractModel public string $Output; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Status = '', string $Output = '' ) { $this->Status = $Status; $this->Output = $Output; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getStatus(): string { @@ -61,9 +57,9 @@ public function setOutput(string $output): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -72,10 +68,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Status = $this->Status; $out->Output = $this->Output; return $out; diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 8f53b40b..673ce736 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -48,7 +48,6 @@ class AgentMember extends AbstractModel public int $DelegateCur; /** - * @param array|null $data // Deprecated, will be removed. * @param string $Name * @param string $Addr * @param int $Port @@ -62,7 +61,6 @@ class AgentMember extends AbstractModel * @param int $DelegateCur */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Addr = '', int $Port = 0, @@ -86,10 +84,7 @@ public function __construct( $this->DelegateMin = $DelegateMin; $this->DelegateMax = $DelegateMax; $this->DelegateCur = $DelegateCur; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -157,9 +152,9 @@ public function IsConsulServer(): bool Consul::MemberTagValueRoleServer === $this->Tags[Consul::MemberTagKeyACLMode]; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -168,10 +163,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Addr = $this->Addr; $out->Port = $this->Port; diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index c7506c32..79865bc9 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -50,7 +50,6 @@ class AgentService extends AbstractModel public null|Locality $Locality; /** - * @param array |null $data Deprecated, will be removed. * @param string $Kind * @param string $ID * @param string $Service @@ -74,7 +73,6 @@ class AgentService extends AbstractModel * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Kind = '', string $ID = '', string $Service = '', @@ -118,10 +116,7 @@ public function __construct( $this->Partition = $Partition; $this->Datacenter = $Datacenter; $this->Locality = $Locality; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getKind(): string { @@ -353,9 +348,9 @@ public function setLocality(null|Locality $Locality): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Tags' === $k) { $n->setTags(...$v); @@ -380,10 +375,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Kind) { $out->Kind = $this->Kind; } diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 0f85b602..7805f07c 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -51,7 +51,6 @@ class AgentServiceCheck extends AbstractModel public string $DeregisterCriticalServiceAfter; /** - * @param array|null $data // Deprecated, will be removed. * @param string $CheckID * @param string $Name * @param iterable $ScriptArgs @@ -78,7 +77,6 @@ class AgentServiceCheck extends AbstractModel * @param string $DeregisterCriticalServiceAfter */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $CheckID = '', string $Name = '', iterable $ScriptArgs = [], @@ -129,10 +127,7 @@ public function __construct( $this->SuccessBeforePassing = $SuccessBeforePassing; $this->FailuresBeforeCritical = $FailuresBeforeCritical; $this->DeregisterCriticalServiceAfter = $DeregisterCriticalServiceAfter; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getCheckID(): string { @@ -401,9 +396,9 @@ public function setDeregisterCriticalServiceAfter(string $deregisterCriticalServ return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -412,10 +407,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->CheckID) { $out->CheckID = $this->CheckID; } diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index 99c377a2..b8718962 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -30,7 +30,6 @@ class AgentServiceChecksInfo extends AbstractModel public HealthChecks $Checks; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $AggregatedStatus = '', null|AgentService $Service = null, null|HealthChecks $Checks = null, @@ -38,10 +37,7 @@ public function __construct( $this->AggregatedStatus = $AggregatedStatus; $this->Service = $Service; $this->Checks = $Checks ?? new HealthChecks(); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getAggregatedStatus(): string { @@ -76,9 +72,9 @@ public function setChecks(HealthChecks $Checks): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Checks' === $k) { $n->Checks = HealthChecks::jsonUnserialize($v); @@ -93,10 +89,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->AggregatedStatus = $this->AggregatedStatus; $out->Service = $this->Service; $out->Checks = $this->Checks; diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index adce2dfd..53184d18 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -28,16 +28,12 @@ class AgentServiceConnect extends AbstractModel public null|AgentServiceRegistration $SidecarService; public function __construct( - null|array $data = null, // Deprecated, will be removed. bool $Native = false, null|AgentServiceRegistration $SidecarService = null, ) { $this->Native = $Native; $this->SidecarService = $SidecarService; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function isNative(): bool { @@ -61,9 +57,9 @@ public function setSidecarService(AgentServiceRegistration $SidecarService): sel return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('SidecarService' === $k) { $n->SidecarService = AgentServiceRegistration::jsonUnserialize($v); @@ -76,10 +72,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Native) { $out->Native = $this->Native; } diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index c237081a..9477f6c3 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -47,7 +47,6 @@ class AgentServiceConnectProxyConfig extends AbstractModel public null|AccessLogsConfig $AccessLogs; /** - * @param array|null $data * @param iterable<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions * @param string $DestinationServiceName * @param string $DestinationServiceID @@ -91,10 +90,7 @@ public function __construct( $this->MeshGateway = $MeshGateway; $this->Expose = $Expose; $this->AccessLogs = $AccessLogs; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} /** * @return \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[] @@ -251,9 +247,9 @@ public function setAccessLogs(null|AccessLogsConfig $AccessLogs): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('EnvoyExtensions' === $k) { foreach ($v as $vv) { @@ -282,10 +278,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ([] !== $this->EnvoyExtensions) { $out->EnvoyExtensions = $this->EnvoyExtensions; } diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index e5d9772b..7c4c8117 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -46,7 +46,6 @@ class AgentServiceRegistration extends AbstractModel public null|Locality $Locality; /** - * @param array|null $data * @param string|\DCarbone\PHPConsulAPI\Agent\ServiceKind $Kind * @param string $ID * @param string $Name @@ -66,7 +65,6 @@ class AgentServiceRegistration extends AbstractModel * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality */ public function __construct( - null|array $data = null, string|ServiceKind $Kind = ServiceKind::Typical, string $ID = '', string $Name = '', @@ -102,10 +100,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; $this->Locality = $Locality; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getKind(): ServiceKind { @@ -304,9 +299,9 @@ public function setLocality(null|Locality $Locality): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Kind' === $k) { $n->setKind($v); @@ -335,10 +330,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Kind !== ServiceKind::Typical) { $out->Kind = $this->Kind; } diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index b151fc35..8b68ecab 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -27,14 +27,10 @@ class AgentToken extends AbstractModel public string $Token; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Token = '', ) { $this->Token = $Token; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getToken(): string { @@ -47,9 +43,9 @@ public function setToken(string $Token): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -58,10 +54,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Token = $this->Token; return $out; } diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index ecf7d2d9..b3c68414 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -28,16 +28,12 @@ class AgentWeights extends AbstractModel public int $Warning; public function __construct( - null|array $data = null, // Deprecated, will be removed. int $Passing = 0, int $Warning = 0, ) { $this->Passing = $Passing; $this->Warning = $Warning; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getPassing(): int { @@ -49,9 +45,9 @@ public function getWarning(): int return $this->Warning; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -60,10 +56,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 index 786ecd2b..c2a570df 100644 --- a/src/Agent/ConnectProxyConfig.php +++ b/src/Agent/ConnectProxyConfig.php @@ -33,7 +33,6 @@ class ConnectProxyConfig extends AbstractModel public array $Upstreams; /** - * @param array|null $data // Deprecated, will be removed. * @param string $ProxyServiceID * @param string $TargetServiceID * @param string $TargetServiceName @@ -42,7 +41,6 @@ class ConnectProxyConfig extends AbstractModel * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ProxyServiceID = '', string $TargetServiceID = '', string $TargetServiceName = '', @@ -56,11 +54,7 @@ public function __construct( $this->ContentHash = $ContentHash; $this->Config = $Config; $this->setUpstreams(...$Upstreams); - - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getProxyServiceID(): string { @@ -131,9 +125,9 @@ public function setUpstreams(Upstream ...$Upstreams): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Upstreams' === $k) { $n->Upstreams = []; @@ -149,10 +143,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ProxyServiceID = $this->ProxyServiceID; $out->TargetServiceID = $this->TargetServiceID; $out->TargetServiceName = $this->TargetServiceName; diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 89ce37d0..860479ea 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -29,13 +29,11 @@ class GaugeValue extends AbstractModel public null|\stdClass $Labels; /** - * @param array|null $data * @param string $Name * @param float $Value * @param \stdClass|null $Labels */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', float $Value = 0.0, null|\stdClass $Labels = null, @@ -43,10 +41,7 @@ public function __construct( $this->Name = $Name; $this->Value = $Value; $this->Labels = $Labels; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -81,9 +76,9 @@ public function setLabels(null|\stdClass $Labels): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -92,10 +87,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Value = $this->Value; $out->Labels = $this->Labels; diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index af44f68e..3f65af10 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -29,7 +29,6 @@ class MemberOpts extends AbstractModel public string $Filter; public function __construct( - null|array $data = null, bool $WAN = false, string $Segment = '', string $Filter = '', @@ -37,10 +36,7 @@ public function __construct( $this->WAN = $WAN; $this->Segment = $Segment; $this->Filter = $Filter; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function isWAN(): bool { @@ -64,9 +60,9 @@ public function setSegment(string $segment): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -75,10 +71,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->WAN) { $out->WAN = $this->WAN; } diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index b65eecaa..0646374a 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -35,7 +35,6 @@ class MetricsInfo extends AbstractModel public array $Samples; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Timestamp = '', iterable $Gauges = [], iterable $Points = [], @@ -47,10 +46,7 @@ public function __construct( $this->setPoints(...$Points); $this->setCounters(...$Counters); $this->setSamples(...$Samples); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getTimestamp(): string { @@ -119,9 +115,9 @@ public function setSamples(SampledValue ...$samples): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Gauges' === $k) { foreach ($v as $vv) { @@ -148,10 +144,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Timestamp = $this->Timestamp; $out->Gauges = $this->Gauges; $out->Points = $this->Points; diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 2b1d8948..7bb0a659 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -29,16 +29,12 @@ class PointValue extends AbstractModel public array $Points; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', iterable $Points = [], ) { $this->Name = $Name; $this->setPoints(...$Points); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -65,9 +61,9 @@ public function setPoints(float ...$points): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -76,10 +72,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 2e02725e..ce631448 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -34,7 +34,6 @@ class SampledValue extends AbstractModel public null|\stdClass $Labels; /** - * @param array|null $data Deprecated, will be removed. * @param string $Name * @param int $Count * @param float $Sum @@ -45,7 +44,6 @@ class SampledValue extends AbstractModel * @param \stdClass|null $Labels */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', int $Count = 0, float $Sum = 0.0, @@ -63,10 +61,7 @@ public function __construct( $this->Mean = $Mean; $this->Stddev = $Stddev; $this->Labels = $Labels ?? new \stdClass(); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -156,9 +151,9 @@ public function setLabels(null|\stdClass $labels): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -167,10 +162,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Count = $this->Count; $out->Sum = $this->Sum; diff --git a/src/Agent/ServiceRegisterOpts.php b/src/Agent/ServiceRegisterOpts.php index 65d092f2..49cb5ccb 100644 --- a/src/Agent/ServiceRegisterOpts.php +++ b/src/Agent/ServiceRegisterOpts.php @@ -28,16 +28,12 @@ class ServiceRegisterOpts extends AbstractModel public string $Token; public function __construct( - null|array $data = null, // Deprecated, will be removed. bool $ReplaceExistingChecks = false, string $Token = '', ) { $this->ReplaceExistingChecks = $ReplaceExistingChecks; $this->Token = $Token; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function isReplaceExistingChecks(): bool { @@ -61,9 +57,9 @@ public function setToken(string $Token): ServiceRegisterOpts return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -72,10 +68,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 122cfd53..ca9f7b99 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -68,10 +68,7 @@ public function __construct( $this->Config = $Config; $this->MeshGateway = $MeshGateway; $this->CentrallyConfigured = $CentrallyConfigured; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getDestinationType(): UpstreamDestType { @@ -216,9 +213,9 @@ public function setCentrallyConfigured(bool $CentrallyConfigured): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('DestinationType' === $k) { $n->setDestinationType($v); @@ -233,10 +230,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->DestinationType !== UpstreamDestType::UNDEFINED) { $out->DestinationType = $this->DestinationType; } diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index 42f51931..a0b1d83a 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -33,7 +33,6 @@ class CatalogDeregistration extends AbstractModel public string $Partition; /** - * @param array|null $data * @param string $Node * @param string $Address * @param string $Datacenter @@ -43,7 +42,6 @@ class CatalogDeregistration extends AbstractModel * @param string $Partition */ public function __construct( - null|array $data = null, // Deprecated, do not use string $Node = '', string $Address = '', string $Datacenter = '', @@ -59,10 +57,7 @@ public function __construct( $this->CheckID = $CheckID; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getNode(): string { @@ -141,9 +136,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -152,10 +147,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Node = $this->Node; if ('' !== $this->Address) { $out->Address = $this->Address; diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index e5259866..8ca131e4 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -29,21 +29,16 @@ class CatalogNode extends AbstractModel public null|\stdClass $Services; /** - * @param array|null $data * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node * @param null|\stdClass $Services */ public function __construct( - null|array $data = null, // Deprecated, do not use, null|Node $Node = null, null|\stdClass $Services = null ) { $this->Node = $Node; $this->setServices($Services); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getNode(): null|Node { @@ -74,9 +69,9 @@ public function setServices(null|\stdClass $Services): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Node' === $k) { $n->Node = null === $v ? null : Node::jsonUnserialize($v); @@ -91,10 +86,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Node = $this->Node; $out->Services = $this->Services; return $out; diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index dc9c1398..4061e865 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -30,21 +30,16 @@ class CatalogNodeServiceList extends AbstractModel public array $Services; /** - * @param array|null $data * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node * @param array<\DCarbone\PHPConsulAPI\Agent\AgentService> $Services */ public function __construct( - null|array $data = null, null|Node $Node = null, array $Services = [] ) { $this->Node = $Node; $this->setServices(...$Services); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getNode(): null|Node { @@ -71,9 +66,9 @@ public function setServices(AgentService ...$Services): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Node' === $k) { $n->Node = null === $v ? null : Node::jsonUnserialize($v); @@ -91,10 +86,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Node = $this->Node; $out->Services = $this->Services; return $out; diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index a48c86cd..1980ef98 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -42,7 +42,6 @@ class CatalogRegistration extends AbstractModel public null|Locality $Locality; /** - * @param array|null $data * @param string $ID * @param string $Node * @param string $Address @@ -57,7 +56,6 @@ class CatalogRegistration extends AbstractModel * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality */ public function __construct( - null|array $data = null, string $ID = '', string $Node = '', string $Address = '', @@ -83,10 +81,7 @@ public function __construct( $this->SkipNodeUpdate = $SkipNodeUpdate; $this->Partition = $Partition; $this->Locality = $Locality; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -220,9 +215,9 @@ public function setLocality(null|Locality $Locality): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('TaggedAddresses' === $k) { $n->TaggedAddresses = null === $v ? null : (object)$v; @@ -245,10 +240,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Node = $this->Node; $out->Address = $this->Address; diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index a5b0f741..1bfd1254 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -52,11 +52,9 @@ class CatalogService extends AbstractModel public string $Partition; /** - * @param array|null $data * @param array $ServiceTags */ public function __construct( - null|array $data = null, // Deprecated, do not use. string $ID = '', string $Node = '', string $Address = '', @@ -103,10 +101,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -364,9 +359,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('TaggedAddresses' === $k) { $n->settaggedAddresses($v); @@ -397,10 +392,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Node = $this->Node; $out->Address = $this->Address; diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index b2f45c98..47499562 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -29,7 +29,6 @@ class CompoundServiceName extends AbstractModel public string $Partition; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', string $Namespace = '', string $Partition = '', @@ -38,10 +37,7 @@ public function __construct( $this->Name = $Name; $this->Namespace = $Namespace; $this->Partition = $Partition; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -76,9 +72,9 @@ public function setPartition(string $Partition): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -87,10 +83,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 569b509b..3773cbc6 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -64,10 +64,7 @@ public function __construct( $this->KeyFile = $KeyFile; $this->SNI = $SNI; $this->FromWildCard = $FromWildCard; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getGateway(): CompoundServiceName { @@ -193,9 +190,9 @@ public function setFromWildCard(string $FromWildCard): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Gateway' === $k) { $n->Gateway = CompoundServiceName::jsonUnserialize($v); @@ -215,10 +212,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Gateway = $this->Gateway; $out->Service = $this->Service; $out->GatewayKind = $this->GatewayKind->value; diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 4f6968f1..a98433e2 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -41,7 +41,6 @@ class Node extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $ID = '', string $Node = '', string $Address = '', @@ -65,10 +64,7 @@ public function __construct( $this->Partition = $Partition; $this->PeerName = $PeerName; $this->Locality = $Locality; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getID(): string { @@ -191,9 +187,9 @@ public function setLocality(null|Locality $Locality): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Locality' === $k) { $n->Locality = Locality::jsonUnserialize($v); @@ -206,10 +202,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->ID = $this->ID; $out->Node = $this->Node; $out->Address = $this->Address; diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index cf02e047..a204bdc7 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -31,16 +31,12 @@ class ServiceAddress extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $address = '', int $port = 0, ) { $this->Address = $address; $this->Port = $port; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getAddress(): string { @@ -64,9 +60,9 @@ public function setPort(int $port): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -75,10 +71,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $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 0a237e98..58fbfb52 100644 --- a/src/Catalog/Weights.php +++ b/src/Catalog/Weights.php @@ -31,16 +31,12 @@ class Weights extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. int $Passing = 0, int $Warning = 0 ) { $this->Passing = $Passing; $this->Warning = $Warning; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getPassing(): int { @@ -64,9 +60,9 @@ public function setWarning(int $Warning): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -75,10 +71,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Passing = $this->Passing; $out->Warning = $this->Warning; return $out; diff --git a/src/ConfigEntry/AccessLogsConfig.php b/src/ConfigEntry/AccessLogsConfig.php index 03563162..ac5de3dc 100644 --- a/src/ConfigEntry/AccessLogsConfig.php +++ b/src/ConfigEntry/AccessLogsConfig.php @@ -128,10 +128,7 @@ public static function jsonUnserialize(\stdClass $decoded): static public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Enabled) { $out->Enabled = $this->Enabled; } diff --git a/src/ConfigEntry/CookieConfig.php b/src/ConfigEntry/CookieConfig.php index 4487c373..dc4be06f 100644 --- a/src/ConfigEntry/CookieConfig.php +++ b/src/ConfigEntry/CookieConfig.php @@ -72,9 +72,9 @@ public function setPath(string $Path): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('TTL' === $k) { $n->TTL = Time::Duration($v); @@ -87,10 +87,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Session) { $out->Session = $this->Session; } diff --git a/src/ConfigEntry/DestinationConfig.php b/src/ConfigEntry/DestinationConfig.php index 69cd0153..ec2d89a8 100644 --- a/src/ConfigEntry/DestinationConfig.php +++ b/src/ConfigEntry/DestinationConfig.php @@ -62,9 +62,9 @@ public function setPort(int $Port): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -73,10 +73,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ([] !== $this->Addresses) { $out->Addresses = $this->Addresses; } diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 1af3ec01..4d7a17db 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -34,7 +34,6 @@ class EnvoyExtension extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Name = '', bool $Required = false, null|\stdClass $Arguments = null, @@ -46,10 +45,7 @@ public function __construct( $this->Arguments = $Arguments; $this->ConsulVersion = $ConsulVersion; $this->EnvoyVersion = $EnvoyVersion; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getName(): string { @@ -106,9 +102,9 @@ public function setEnvoyVersion(string $EnvoyVersion): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -117,10 +113,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Required = $this->Required; $out->Arguments = $this->Arguments; diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index 358ec5e4..ecc79264 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -29,20 +29,15 @@ class ExposeConfig extends AbstractModel public array $Paths; /** - * @param array|null $data * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> $Paths */ public function __construct( - null|array $data = null, // Deprecated, will be removed. bool $Checks = false, array $Paths = [], ) { $this->Checks = $Checks; $this->setPaths(...$Paths); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function isChecks(): bool { @@ -86,10 +81,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Checks) { $out->Checks = true; } diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index 0576fc76..4ac4994a 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -34,7 +34,6 @@ class ExposePath extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. int $ListenerPort = 0, string $Path = '', int $LocalPathPort = 0, @@ -46,10 +45,7 @@ public function __construct( $this->LocalPathPort = $LocalPathPort; $this->Protocol = $Protocol; $this->ParsedFromCheck = $ParsedFromCheck; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getListenerPort(): int { @@ -123,10 +119,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (0 !== $this->ListenerPort) { $out->ListenerPort = $this->ListenerPort; } diff --git a/src/ConfigEntry/GatewayServiceTLSConfig.php b/src/ConfigEntry/GatewayServiceTLSConfig.php index aba5c070..d334c1e6 100644 --- a/src/ConfigEntry/GatewayServiceTLSConfig.php +++ b/src/ConfigEntry/GatewayServiceTLSConfig.php @@ -42,9 +42,9 @@ public function setSDS(null|GatewayTLSSDSConfig $SDS): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach($decoded as $k => $v) { if ('SDS' === $k) { $n->SDS = GatewayTLSSDSConfig::jsonUnserialize($v); diff --git a/src/ConfigEntry/GatewayTLSConfig.php b/src/ConfigEntry/GatewayTLSConfig.php index ab4cda34..18b1b316 100644 --- a/src/ConfigEntry/GatewayTLSConfig.php +++ b/src/ConfigEntry/GatewayTLSConfig.php @@ -106,9 +106,9 @@ public function setCipherSuites(string ...$CipherSuites): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('tls_min_version' === $k) { $n->TLSMinVersion = (string)$v; @@ -127,10 +127,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Enabled = $this->Enabled; if (null !== $this->SDS) { $out->SDS = $this->SDS->jsonSerialize(); diff --git a/src/ConfigEntry/GatewayTLSSDSConfig.php b/src/ConfigEntry/GatewayTLSSDSConfig.php index 5739c1de..46e506de 100644 --- a/src/ConfigEntry/GatewayTLSSDSConfig.php +++ b/src/ConfigEntry/GatewayTLSSDSConfig.php @@ -57,9 +57,9 @@ public function setCertResource(string $CertResource): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('cluster_name' === $k) { $n->ClusterName = (string)$v; @@ -74,10 +74,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->ClusterName) { $out->ClusterName = $this->ClusterName; } diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php index 3c13e207..b0b7aed9 100644 --- a/src/ConfigEntry/HTTPHeaderModifiers.php +++ b/src/ConfigEntry/HTTPHeaderModifiers.php @@ -96,9 +96,9 @@ public function setRemove(string ...$Remove): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -107,10 +107,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); _enc_obj_if_valued($out, 'Add', $this->Add); _enc_obj_if_valued($out, 'Set', $this->Set); if ([] !== $this->Remove) { diff --git a/src/ConfigEntry/HashPolicy.php b/src/ConfigEntry/HashPolicy.php index 1437fde5..7525ff63 100644 --- a/src/ConfigEntry/HashPolicy.php +++ b/src/ConfigEntry/HashPolicy.php @@ -99,9 +99,9 @@ public function setTerminal(bool $Terminal): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('field_value' === $k) { $n->FieldValue = $v; @@ -118,10 +118,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Field) { $out->Field = $this->Field; } diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index d385eb5d..3b556cf7 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -133,9 +133,9 @@ public function setDefaults(null|IngressServiceConfig $Defaults): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('TLS' === $k) { $n->TLS = GatewayTLSConfig::jsonUnserialize($v); @@ -155,10 +155,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/IngressListener.php b/src/ConfigEntry/IngressListener.php index 0ffbe2f8..3a1a3914 100644 --- a/src/ConfigEntry/IngressListener.php +++ b/src/ConfigEntry/IngressListener.php @@ -93,9 +93,9 @@ public function setTLS(null|GatewayTLSConfig $TLS): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Services' === $k) { $n->Services = []; @@ -113,10 +113,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Port = $this->Port; $out->Protocol = $this->Protocol; $out->Services = $this->Services; diff --git a/src/ConfigEntry/IngressService.php b/src/ConfigEntry/IngressService.php index 1464c877..65e06ddd 100644 --- a/src/ConfigEntry/IngressService.php +++ b/src/ConfigEntry/IngressService.php @@ -188,9 +188,9 @@ public function setPassiveHealthCheck(null|PassiveHealthCheck $PassiveHealthChec return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach($decoded as $k => $v) { if ('RequestHeaders' === $k || 'request_headers' === $k) { $n->RequestHeaders = HTTPHeaderModifiers::jsonUnserialize($v, $n->RequestHeaders); @@ -209,10 +209,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Hosts = $this->Hosts; if ('' !== $this->Namespace) { diff --git a/src/ConfigEntry/IngressServiceConfig.php b/src/ConfigEntry/IngressServiceConfig.php index 72788854..80e4c27b 100644 --- a/src/ConfigEntry/IngressServiceConfig.php +++ b/src/ConfigEntry/IngressServiceConfig.php @@ -85,9 +85,9 @@ public function setPassiveHealthCheck(null|PassiveHealthCheck $PassiveHealthChec return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('PassiveHealthCheck' === $k || 'passive_health_check' === $k) { $n->PassiveHealthCheck = null === $v ? null : PassiveHealthCheck::jsonUnserialize($v); @@ -100,10 +100,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->MaxConnections = $this->MaxConnections; $out->MaxPendingRequests = $this->MaxPendingRequests; $out->MaxConcurrentRequests = $this->MaxConcurrentRequests; diff --git a/src/ConfigEntry/InstanceLevelRateLimits.php b/src/ConfigEntry/InstanceLevelRateLimits.php index 2e37c063..e05de6c3 100644 --- a/src/ConfigEntry/InstanceLevelRateLimits.php +++ b/src/ConfigEntry/InstanceLevelRateLimits.php @@ -78,9 +78,9 @@ public function setRoutes(InstanceLevelRouteRateLimits ...$Routes): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('requests_per_second' === $k) { $n->RequestsPerSecond = $v; @@ -100,10 +100,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->RequestsPerSecond = $this->RequestsPerSecond; $out->RequestsMaxBurst = $this->RequestsMaxBurst; $out->Routes = $this->Routes; diff --git a/src/ConfigEntry/InstanceLevelRouteRateLimits.php b/src/ConfigEntry/InstanceLevelRouteRateLimits.php index 32d41890..4dcddb5c 100644 --- a/src/ConfigEntry/InstanceLevelRouteRateLimits.php +++ b/src/ConfigEntry/InstanceLevelRouteRateLimits.php @@ -99,9 +99,9 @@ public function setRequestsMaxBurst(int $RequestsMaxBurst): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('path_exact' === $k) { $n->PathExact = $v; @@ -122,10 +122,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->PathExact = $this->PathExact; $out->PathPrefix = $this->PathPrefix; $out->PathRegex = $this->PathRegex; diff --git a/src/ConfigEntry/IntentionHTTPHeaderPermission.php b/src/ConfigEntry/IntentionHTTPHeaderPermission.php index 050f6d35..976ba85d 100644 --- a/src/ConfigEntry/IntentionHTTPHeaderPermission.php +++ b/src/ConfigEntry/IntentionHTTPHeaderPermission.php @@ -132,10 +132,7 @@ public function setInvert(bool $Invert): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ($this->Present) { $out->Present = $this->Present; diff --git a/src/ConfigEntry/IntentionHTTPPermission.php b/src/ConfigEntry/IntentionHTTPPermission.php index 25f9097e..ab77b5f7 100644 --- a/src/ConfigEntry/IntentionHTTPPermission.php +++ b/src/ConfigEntry/IntentionHTTPPermission.php @@ -111,9 +111,9 @@ public function setMethods(string ...$Methods): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('path_exact' === $k) { $n->PathExact = $v; @@ -135,10 +135,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->PathExact) { $out->PathExact = $this->PathExact; } diff --git a/src/ConfigEntry/IntentionJWTClaimVerification.php b/src/ConfigEntry/IntentionJWTClaimVerification.php index 455da4ad..169e0bfd 100644 --- a/src/ConfigEntry/IntentionJWTClaimVerification.php +++ b/src/ConfigEntry/IntentionJWTClaimVerification.php @@ -67,10 +67,7 @@ public function setValue(string $Value): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ([] !== $this->Path) { $out->Path = $this->Path; } diff --git a/src/ConfigEntry/IntentionJWTRequirement.php b/src/ConfigEntry/IntentionJWTRequirement.php index 633bf534..c4d754fc 100644 --- a/src/ConfigEntry/IntentionJWTRequirement.php +++ b/src/ConfigEntry/IntentionJWTRequirement.php @@ -62,9 +62,9 @@ public function setVerifyClaims(IntentionJWTClaimVerification ...$VerifyClaims): return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('VerifyClaims' === $k || 'verify_claims' === $k) { $n->VerifyClaims = []; @@ -80,10 +80,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Name) { $out->Name = $this->Name; } diff --git a/src/ConfigEntry/IntentionPermission.php b/src/ConfigEntry/IntentionPermission.php index 5ee73f47..374dfa7c 100644 --- a/src/ConfigEntry/IntentionPermission.php +++ b/src/ConfigEntry/IntentionPermission.php @@ -71,9 +71,9 @@ public function setJWT(null|IntentionJWTRequirement $JWT): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ($k === 'Action') { $n->{$k} = IntentionAction::from($v); @@ -90,10 +90,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Action = $this->Action->value; if (null !== $this->HTTP) { $out->HTTP = $this->HTTP; diff --git a/src/ConfigEntry/LeastRequestConfig.php b/src/ConfigEntry/LeastRequestConfig.php index c8af7ffd..9484b8dc 100644 --- a/src/ConfigEntry/LeastRequestConfig.php +++ b/src/ConfigEntry/LeastRequestConfig.php @@ -42,9 +42,9 @@ public function setChoiceCount(int $ChoiceCount): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('choice_count' === $k) { $n->ChoiceCount = $v; diff --git a/src/ConfigEntry/LinkedService.php b/src/ConfigEntry/LinkedService.php index e1efbe54..3035a496 100644 --- a/src/ConfigEntry/LinkedService.php +++ b/src/ConfigEntry/LinkedService.php @@ -113,9 +113,9 @@ public function setSNI(string $SNI): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('ca_file' === $k) { $n->CAFile = $v; @@ -132,10 +132,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; } diff --git a/src/ConfigEntry/LoadBalancer.php b/src/ConfigEntry/LoadBalancer.php index e23ef711..4eb04358 100644 --- a/src/ConfigEntry/LoadBalancer.php +++ b/src/ConfigEntry/LoadBalancer.php @@ -95,9 +95,9 @@ public function setHashPolicies(HashPolicy ...$HashPolicies): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach($decoded as $k => $v) { if ('RingHashConfig' === $k || 'ring_hash_config' === $k) { $n->RingHashConfig = RingHashConfig::jsonUnserialize($v); @@ -116,10 +116,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Policy) { $out->Policy = $this->Policy; } diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 37d645a0..c73f1361 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -35,7 +35,6 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry public null|PeeringMeshConfig $Peering; public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Partition = '', string $Namespace = '', null|TransparentProxyMeshConfig $TransparentProxy = null, @@ -57,11 +56,7 @@ public function __construct( $this->TLS = $TLS; $this->HTTP = $HTTP; $this->Peering = $Peering; - - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getKind(): string { @@ -151,10 +146,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = Consul::MeshConfigMesh; if ('' !== $this->Partition) { $out->Partition = $this->Partition; diff --git a/src/ConfigEntry/MeshDirectionalTLSConfig.php b/src/ConfigEntry/MeshDirectionalTLSConfig.php index 32e31311..405e5abc 100644 --- a/src/ConfigEntry/MeshDirectionalTLSConfig.php +++ b/src/ConfigEntry/MeshDirectionalTLSConfig.php @@ -97,10 +97,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->TLSMinVersion) { $out->TLSMinVersion = $this->TLSMinVersion; } diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 94302e0d..8ed4a1f2 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -31,10 +31,7 @@ public function __construct( string|MeshGatewayMode $mode = MeshGatewayMode::Default, ) { $this->setMode($mode); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getMode(): MeshGatewayMode { @@ -47,9 +44,9 @@ public function setMode(string|MeshGatewayMode $Mode): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Mode' === $k) { $n->setMode($v); @@ -62,10 +59,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); return $out; } } diff --git a/src/ConfigEntry/MeshHTTPConfig.php b/src/ConfigEntry/MeshHTTPConfig.php index ece4e585..5f658b25 100644 --- a/src/ConfigEntry/MeshHTTPConfig.php +++ b/src/ConfigEntry/MeshHTTPConfig.php @@ -53,10 +53,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->SanitizeXForwardClientCert = $this->SanitizeXForwardClientCert; return $out; } diff --git a/src/ConfigEntry/MeshTLSConfig.php b/src/ConfigEntry/MeshTLSConfig.php index 881a5131..cfddc757 100644 --- a/src/ConfigEntry/MeshTLSConfig.php +++ b/src/ConfigEntry/MeshTLSConfig.php @@ -73,10 +73,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (null !== $this->Incoming) { $out->Incoming = $this->Incoming; } diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index fa4ae803..8b412604 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -49,10 +49,7 @@ public function __construct( $this->EnforcingConsecutive5xx = $EnforcingConsecutive5xx; $this->MaxEjectionPercent = $MaxEjectionPercent; $this->BaseEjectionTime = Time::Duration($BaseEjectionTime); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getInterval(): Time\Duration { @@ -109,9 +106,9 @@ public function setBaseEjectionTime(null|Time\Duration $BaseEjectionTime): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Interval' === $k) { $n->Interval = Time::ParseDuration($v); @@ -132,10 +129,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ($this->Interval->Nanoseconds() !== 0) { $out->Interval = $this->Interval; } diff --git a/src/ConfigEntry/PeeringMeshConfig.php b/src/ConfigEntry/PeeringMeshConfig.php index 252679ad..7628a858 100644 --- a/src/ConfigEntry/PeeringMeshConfig.php +++ b/src/ConfigEntry/PeeringMeshConfig.php @@ -53,10 +53,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->PeerThroughMeshGateways = $this->PeerThroughMeshGateways; return $out; } diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index fcda39fc..3c89933c 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -45,7 +45,6 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; /** - * @param array|null $data * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions */ public function __construct( @@ -86,11 +85,7 @@ public function __construct( $this->Meta = $Meta; $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; - - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} } public function getKind(): string @@ -242,9 +237,9 @@ public function setPrioritizeByLocality(null|ServiceResolverPrioritizeByLocality return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('ProxyMode' === $k) { $n->Mode = ProxyMode::from($v); @@ -275,10 +270,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/RateLimits.php b/src/ConfigEntry/RateLimits.php index 7d0e0f05..43714f5d 100644 --- a/src/ConfigEntry/RateLimits.php +++ b/src/ConfigEntry/RateLimits.php @@ -42,9 +42,9 @@ public function setInstanceLevel(InstanceLevelRateLimits $instanceLevel): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('InstanceLevel' === $k || 'instance_level' === $k) { $n->InstanceLevel = InstanceLevelRateLimits::jsonUnserialize($v); @@ -57,10 +57,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->InstanceLevel = $this->InstanceLevel; return $out; } diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php index 039a6485..53d1e9b4 100644 --- a/src/ConfigEntry/RingHashConfig.php +++ b/src/ConfigEntry/RingHashConfig.php @@ -55,9 +55,9 @@ public function setMaximumRingSize(int $MaximumRingSize): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('minimum_ring_size' === $k) { $n->MinimumRingSize = $v; @@ -72,10 +72,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (0 !== $this->MinimumRingSize) { $out->MinimumRingSize = $this->MinimumRingSize; } diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index bb5dc804..8cdb0051 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -46,36 +46,35 @@ class ServiceConfigEntry extends AbstractModel implements ConfigEntry public int $LocalRequestTimeoutMs; public string $BalanceInboundConnections; public null|RateLimits $RateLimits; + /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */ public array $EnvoyExtensions; /** - * @param array|null $data * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Kind = '', - string $Name = '', - string $Partition = '', - string $Namespace = '', - string $Protocol = '', - string|ProxyMode $Mode = ProxyMode::Default, + 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 = [], - null|\stdClass $Meta = null, - int $CreateIndex = 0, - int $ModifyIndex = 0, + 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 = [], + null|\stdClass $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, ) { $this->Kind = $Kind; $this->Name = $Name; @@ -99,10 +98,7 @@ public function __construct( $this->Meta = $Meta; $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getKind(): string { @@ -305,9 +301,9 @@ public function setEnvoyExtensions(EnvoyExtension ...$EnvoyExtensions): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Mode' === $k) { $n->Mode = ProxyMode::from($v); @@ -348,10 +344,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php index abad027b..4c2d2acc 100644 --- a/src/ConfigEntry/ServiceIntentionsConfigEntry.php +++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php @@ -111,9 +111,9 @@ public function setJWT(null|IntentionJWTRequirement $JWT): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Sources' === $k) { $n->Sources = []; @@ -131,10 +131,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index 3a19b416..f4676113 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -222,9 +222,9 @@ public function setLoadBalancer(null|LoadBalancer $LoadBalancer): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('default_subset' === $k) { $n->DefaultSubset = $v; diff --git a/src/ConfigEntry/ServiceResolverFailoverPolicy.php b/src/ConfigEntry/ServiceResolverFailoverPolicy.php index 97b40ea7..629af612 100644 --- a/src/ConfigEntry/ServiceResolverFailoverPolicy.php +++ b/src/ConfigEntry/ServiceResolverFailoverPolicy.php @@ -62,9 +62,9 @@ public function setRegions(string ...$Regions): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -73,10 +73,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Mode) { $out->Mode = $this->Mode; } diff --git a/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php index 2e88cf9a..b7060f7f 100644 --- a/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php +++ b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php @@ -42,9 +42,9 @@ public function setMode(string $Mode): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -53,10 +53,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Mode) { $out->Mode = $this->Mode; } diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php index 7aad16b5..182ded2c 100644 --- a/src/ConfigEntry/ServiceRoute.php +++ b/src/ConfigEntry/ServiceRoute.php @@ -57,9 +57,9 @@ public function setDestination(null|ServiceRouteDestination $Destination): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Match' === $k) { $n->Match = null === $v ? null : ServiceRouteMatch::jsonUnserialize($v); @@ -74,10 +74,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (null !== $this->Match) { $out->Match = $this->Match; } diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index 7bdb6b30..e7db78f9 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -224,9 +224,9 @@ public function setResponseHeaders(null|HTTPHeaderModifiers $ResponseHeaders): s return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('service_subset' === $k) { $n->ServiceSubset = $v; @@ -257,10 +257,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->Service) { $out->Service = $this->Service; } diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php index 84d7e778..c4ca1f6e 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -133,9 +133,9 @@ public function setMethods(string ...$Methods): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('path_exact' === $k) { $n->PathExact = $v; @@ -164,10 +164,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if ('' !== $this->PathExact) { $out->PathExact = $this->PathExact; } diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php index 2ef4866c..751acb45 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -127,9 +127,9 @@ public function setInvert(bool $Invert): static return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -138,10 +138,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ($this->Present) { $out->Present = $this->Present; diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php index 0b854236..af9bad16 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -85,9 +85,9 @@ public function setRegex(string $Regex): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -96,10 +96,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ($this->Present) { $out->Present = $this->Present; diff --git a/src/ConfigEntry/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php index 1f21b33f..5385f7f2 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -42,7 +42,7 @@ public function setHTTP(null|ServiceRouteHTTPMatch $HTTP): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { $n = $into ?? new self(null); foreach ($decoded as $k => $v) { @@ -57,10 +57,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (null !== $this->HTTP) { $out->HTTP = $this->HTTP; } diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 10533aa8..278d7c34 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -102,9 +102,9 @@ public function setRoutes(ServiceRoute ...$Routes): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Routes' === $k) { $n->Routes = []; @@ -120,10 +120,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php index 8875650a..5ef784bf 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -127,9 +127,9 @@ public function setResponseHeaders(null|HTTPHeaderModifiers $ResponseHeaders): s return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('service_subset' === $k) { $n->ServiceSubset = $v; @@ -146,10 +146,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Weight = $this->Weight; if ('' !== $this->Service) { $out->Service = $this->Service; diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index ba5f435f..a2f8a8ca 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -102,9 +102,9 @@ public function setSplits(ServiceSplit ...$Splits): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Splits' === $k) { $n->Splits = []; @@ -120,10 +120,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/SourceIntention.php b/src/ConfigEntry/SourceIntention.php index ce6a54bf..1bc15f4e 100644 --- a/src/ConfigEntry/SourceIntention.php +++ b/src/ConfigEntry/SourceIntention.php @@ -233,9 +233,9 @@ public function setLegacyUpdateTime(null|Time\Time $LegacyUpdateTime): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('sameness_group' === $k) { $n->SamenessGroup = $v; @@ -265,10 +265,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; if ('' !== $this->Peer) { $out->Peer = $this->Peer; diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php index 64b8a8bc..7a0eba7f 100644 --- a/src/ConfigEntry/TerminatingGatewayConfigEntry.php +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -118,9 +118,9 @@ public function setNamespace(string $Namespace): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Services' === $k) { $n->Services = []; @@ -136,10 +136,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ([] !== $this->Services) { diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index cdb83f22..1111924f 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -34,10 +34,7 @@ public function __construct( ) { $this->OutboundListenerPort = $OutboundListenerPort; $this->DialedDirectly = $DialedDirectly; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)$data, $this); - } - } +} public function getOutboundListenerPort(): int { @@ -61,9 +58,9 @@ public function setDialedDirectly(bool $DialedDirectly): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { $n->{$k} = $v; } @@ -72,10 +69,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (0 !== $this->OutboundListenerPort) { $out->OutboundListenerPort = $this->OutboundListenerPort; } diff --git a/src/ConfigEntry/UpstreamConfig.php b/src/ConfigEntry/UpstreamConfig.php new file mode 100644 index 00000000..01710a45 --- /dev/null +++ b/src/ConfigEntry/UpstreamConfig.php @@ -0,0 +1,228 @@ +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(): ?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 ($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(); + } +} diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php index 858b03eb..c01e76b6 100644 --- a/src/ConfigEntry/UpstreamConfiguration.php +++ b/src/ConfigEntry/UpstreamConfiguration.php @@ -21,153 +21,76 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class UpstreamConfiguration extends AbstractModel { - 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; - 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 ($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/Consul.php b/src/Consul.php index f7cccf5c..6f54b6d2 100644 --- a/src/Consul.php +++ b/src/Consul.php @@ -216,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 73bec637..2e5c7365 100644 --- a/src/Coordinate/Coordinate.php +++ b/src/Coordinate/Coordinate.php @@ -40,11 +40,9 @@ class Coordinate extends AbstractModel public float $Height; /** - * @param array|null $data * @param array $Vec */ public function __construct( - null|array $data = null, // Deprecated, will be removed. null|CoordinateConfig $config = null, array $Vec = [], float $Error = 0.0, @@ -237,9 +235,9 @@ private static function _unitVectorAt(array $vec1, array $vec2): CoordinateUnitV return new CoordinateUnitVectorAt(vec: $ret, mag: 0.0); } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Vec' === $k) { $n->Vec = (array)$v; @@ -252,10 +250,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Vec = $this->Vec; $out->Error = $this->Error; $out->Adjustment = $this->Adjustment; diff --git a/src/Coordinate/CoordinateConfig.php b/src/Coordinate/CoordinateConfig.php index 4b1902dd..1a53735e 100644 --- a/src/Coordinate/CoordinateConfig.php +++ b/src/Coordinate/CoordinateConfig.php @@ -203,10 +203,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Dimensionality = $this->Dimensionality; $out->VivaldiErrorMax = $this->VivaldiErrorMax; $out->VivaldiCE = $this->VivaldiCE; diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php index e1152b49..6d61cdff 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -30,11 +30,9 @@ class CoordinateDatacenterMap extends AbstractModel public array $Coordinates; /** - * @param array|null $data * @param array<\DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry> $Coordinates */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Datacenter = '', string $AreaID = '', array $Coordinates = [], @@ -71,9 +69,9 @@ public function setCoordinates(CoordinateEntry ...$Coordinates): self return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Coordinates' === $k) { $n->Coordinates = []; @@ -89,10 +87,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Datacenter = $this->Datacenter; $out->AreaID = $this->AreaID; $out->Coordinates = $this->Coordinates; diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index 0925bf94..f517af76 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -33,7 +33,6 @@ class CoordinateEntry extends AbstractModel * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated, will be removed. string $Node = '', string $Segment = '', string $Partition = '', @@ -94,7 +93,7 @@ public function setCoord(null|Coordinate $Coord): self public static function jsonUnserialize(\stdClass $decoded, null | self $into = null): self { - $n = $into ?? new self(); + $n = new self(); foreach($decoded as $k => $v) { if ('Coord' === $k) { $n->Coord = Coordinate::jsonUnserialize($v); @@ -107,10 +106,7 @@ public static function jsonUnserialize(\stdClass $decoded, null | self $into = n public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Node = $this->Node; $out->Segment = $this->Segment; if ('' !== $this->Partition) { diff --git a/src/Event/UserEvent.php b/src/Event/UserEvent.php index ae640733..1181d846 100644 --- a/src/Event/UserEvent.php +++ b/src/Event/UserEvent.php @@ -36,7 +36,6 @@ class UserEvent extends AbstractModel /** * UserEvent constructor. * - * @param array $data * @param bool $_decodeValue */ public function __construct(array $data = [], bool $_decodeValue = false) diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index a8dad9bc..21198dc2 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -36,7 +36,6 @@ class HealthCheckDefinition extends AbstractModel implements \JsonSerializable public Time\Duration $DeregisterCriticalServiceAfterDuration; public function __construct( - null|array $data = null, string $HTTP = '', iterable $Header = [], string $Method = '', @@ -163,9 +162,9 @@ public function setDeregisterCriticalServiceAfterDuration( return $this; } - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $k => $v) { if ('Interval' === $k || 'IntervalDuration' === $k) { $n->IntervalDuration = Time::Duration($v); @@ -182,10 +181,7 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $into = nul public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->HTTP = $this->HTTP; $out->Header = $this->Header; $out->Method = $this->Method; diff --git a/src/Health/HealthChecks.php b/src/Health/HealthChecks.php index e60860c4..3bcb06fb 100644 --- a/src/Health/HealthChecks.php +++ b/src/Health/HealthChecks.php @@ -123,9 +123,9 @@ public function offsetUnset($offset): void /** * @param array<\stdClass> $decoded */ - public static function jsonUnserialize(array $decoded, null|self $into = null): static + public static function jsonUnserialize(array $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach ($decoded as $d) { $n->Checks[] = HealthCheck::jsonUnserialize($d); } diff --git a/src/KV/KVPair.php b/src/KV/KVPair.php index 0a81ec7a..91452569 100644 --- a/src/KV/KVPair.php +++ b/src/KV/KVPair.php @@ -42,7 +42,6 @@ class KVPair extends AbstractModel /** * KVPair constructor. - * @param array $data * @param bool $_decodeValue */ public function __construct(array $data = [], bool $_decodeValue = false) diff --git a/src/KV/KVTxnOp.php b/src/KV/KVTxnOp.php index f7cf0622..e3824339 100644 --- a/src/KV/KVTxnOp.php +++ b/src/KV/KVTxnOp.php @@ -33,7 +33,6 @@ class KVTxnOp extends AbstractModel /** * KVTxnOp constructor. - * @param array $data * @param bool $_decodeValue */ public function __construct(array $data = [], bool $_decodeValue = false) diff --git a/src/Metrics/Label.php b/src/Metrics/Label.php index 7020a158..cc5d6f86 100644 --- a/src/Metrics/Label.php +++ b/src/Metrics/Label.php @@ -66,10 +66,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Value = $this->Value; return $out; diff --git a/src/Peering/Locality.php b/src/Peering/Locality.php index 061487ff..2b50af25 100644 --- a/src/Peering/Locality.php +++ b/src/Peering/Locality.php @@ -66,10 +66,7 @@ public static function jsonUnserialize(\stdClass $decoded): static public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Region = $this->Region; $out->Zone = $this->Zone; return $out; diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 4172a2ac..2e2b0a6e 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -50,7 +50,6 @@ class QueryOptions implements RequestOptions * @param array|null $data */ public function __construct( - null|array $data = null, // Deprecated do not use. string $Namespace = '', string $Datacenter = '', bool $AllowStale = false, diff --git a/src/SimpleJsonUnserializeTrait.php b/src/SimpleJsonUnserializeTrait.php index 92561ed2..9642616f 100644 --- a/src/SimpleJsonUnserializeTrait.php +++ b/src/SimpleJsonUnserializeTrait.php @@ -22,9 +22,9 @@ trait SimpleJsonUnserializeTrait { - public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): self + public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(); + $n = new self(); foreach($decoded as $k => $v) { $n->{$k} = $v; } diff --git a/src/WriteOptions.php b/src/WriteOptions.php index 4f4232b8..2163b95c 100644 --- a/src/WriteOptions.php +++ b/src/WriteOptions.php @@ -31,11 +31,7 @@ class WriteOptions implements RequestOptions public Time\Duration $Timeout; - /** - * @param array|null $data - */ public function __construct( - null|array $data = null, // Deprecated do not use. string $Namespace = '', string $Datacenter = '', string $Token = '', @@ -47,9 +43,6 @@ public function __construct( $this->Token = $Token; $this->RelayFactor = $RelayFactor; $this->Timeout = Time::Duration($Timeout); - if (null !== $data && [] !== $data) { - $this->_fromMap((object)$data); - } } public function getNamespace(): string @@ -116,24 +109,8 @@ public function apply(Request $r): void if (0 !== $this->RelayFactor) { $r->params->set('relay-factor', (string)$this->RelayFactor); } - if (0 < $this->Timeout->Nanoseconds()) { $r->timeout = $this->Timeout; } } - - /** - * @param \stdClass $data - * @deprecated This is only here to support construction with map. It will be removed in a future version. - */ - private function _fromMap(\stdClass $data): void - { - foreach ($data as $k => $v) { - if ('Timeout' === $k) { - $this->Timeout = Time::Duration($v); - } else { - $this->{$k} = $v; - } - } - } } diff --git a/src/funcs.php b/src/funcs.php index 7db3a63c..ad8a1bb0 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -46,28 +46,3 @@ function _enc_obj_if_valued(\stdClass &$out, string $field, \stdClass | \JsonSer $out->{$field} = $obj; } } - -function MakeConfigEntry(string $kind, string $name): ConfigEntry\ConfigEntry -{ - switch ($kind) { - case Consul::ServiceDefaults: - return new ConfigEntry\ServiceConfigEntry(kind: $kind, name: $name); - case Consul::ProxyDefaults: - return new ConfigEntry\ProxyConfigEntry(kind: $kind, name: $name); - case Consul::ServiceRouter: - return new ConfigEntry\ServiceRouterConfigEntry(kind: $kind, name: $name); - case Consul::ServiceSplitter: - return new ConfigEntry\ServiceSplitterConfigEntry(kind: $kind, name: $name); - case Consul::ServiceResolver: - return new ConfigEntry\ServiceResolverConfigEntry(kind: $kind, name: $name); - case Consul::IngressGateway: - return new ConfigEntry\IngressGatewayConfigEntry(kind: $kind, name: $name); - case Consul::TerminatingGateway: - return new ConfigEntry\TerminatingGatewayConfigEntry(kind: $kind, name: $name); - case Consul::ServiceIntentions: - return new ConfigEntry\ServiceIntentionsConfigEntry(kind: $kind, name: $name); - - default: - throw new \InvalidArgumentException(sprintf('Unknown kind "%s"', $kind)); - } -} From 779f4350ece8c39e764dbbeb6da4e4fcad8382b1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 6 Jul 2025 13:51:33 -0500 Subject: [PATCH 62/79] some cleanup --- src/ACL/ACLAuthMethod.php | 4 +- src/ACL/ACLLoginParams.php | 32 +++-------- src/ACL/ACLOIDCAuthURLParams.php | 22 ++------ src/ACL/ACLPolicy.php | 5 +- src/ACL/ACLPolicyListEntry.php | 8 ++- src/ACL/ACLRole.php | 20 +++++-- src/ACL/ACLRolePolicyLink.php | 8 +++ src/Agent/AgentCheckRegistration.php | 9 ++-- src/Agent/AgentService.php | 59 ++++++--------------- src/Agent/AgentServiceCheck.php | 73 ++++++++++---------------- src/Agent/AgentServiceRegistration.php | 37 +++---------- src/Agent/MetricsInfo.php | 19 +++++-- src/Catalog/Node.php | 18 ++----- src/ConfigEntry/ConfigEntryTrait.php | 16 ++---- src/MetaContainer.php | 37 +++++++++++++ src/Operator/AutopilotServer.php | 2 +- 16 files changed, 162 insertions(+), 207 deletions(-) create mode 100644 src/MetaContainer.php diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index d978df8e..320b9120 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -40,7 +40,7 @@ class ACLAuthMethod extends AbstractModel public string $Partition; /** - * @param iterable<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules + * @param array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules */ public function __construct( string $Name = '', @@ -52,7 +52,7 @@ public function __construct( null|\stdClass $Config = null, int $CreateIndex = 0, int $ModifyIndex = 0, - iterable $NamespaceRules = [], + array $NamespaceRules = [], string $Namespace = '', string $Partition = '', ) { diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index 1d83cace..c6044895 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -21,22 +21,24 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\MetaContainer; class ACLLoginParams extends AbstractModel { + use MetaContainer; + public string $AuthMethod; public string $BearerToken; - public null|array $Meta; public function __construct( string $AuthMethod = '', string $BearerToken = '', - null|array|\stdClass $Meta = null, + null|\stdClass $Meta = null, ) { $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; - $this->setMeta($Meta); -} + $this->Meta = $Meta; + } public function getAuthMethod(): string { @@ -60,29 +62,11 @@ public function setBearerToken(string $BearerToken): self return $this; } - public function getMeta(): array - { - return $this->Meta; - } - - public function setMeta(null|array|\stdClass $Meta): self - { - $this->Meta = match($Meta) { - null => null, - default => (array)$Meta, - }; - return $this; - } - public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - if ('Meta' === $k) { - $n->setMeta($v); - } else { - $n->{$k} = $v; - } + $n->{$k} = $v; } return $n; } @@ -92,7 +76,7 @@ public function jsonSerialize(): \stdClass $out = $this->_startJsonSerialize(); $out->AuthMethod = $this->AuthMethod; $out->BearerToken = $this->BearerToken; - if (null !== $this->Meta && [] !== $this->Meta) { + if (null !== $this->Meta) { $out->Meta = $this->Meta; } return $out; diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index a8afbec1..3a572767 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -21,13 +21,15 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\MetaContainer; class ACLOIDCAuthURLParams extends AbstractModel { + use MetaContainer; + public string $AuthMethod; public string $RedirectURI; public string $ClientNonce; - public null|\stdClass $Meta; public function __construct( string $AuthMethod = '', @@ -74,27 +76,11 @@ public function setClientNonce(string $ClientNonce): self return $this; } - public function getMeta(): null|\stdClass - { - return $this->Meta; - } - - public function setMeta(null|\stdClass $Meta): self - { - $this->Meta = $Meta; - return $this; - } - - public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - if ('Meta' === $k) { - $n->setMeta($v); - } else { - $n->{$k} = $v; - } + $n->{$k} = $v; } return $n; } diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 1fbcd8cb..705012fb 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -36,12 +36,15 @@ class ACLPolicy extends AbstractModel public string $Namespace; public string $Partition; + /** + * @param array $Datacenters + */ public function __construct( string $ID = '', string $Name = '', string $Description = '', string $Rules = '', - iterable $Datacenters = [], + array $Datacenters = [], string $Hash = '', int $CreateIndex = 0, int $ModifyIndex = 0, diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index c9fc82b3..e23df05e 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -34,11 +34,14 @@ class ACLPolicyListEntry extends AbstractModel public string $Namespace; public string $Partition; + /** + * @param array $Datacenters + */ public function __construct( string $ID = '', string $Name = '', string $Description = '', - iterable $Datacenters = [], + array $Datacenters = [], string $Hash = '', int $CreateIndex = 0, int $ModifyIndex = 0, @@ -89,6 +92,9 @@ public function setDescription(string $Description): self return $this; } + /** + * @return array + */ public function getDatacenters(): array { return $this->Datacenters; diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index fd89e695..6af27890 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -41,14 +41,20 @@ class ACLRole extends AbstractModel 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 = '', - iterable $Policies = [], - iterable $ServiceIdentities = [], - iterable $NodeIdentities = [], - iterable $TemplatedPolicies = [], + array $Policies = [], + array $ServiceIdentities = [], + array $NodeIdentities = [], + array $TemplatedPolicies = [], string $Hash = '', int $CreateIndex = 0, int $ModifyIndex = 0, @@ -218,18 +224,22 @@ public static function jsonUnserialize(\stdClass $decoded): self $n = new self(); foreach ($decoded as $k => $v) { if ('Policies' === $k) { + $n->Policies = []; foreach ($v as $vv) { - $n->Policies[] = ACLTokenPolicyLink::jsonUnserialize($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); } diff --git a/src/ACL/ACLRolePolicyLink.php b/src/ACL/ACLRolePolicyLink.php index 649dbc90..8e6f93bb 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 ($decoded as $k => $v) { + $n->{$k} = $v; + } + return $n; + } } diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 40543d9c..84d222f6 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -27,19 +27,22 @@ class AgentCheckRegistration extends AgentServiceCheck public string $Namespace; public string $Partition; + /** + * @param array $Args + */ public function __construct( string $ID = '', string $ServiceID = '', string $CheckID = '', string $Name = '', - iterable $ScriptArgs = [], + array $Args = [], string $DockerContainerID = '', string $Shell = '', string $Interval = '', string $Timeout = '', string $TTL = '', string $HTTP = '', - iterable $Header = [], + null|\stdClass $Header = null, string $Method = '', string $TCP = '', string $Status = '', @@ -60,7 +63,7 @@ public function __construct( parent::__construct( CheckID: $CheckID, Name: $Name, - ScriptArgs: $ScriptArgs, + Args: $Args, DockerContainerID: $DockerContainerID, Shell: $Shell, Interval: $Interval, diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 79865bc9..20104613 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -22,16 +22,18 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Catalog\ServiceAddress; +use DCarbone\PHPConsulAPI\MetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; class AgentService extends AbstractModel { - public string $Kind; + use MetaContainer; + + public ServiceKind $Kind; public string $ID; public string $Service; /** @var array */ public array $Tags; - public null|\stdClass $Meta; public int $Port; public string $Address; public string $SocketPath; @@ -50,34 +52,14 @@ class AgentService extends AbstractModel public null|Locality $Locality; /** - * @param string $Kind - * @param string $ID - * @param string $Service - * @param string $SocketPath - * @param iterable $Tags - * @param \stdClass|null $Meta - * @param int $Port - * @param string $Address - * @param \stdClass|null $TaggedAddresses - * @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights - * @param bool $EnableTagOverride - * @param int $CreateIndex - * @param int $ModifyIndex - * @param string $ContentHash - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig|null $Proxy - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnect|null $Connect - * @param string $PeerName - * @param string $Namespace - * @param string $Partition - * @param string $Datacenter - * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality + * @param array $Tags */ public function __construct( - string $Kind = '', + string|ServiceKind $Kind = '', string $ID = '', string $Service = '', string $SocketPath = '', - iterable $Tags = [], + array $Tags = [], null|\stdClass $Meta = null, int $Port = 0, string $Address = '', @@ -95,7 +77,7 @@ public function __construct( string $Datacenter = '', null|Locality $Locality = null, ) { - $this->Kind = $Kind; + $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind; $this->ID = $ID; $this->Service = $Service; $this->Meta = $Meta; @@ -118,14 +100,14 @@ public function __construct( $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; } @@ -165,17 +147,6 @@ public function setTags(string ...$Tags): self return $this; } - public function getMeta(): null|\stdClass - { - return $this->Meta; - } - - public function setMeta(null|\stdClass $Meta): self - { - $this->Meta = $Meta; - return $this; - } - public function getPort(): int { return $this->Port; @@ -352,10 +323,10 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - if ('Tags' === $k) { + if ('Kind' === $k) { + $n->Kind = ServiceKind::from($v); + } elseif ('Tags' === $k) { $n->setTags(...$v); - } elseif ('Meta' === $k) { - $n->setMeta($v); } elseif ('Proxy' === $k) { $n->Proxy = null === $v ? null : AgentServiceConnectProxyConfig::jsonUnserialize($v); } elseif ('Weights' === $k) { @@ -376,7 +347,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { $out = $this->_startJsonSerialize(); - if ('' !== $this->Kind) { + if (ServiceKind::Typical !== $this->Kind) { $out->Kind = $this->Kind; } $out->ID = $this->ID; diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 7805f07c..6d9c55dd 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -27,7 +27,7 @@ class AgentServiceCheck extends AbstractModel public string $CheckID; public string $Name; /** @var string[] */ - public array $ScriptArgs; + public array $Args; public string $DockerContainerID; public string $Shell; public string $Interval; @@ -51,45 +51,22 @@ class AgentServiceCheck extends AbstractModel public string $DeregisterCriticalServiceAfter; /** - * @param string $CheckID - * @param string $Name - * @param iterable $ScriptArgs - * @param string $DockerContainerID - * @param string $Shell - * @param string $Interval - * @param string $Timeout - * @param string $TTL - * @param string $HTTP - * @param \stdClass|null $Header - * @param string $Method - * @param string $TCP - * @param string $Status - * @param string $Notes - * @param bool $TLSSkipVerify - * @param string $GRPC - * @param bool $GRPCUseTLS - * @param string $H2PING - * @param bool $H2PINGUseTLS - * @param string $AliasNode - * @param string $AliasService - * @param int $SuccessBeforePassing - * @param int $FailuresBeforeCritical - * @param string $DeregisterCriticalServiceAfter + * @param array $Args */ public function __construct( - string $CheckID = '', - string $Name = '', - iterable $ScriptArgs = [], - string $DockerContainerID = '', - string $Shell = '', - string $Interval = '', - string $Timeout = '', - string $TTL = '', - string $HTTP = '', + string $CheckID = '', + string $Name = '', + array $Args = [], + string $DockerContainerID = '', + string $Shell = '', + string $Interval = '', + string $Timeout = '', + string $TTL = '', + string $HTTP = '', null|\stdClass $Header = null, - string $Method = '', - string $TCP = '', - string $Status = '', + string $Method = '', + string $TCP = '', + string $Status = '', string $Notes = '', bool $TLSSkipVerify = false, string $GRPC = '', @@ -104,8 +81,8 @@ public function __construct( ) { $this->CheckID = $CheckID; $this->Name = $Name; - $this->ScriptArgs = []; - $this->setScriptArgs(...$ScriptArgs); + $this->Args = []; + $this->setArgs(...$Args); $this->DockerContainerID = $DockerContainerID; $this->Shell = $Shell; $this->Interval = $Interval; @@ -154,14 +131,14 @@ public function setName(string $name): self /** * @return array */ - public function getScriptArgs(): array + public function getArgs(): array { - return $this->ScriptArgs; + return $this->Args; } - public function setScriptArgs(string ...$args): self + public function setArgs(string ...$args): self { - $this->ScriptArgs = $args; + $this->Args = $args; return $this; } @@ -400,7 +377,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('ScriptArgs' === $k) { + $n->Args = $v; + } else { + $n->{$k} = $v; + } } return $n; } @@ -414,8 +395,8 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Name) { $out->Name = $this->Name; } - if ([] !== $this->ScriptArgs) { - $out->ScriptArgs = $this->ScriptArgs; + if ([] !== $this->Args) { + $out->ScriptArgs = $this->Args; } if ('' !== $this->DockerContainerID) { $out->DockerContainerID = $this->DockerContainerID; diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 7c4c8117..d4a6f128 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -22,10 +22,13 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Catalog\ServiceAddress; +use DCarbone\PHPConsulAPI\MetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; class AgentServiceRegistration extends AbstractModel { + use MetaContainer; + public ServiceKind $Kind; public string $ID; public string $Name; @@ -35,7 +38,6 @@ class AgentServiceRegistration extends AbstractModel public string $Address; public null|\stdClass $TaggedAddresses; public bool $EnableTagOverride; - public null|\stdClass $Meta; public null|AgentWeights $Weights; public null|AgentServiceCheck $Check; public AgentServiceChecks $Checks; @@ -46,29 +48,13 @@ class AgentServiceRegistration extends AbstractModel public null|Locality $Locality; /** - * @param string|\DCarbone\PHPConsulAPI\Agent\ServiceKind $Kind - * @param string $ID - * @param string $Name - * @param iterable $Tags - * @param int $Port - * @param string $Address - * @param \stdClass|null $TaggedAddresses - * @param bool $EnableTagOverride - * @param \stdClass|null $Meta - * @param \DCarbone\PHPConsulAPI\Agent\AgentWeights|null $Weights - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceCheck|null $Check - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceChecks|null $Checks - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig|null $Proxy - * @param \DCarbone\PHPConsulAPI\Agent\AgentServiceConnect|null $Connect - * @param string $Namespace - * @param string $Partition - * @param \DCarbone\PHPConsulAPI\Peering\Locality|null $Locality + * @param array $Tags */ public function __construct( string|ServiceKind $Kind = ServiceKind::Typical, string $ID = '', string $Name = '', - iterable $Tags = [], + array $Tags = [], int $Port = 0, string $Address = '', null|\stdClass $TaggedAddresses = null, @@ -83,7 +69,7 @@ public function __construct( string $Partition = '', null|Locality $Locality = null, ) { - $this->setKind($Kind); + $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind; $this->ID = $ID; $this->Name = $Name; $this->setTags(...$Tags); @@ -200,17 +186,6 @@ public function setEnableTagOverride(bool $EnableTagOverride): self return $this; } - public function getMeta(): null|\stdClass - { - return $this->Meta; - } - - public function setMeta(null|\stdClass $Meta): self - { - $this->Meta = $Meta; - return $this; - } - public function getWeights(): null|AgentWeights { return $this->Weights; diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index 0646374a..4a3a9319 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -34,12 +34,19 @@ class MetricsInfo extends AbstractModel /** @var \DCarbone\PHPConsulAPI\Agent\SampledValue[] */ public array $Samples; + /** + * @param string $Timestamp + * @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 = '', - iterable $Gauges = [], - iterable $Points = [], - iterable $Counters = [], - iterable $Samples = [], + array $Gauges = [], + array $Points = [], + array $Counters = [], + array $Samples = [], ) { $this->Timestamp = $Timestamp; $this->setGauges(...$Gauges); @@ -120,18 +127,22 @@ public static function jsonUnserialize(\stdClass $decoded): self $n = new self(); foreach ($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); } diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index a98433e2..355aec9c 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -21,25 +21,24 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\MetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; class Node extends AbstractModel { + use MetaContainer; + public string $ID; public string $Node; public string $Address; public string $Datacenter; public null|\stdClass $TaggedAddresses; - public null|\stdClass $Meta; public int $CreateIndex; public int $ModifyIndex; public string $Partition; public string $PeerName; public null|Locality $Locality; - /** - * @param array|null $data - */ public function __construct( string $ID = '', string $Node = '', @@ -121,17 +120,6 @@ public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self return $this; } - public function getMeta(): null|\stdClass - { - return $this->Meta; - } - - public function setMeta(null|\stdClass $Meta): self - { - $this->Meta = $Meta; - return $this; - } - public function getCreateIndex(): int { return $this->CreateIndex; diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php index 85b6c4f7..d06c4fc6 100644 --- a/src/ConfigEntry/ConfigEntryTrait.php +++ b/src/ConfigEntry/ConfigEntryTrait.php @@ -20,10 +20,13 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\MetaContainer; + trait ConfigEntryTrait { + use MetaContainer; + public string $Namespace; - public null|\stdClass $Meta; public int $CreateIndex; public int $ModifyIndex; @@ -38,17 +41,6 @@ public function setNamespace(string $Namespace): self return $this; } - public function getMeta(): null|\stdClass - { - return $this->Meta; - } - - public function setMeta(null|\stdClass $Meta): self - { - $this->Meta = $Meta; - return $this; - } - public function getCreateIndex(): int { return $this->CreateIndex; diff --git a/src/MetaContainer.php b/src/MetaContainer.php new file mode 100644 index 00000000..fd2cc972 --- /dev/null +++ b/src/MetaContainer.php @@ -0,0 +1,37 @@ +Meta; + } + + public function setMeta(null|\stdClass $Meta): self + { + $this->Meta = $Meta; + return $this; + } +} \ No newline at end of file diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index 3e0ff8d0..3308c52f 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -57,7 +57,7 @@ class AutopilotServer extends AbstractModel implements \JsonSerializable public string $UpgradeVersion = ''; public bool $ReadReplica = false; public string $Status = ''; - public array $Meta = []; + public null|\stdClass $Meta; public string $NodeType = ''; public function __construct(?array $data = []) From 2dc43b88430cc39b0496155908688c977ded38bb Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 6 Jul 2025 16:19:20 -0500 Subject: [PATCH 63/79] small bits more work --- src/ConfigEntry/ServiceResolverFailover.php | 128 ++++++++++++++-- .../ServiceResolverFailoverTarget.php | 140 ++++++++++++++++++ 2 files changed, 254 insertions(+), 14 deletions(-) create mode 100644 src/ConfigEntry/ServiceResolverFailoverTarget.php diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php index 532a997a..4e84cfd5 100644 --- a/src/ConfigEntry/ServiceResolverFailover.php +++ b/src/ConfigEntry/ServiceResolverFailover.php @@ -21,26 +21,40 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceResolverFailover extends AbstractModel { - 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; + /** @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 ($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/ServiceResolverFailoverTarget.php b/src/ConfigEntry/ServiceResolverFailoverTarget.php new file mode 100644 index 00000000..6e14972d --- /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 ($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; + } +} From ca4434190751a4588aedf5bb53ceeb647fa2a7b0 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 6 Jul 2025 16:22:06 -0500 Subject: [PATCH 64/79] small things --- src/ACL/ACLAuthMethodListEntry.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 6d7871e9..47e96298 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -30,11 +30,6 @@ class ACLAuthMethodListEntry extends AbstractModel 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; public int $ModifyIndex; @@ -178,9 +173,6 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - if (null === $v) { - continue; - } if ('MaxTokenTTL' === $k) { $n->setMaxTokenTTL($v); } else { From 23a511f09f8dd8226db62e03645b781338ca49f8 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sun, 6 Jul 2025 16:23:09 -0500 Subject: [PATCH 65/79] small things --- src/ACL/ACLAuthMethodListEntry.php | 13 ------------- src/ACL/ACLPolicyListEntry.php | 1 + 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 47e96298..8b5e5fb6 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -112,24 +112,11 @@ public function setMaxTokenTTL(null|int|float|string|\DateInterval|Time\Duration 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; diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index e23df05e..9bac385a 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -27,6 +27,7 @@ class ACLPolicyListEntry extends AbstractModel public string $ID; public string $Name; public string $Description; + /** @var array */ public array $Datacenters; public string $Hash; public int $CreateIndex; From 48a9e9107eec1d3cf72b942676721399b8bcd431 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Mon, 7 Jul 2025 22:03:38 -0500 Subject: [PATCH 66/79] more work --- src/ConfigEntry/ServiceResolverRedirect.php | 109 +++++++++++++++--- src/ConfigEntry/ServiceResolverSubset.php | 40 +++++-- src/ConfigEntry/ServiceRouteMatch.php | 4 +- .../TerminatingGatewayConfigEntry.php | 2 - src/ConfigEntry/UpstreamConfig.php | 36 ++++++ src/ConfigEntry/UpstreamLimits.php | 59 ++++++---- 6 files changed, 204 insertions(+), 46 deletions(-) diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php index 5e507e5d..ec766ce9 100644 --- a/src/ConfigEntry/ServiceResolverRedirect.php +++ b/src/ConfigEntry/ServiceResolverRedirect.php @@ -21,26 +21,34 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceResolverRedirect extends AbstractModel { - 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 $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 ($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 d399c403..a9a68717 100644 --- a/src/ConfigEntry/ServiceResolverSubset.php +++ b/src/ConfigEntry/ServiceResolverSubset.php @@ -21,21 +21,18 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class ServiceResolverSubset extends AbstractModel { - protected const FIELDS = [ - self::FIELD_FILTER => Transcoding::OMITEMPTY_STRING_FIELD, - self::FIELD_ONLY_PASSING => Transcoding::OMITEMPTY_BOOLEAN_FIELD, - ]; - - private const FIELD_FILTER = 'Filter'; - private const FIELD_ONLY_PASSING = 'OnlyPassing'; - public string $Filter; public bool $OnlyPassing; + public function __construct(string $Filter = '', bool $OnlyPassing = false) + { + $this->Filter = $Filter; + $this->OnlyPassing = $OnlyPassing; + } + public function getFilter(): string { return $this->Filter; @@ -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 ($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/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php index 5385f7f2..f77ce860 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -26,7 +26,7 @@ class ServiceRouteMatch extends AbstractModel { public null|ServiceRouteHTTPMatch $HTTP = null; - public function __construct(null|ServiceRouteHTTPMatch $HTTP) + public function __construct(null|ServiceRouteHTTPMatch $HTTP = null) { $this->HTTP = $HTTP; } @@ -44,7 +44,7 @@ public function setHTTP(null|ServiceRouteHTTPMatch $HTTP): self public static function jsonUnserialize(\stdClass $decoded): self { - $n = $into ?? new self(null); + $n = new self(); foreach ($decoded as $k => $v) { if ('HTTP' === $k) { $n->HTTP = ServiceRouteHTTPMatch::jsonUnserialize($v); diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php index 7a0eba7f..eba18327 100644 --- a/src/ConfigEntry/TerminatingGatewayConfigEntry.php +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -22,8 +22,6 @@ use DCarbone\PHPConsulAPI\AbstractModel; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; - class TerminatingGatewayConfigEntry extends AbstractModel implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/UpstreamConfig.php b/src/ConfigEntry/UpstreamConfig.php index 01710a45..a8b18acb 100644 --- a/src/ConfigEntry/UpstreamConfig.php +++ b/src/ConfigEntry/UpstreamConfig.php @@ -21,6 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; class UpstreamConfig extends AbstractModel { @@ -224,5 +225,40 @@ public static function jsonUnserialize(\stdClass $decoded): self 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/UpstreamLimits.php b/src/ConfigEntry/UpstreamLimits.php index 10868d89..2bb867d4 100644 --- a/src/ConfigEntry/UpstreamLimits.php +++ b/src/ConfigEntry/UpstreamLimits.php @@ -21,29 +21,22 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; class UpstreamLimits extends AbstractModel { - 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 null|int $MaxConnections = null; + public null|int $MaxPendingRequests = null; + public null|int $MaxConcurrentRequests = null; + + 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(): ?int { @@ -77,4 +70,30 @@ public function setMaxConcurrentRequests(?int $MaxConcurrentRequests): self $this->MaxConcurrentRequests = $MaxConcurrentRequests; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new self(); + foreach ($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; + } } From 14bc66e2b3bef53f6bf60ea9baeeb4b1878496d0 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 8 Jul 2025 17:20:28 -0500 Subject: [PATCH 67/79] more stuff --- phpunit.xml | 48 +++++++------- src/Coordinate/Coordinate.php | 3 - src/Coordinate/CoordinateClient.php | 1 - src/Coordinate/CoordinateDatacenterMap.php | 3 - src/Coordinate/CoordinateEntry.php | 6 -- src/Event/UserEvent.php | 74 +++++++++++++++------- 6 files changed, 74 insertions(+), 61 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 4aeef048..c083232c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,35 +16,35 @@ ./tests/Usage/ConfigUsageTest.php - - - + + ./tests/Usage/RequestUsageTest.php + - - - + + ./tests/Usage/ACL + ./tests/Usage/Agent - - - - - - - - - - - - - - - + + ./tests/Usage/Catalog + + + ./tests/Usage/Coordinate + + + ./tests/Usage/KV + + + ./tests/Usage/Operator + + + ./tests/Usage/Session + - - - + + ./tests/Usage/Random + diff --git a/src/Coordinate/Coordinate.php b/src/Coordinate/Coordinate.php index 2e5c7365..c85d7159 100644 --- a/src/Coordinate/Coordinate.php +++ b/src/Coordinate/Coordinate.php @@ -60,9 +60,6 @@ public function __construct( $this->Adjustment = $Adjustment; $this->Height = $Height; } - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)($data), $this); - } } /** diff --git a/src/Coordinate/CoordinateClient.php b/src/Coordinate/CoordinateClient.php index 4a443303..8759c496 100644 --- a/src/Coordinate/CoordinateClient.php +++ b/src/Coordinate/CoordinateClient.php @@ -20,7 +20,6 @@ limitations under the License. */ -use DCarbone\Go\HTTP; use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\QueryOptions; use DCarbone\PHPConsulAPI\WriteOptions; diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php index 6d61cdff..d317582a 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -40,9 +40,6 @@ public function __construct( $this->Datacenter = $Datacenter; $this->AreaID = $AreaID; $this->setCoordinates(...$Coordinates); - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)($data), $this); - } } public function getDatacenter(): string diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index f517af76..183222d6 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -29,9 +29,6 @@ class CoordinateEntry extends AbstractModel public string $Partition; public null|Coordinate $Coord; - /** - * @param array|null $data - */ public function __construct( string $Node = '', string $Segment = '', @@ -42,9 +39,6 @@ public function __construct( $this->Segment = $Segment; $this->Partition = $Partition; $this->Coord = $Coord; - if (null !== $data && [] !== $data) { - self::jsonUnserialize((object)($data), $this); - } } public function getNode(): string diff --git a/src/Event/UserEvent.php b/src/Event/UserEvent.php index 1181d846..1035527b 100644 --- a/src/Event/UserEvent.php +++ b/src/Event/UserEvent.php @@ -24,30 +24,33 @@ class UserEvent extends AbstractModel { - 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 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 @@ -89,4 +92,27 @@ public function getLTime(): int { return $this->LTime; } + + public static function jsonUnserialize(\stdclass $decoded): self + { + $n = new self(); + foreach ($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; + } } From 1448c1cf225938191a2333a2aa7867e6b3ccb24e Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 15:43:28 -0500 Subject: [PATCH 68/79] updating Values type and HealthCheckDefinition --- src/Health/HealthCheckDefinition.php | 113 +++++++++++++++++++++++---- src/Values.php | 59 ++++++++++++-- 2 files changed, 153 insertions(+), 19 deletions(-) diff --git a/src/Health/HealthCheckDefinition.php b/src/Health/HealthCheckDefinition.php index 21198dc2..b74ff618 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -22,42 +22,56 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\Values; class HealthCheckDefinition extends AbstractModel implements \JsonSerializable { public string $HTTP; - public array $Header; + 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; + /** + * @param array>|\DCarbone\PHPConsulAPI\Values|null $Header + */ public function __construct( string $HTTP = '', - iterable $Header = [], + null|array|\stdClass|Values $Header = null, string $Method = '', string $Body = '', bool $TLSSkipVerify = false, string $TCP = '', + 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->setHeader($Header); $this->Method = $Method; $this->Body = $Body; $this->TLSSkipVerify = $TLSSkipVerify; $this->TCP = $TCP; + $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); - if (null !== $data && [] !== $data) { - static::jsonUnserialize((object)$data, $this); - } } public function getHTTP(): string @@ -71,13 +85,24 @@ public function setHTTP(string $HTTP): self return $this; } - public function getHeader(): array + public function getHeader(): Values { return $this->Header; } - public function setHeader(string ...$Header): self + /** + * @param array>|\DCarbone\PHPConsulAPI\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; } @@ -126,14 +151,68 @@ public function setTCP(string $TCP): self return $this; } + public function isTCPUseTLS(): bool + { + return $this->TCPUseTLS; + } + + public function setTCPUseTLS(bool $TCPUseTLS): HealthCheckDefinition + { + $this->TCPUseTLS = $TCPUseTLS; + return $this; + } + + public function getUDP(): string + { + return $this->UDP; + } + + public function setUDP(string $UDP): HealthCheckDefinition + { + $this->UDP = $UDP; + return $this; + } + + public function getGRPC(): string + { + return $this->GRPC; + } + + public function setGRPC(string $GRPC): HealthCheckDefinition + { + $this->GRPC = $GRPC; + return $this; + } + + public function getOSService(): string + { + return $this->OSService; + } + + public function setOSService(string $OSService): HealthCheckDefinition + { + $this->OSService = $OSService; + return $this; + } + + public function isGRPCUseTLS(): bool + { + return $this->GRPCUseTLS; + } + + public function setGRPCUseTLS(bool $GRPCUseTLS): HealthCheckDefinition + { + $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 { + public function setIntervalDuration(null|int|float|string|\DateInterval|Time\Duration $IntervalDuration): self + { $this->IntervalDuration = Time::Duration($IntervalDuration); return $this; } @@ -143,9 +222,8 @@ public function getTimeoutDuration(): Time\Duration return $this->TimeoutDuration; } - public function setTimeoutDuration( - null|int|float|string|\DateInterval|Time\Duration $TimeoutDuration - ): self { + public function setTimeoutDuration(null|int|float|string|\DateInterval|Time\Duration $TimeoutDuration): self + { $this->TimeoutDuration = Time::Duration($TimeoutDuration); return $this; } @@ -172,6 +250,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $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; } @@ -188,6 +268,11 @@ public function jsonSerialize(): \stdClass $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; diff --git a/src/Values.php b/src/Values.php index 3d2b60fb..0662ba12 100644 --- a/src/Values.php +++ b/src/Values.php @@ -20,10 +20,32 @@ limitations under the License. */ -class Values implements \ArrayAccess, \Countable, \JsonSerializable +/** + * @implements \IteratorAggregate> + * @implements \ArrayAccess> + */ +class Values implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable { + /** @var array> */ private array $values = []; + /** + * @param array> $values + * @return self + */ + public static function fromArray(array $values): self + { + $out = new self(); + foreach ($values as $hdr => $vals) { + if (is_array($vals)) { + $out->add($hdr, ...$vals); + } else { + $out->add($hdr, $vals); + } + } + return $out; + } + public function get(string $key): string { if (isset($this->values[$key])) { @@ -33,6 +55,10 @@ public function get(string $key): string return ''; } + /** + * @param string $key + * @return array + */ public function getAll(string $key): array { if (isset($this->values[$key])) { @@ -66,12 +92,18 @@ public function count(): int return count($this->values); } + /** + * @return array> + */ public function toPsr7Array(): array { return $this->values; } - public function getIterator(): iterable + /** + * @return \Traversable> + */ + public function getIterator(): \Traversable { if ([] === $this->values) { return new \EmptyIterator(); @@ -79,19 +111,33 @@ public function getIterator(): iterable return new \ArrayIterator($this->values); } + public function offsetExists(mixed $offset): bool { return array_key_exists($offset, $this->values); } - public function offsetGet(mixed $offset): string + /** + * @param mixed $offset + * @return array + */ + public function offsetGet(mixed $offset): array { - return $this->get($offset); + return $this->values[$offset] ?? []; } + /** + * @param string $offset + * @param array $value + * @return void + */ public function offsetSet(mixed $offset, mixed $value): void { - $this->set($offset, $value); + if (is_array($value)) { + $this->set($offset, ...$value); + } else { + $this->set($offset, $value); + } } public function offsetUnset(mixed $offset): void @@ -99,6 +145,9 @@ public function offsetUnset(mixed $offset): void $this->delete($offset); } + /** + * @return array> + */ public function jsonSerialize(): array { return $this->values; From 96d263cb37d3247dfefa436083b690bf4351e0b0 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 16:19:55 -0500 Subject: [PATCH 69/79] hated the stdClass crap i was doing --- src/ConfigEntry/HTTPHeaderModifiers.php | 82 +++++++++++++++---------- src/ConfigEntry/ProxyConfigEntry.php | 40 ++++++++---- src/ConfigEntry/ServiceConfigEntry.php | 47 +++++++------- src/MetaContainer.php | 21 +++++-- src/funcs.php | 10 ++- 5 files changed, 125 insertions(+), 75 deletions(-) diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php index b0b7aed9..6bd361cf 100644 --- a/src/ConfigEntry/HTTPHeaderModifiers.php +++ b/src/ConfigEntry/HTTPHeaderModifiers.php @@ -22,62 +22,72 @@ use DCarbone\PHPConsulAPI\AbstractModel; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; - class HTTPHeaderModifiers extends AbstractModel { - public \stdClass $Add; - public \stdClass $Set; + /** @var array */ + public array $Add; + /** @var array */ + public array $Set; /** @var array */ public array $Remove; /** + * @param array $Add + * @param array $Set * @param array $Remove */ public function __construct( - null|\stdClass $Add = null, - null|\stdClass $Set = null, + null|array|\stdClass $Add = null, + null|array|\stdClass $Set = null, array $Remove = [] ) { - $this->Add = $Add ?? new \stdClass(); - $this->Set = $Set ?? new \stdClass(); + $this->setAdd($Add); + $this->setSet($Set); $this->setRemove(...$Remove); } - public function getAdd(): \stdClass + /** + * @return array + */ + public function getAdd(): array { return $this->Add; } - public function setAddKey(string $key, string $value): self - { - $this->Add->{$key} = $value; - return $this; - } - - public function setAdd(\stdClass $Add): self + /** + * @param null|\stdClass|array $Add + * @return $this + */ + public function setAdd(null|\stdClass|array $Add): self { - foreach ($Add as $k => $v) { - $this->setaddKey($k, $v); + $this->Add = []; + if (null !== $Add) { + foreach ($Add as $k => $v) { + $this->Add[$k] = $v; + } } return $this; } - public function getSet(): \stdClass + /** + * @return array + */ + public function getSet(): array { return $this->Set; } - public function setSetKey(string $key, string $value): self - { - $this->Set->{$key} = $value; - return $this; - } - - public function setSet(\stdClass $Set): self + /** + * @param null|\stdClass|array $Set + * @return $this + */ + public function setSet(null|\stdClass|array $Set): self { - foreach ($Set as $k => $v) { - $this->setSetKey($k, $v); + $this->Set = []; + if (null !== $Set) { + foreach ($Set as $k => $v) { + $this->Set[$k] = $v; + } } return $this; } @@ -100,7 +110,13 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Set' === $k) { + $n->setSet($v); + } elseif ('Add' === $k) { + $n->setAdd($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -108,8 +124,12 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { $out = $this->_startJsonSerialize(); - _enc_obj_if_valued($out, 'Add', $this->Add); - _enc_obj_if_valued($out, 'Set', $this->Set); + if ([] !== $this->Add) { + $out->Add = $this->Add; + } + if ([] !== $this->Set) { + $out->Set = $this->Set; + } if ([] !== $this->Remove) { $out->Remove = $this->Remove; } diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index 3c89933c..7b45a48b 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -34,7 +34,8 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry public null|ProxyMode $Mode; public null|TransparentProxyConfig $TransparentProxy; public MutualTLSMode $MutualTLSMode; - public null|\stdClass $Config; + /** @var array */ + public array $Config; public MeshGatewayConfig $MeshGateway; public ExposeConfig $Expose; @@ -45,17 +46,18 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; /** + * @param null|\stdClass|array $Config * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions + * @param null|\stdClass|array $Meta */ public function __construct( - array|null $data = null, // Deprecated, will be removed. string $Kind = '', string $Name = '', string $Partition = '', string|ProxyMode $Mode = ProxyMode::Default, null|TransparentProxyConfig $TransparentProxy = null, string|MutualTLSMode $MutualTLSMode = MutualTLSMode::Default, - null|\stdClass $Config = null, + null|\stdClass|array $Config = null, null|MeshGatewayConfig $MeshGateway = null, null|ExposeConfig $Expose = null, null|AccessLogsConfig $AccessLogs = null, @@ -63,7 +65,7 @@ public function __construct( null|ServiceResolverFailoverPolicy $FailoverPolicy = null, null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null, string $Namespace = '', - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -75,14 +77,14 @@ public function __construct( $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode); $this->TransparentProxy = $TransparentProxy; $this->MutualTLSMode = $MutualTLSMode instanceof MutualTLSMode ? $MutualTLSMode : MutualTLSMode::from($MutualTLSMode); - $this->Config = $Config; + $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->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; } @@ -154,14 +156,26 @@ public function setMutualTLSMode(MutualTLSMode $MutualTLSMode): self return $this; } - public function getConfig(): null|\stdClass + /** + * @return array + */ + public function getConfig(): array { return $this->Config; } - public function setConfig(null|\stdClass $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; } @@ -261,6 +275,10 @@ public static function jsonUnserialize(\stdClass $decoded): self $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; } @@ -285,7 +303,7 @@ public function jsonSerialize(): \stdClass if (MutualTLSMode::Default !== $this->MutualTLSMode) { $out->MutualTLSMode = $this->MutualTLSMode->value; } - if (null !== $this->Config) { + if ([] !== $this->Config) { $out->Config = $this->Config; } _enc_obj_if_valued($out, 'MeshGateway', $this->MeshGateway); @@ -304,7 +322,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Namespace) { $out->Namespace = $this->Namespace; } - if (null !== $this->Meta) { + if ([] !== $this->Meta) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index 8cdb0051..e0f41c0e 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -51,30 +51,31 @@ class ServiceConfigEntry extends AbstractModel implements ConfigEntry /** * @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, + 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 = [], - null|\stdClass $Meta = null, - int $CreateIndex = 0, - int $ModifyIndex = 0, + 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 = [], + null|\stdClass|array $Meta = null, + int $CreateIndex = 0, + int $ModifyIndex = 0, ) { $this->Kind = $Kind; $this->Name = $Name; @@ -95,10 +96,10 @@ public function __construct( $this->BalanceInboundConnections = $BalanceInboundConnections; $this->RateLimits = $RateLimits; $this->setEnvoyExtensions(...$EnvoyExtensions); - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; -} + } public function getKind(): string { @@ -394,7 +395,7 @@ public function jsonSerialize(): \stdClass if ([] !== $this->EnvoyExtensions) { $out->EnvoyExtensions = $this->EnvoyExtensions; } - if (null !== $this->Meta) { + if ([] !== $this->Meta) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/MetaContainer.php b/src/MetaContainer.php index fd2cc972..22695b66 100644 --- a/src/MetaContainer.php +++ b/src/MetaContainer.php @@ -22,16 +22,29 @@ trait MetaContainer { - public null|\stdClass $Meta; + /** @var array */ + public array $Meta; - public function getMeta(): null|\stdClass + /** + * @return array + */ + public function getMeta(): array { return $this->Meta; } - public function setMeta(null|\stdClass $Meta): self + /** + * @param null|\stdClass|array $Meta + * @return self + */ + public function setMeta(null|\stdClass|array $Meta): self { - $this->Meta = $Meta; + $this->Meta = []; + if (null !== $Meta) { + foreach ($Meta as $k => $v) { + $this->Meta[$k] = $v; + } + } return $this; } } \ No newline at end of file diff --git a/src/funcs.php b/src/funcs.php index ad8a1bb0..f952131e 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -36,13 +36,11 @@ function dur_to_millisecond(Time\Duration $dur): string $_zeroObject = new \stdclass(); -function _enc_obj_if_valued(\stdClass &$out, string $field, \stdClass | \JsonSerializable $obj): void +function _enc_obj_if_valued(\stdClass &$out, string $field, \JsonSerializable $obj): void { global $_zeroObject; - if ($obj instanceof \JsonSerializable) { - $obj = $obj->jsonSerialize(); - } - if ($obj != $_zeroObject) { - $out->{$field} = $obj; + $val = $obj->jsonSerialize(); + if ($val != $_zeroObject) { + $out->{$field} = $val; } } From daaa36f4b21ea14b7a35474dab3da6519ea11cdd Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 16:29:26 -0500 Subject: [PATCH 70/79] blech --- .../ServiceResolverConfigEntry.php | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index f4676113..e031b0cc 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -34,28 +34,35 @@ class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry public string $Name; public string $Partition; public string $DefaultSubset; - public null|\stdClass $Subsets; + /** @var array */ + public array $Subsets; public null|ServiceResolverRedirect $Redirect; - public null|\stdClass $Failover; + /** @var array */ + public array $Failover; public Time\Duration $ConnectTimeout; public Time\Duration $RequestTimeout; public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; public null|LoadBalancer $LoadBalancer; + /** + * @param null|\stdClass|array $Subsets + * @param null|\stdClass|array $Failover + * @param null|\stdClass|array $Meta + */ public function __construct( string $Kind = '', string $Name = '', string $Partition = '', string $Namespace = '', string $DefaultSubnet = '', - null|\stdClass $Subsets = null, + null|\stdClass|array $Subsets = null, null|ServiceResolverRedirect $Redirect = null, - null|\stdClass $Failover = null, + null|\stdClass|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|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -71,7 +78,7 @@ public function __construct( $this->RequestTimeout = Time::Duration($RequestTimeout); $this->PrioritizeByLocality = $PrioritizeByLocality; $this->LoadBalancer = $LoadBalancer; - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; } @@ -121,25 +128,31 @@ public function setDefaultSubset(string $DefaultSubset): self return $this; } - public function getSubsets(): null|\stdClass + /** + * @return array + */ + public function getSubsets(): array { return $this->Subsets; } public function setSubsetKey(string $key, ServiceResolverSubset $subset): self { - if (!isset($this->Subsets)) { - $this->Subsets = new \stdClass(); - } - $this->Subsets->{$key} = $subset; + $this->Subsets[$key] = $subset; return $this; } - public function setSubsets(\stdClass $subsets): self + /** + * @param null|\stdClass|array $Subsets + * @return $this + */ + public function setSubsets(null|\stdClass|array $Subsets): self { - unset($this->Subsets); - foreach ($subsets as $k => $v) { - $this->setSubsetKey($k, $v); + $this->Subsets = []; + if (null !== $Subsets) { + foreach ($Subsets as $k => $v) { + $this->setSubsetKey($k, $v); + } } return $this; } @@ -155,25 +168,31 @@ public function setRedirect(null|ServiceResolverRedirect $Redirect): self return $this; } - public function getFailover(): null|\stdClass + /** + * @return array + */ + public function getFailover(): array { return $this->Failover; } public function setFailoverKey(string $key, ServiceResolverFailover $failover): self { - if (!isset($this->Failover)) { - $this->Failover = new \stdClass(); - } - $this->Failover->{$key} = $failover; + $this->Failover[$key] = $failover; return $this; } - public function setFailover(\stdClass $failover): self + /** + * @param null|\stdClass|array $Failover + * @return $this + */ + public function setFailover(null|\stdClass|array $Failover): self { - unset($this->Failover); - foreach ($failover as $k => $v) { - $this->setFailoverKey($k, $v); + $this->Failover = []; + if (null !== $Failover) { + foreach ($Failover as $k => $v) { + $this->setFailoverKey($k, $v); + } } return $this; } @@ -246,6 +265,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $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; } @@ -270,11 +291,15 @@ public function jsonSerialize(): \stdClass if ('' !== $this->DefaultSubset) { $out->DefaultSubset = $this->DefaultSubset; } - _enc_obj_if_valued($out, 'Subsets', $this->Subsets); + if ([] !== $this->Subsets) { + $out->Subsets = $this->Subsets; + } if (null !== $this->Redirect) { $out->Redirect = $this->Redirect; } - _enc_obj_if_valued($out, 'Failover', $this->Failover); + if ([] !== $this->Failover) { + $out->Failover = $this->Failover; + } if (0 !== $this->ConnectTimeout->Nanoseconds()) { $out->ConnectTimeout = (string)$this->ConnectTimeout; } @@ -287,7 +312,7 @@ public function jsonSerialize(): \stdClass if (null !== $this->LoadBalancer) { $out->LoadBalancer = $this->LoadBalancer; } - if (null !== $this->Meta) { + if ([] !== $this->Meta) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; From e16fcf2b4ea1825c83e5d1ec080eb6ce5f06f0ee Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 16:42:17 -0500 Subject: [PATCH 71/79] more less. --- src/ACL/ACLAuthMethod.php | 28 ++++++++++++++++----- src/Agent/AgentClient.php | 2 +- src/QueryOptions.php | 53 ++++++++++++++++----------------------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 320b9120..463efcd3 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -31,7 +31,8 @@ class ACLAuthMethod extends AbstractModel public string $Description; public Time\Duration $MaxTokenTTL; public string $TokenLocality; - public null|\stdClass $Config; + /** @var array */ + public array $Config; public int $CreateIndex; public int $ModifyIndex; /** @var \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule[] */ @@ -40,6 +41,7 @@ class ACLAuthMethod extends AbstractModel public string $Partition; /** + * @param null|\stdClass|array $Config * @param array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules */ public function __construct( @@ -49,7 +51,7 @@ public function __construct( string $Description = '', null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null, string $TokenLocality = '', - null|\stdClass $Config = null, + null|\stdClass|array $Config = null, int $CreateIndex = 0, int $ModifyIndex = 0, array $NamespaceRules = [], @@ -62,7 +64,7 @@ public function __construct( $this->Description = $Description; $this->MaxTokenTTL = Time::Duration($MaxTokenTTL); $this->TokenLocality = $TokenLocality; - $this->Config = $Config; + $this->setConfig($Config); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->setNamespaceRules(...$NamespaceRules); @@ -136,14 +138,26 @@ public function setTokenLocality(string $TokenLocality): self return $this; } - public function getConfig(): null|\stdClass + /** + * @return array + */ + public function getConfig(): array { return $this->Config; } - public function setConfig(null|\stdClass $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; } @@ -222,6 +236,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $vv) { $n->NamespaceRules[] = ACLAuthMethodNamespaceRule::jsonUnserialize($vv); } + } elseif ('Config' === $k) { + $n->setConfig($v); } else { $n->{$k} = $v; } diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index 2bc90f40..b7a520fa 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -255,7 +255,7 @@ public function UpdateTTL(string $checkID, string $output, string $status): null 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; diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 2e2b0a6e..62576cb0 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -37,7 +37,8 @@ class QueryOptions implements RequestOptions public string $Token; public string $Near; public string $Filter; - public null|\stdClass $NodeMeta; + /** @var array */ + public array $NodeMeta; public int $RelayFactor; public bool $LocalOnly; public bool $Connect; @@ -47,7 +48,7 @@ class QueryOptions implements RequestOptions public bool $Pretty; /** - * @param array|null $data + * @param null|\stdClass|array $NodeMeta */ public function __construct( string $Namespace = '', @@ -63,7 +64,7 @@ public function __construct( string $Token = '', string $Near = '', string $Filter = '', - null|\stdClass $NodeMeta = null, + null|\stdClass|array $NodeMeta = null, int $RelayFactor = 0, bool $LocalOnly = false, bool $Connect = false, @@ -83,15 +84,12 @@ public function __construct( $this->Token = $Token; $this->Near = $Near; $this->Filter = $Filter; - $this->NodeMeta = $NodeMeta; + $this->setNodeMeta($NodeMeta); $this->RelayFactor = $RelayFactor; $this->LocalOnly = $LocalOnly; $this->Connect = $Connect; $this->Timeout = Time::Duration($Timeout); $this->Pretty = $Pretty; - if (null !== $data && [] !== $data) { - $this->_fromMap((object)$data); - } } public function getNamespace(): string @@ -224,14 +222,26 @@ public function setFilter(string $filter): void $this->Filter = $filter; } - public function getNodeMeta(): null|\stdClass + /** + * @return array + */ + public function getNodeMeta(): array { return $this->NodeMeta; } - public function setNodeMeta(null|\stdClass $nodeMeta): void + /** + * @param null|\stdClass|array $nodeMeta + * @return void + */ + public function setNodeMeta(null|\stdClass|array $nodeMeta): void { - $this->NodeMeta = $nodeMeta; + $this->NodeMeta = []; + if (null !== $nodeMeta) { + foreach ($nodeMeta as $k => $v) { + $this->NodeMeta[$k] = $v; + } + } } public function getRelayFactor(): int @@ -316,7 +326,7 @@ public function apply(Request $r): void if ('' !== $this->Filter) { $r->params->set('filter', $this->Filter); } - if (null !== $this->NodeMeta) { + if ([] !== $this->NodeMeta) { foreach ($this->NodeMeta as $k => $v) { $r->params->add('node-meta', "{$k}:{$v}"); } @@ -354,25 +364,4 @@ public function apply(Request $r): void $r->params->set('pretty', ''); } } - - /** - * @param \stdClass $data - * @deprecated This is only here to support construction with map. It will be removed in a future version. - */ - private function _fromMap(\stdClass $data): void - { - foreach ($data as $k => $v) { - if ('MaxAge' === $k) { - $this->MaxAge = Time::Duration($v); - } elseif ('StaleIfError' === $k) { - $this->StaleIfError = Time::Duration($v); - } elseif ('WaitTime' === $k) { - $this->WaitTime = Time::Duration($v); - } elseif ('Timeout' === $k) { - $this->Timeout = Time::Duration($v); - } else { - $this->{$k} = $v; - } - } - } } From c505599c55fd91923ea518c7a002d7778c4c9824 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 20:41:35 -0500 Subject: [PATCH 72/79] smidge more work --- src/ACL/ACLLoginParams.php | 15 ++++-- src/ACL/ACLOIDCAuthURLParams.php | 15 ++++-- src/Agent/AgentMember.php | 33 ++++++------ src/Agent/AgentService.php | 37 +++++++++----- src/Agent/AgentServiceCheck.php | 53 +++++++++++++------- src/Agent/AgentServiceConnectProxyConfig.php | 53 +++++++++++--------- src/Agent/AgentServiceRegistration.php | 38 +++++++++----- src/ConfigEntry/ConfigEntry.php | 5 +- src/MapResponse.php | 26 ++++++++-- src/MetaContainer.php | 22 ++++---- 10 files changed, 189 insertions(+), 108 deletions(-) diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index c6044895..f562f78c 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -30,14 +30,17 @@ class ACLLoginParams extends AbstractModel public string $AuthMethod; public string $BearerToken; + /** + * @param \stdClass|array|null $Meta + */ public function __construct( string $AuthMethod = '', string $BearerToken = '', - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, ) { $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; - $this->Meta = $Meta; + $this->setMeta($Meta); } public function getAuthMethod(): string @@ -66,7 +69,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Meta' === $k) { + $n->setMeta($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -76,7 +83,7 @@ public function jsonSerialize(): \stdClass $out = $this->_startJsonSerialize(); $out->AuthMethod = $this->AuthMethod; $out->BearerToken = $this->BearerToken; - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } return $out; diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 3a572767..87be39c3 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -31,16 +31,19 @@ class ACLOIDCAuthURLParams extends AbstractModel public string $RedirectURI; public string $ClientNonce; + /** + * @param \stdClass|array|null $Meta + */ public function __construct( string $AuthMethod = '', string $RedirectURI = '', string $ClientNonce = '', - null|\stdClass $Meta = null + null|\stdClass|array $Meta = null ) { $this->AuthMethod = $AuthMethod; $this->RedirectURI = $RedirectURI; $this->ClientNonce = $ClientNonce; - $this->Meta = $Meta; + $this->setMeta($Meta); } public function getAuthMethod(): string @@ -80,7 +83,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Meta' === $k) { + $n->setMeta($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -91,7 +98,7 @@ public function jsonSerialize(): \stdClass $out->AuthMethod = $this->AuthMethod; $out->RedirectURI = $this->RedirectURI; $out->ClientNonce = $this->ClientNonce; - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } return $out; diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 673ce736..64fdba3f 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -28,7 +28,8 @@ class AgentMember extends AbstractModel public string $Name; public string $Addr; public int $Port; - public null|\stdClass $Tags; + /** @var array */ + public array $Tags; /** * Status of the Member which corresponds to github.com/hashicorp/serf/serf.MemberStatus * Value is one of: @@ -48,23 +49,13 @@ class AgentMember extends AbstractModel public int $DelegateCur; /** - * @param string $Name - * @param string $Addr - * @param int $Port - * @param \stdClass|null $Tags - * @param int $Status - * @param int $ProtocolMin - * @param int $ProtocolMax - * @param int $ProtocolCur - * @param int $DelegateMin - * @param int $DelegateMax - * @param int $DelegateCur + * @param null|\stdClass|array $Tags */ public function __construct( string $Name = '', string $Addr = '', int $Port = 0, - null|\stdClass $Tags = null, + null|\stdClass|array $Tags = null, int $Status = 0, int $ProtocolMin = 0, int $ProtocolMax = 0, @@ -76,7 +67,12 @@ public function __construct( $this->Name = $Name; $this->Addr = $Addr; $this->Port = $Port; - $this->Tags = $Tags; + $this->Tags = []; + if (null !== $Tags) { + foreach ($Tags as $k => $v) { + $this->Tags[$k] = $v; + } + } $this->Status = $Status; $this->ProtocolMin = $ProtocolMin; $this->ProtocolMax = $ProtocolMax; @@ -84,7 +80,7 @@ public function __construct( $this->DelegateMin = $DelegateMin; $this->DelegateMax = $DelegateMax; $this->DelegateCur = $DelegateCur; -} + } public function getName(): string { @@ -156,6 +152,13 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { + if ('Tags' === $k) { + if (null !== $v) { + foreach ($v as $k => $vv) { + $n->Tags[$k] = $vv; + } + } + } $n->{$k} = $v; } return $n; diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 20104613..06d78cb7 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -21,7 +21,6 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Catalog\ServiceAddress; use DCarbone\PHPConsulAPI\MetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; @@ -37,7 +36,8 @@ class AgentService extends AbstractModel public int $Port; public string $Address; public string $SocketPath; - public null|\stdClass $TaggedAddresses; + /** @var array */ + public null|array $TaggedAddresses; public AgentWeights $Weights; public bool $EnableTagOverride; public int $CreateIndex; @@ -53,6 +53,8 @@ class AgentService extends AbstractModel /** * @param array $Tags + * @param null|\stdClass|array $Meta + * @param null|\stdClass|array $TaggedAddresses */ public function __construct( string|ServiceKind $Kind = '', @@ -60,10 +62,10 @@ public function __construct( string $Service = '', string $SocketPath = '', array $Tags = [], - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $Port = 0, string $Address = '', - null|\stdClass $TaggedAddresses = null, + null|\stdClass|array $TaggedAddresses = null, null|AgentWeights $Weights = null, bool $EnableTagOverride = false, int $CreateIndex = 0, @@ -80,7 +82,7 @@ public function __construct( $this->Kind = is_string($Kind) ? ServiceKind::from($Kind) : $Kind; $this->ID = $ID; $this->Service = $Service; - $this->Meta = $Meta; + $this->setMeta($Meta); $this->Port = $Port; $this->setTags(...$Tags); $this->Address = $Address; @@ -98,7 +100,7 @@ public function __construct( $this->Partition = $Partition; $this->Datacenter = $Datacenter; $this->Locality = $Locality; -} + } public function getKind(): ServiceKind { @@ -169,20 +171,27 @@ public function setAddress(string $Address): self return $this; } - public function getTaggedAddresses(): null|\stdClass + /** + * @return null|array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress> + */ + public function getTaggedAddresses(): null|array { return $this->TaggedAddresses; } - public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self + /** + * @param null|\stdClass|array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress> $TaggedAddresses + * @return $this + */ + public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self { if (null === $TaggedAddresses) { $this->TaggedAddresses = null; return $this; } - $this->TaggedAddresses = new \stdClass(); - foreacH($TaggedAddresses as $k => $v) { - $this->TaggedAddresses->{$k} = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize($v); + $this->TaggedAddresses = []; + foreach ($TaggedAddresses as $k => $v) { + $this->TaggedAddresses[] = $v; } return $this; } @@ -332,11 +341,13 @@ public static function jsonUnserialize(\stdClass $decoded): self } elseif ('Weights' === $k) { $n->Weights = AgentWeights::jsonUnserialize($v); } elseif ('TaggedAddresses' === $k) { - $n->settaggedAddresses($v); + $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; } @@ -353,7 +364,7 @@ public function jsonSerialize(): \stdClass $out->ID = $this->ID; $out->Service = $this->Service; $out->Tags = $this->Tags; - $out->Meta = $this->Meta; + $out->Meta = $this->getMeta(); $out->Port = $this->Port; $out->Address = $this->Address; if ('' !== $this->SocketPath) { diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 6d9c55dd..5a75a08e 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -21,6 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\Values; class AgentServiceCheck extends AbstractModel { @@ -34,7 +35,7 @@ class AgentServiceCheck extends AbstractModel public string $Timeout; public string $TTL; public string $HTTP; - public null|\stdClass $Header; + public Values $Header; public string $Method; public string $TCP; public string $Status; @@ -52,21 +53,22 @@ class AgentServiceCheck extends AbstractModel /** * @param array $Args + * @param null|\stdClass|array>|\DCarbone\PHPConsulAPI\Values $Header */ public function __construct( - string $CheckID = '', - string $Name = '', - array $Args = [], - string $DockerContainerID = '', - string $Shell = '', - string $Interval = '', - string $Timeout = '', - string $TTL = '', - string $HTTP = '', - null|\stdClass $Header = null, - string $Method = '', - string $TCP = '', - string $Status = '', + string $CheckID = '', + string $Name = '', + array $Args = [], + string $DockerContainerID = '', + string $Shell = '', + string $Interval = '', + string $Timeout = '', + string $TTL = '', + string $HTTP = '', + null|array|\stdClass|Values $Header = null, + string $Method = '', + string $TCP = '', + string $Status = '', string $Notes = '', bool $TLSSkipVerify = false, string $GRPC = '', @@ -89,7 +91,7 @@ public function __construct( $this->Timeout = $Timeout; $this->TTL = $TTL; $this->HTTP = $HTTP; - $this->Header = $Header; + $this->setHeader($Header); $this->Method = $Method; $this->TCP = $TCP; $this->Status = $Status; @@ -208,13 +210,24 @@ public function setHTTP(string $http): self return $this; } - public function getHeader(): null|\stdClass + public function getHeader(): null|Values { - return $this->Header; + return $this->Header ?? null; } - public function setHeader(null|\stdClass $Header): self + /** + * @param \stdClass|array>|\DCarbone\PHPConsulAPI\Values|null $Header + * @return $this + */ + public function setHeader(null|\stdClass|array|Values $Header): self { + if (null === $Header) { + unset($this->Header); + return $this; + } + if (!$Header instanceof Values) { + $Header = Values::fromArray((array)$Header); + } $this->Header = $Header; return $this; } @@ -379,6 +392,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($decoded as $k => $v) { if ('ScriptArgs' === $k) { $n->Args = $v; + } elseif ('Header' === $k) { + $n->setHeader($v); } else { $n->{$k} = $v; } @@ -416,7 +431,7 @@ public function jsonSerialize(): \stdClass if ('' !== $this->HTTP) { $out->HTTP = $this->HTTP; } - if (null !== $this->Header) { + if (isset($this->Header)) { $out->Header = $this->Header; } if ('' !== $this->Method) { diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 9477f6c3..e7258dce 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -30,7 +30,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel { - /** @var \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[] */ + /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */ public array $EnvoyExtensions; public string $DestinationServiceName; public string $DestinationServiceID; @@ -39,7 +39,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel public string $LocalServiceSocketPath; public ProxyMode $Mode; public null|TransparentProxyConfig $TransparentProxy; - public null|\stdClass $Config; + public array $Config; /** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */ public array $Upstreams; public null|MeshGatewayConfig $MeshGateway; @@ -47,22 +47,11 @@ class AgentServiceConnectProxyConfig extends AbstractModel public null|AccessLogsConfig $AccessLogs; /** - * @param iterable<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions - * @param string $DestinationServiceName - * @param string $DestinationServiceID - * @param string $LocalServiceAddress - * @param int $LocalServicePort - * @param string $LocalServiceSocketPath - * @param string|\DCarbone\PHPConsulAPI\ConfigEntry\ProxyMode $Mode - * @param \DCarbone\PHPConsulAPI\ConfigEntry\TransparentProxyConfig|null $TransparentProxy - * @param null|\stdClass $Config - * @param iterable<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams - * @param \DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig|null $MeshGateway - * @param \DCarbone\PHPConsulAPI\ConfigEntry\ExposeConfig|null $Expose - * @param \DCarbone\PHPConsulAPI\ConfigEntry\AccessLogsConfig|null $AccessLogs + * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions + * @param null|\stdClass|array $Config + * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams */ public function __construct( - null|array $data = [], // Deprecated, will be removed. iterable $EnvoyExtensions = [], string $DestinationServiceName = '', string $DestinationServiceID = '', @@ -71,7 +60,7 @@ public function __construct( string $LocalServiceSocketPath = '', string|ProxyMode $Mode = ProxyMode::Default, null|TransparentProxyConfig $TransparentProxy = null, - null|\stdClass $Config = null, + null|\stdClass|array $Config = null, iterable $Upstreams = [], null|MeshGatewayConfig $MeshGateway = null, null|ExposeConfig $Expose = null, @@ -82,7 +71,7 @@ public function __construct( $this->DestinationServiceID = $DestinationServiceID; $this->LocalServiceAddress = $LocalServiceAddress; $this->LocalServicePort = $LocalServicePort; - $this->Config = $Config; + $this->setConfig($Config); $this->LocalServiceSocketPath = $LocalServiceSocketPath; $this->Mode = $Mode instanceof ProxyMode ? $Mode : ProxyMode::from($Mode); $this->TransparentProxy = $TransparentProxy; @@ -90,7 +79,7 @@ public function __construct( $this->MeshGateway = $MeshGateway; $this->Expose = $Expose; $this->AccessLogs = $AccessLogs; -} + } /** * @return \DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension[] @@ -189,14 +178,28 @@ public function setTransparentProxy(null|TransparentProxyConfig $TransparentProx return $this; } - public function getConfig(): null|\stdClass + /** + * @return array|null + */ + public function getConfig(): null|array { - return $this->Config; + return $this->Config ?? null; } - public function setConfig(null|\stdClass $Config): self + /** + * @param \stdClass|array|null $Config + * @return $this + */ + public function setConfig(null|\stdClass|array $Config): self { - $this->Config = $Config; + if (null === $Config) { + unset($this->Config); + return $this; + } + $this->Config = []; + foreach ($Config as $k => $v) { + $this->Config[$k] = $v; + } return $this; } @@ -269,6 +272,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $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; } @@ -294,7 +299,7 @@ public function jsonSerialize(): \stdClass if (0 !== $this->LocalServicePort) { $out->LocalServicePort = $this->LocalServicePort; } - if (null !== $this->Config) { + if (isset($this->Config)) { $out->Config = $this->Config; } if ('' !== $this->LocalServiceSocketPath) { diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index d4a6f128..cdd404aa 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -36,7 +36,8 @@ class AgentServiceRegistration extends AbstractModel public array $Tags; public int $Port; public string $Address; - public null|\stdClass $TaggedAddresses; + /** @var array<\DCarbone\PHPConsulAPI\Catalog\ServiceAddress> */ + public array $TaggedAddresses; public bool $EnableTagOverride; public null|AgentWeights $Weights; public null|AgentServiceCheck $Check; @@ -49,6 +50,8 @@ class AgentServiceRegistration extends AbstractModel /** * @param array $Tags + * @param null|\stdClass|array $TaggedAddresses + * @param null|\stdClass|array $Meta */ public function __construct( string|ServiceKind $Kind = ServiceKind::Typical, @@ -57,9 +60,9 @@ public function __construct( array $Tags = [], int $Port = 0, string $Address = '', - null|\stdClass $TaggedAddresses = null, + null|\stdClass|array $TaggedAddresses = null, bool $EnableTagOverride = false, - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, null|AgentWeights $Weights = null, null|AgentServiceCheck $Check = null, null|AgentServiceChecks $Checks = null, @@ -77,7 +80,7 @@ public function __construct( $this->Address = $Address; $this->setTaggedAddresses($TaggedAddresses); $this->EnableTagOverride = $EnableTagOverride; - $this->Meta = $Meta; + $this->setMeta($Meta); $this->Weights = $Weights; $this->Check = $Check; $this->Checks = $Checks ?? new AgentServiceChecks(); @@ -86,7 +89,7 @@ public function __construct( $this->Namespace = $Namespace; $this->Partition = $Partition; $this->Locality = $Locality; -} + } public function getKind(): ServiceKind { @@ -157,20 +160,27 @@ public function setAddress(string $Address): self return $this; } - public function getTaggedAddresses(): \stdClass + /** + * @return array|null + */ + public function getTaggedAddresses(): null|array { - return $this->TaggedAddresses; + return $this->TaggedAddresses ?? null; } - public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self + /** + * @param \stdClass|array|null $TaggedAddresses + * @return $this + */ + public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self { if (null === $TaggedAddresses) { - $this->TaggedAddresses = null; + unset($this->TaggedAddresses); return $this; } - $this->TaggedAddresses = new \stdClass(); + $this->TaggedAddresses = []; foreach ($TaggedAddresses as $k => $v) { - $this->TaggedAddresses->{$k} = $v instanceof ServiceAddress ? $v : ServiceAddress::jsonUnserialize((object)$v); + $this->TaggedAddresses[$k] = $v; } return $this; } @@ -296,6 +306,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $n->Connect = AgentServiceConnect::jsonUnserialize($v); } elseif ('Locality' === $k) { $n->Locality = Locality::jsonUnserialize($v); + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -324,13 +336,13 @@ public function jsonSerialize(): \stdClass if ('' !== $this->Address) { $out->Address = $this->Address; } - if (null !== $this->TaggedAddresses) { + if (isset($this->TaggedAddresses)) { $out->TaggedAddresses = $this->TaggedAddresses; } if ($this->EnableTagOverride) { $out->EnableTagOverride = $this->EnableTagOverride; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } if (null !== $this->Weights) { diff --git a/src/ConfigEntry/ConfigEntry.php b/src/ConfigEntry/ConfigEntry.php index a8332bea..e90438a5 100644 --- a/src/ConfigEntry/ConfigEntry.php +++ b/src/ConfigEntry/ConfigEntry.php @@ -34,7 +34,10 @@ public function GetName(): string; public function GetNamespace(): string; - public function GetMeta(): \stdClass; + /** + * @return array|null + */ + public function GetMeta(): null|array; public function GetCreateIndex(): int; diff --git a/src/MapResponse.php b/src/MapResponse.php index 4425a4f1..02c4cbd3 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -20,17 +20,33 @@ limitations under the License. */ +/** + * @template T + */ class MapResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|\stdClass $Map = null; - - public function getValue(): null|\stdClass + /** + * @var array|null + */ + public null|array $Map; + + /** + * @return array|null + */ + public function getValue(): null|array { - return $this->Map; + return $this->Map ?? null; } public function unmarshalValue(mixed $decoded): void { - $this->Map = $decoded; + if (null === $decoded) { + unset($this->Map); + return; + } + $this->Map = []; + foreach ($decoded as $k => $v) { + $this->Map[$k] = $v; + } } } diff --git a/src/MetaContainer.php b/src/MetaContainer.php index 22695b66..c00214ff 100644 --- a/src/MetaContainer.php +++ b/src/MetaContainer.php @@ -22,29 +22,31 @@ trait MetaContainer { - /** @var array */ + /** @var array */ public array $Meta; /** - * @return array + * @return array|null */ - public function getMeta(): array + public function getMeta(): null|array { - return $this->Meta; + return $this->Meta ?? null; } /** - * @param null|\stdClass|array $Meta + * @param null|\stdClass|array $Meta * @return self */ public function setMeta(null|\stdClass|array $Meta): self { + if (null === $Meta) { + unset($this->Meta); + return $this; + } $this->Meta = []; - if (null !== $Meta) { - foreach ($Meta as $k => $v) { - $this->Meta[$k] = $v; - } + foreach ($Meta as $k => $v) { + $this->Meta[$k] = $v; } return $this; } -} \ No newline at end of file +} From 0bc0cf0f6182fd141df461cedd574e06b91780f2 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 21:48:41 -0500 Subject: [PATCH 73/79] mo stuff --- src/Catalog/Node.php | 45 +++-- src/ConfigEntry/IngressGatewayConfigEntry.php | 11 +- src/ConfigEntry/MeshConfigEntry.php | 13 +- .../ServiceIntentionsConfigEntry.php | 9 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 9 +- .../ServiceSplitterConfigEntry.php | 9 +- .../TerminatingGatewayConfigEntry.php | 9 +- src/Operator/Area.php | 8 +- src/Operator/AreaJoinResponse.php | 6 +- src/Operator/AutopilotConfiguration.php | 20 +- src/Operator/AutopilotServer.php | 179 +++++++++++------- src/Operator/AutopilotServerStatus.php | 2 + src/Operator/AutopilotServerType.php | 2 + src/Operator/AutopilotState.php | 18 +- src/Operator/AutopilotStateResponse.php | 2 +- src/Operator/AutopilotUpgrade.php | 18 +- src/Operator/AutopilotZone.php | 6 +- src/Operator/AutopilotZoneUpgradeVersions.php | 8 +- src/Operator/OperatorAreaJoinResponse.php | 2 +- src/Operator/OperatorAreasResponse.php | 2 +- ...OperatorAutopilotConfigurationResponse.php | 2 +- src/Operator/OperatorHealthReply.php | 6 +- src/Operator/OperatorHealthReplyResponse.php | 2 +- .../OperatorRaftConfigurationResponse.php | 2 +- src/Operator/OperatorSerfMembersResponse.php | 2 +- .../OperatorServerHealthsResponse.php | 2 +- src/Operator/RaftConfiguration.php | 4 +- src/Operator/RaftServer.php | 12 +- src/Operator/SerfMember.php | 18 +- src/Operator/ServerHealth.php | 22 +-- 30 files changed, 271 insertions(+), 179 deletions(-) diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 355aec9c..7cdfecd2 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -32,20 +32,25 @@ class Node extends AbstractModel public string $Node; public string $Address; public string $Datacenter; - public null|\stdClass $TaggedAddresses; + /** @var array */ + public array $TaggedAddresses; public int $CreateIndex; public int $ModifyIndex; public string $Partition; public string $PeerName; public null|Locality $Locality; + /** + * @param \stdClass|array|null $TaggedAddresses + * @param \stdClass|array|null $Meta + */ public function __construct( string $ID = '', string $Node = '', string $Address = '', string $Datacenter = '', - null|\stdClass $TaggedAddresses = null, - null|\stdClass $Meta = null, + null|\stdClass|array $TaggedAddresses = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, string $Partition = '', @@ -56,14 +61,14 @@ public function __construct( $this->Node = $Node; $this->Address = $Address; $this->Datacenter = $Datacenter; - $this->TaggedAddresses = $TaggedAddresses ?? new \stdClass(); - $this->Meta = $Meta ?? new \stdClass(); + $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 { @@ -109,14 +114,28 @@ public function setDatacenter(string $Datacenter): self return $this; } - public function getTaggedAddresses(): null|\stdClass + /** + * @return array|null + */ + public function getTaggedAddresses(): null|array { return $this->TaggedAddresses; } - public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self + /** + * @param \stdClass|array|null $TaggedAddresses + * @return $this + */ + public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self { - $this->TaggedAddresses = $TaggedAddresses; + if (null === $TaggedAddresses) { + unset($this->TaggedAddresses); + return $this; + } + $this->TaggedAddresses = []; + foreach ($TaggedAddresses as $k => $v) { + $this->TaggedAddresses[$k] = $v; + } return $this; } @@ -181,6 +200,10 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($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; } @@ -195,8 +218,8 @@ public function jsonSerialize(): \stdClass $out->Node = $this->Node; $out->Address = $this->Address; $out->Datacenter = $this->Datacenter; - $out->TaggedAddresses = $this->TaggedAddresses; - $out->Meta = $this->Meta; + $out->TaggedAddresses = $this->getTaggedAddresses(); + $out->Meta = $this->getMeta(); $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; if ('' !== $this->Partition) { diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index 3b556cf7..09971213 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -36,6 +36,7 @@ class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener> $Listeners + * @param null|\stdClass|array $Meta */ public function __construct( string $Kind = '', @@ -44,7 +45,7 @@ public function __construct( string $Namespace = '', null|GatewayTLSConfig $TLS = null, array $Listeners = [], - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, null|IngressServiceConfig $Defaults = null, int $CreateIndex = 0, int $ModifyIndex = 0, @@ -55,7 +56,7 @@ public function __construct( $this->Namespace = $Namespace; $this->TLS = $TLS ?? new GatewayTLSConfig(); $this->setListeners(...$Listeners); - $this->Meta = $Meta; + $this->setMeta($Meta); $this->Defaults = $Defaults; $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; @@ -146,6 +147,8 @@ public static function jsonUnserialize(\stdClass $decoded): self } } elseif ('Defaults' === $k) { $n->Defaults = null === $v ? null : IngressServiceConfig::jsonUnserialize($v); + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -166,11 +169,11 @@ public function jsonSerialize(): \stdClass } $out->TLS = $this->TLS; $out->Listeners = $this->Listeners; - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } if (null !== $this->Defaults) { - $out->Defaults = $this->Defaults->jsonSerialize(); + $out->Defaults = $this->Defaults; } $out->CreateIndex = $this->CreateIndex; $out->ModifyIndex = $this->ModifyIndex; diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index c73f1361..0f026444 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -34,6 +34,9 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry public null|MeshHTTPConfig $HTTP; public null|PeeringMeshConfig $Peering; + /** + * @param \stdClass|array|null $Meta + */ public function __construct( string $Partition = '', string $Namespace = '', @@ -42,13 +45,13 @@ public function __construct( null|MeshTLSConfig $TLS = null, null|MeshHTTPConfig $HTTP = null, null|PeeringMeshConfig $Peering = null, - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0 ) { - $this->Partition = $Partition; + $this->Partition = $Partition; $this->Namespace = $Namespace; - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->TransparentProxy = $TransparentProxy; @@ -137,6 +140,8 @@ public static function jsonUnserialize(\stdClass $decoded, null|self $n = null): $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; } @@ -164,7 +169,7 @@ public function jsonSerialize(): \stdClass if (null !== $this->Peering) { $out->Peering = $this->Peering; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php index 4c2d2acc..05c7a566 100644 --- a/src/ConfigEntry/ServiceIntentionsConfigEntry.php +++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php @@ -36,6 +36,7 @@ class ServiceIntentionsConfigEntry extends AbstractModel implements ConfigEntry /** * @param array $Sources + * @param null|\stdClass|array $Meta */ public function __construct( string $Kind = '', @@ -44,7 +45,7 @@ public function __construct( string $Namespace = '', array $Sources = [], null|IntentionJWTRequirement $JWT = null, - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -54,7 +55,7 @@ public function __construct( $this->Namespace = $Namespace; $this->setSources(...$Sources); $this->JWT = $JWT; - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; } @@ -122,6 +123,8 @@ public static function jsonUnserialize(\stdClass $decoded): self } } elseif ('JWT' === $k) { $n->JWT = null === $v ? null : IntentionJWTRequirement::jsonUnserialize($v); + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -146,7 +149,7 @@ public function jsonSerialize(): \stdClass if (null !== $this->JWT) { $out->JWT = $this->JWT; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 278d7c34..4c79c22e 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -34,6 +34,7 @@ class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRoute> $Routes + * @param null|\stdClass|array $Meta */ public function __construct( string $Kind = '', @@ -41,7 +42,7 @@ public function __construct( string $Partition = '', string $Namespace = '', array $Routes = [], - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -50,7 +51,7 @@ public function __construct( $this->Partition = $Partition; $this->Namespace = $Namespace; $this->setRoutes(...$Routes); - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; } @@ -111,6 +112,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $vv) { $n->Routes[] = ServiceRoute::jsonUnserialize($vv); } + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -132,7 +135,7 @@ public function jsonSerialize(): \stdClass if ([] !== $this->Routes) { $out->Routes = $this->Routes; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index a2f8a8ca..3fa62ad2 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -34,6 +34,7 @@ class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceSplit> $Splits + * @param array $Meta */ public function __construct( string $Kind = '', @@ -41,7 +42,7 @@ public function __construct( string $Partition = '', string $Namespace = '', array $Splits = [], - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -50,7 +51,7 @@ public function __construct( $this->Partition = $Partition; $this->Namespace = $Namespace; $this->setSplits(...$Splits); - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; } @@ -111,6 +112,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $vv) { $n->Splits[] = ServiceSplit::jsonUnserialize($vv); } + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -132,7 +135,7 @@ public function jsonSerialize(): \stdClass if ([] !== $this->Splits) { $out->Splits = $this->Splits; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php index eba18327..664a956a 100644 --- a/src/ConfigEntry/TerminatingGatewayConfigEntry.php +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -34,12 +34,13 @@ class TerminatingGatewayConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\LinkedService> $Services + * @param array $Meta */ public function __construct( string $Kind = '', string $Name = '', array $Services = [], - null|\stdClass $Meta = null, + null|\stdClass|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, string $Partition = '', @@ -48,7 +49,7 @@ public function __construct( $this->Kind = $Kind; $this->Name = $Name; $this->setServices(...$Services); - $this->Meta = $Meta; + $this->setMeta($Meta); $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; $this->Partition = $Partition; @@ -125,6 +126,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $vv) { $n->Services[] = LinkedService::jsonUnserialize($vv); } + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } @@ -140,7 +143,7 @@ public function jsonSerialize(): \stdClass if ([] !== $this->Services) { $out->Services = $this->Services; } - if (null !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/Operator/Area.php b/src/Operator/Area.php index d922cf5c..51821ec5 100644 --- a/src/Operator/Area.php +++ b/src/Operator/Area.php @@ -24,10 +24,10 @@ class Area extends AbstractModel { - public string $ID = ''; - public string $PeerDatacenter = ''; - public array $RetryJoin = []; - public bool $UseTLS = false; + public string $ID; + public string $PeerDatacenter; + public array $RetryJoin; + public bool $UseTLS; public function getID(): string { diff --git a/src/Operator/AreaJoinResponse.php b/src/Operator/AreaJoinResponse.php index 895c24e5..8ff3af60 100644 --- a/src/Operator/AreaJoinResponse.php +++ b/src/Operator/AreaJoinResponse.php @@ -24,9 +24,9 @@ class AreaJoinResponse extends AbstractModel { - public string $Address = ''; - public bool $Joined = false; - public string $Error = ''; + public string $Address; + public bool $Joined; + public string $Error; public function getAddress(): string { diff --git a/src/Operator/AutopilotConfiguration.php b/src/Operator/AutopilotConfiguration.php index 0e2916f6..24740ddc 100644 --- a/src/Operator/AutopilotConfiguration.php +++ b/src/Operator/AutopilotConfiguration.php @@ -39,16 +39,16 @@ class AutopilotConfiguration extends AbstractModel 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 ?ReadableDuration $LastContactThreshold; + public int $MaxTrailingLogs; + public int $MinQuorum; + public ?ReadableDuration $ServerStabilizationTime; + public string $RedundancyZoneTag; + public bool $DisableUpgradeMigration; + public string $UpgradeVersionTag; + public int $CreateIndex; + public int $ModifyIndex; public function isCleanupDeadServers(): bool { diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index 3308c52f..bb666ec2 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -22,50 +22,65 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\MetaContainer; class AutopilotServer extends AbstractModel implements \JsonSerializable { - 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 MetaContainer; + + public string $ID; + public string $Name; + public string $Address; + public string $NodeStatus; + public string $Version; + public null|Time\Duration $LastContact; + 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 null|\stdClass $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 +138,18 @@ public function setVersion(string $Version): self return $this; } - public function getLastContact(): ?ReadableDuration + public function getLastContact(): null|Time\Duration { - return $this->LastContact; + return $this->LastContact ?? null; } - public function setLastContact(?ReadableDuration $LastContact): self + public function setLastContact(null|string|int|float|\DateInterval|Time\Duration $LastContact): self { - $this->LastContact = $LastContact; + if (null === $LastContact) { + unset($this->LastContact); + return $this; + } + $this->LastContact = Time::Duration($LastContact); return $this; } @@ -211,45 +230,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 ($decoded as $k => $v) { + if ('lastContact' === $k) { + $n->setLastContact($v); + } elseif ('StableSince' === $k) { + $n->StableSince = Time\Time::createFromFormat(DATE_RFC3339, $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 = isset($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 index b732d9e3..e16fbaa1 100644 --- a/src/Operator/AutopilotServerStatus.php +++ b/src/Operator/AutopilotServerStatus.php @@ -27,4 +27,6 @@ enum AutopilotServerStatus: string case Voter = 'voter'; case NonVoter = 'non-voter'; case Staging = 'staging'; + + case UNDEFINED = ''; } diff --git a/src/Operator/AutopilotServerType.php b/src/Operator/AutopilotServerType.php index 70107e96..c421012f 100644 --- a/src/Operator/AutopilotServerType.php +++ b/src/Operator/AutopilotServerType.php @@ -27,4 +27,6 @@ enum AutopilotServerType: string 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..d4545ef4 100644 --- a/src/Operator/AutopilotState.php +++ b/src/Operator/AutopilotState.php @@ -52,15 +52,15 @@ class AutopilotState extends AbstractModel 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; + public array $Servers; + public string $Leader; + public array $Voters; + public array $ReadReplicas; + public array $RedundancyZone; + public ?AutopilotUpgrade $Upgrade; public function isHealthy(): bool { diff --git a/src/Operator/AutopilotStateResponse.php b/src/Operator/AutopilotStateResponse.php index 9e54d9c7..0e35370d 100644 --- a/src/Operator/AutopilotStateResponse.php +++ b/src/Operator/AutopilotStateResponse.php @@ -25,7 +25,7 @@ class AutopilotStateResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|AutopilotState $AutopilotState = null; + public null|AutopilotState $AutopilotState; public function getValue(): null|AutopilotState { diff --git a/src/Operator/AutopilotUpgrade.php b/src/Operator/AutopilotUpgrade.php index fa372a69..9d232f5d 100644 --- a/src/Operator/AutopilotUpgrade.php +++ b/src/Operator/AutopilotUpgrade.php @@ -49,15 +49,15 @@ class AutopilotUpgrade extends AbstractModel 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; + public array $TargetVersionVoters; + public array $TargetVersionNonVoters; + public array $TargetVersionReadReplicas; + public array $OtherVersionVoters; + public array $OtherVersionNonVoters; + public array $OtherVersionReadReplicas; + public array $RedundancyZones; public function getStatus(): string { diff --git a/src/Operator/AutopilotZone.php b/src/Operator/AutopilotZone.php index b24ca654..801ed9fe 100644 --- a/src/Operator/AutopilotZone.php +++ b/src/Operator/AutopilotZone.php @@ -24,9 +24,9 @@ class AutopilotZone extends AbstractModel { - public array $Servers = []; - public array $Voters = []; - public int $FailureTolerance = 0; + public array $Servers; + public array $Voters; + public int $FailureTolerance; public function getServers(): array { diff --git a/src/Operator/AutopilotZoneUpgradeVersions.php b/src/Operator/AutopilotZoneUpgradeVersions.php index 9b07c349..43f087db 100644 --- a/src/Operator/AutopilotZoneUpgradeVersions.php +++ b/src/Operator/AutopilotZoneUpgradeVersions.php @@ -37,10 +37,10 @@ class AutopilotZoneUpgradeVersions extends AbstractModel 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 = []; + public array $TargetVersionVoters; + public array $TargetVersionNonVoters; + public array $OtherVersionVoters; + public array $OtherVersionNonVoters; public function getTargetVersionVoters(): array { diff --git a/src/Operator/OperatorAreaJoinResponse.php b/src/Operator/OperatorAreaJoinResponse.php index 88fe7404..77ebcc77 100644 --- a/src/Operator/OperatorAreaJoinResponse.php +++ b/src/Operator/OperatorAreaJoinResponse.php @@ -26,7 +26,7 @@ class OperatorAreaJoinResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Operator\AreaJoinResponse[] */ - public array $AreaJoinResponses = []; + public array $AreaJoinResponses; /** * @return \DCarbone\PHPConsulAPI\Operator\AreaJoinResponse[] diff --git a/src/Operator/OperatorAreasResponse.php b/src/Operator/OperatorAreasResponse.php index 928e3fba..fd436b00 100644 --- a/src/Operator/OperatorAreasResponse.php +++ b/src/Operator/OperatorAreasResponse.php @@ -26,7 +26,7 @@ class OperatorAreasResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Operator\Area[] */ - public array $Areas = []; + public array $Areas; /** * @return \DCarbone\PHPConsulAPI\Operator\Area[] diff --git a/src/Operator/OperatorAutopilotConfigurationResponse.php b/src/Operator/OperatorAutopilotConfigurationResponse.php index 30ad276a..384d04e0 100644 --- a/src/Operator/OperatorAutopilotConfigurationResponse.php +++ b/src/Operator/OperatorAutopilotConfigurationResponse.php @@ -25,7 +25,7 @@ class OperatorAutopilotConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|AutopilotConfiguration $AutopilotConfiguration = null; + public null|AutopilotConfiguration $AutopilotConfiguration; public function getValue(): null|AutopilotConfiguration { diff --git a/src/Operator/OperatorHealthReply.php b/src/Operator/OperatorHealthReply.php index a837eb7a..f60e8abb 100644 --- a/src/Operator/OperatorHealthReply.php +++ b/src/Operator/OperatorHealthReply.php @@ -35,9 +35,9 @@ class OperatorHealthReply extends AbstractModel private const FIELD_SERVERS = 'Servers'; - public bool $Healthy = false; - public int $FailureTolerance = 0; - public array $Servers = []; + public bool $Healthy; + public int $FailureTolerance; + public array $Servers; public function isHealthy(): bool { diff --git a/src/Operator/OperatorHealthReplyResponse.php b/src/Operator/OperatorHealthReplyResponse.php index deccc502..2fa54b27 100644 --- a/src/Operator/OperatorHealthReplyResponse.php +++ b/src/Operator/OperatorHealthReplyResponse.php @@ -25,7 +25,7 @@ class OperatorHealthReplyResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|OperatorHealthReply $OperatorHealthReply = null; + public null|OperatorHealthReply $OperatorHealthReply; public function getValue(): null|OperatorHealthReply { diff --git a/src/Operator/OperatorRaftConfigurationResponse.php b/src/Operator/OperatorRaftConfigurationResponse.php index 89b700df..35d164db 100644 --- a/src/Operator/OperatorRaftConfigurationResponse.php +++ b/src/Operator/OperatorRaftConfigurationResponse.php @@ -25,7 +25,7 @@ class OperatorRaftConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|RaftConfiguration $RaftConfiguration = null; + public null|RaftConfiguration $RaftConfiguration; public function getValue(): null|RaftConfiguration { diff --git a/src/Operator/OperatorSerfMembersResponse.php b/src/Operator/OperatorSerfMembersResponse.php index 33688ac6..15abdfb2 100644 --- a/src/Operator/OperatorSerfMembersResponse.php +++ b/src/Operator/OperatorSerfMembersResponse.php @@ -26,7 +26,7 @@ class OperatorSerfMembersResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Operator\SerfMember[] */ - public array $SerfMembers = []; + public array $SerfMembers; /** * @return \DCarbone\PHPConsulAPI\Operator\SerfMember[] diff --git a/src/Operator/OperatorServerHealthsResponse.php b/src/Operator/OperatorServerHealthsResponse.php index 9c1fdc21..608a6be9 100644 --- a/src/Operator/OperatorServerHealthsResponse.php +++ b/src/Operator/OperatorServerHealthsResponse.php @@ -26,7 +26,7 @@ class OperatorServerHealthsResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Operator\ServerHealth[] */ - public array $ServerHealths = []; + public array $ServerHealths; /** * @return \DCarbone\PHPConsulAPI\Operator\ServerHealth[] diff --git a/src/Operator/RaftConfiguration.php b/src/Operator/RaftConfiguration.php index 525f4e4a..c9f4dc6b 100644 --- a/src/Operator/RaftConfiguration.php +++ b/src/Operator/RaftConfiguration.php @@ -35,8 +35,8 @@ class RaftConfiguration extends AbstractModel private const FIELD_SERVERS = 'Servers'; - public array $Servers = []; - public int $Index = 0; + public array $Servers; + public int $Index; public function getServers(): array { diff --git a/src/Operator/RaftServer.php b/src/Operator/RaftServer.php index 9fa59d0a..f83d894b 100644 --- a/src/Operator/RaftServer.php +++ b/src/Operator/RaftServer.php @@ -24,12 +24,12 @@ class RaftServer extends AbstractModel { - public string $ID = ''; - public string $Node = ''; - public string $Address = ''; - public bool $Leader = false; - public string $ProtocolVersion = ''; - public bool $Voter = false; + public string $ID; + public string $Node; + public string $Address; + public bool $Leader; + public string $ProtocolVersion; + public bool $Voter; public function getID(): string { diff --git a/src/Operator/SerfMember.php b/src/Operator/SerfMember.php index 3ce951ba..a3857188 100644 --- a/src/Operator/SerfMember.php +++ b/src/Operator/SerfMember.php @@ -34,15 +34,15 @@ class SerfMember extends AbstractModel private const FIELD_RTT = 'RTT'; - public string $ID = ''; - public string $Name = ''; - public string $Addr = ''; - public int $Port = 0; - public string $Datacenter = ''; - public string $Role = ''; - public string $Build = ''; - public int $Protocol = 0; - public string $Status = ''; + public string $ID; + public string $Name; + public string $Addr; + public int $Port; + public string $Datacenter; + public string $Role; + public string $Build; + public int $Protocol; + public string $Status; public Time\Duration $RTT; public function __construct(?array $data = []) diff --git a/src/Operator/ServerHealth.php b/src/Operator/ServerHealth.php index e50af771..029fb82c 100644 --- a/src/Operator/ServerHealth.php +++ b/src/Operator/ServerHealth.php @@ -39,17 +39,17 @@ class ServerHealth extends AbstractModel private const FIELD_LAST_CONTACT = 'LastContact'; private const FIELD_STABLE_SINCE = 'StableSince'; - public string $ID = ''; - public string $Name = ''; - public string $Address = ''; - public string $SerfStatus = ''; - public string $Version = ''; - public bool $Leader = false; - public ?ReadableDuration $LastContact = null; - public int $LastTerm = 0; - public int $LastIndex = 0; - public bool $Healthy = false; - public bool $Voter = false; + public string $ID; + public string $Name; + public string $Address; + public string $SerfStatus; + public string $Version; + public bool $Leader; + public ?ReadableDuration $LastContact; + public int $LastTerm; + public int $LastIndex; + public bool $Healthy; + public bool $Voter; public Time\Time $StableSince; public function __construct(?array $data = []) From 686859c29bedff1ceb252c92cc5f6da4db947b0a Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Fri, 26 Sep 2025 21:59:08 -0500 Subject: [PATCH 74/79] more work. --- src/ACL/ACLToken.php | 7 +++++ src/ACL/ACLTokenExpanded.php | 54 ++++++++++++++++-------------------- src/ACL/ACLTokenFields.php | 12 ++++---- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index 5da848c7..58593097 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -27,6 +27,13 @@ class ACLToken extends AbstractModel { 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, diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index f73f0e6b..a0831ab7 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -37,33 +37,15 @@ class ACLTokenExpanded extends ACLToken public string $ResolvedByAgent; /** - * @param iterable $ExpandedPolicies - * @param iterable $ExpandedRoles - * @param iterable $NamespaceDefaultPolicyIDs - * @param iterable $NamespaceDefaultRoleIDs - * @param string $AgentACLDefaultPolicy - * @param string $AgentACLDownPolicy - * @param string $ResolvedByAgent - * @param int $CreateIndex - * @param int $ModifyIndex - * @param string $AccessorID - * @param string $SecretID - * @param string $Description - * @param iterable $Policies - * @param iterable $Roles - * @param iterable $ServiceIdentities - * @param iterable $NodeIdentities - * @param iterable $TemplatePolicies - * @param bool $Local - * @param string $AuthMethod - * @param \DateInterval|float|int|string|\DCarbone\Go\Time\Duration|null $ExpirationTTL - * @param \DCarbone\Go\Time\Time|null $ExpirationTime - * @param \DCarbone\Go\Time\Time|null $CreateTime - * @param string $Hash - * @param string $Namespace - * @param string $Rules - * @param string $Partition - * @param string $AuthMethodNamespace + * @param array<\DCarbone\PHPConsulAPI\ACL\ACLPolicy> $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( iterable $ExpandedPolicies = [], @@ -140,7 +122,7 @@ public function setExpandedPolicies(ACLPolicy ...$ExpandedPolicies): self } /** - * @return \DCarbone\PHPConsulAPI\ACL\ACLRole[] + * @return array<\DCarbone\PHPConsulAPI\ACL\ACLRole> */ public function getExpandedRoles(): array { @@ -220,7 +202,9 @@ public static function jsonUnserialize(\stdClass $decoded, null|ACLToken $into = foreach ($decoded as $k => $v) { if ($n->_jsonUnserializeField($k, $v, $n)) { continue; - } elseif ('ExpandedPolicies' === $k) { + } + + if ('ExpandedPolicies' === $k) { foreach ($v as $vv) { $n->ExpandedPolicies[] = ACLPolicy::jsonUnserialize($vv); } @@ -241,6 +225,16 @@ public static function jsonUnserialize(\stdClass $decoded, null|ACLToken $into = public function jsonSerialize(): \stdClass { - return parent::jsonSerialize(); // TODO: Change the autogenerated stub + $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/ACLTokenFields.php b/src/ACL/ACLTokenFields.php index f37248d8..7bcf82fd 100644 --- a/src/ACL/ACLTokenFields.php +++ b/src/ACL/ACLTokenFields.php @@ -29,15 +29,15 @@ trait ACLTokenFields public string $AccessorID; public string $SecretID; public string $Description; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> */ public array $Policies; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> */ public array $Roles; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> */ public array $ServiceIdentities; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> */ public array $NodeIdentities; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[] */ + /** @var array>\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> */ public array $TemplatePolicies; public bool $Local; public string $AuthMethod; @@ -286,7 +286,7 @@ public function setAuthMethodNamespace(string $AuthMethodNamespace): self return $this; } - public function _jsonUnserializeField(string $k, mixed $v, object $n): bool + protected function _jsonUnserializeField(string $k, mixed $v, object $n): bool { if ('Policies' === $k) { foreach ($v as $vv) { From 55e268c7d5a7a43c008f104fdf8b1de547cbbdea Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Sat, 27 Sep 2025 22:36:11 -0500 Subject: [PATCH 75/79] more fixin' --- src/Agent/AgentCheckRegistration.php | 6 ++-- src/Agent/AgentMember.php | 7 +++-- src/Agent/AgentServicesResponse.php | 12 +++++--- src/Agent/ConnectProxyConfig.php | 37 ++++++++++++++-------- src/Agent/GaugeValue.php | 39 ++++++++++++++++------- src/Agent/MetricsInfo.php | 1 - src/Agent/SampledValue.php | 46 ++++++++++++++++++---------- src/Agent/Upstream.php | 35 ++++++++++++++++----- 8 files changed, 125 insertions(+), 58 deletions(-) diff --git a/src/Agent/AgentCheckRegistration.php b/src/Agent/AgentCheckRegistration.php index 84d222f6..5110681c 100644 --- a/src/Agent/AgentCheckRegistration.php +++ b/src/Agent/AgentCheckRegistration.php @@ -20,6 +20,8 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\Values; + class AgentCheckRegistration extends AgentServiceCheck { public string $ID; @@ -42,7 +44,7 @@ public function __construct( string $Timeout = '', string $TTL = '', string $HTTP = '', - null|\stdClass $Header = null, + null|\stdClass|array|Values $Header = null, string $Method = '', string $TCP = '', string $Status = '', @@ -90,7 +92,7 @@ public function __construct( $this->ServiceID = $ServiceID; $this->Namespace = $Namespace; $this->Partition = $Partition; -} + } public function getID(): string { diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 64fdba3f..5083c02b 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -154,12 +154,13 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($decoded as $k => $v) { if ('Tags' === $k) { if (null !== $v) { - foreach ($v as $k => $vv) { - $n->Tags[$k] = $vv; + foreach ($v as $kk => $vv) { + $n->Tags[$kk] = $vv; } } + } else { + $n->{$k} = $v; } - $n->{$k} = $v; } return $n; } diff --git a/src/Agent/AgentServicesResponse.php b/src/Agent/AgentServicesResponse.php index 852a88bb..48d44523 100644 --- a/src/Agent/AgentServicesResponse.php +++ b/src/Agent/AgentServicesResponse.php @@ -25,9 +25,13 @@ class AgentServicesResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - public null|\stdClass $Services = null; + /** @var null|array */ + public null|array $Services = null; - public function getValue(): null|\stdClass + /** + * @return array|null + */ + public function getValue(): null|array { return $this->Services; } @@ -38,9 +42,9 @@ public function unmarshalValue(mixed $decoded): void $this->Services = null; return; } - $this->Services = new \stdClass(); + $this->Services = []; foreach ($decoded as $k => $v) { - $this->Services->{$k} = AgentService::jsonUnserialize($v); + $this->Services[$k] = AgentService::jsonUnserialize($v); } } } diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php index c2a570df..366374c3 100644 --- a/src/Agent/ConnectProxyConfig.php +++ b/src/Agent/ConnectProxyConfig.php @@ -28,16 +28,13 @@ class ConnectProxyConfig extends AbstractModel public string $TargetServiceID; public string $TargetServiceName; public string $ContentHash; - public null|\stdClass $Config; + /** @var array */ + public array $Config; /** @var array<\DCarbone\PHPConsulAPI\Agent\Upstream> */ public array $Upstreams; /** - * @param string $ProxyServiceID - * @param string $TargetServiceID - * @param string $TargetServiceName - * @param string $ContentHash - * @param \stdClass|null $Config + * @param array|\stdClass|null $Config * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams */ public function __construct( @@ -45,14 +42,14 @@ public function __construct( string $TargetServiceID = '', string $TargetServiceName = '', string $ContentHash = '', - null|\stdClass $Config = null, + null|\stdClass|array $Config = null, array $Upstreams = [], ) { $this->ProxyServiceID = $ProxyServiceID; $this->TargetServiceID = $TargetServiceID; $this->TargetServiceName = $TargetServiceName; $this->ContentHash = $ContentHash; - $this->Config = $Config; + $this->setConfig($Config); $this->setUpstreams(...$Upstreams); } @@ -100,14 +97,28 @@ public function setContentHash(string $ContentHash): self return $this; } - public function getConfig(): null|\stdClass + /** + * @return null|array + */ + public function getConfig(): null|array { return $this->Config; } - public function setConfig(?\stdClass $Config): self + /** + * @param \stdClass|array|null $Config + * @return $this + */ + public function setConfig(null|\stdClass|array $Config): self { - $this->Config = $Config; + if (null === $Config) { + unset($this->Config); + return $this; + } + $this->Config = []; + foreach ($Config as $k => $v) { + $this->Config[$k] = $v; + } return $this; } @@ -134,6 +145,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $vv) { $n->Upstreams[] = Upstream::jsonUnserialize($vv); } + } elseif ('Config' === $k) { + $n->setConfig($v); } else { $n->{$k} = $v; } @@ -148,7 +161,7 @@ public function jsonSerialize(): \stdClass $out->TargetServiceID = $this->TargetServiceID; $out->TargetServiceName = $this->TargetServiceName; $out->ContentHash = $this->ContentHash; - $out->Config = $this->Config; + $out->Config = $this->getConfig(); $out->Upstreams = $this->Upstreams; return $out; } diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 860479ea..765e55b0 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -26,21 +26,20 @@ class GaugeValue extends AbstractModel { public string $Name; public float $Value; - public null|\stdClass $Labels; + /** @var array */ + public array $Labels; /** - * @param string $Name - * @param float $Value - * @param \stdClass|null $Labels + * @param array|\stdClass|null $Labels */ public function __construct( string $Name = '', float $Value = 0.0, - null|\stdClass $Labels = null, + null|\stdClass|array $Labels = null, ) { $this->Name = $Name; $this->Value = $Value; - $this->Labels = $Labels; + $this->setLabels($Labels); } public function getName(): string @@ -65,14 +64,28 @@ public function setValue(float $value): self return $this; } - public function getLabels(): null|\stdClass + /** + * @return null|array + */ + public function getLabels(): null|array { return $this->Labels; } - public function setLabels(null|\stdClass $Labels): self + /** + * @param \stdClass|array|null $Labels + * @return $this + */ + public function setLabels(null|\stdClass|array $Labels): self { - $this->Labels = $Labels; + if (null === $Labels) { + unset($this->Labels); + return $this; + } + $this->Labels = []; + foreach ($Labels as $k => $v) { + $this->Labels[$k] = $v; + } return $this; } @@ -80,7 +93,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Labels' === $k) { + $n->setLabels($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -90,7 +107,7 @@ public function jsonSerialize(): \stdClass $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Value = $this->Value; - $out->Labels = $this->Labels; + $out->Labels = $this->getLabels(); return $out; } } diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index 4a3a9319..6e17f26f 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -35,7 +35,6 @@ class MetricsInfo extends AbstractModel public array $Samples; /** - * @param string $Timestamp * @param array<\DCarbone\PHPConsulAPI\Agent\GaugeValue> $Gauges * @param array<\DCarbone\PHPConsulAPI\Agent\PointValue> $Points * @param array<\DCarbone\PHPConsulAPI\Agent\SampledValue> $Counters diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index ce631448..e9b66663 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -31,17 +31,11 @@ class SampledValue extends AbstractModel public float $Max; public float $Mean; public float $Stddev; - public null|\stdClass $Labels; + /** @var array */ + public array $Labels; /** - * @param string $Name - * @param int $Count - * @param float $Sum - * @param float $Min - * @param float $Max - * @param float $Mean - * @param float $Stddev - * @param \stdClass|null $Labels + * @param \stdClass|array|null $Labels */ public function __construct( string $Name = '', @@ -51,7 +45,7 @@ public function __construct( float $Max = 0.0, float $Mean = 0.0, float $Stddev = 0.0, - null|\stdClass $Labels = null, + null|\stdClass|array $Labels = null, ) { $this->Name = $Name; $this->Count = $Count; @@ -60,8 +54,8 @@ public function __construct( $this->Max = $Max; $this->Mean = $Mean; $this->Stddev = $Stddev; - $this->Labels = $Labels ?? new \stdClass(); -} + $this->setLabels($Labels); + } public function getName(): string { @@ -140,14 +134,28 @@ public function setStddev(float $stddev): self return $this; } - public function getLabels(): null|\stdClass + /** + * @return array|null + */ + public function getLabels(): null|array { return $this->Labels; } - public function setLabels(null|\stdClass $labels): self + /** + * @param \stdClass|array|null $Labels + * @return $this + */ + public function setLabels(null|\stdClass|array $Labels): self { - $this->Labels = $labels ?? new \stdClass(); + if (null === $Labels) { + unset($this->Labels); + return $this; + } + $this->Labels = []; + foreach ($Labels as $k => $v) { + $this->Labels[$k] = $v; + } return $this; } @@ -155,7 +163,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Labels' === $k) { + $n->setLabels($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -170,7 +182,7 @@ public function jsonSerialize(): \stdClass $out->Max = $this->Max; $out->Mean = $this->Mean; $out->Stddev = $this->Stddev; - $out->Labels = $this->Labels; + $out->Labels = $this->getLabels(); return $out; } } diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index ca9f7b99..c13b8e4c 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -35,12 +35,15 @@ class Upstream extends AbstractModel public int $LocalBindPort; public string $LocalBindSocketPath; public string $LocalBindSocketMode; - public null|\stdClass $Config; + /** @var array */ + public null|array $Config; public null|MeshGatewayConfig $MeshGateway; public bool $CentrallyConfigured; + /** + * @param \stdClass|array|null $Config + */ public function __construct( - null|array $data = [], // Deprecated, will be removed. string|UpstreamDestType $DestinationType = UpstreamDestType::UNDEFINED, string $DestinationPartition = '', string $DestinationNamespace = '', @@ -51,7 +54,7 @@ public function __construct( int $LocalBindPort = 0, string $LocalBindSocketPath = '', string $LocalBindSocketMode = '', - null|\stdClass $Config = null, + null|\stdClass|array $Config = null, null|MeshGatewayConfig $MeshGateway = null, bool $CentrallyConfigured = false, ) { @@ -65,10 +68,10 @@ public function __construct( $this->LocalBindPort = $LocalBindPort; $this->LocalBindSocketPath = $LocalBindSocketPath; $this->LocalBindSocketMode = $LocalBindSocketMode; - $this->Config = $Config; + $this->setConfig($Config); $this->MeshGateway = $MeshGateway; $this->CentrallyConfigured = $CentrallyConfigured; -} + } public function getDestinationType(): UpstreamDestType { @@ -180,14 +183,28 @@ public function setLocalBindSocketMode(string $LocalBindSocketMode): self return $this; } - public function getConfig(): null|\stdClass + /** + * @return null|array + */ + public function getConfig(): null|array { return $this->Config; } - public function setConfig(null|\stdClass $Config): self + /** + * @param \stdClass|array|null $Config + * @return $this + */ + public function setConfig(null|\stdClass|array $Config): self { - $this->Config = $Config; + if (null == $Config) { + $this->Config = null; + return $this; + } + $this->Config = []; + foreach ($Config as $k => $v) { + $this->Config[$k] = $v; + } return $this; } @@ -221,6 +238,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $n->setDestinationType($v); } elseif ('MeshGateway' === $k) { $n->MeshGateway = MeshGatewayConfig::jsonUnserialize($v); + } elseif ('Config' === $k) { + $n->setConfig($v); } else { $n->{$k} = $v; } From 50965f340359cb79f43e178034947020cf1819a1 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Tue, 30 Sep 2025 20:56:59 -0500 Subject: [PATCH 76/79] some updates --- src/ACL/ACLAuthMethod.php | 6 +- src/ACL/ACLAuthMethodNamespaceRule.php | 8 +- src/ACL/ACLBindingRule.php | 10 +- src/ACL/ACLLink.php | 8 +- src/ACL/ACLLoginParams.php | 4 +- src/ACL/ACLNodeIdentity.php | 8 +- src/ACL/ACLOIDCAuthURLParams.php | 4 +- src/ACL/ACLServiceIdentity.php | 11 +- src/ACL/ACLTemplatedPolicy.php | 3 + src/ACL/ACLToken.php | 10 +- src/ACL/ACLTokenExpanded.php | 18 +- src/ACL/ACLTokenListEntry.php | 27 +- src/ACL/BindingRuleBindType.php | 2 + src/ACL/KubernetesAuthMethodConfig.php | 11 +- src/ACL/OIDCAuthMethodConfig.php | 426 ++++++++++++++++++++++++- src/Agent/AgentCheckUpdate.php | 8 +- src/Catalog/CatalogNode.php | 52 +-- src/Catalog/CatalogRegistration.php | 67 ++-- src/Catalog/CatalogService.php | 116 ++++--- src/Catalog/CompoundServiceName.php | 5 +- src/Catalog/GatewayService.php | 12 +- src/Catalog/Node.php | 37 +-- src/Catalog/ServiceAddress.php | 11 +- src/Catalog/Weights.php | 11 +- src/MetaContainer.php | 12 +- src/NodeMetaContainer.php | 61 ++++ src/ServiceMetaContainer.php | 60 ++++ src/TaggedAddressContainer.php | 60 ++++ 28 files changed, 798 insertions(+), 270 deletions(-) create mode 100644 src/NodeMetaContainer.php create mode 100644 src/ServiceMetaContainer.php create mode 100644 src/TaggedAddressContainer.php diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 463efcd3..97949ace 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -41,7 +41,7 @@ class ACLAuthMethod extends AbstractModel public string $Partition; /** - * @param null|\stdClass|array $Config + * @param array $Config * @param array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> $NamespaceRules */ public function __construct( @@ -51,7 +51,7 @@ public function __construct( string $Description = '', null|int|float|string|\DateInterval|Time\Duration $MaxTokenTTL = null, string $TokenLocality = '', - null|\stdClass|array $Config = null, + array $Config = [], int $CreateIndex = 0, int $ModifyIndex = 0, array $NamespaceRules = [], @@ -184,7 +184,7 @@ public function setModifyIndex(int $ModifyIndex): self } /** - * @return \DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule[] + * @return array<\DCarbone\PHPConsulAPI\ACL\ACLAuthMethodNamespaceRule> */ public function getNamespaceRules(): array { diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index a69bc613..620c2533 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -27,13 +27,11 @@ class ACLAuthMethodNamespaceRule extends AbstractModel public string $Selector; public string $BindNamespace; - public function __construct( - string $Selector = '', - string $BindNamespace = '', - ) { + public function __construct(string $Selector = '', string $BindNamespace = '') + { $this->Selector = $Selector; $this->BindNamespace = $BindNamespace; -} + } public function getSelector(): string { diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index a4c9e421..5af47e1d 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -28,7 +28,7 @@ class ACLBindingRule extends AbstractModel public string $Description; public string $AuthMethod; public string $Selector; - public string $BindType; + public BindingRuleBindType $BindType; public string $BindName; public int $CreateIndex; public int $ModifyIndex; @@ -39,7 +39,7 @@ public function __construct( string $Description = '', string $AuthMethod = '', string $Selector = '', - string $BindType = '', + string|BindingRuleBindType $BindType = BindingRuleBindType::UNDEFINED, string $BindName = '', int $CreateIndex = 0, int $ModifyIndex = 0, @@ -49,7 +49,7 @@ public function __construct( $this->Description = $Description; $this->AuthMethod = $AuthMethod; $this->Selector = $Selector; - $this->BindType = $BindType; + $this->BindType = ($BindType instanceof BindingRuleBindType) ? $BindType : BindingRuleBindType::from($BindType); $this->BindName = $BindName; $this->CreateIndex = $CreateIndex; $this->ModifyIndex = $ModifyIndex; @@ -100,12 +100,12 @@ 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(BindingRuleBindType $BindType): self { $this->BindType = $BindType; return $this; diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index 925ff716..ff5a0104 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -27,13 +27,11 @@ class ACLLink extends AbstractModel public string $ID; public string $Name; - public function __construct( - string $ID = '', - string $Name = '', - ) { + public function __construct(string $ID = '', string $Name = '') + { $this->ID = $ID; $this->Name = $Name; -} + } public function getID(): string { diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index f562f78c..f560aa6b 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -31,12 +31,12 @@ class ACLLoginParams extends AbstractModel public string $BearerToken; /** - * @param \stdClass|array|null $Meta + * @param array $Meta */ public function __construct( string $AuthMethod = '', string $BearerToken = '', - null|\stdClass|array $Meta = null, + array $Meta = [], ) { $this->AuthMethod = $AuthMethod; $this->BearerToken = $BearerToken; diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index f0e0cbf5..852b79c4 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -27,13 +27,11 @@ class ACLNodeIdentity extends AbstractModel public string $NodeName; public string $Datacenter; - public function __construct( - string $NodeName = '', - string $Datacenter = '' - ) { + public function __construct(string $NodeName = '', string $Datacenter = '') + { $this->NodeName = $NodeName; $this->Datacenter = $Datacenter; -} + } public function getNodeName(): string { diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 87be39c3..d29749d4 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -32,13 +32,13 @@ class ACLOIDCAuthURLParams extends AbstractModel public string $ClientNonce; /** - * @param \stdClass|array|null $Meta + * @param array $Meta */ public function __construct( string $AuthMethod = '', string $RedirectURI = '', string $ClientNonce = '', - null|\stdClass|array $Meta = null + array $Meta = [], ) { $this->AuthMethod = $AuthMethod; $this->RedirectURI = $RedirectURI; diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 6da2fd0d..153806e7 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -28,13 +28,14 @@ class ACLServiceIdentity extends AbstractModel /** @var string[] */ public array $Datacenters; - public function __construct( - string $ServiceName = '', - iterable $Datacenters = [] - ) { + /** + * @param array $Datacenters + */ + public function __construct(string $ServiceName = '', array $Datacenters = []) + { $this->ServiceName = $ServiceName; $this->setDatacenters(...$Datacenters); -} + } public function getServiceName(): string { diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php index fba2bccb..04d90697 100644 --- a/src/ACL/ACLTemplatedPolicy.php +++ b/src/ACL/ACLTemplatedPolicy.php @@ -29,6 +29,9 @@ class ACLTemplatedPolicy extends AbstractModel /** @var string[] */ public array $Datacenters; + /** + * @param array $Datacenters + */ public function __construct( string $TemplateName = '', null|ACLTemplatedPolicyVariables $TemplateVariables = null, diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index 58593097..d94a5459 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -40,11 +40,11 @@ public function __construct( string $AccessorID = '', string $SecretID = '', string $Description = '', - iterable $Policies = [], - iterable $Roles = [], - iterable $ServiceIdentities = [], - iterable $NodeIdentities = [], - iterable $TemplatePolicies = [], + array $Policies = [], + array $Roles = [], + array $ServiceIdentities = [], + array $NodeIdentities = [], + array $TemplatePolicies = [], bool $Local = false, string $AuthMethod = '', null|int|float|string|\DateInterval|Time\Duration $ExpirationTTL = null, diff --git a/src/ACL/ACLTokenExpanded.php b/src/ACL/ACLTokenExpanded.php index a0831ab7..da4806ca 100644 --- a/src/ACL/ACLTokenExpanded.php +++ b/src/ACL/ACLTokenExpanded.php @@ -48,10 +48,10 @@ class ACLTokenExpanded extends ACLToken * @param array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> $TemplatePolicies */ public function __construct( - iterable $ExpandedPolicies = [], - iterable $ExpandedRoles = [], - iterable $NamespaceDefaultPolicyIDs = [], - iterable $NamespaceDefaultRoleIDs = [], + array $ExpandedPolicies = [], + array $ExpandedRoles = [], + array $NamespaceDefaultPolicyIDs = [], + array $NamespaceDefaultRoleIDs = [], string $AgentACLDefaultPolicy = '', string $AgentACLDownPolicy = '', string $ResolvedByAgent = '', @@ -60,11 +60,11 @@ public function __construct( string $AccessorID = '', string $SecretID = '', string $Description = '', - iterable $Policies = [], - iterable $Roles = [], - iterable $ServiceIdentities = [], - iterable $NodeIdentities = [], - iterable $TemplatePolicies = [], + array $Policies = [], + array $Roles = [], + array $ServiceIdentities = [], + array $NodeIdentities = [], + array $TemplatePolicies = [], bool $Local = false, string $AuthMethod = '', \DateInterval|float|int|string|Time\Duration|null $ExpirationTTL = null, diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index 913b2701..88a9f3d3 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -30,15 +30,15 @@ class ACLTokenListEntry extends AbstractModel public string $AccessorID; public string $SecretID; public string $Description; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenPolicyLink> */ public array $Policies; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLRolePolicyLink[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTokenRoleLink> */ public array $Roles; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLServiceIdentity> */ public array $ServiceIdentities; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLNodeIdentity> */ public array $NodeIdentities; - /** @var \DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy[] */ + /** @var array<\DCarbone\PHPConsulAPI\ACL\ACLTemplatedPolicy> */ public array $TemplatedPolicies; public bool $Local; public string $AuthMethod; @@ -50,17 +50,24 @@ class ACLTokenListEntry extends AbstractModel 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 = '', - iterable $Policies = [], - iterable $Roles = [], - iterable $ServiceIdentities = [], - iterable $NodeIdentities = [], - iterable $TemplatedPolicies = [], + array $Policies = [], + array $Roles = [], + array $ServiceIdentities = [], + array $NodeIdentities = [], + array $TemplatedPolicies = [], bool $Local = false, string $AuthMethod = '', null|Time\Time $ExpirationTime = null, diff --git a/src/ACL/BindingRuleBindType.php b/src/ACL/BindingRuleBindType.php index 98103191..d42ece3c 100644 --- a/src/ACL/BindingRuleBindType.php +++ b/src/ACL/BindingRuleBindType.php @@ -27,4 +27,6 @@ enum BindingRuleBindType: string case Node = 'node'; case Policy = 'policy'; case TemplatedPolicy = 'templated-policy'; + + case UNDEFINED = ''; } diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index 2280ef6c..b8aff5e6 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -28,15 +28,12 @@ class KubernetesAuthMethodConfig extends AbstractModel public string $CACert; public string $ServiceAccountJWT; - public function __construct( - string $Host = '', - string $CACert = '', - string $ServiceAccountJWT = '' - ) { + public function __construct(string $Host = '', string $CACert = '', string $ServiceAccountJWT = '') + { $this->Host = $Host; $this->CACert = $CACert; $this->ServiceAccountJWT = $ServiceAccountJWT; -} + } public function getHost(): string { @@ -75,7 +72,7 @@ public function setServiceAccountJWT(string $ServiceAccountJWT): self * RenderToConfig converts this into a map[string]interface{} suitable for use * in the ACLAuthMethod.Config field. * - * @return array + * @return array */ public function RenderToConfig(): array { diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index f47a1825..c8f5effc 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -20,19 +20,383 @@ limitations under the License. */ +use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; class OIDCAuthMethodConfig extends AbstractModel { + /** @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 ($decoded as $k => $v) { - $n->{$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; } @@ -40,6 +404,64 @@ public static function jsonUnserialize(\stdClass $decoded): self 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/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php index 0dfeebeb..bfa1eabe 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -27,13 +27,11 @@ class AgentCheckUpdate extends AbstractModel public string $Status; public string $Output; - public function __construct( - string $Status = '', - string $Output = '' - ) { + public function __construct(string $Status = '', string $Output = '') + { $this->Status = $Status; $this->Output = $Output; -} + } public function getStatus(): string { diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index 8ca131e4..dc504e04 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -26,47 +26,20 @@ class CatalogNode extends AbstractModel { public null|Node $Node; - public null|\stdClass $Services; - - /** - * @param \DCarbone\PHPConsulAPI\Catalog\Node|null $Node - * @param null|\stdClass $Services - */ - public function __construct( - null|Node $Node = null, - null|\stdClass $Services = null - ) { - $this->Node = $Node; - $this->setServices($Services); -} + /** @var array */ + public array $Services; public function getNode(): null|Node { - return $this->Node; - } - - public function setNode(?Node $Node): self - { - $this->Node = $Node; - return $this; + return $this->Node ?? null; } - public function getServices(): null|\stdClass - { - return $this->Services; - } - - public function setServices(null|\stdClass $Services): self + /** + * @return null|array + */ + public function getServices(): null|array { - if (null === $Services) { - $this->Services = null; - return $this; - } - $this->Services = new \stdClass(); - foreach ($Services as $k => $v) { - $this->Services->{$k} = $v instanceof AgentService ? $v : AgentService::jsonUnserialize($v); - } - return $this; + return $this->Services ?? null; } public static function jsonUnserialize(\stdClass $decoded): self @@ -76,7 +49,10 @@ public static function jsonUnserialize(\stdClass $decoded): self if ('Node' === $k) { $n->Node = null === $v ? null : Node::jsonUnserialize($v); } elseif ('Services' === $k) { - $n->setServices($v); + $n->Services = []; + foreach ($v as $kk => $vv) { + $n->Services[$kk] = AgentService::jsonUnserialize($vv); + } } else { $n->{$k} = $v; } @@ -87,8 +63,8 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { $out = $this->_startJsonSerialize(); - $out->Node = $this->Node; - $out->Services = $this->Services; + $out->Node = $this->getNode(); + $out->Services = $this->getServices(); return $out; } } diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index 1980ef98..f1cf92e9 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -24,15 +24,18 @@ use DCarbone\PHPConsulAPI\Agent\AgentCheck; use DCarbone\PHPConsulAPI\Agent\AgentService; use DCarbone\PHPConsulAPI\Health\HealthChecks; +use DCarbone\PHPConsulAPI\NodeMetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; +use DCarbone\PHPConsulAPI\TaggedAddressContainer; class CatalogRegistration extends AbstractModel { + use TaggedAddressContainer; + use NodeMetaContainer; + public string $ID; public string $Node; public string $Address; - public null|\stdClass $TaggedAddresses; - public null|\stdClass $NodeMeta; public string $Datacenter; public null|AgentService $Service; public null|AgentCheck $Check; @@ -45,8 +48,8 @@ class CatalogRegistration extends AbstractModel * @param string $ID * @param string $Node * @param string $Address - * @param \stdClass|null $TaggedAddresses - * @param \stdClass|null $NodeMeta + * @param array $TaggedAddresses + * @param array $NodeMeta * @param string $Datacenter * @param \DCarbone\PHPConsulAPI\Agent\AgentService|null $Service * @param \DCarbone\PHPConsulAPI\Agent\AgentCheck|null $Check @@ -59,8 +62,8 @@ public function __construct( string $ID = '', string $Node = '', string $Address = '', - null|\stdClass $TaggedAddresses = null, - null|\stdClass $NodeMeta = null, + array $TaggedAddresses = [], + array $NodeMeta = [], string $Datacenter = '', null|AgentService $Service = null, null|AgentCheck $Check = null, @@ -72,8 +75,8 @@ public function __construct( $this->ID = $ID; $this->Node = $Node; $this->Address = $Address; - $this->TaggedAddresses = $TaggedAddresses; - $this->NodeMeta = $NodeMeta; + $this->setTaggedAddresses($TaggedAddresses); + $this->setNodeMeta($NodeMeta); $this->Datacenter = $Datacenter; $this->Service = $Service; $this->Check = $Check; @@ -81,7 +84,7 @@ public function __construct( $this->SkipNodeUpdate = $SkipNodeUpdate; $this->Partition = $Partition; $this->Locality = $Locality; -} + } public function getID(): string { @@ -116,28 +119,6 @@ public function setAddress(string $Address): self return $this; } - public function getTaggedAddresses(): null|\stdClass - { - return $this->TaggedAddresses; - } - - public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self - { - $this->TaggedAddresses = $TaggedAddresses; - return $this; - } - - public function getNodeMeta(): null|\stdClass - { - return $this->NodeMeta; - } - - public function setNodeMeta(null|\stdClass $NodeMeta): self - { - $this->NodeMeta = $NodeMeta; - return $this; - } - public function getDatacenter(): string { return $this->Datacenter; @@ -149,23 +130,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; @@ -220,9 +201,9 @@ public static function jsonUnserialize(\stdClass $decoded): self $n = new self(); foreach ($decoded as $k => $v) { if ('TaggedAddresses' === $k) { - $n->TaggedAddresses = null === $v ? null : (object)$v; + $n->setTaggedAddresses($v); } elseif ('NodeMeta' === $k) { - $n->NodeMeta = null === $v ? null : (object)$v; + $n->setNodeMeta($v); } elseif ('Service' === $k) { $n->Service = null === $v ? null : AgentService::jsonUnserialize($v); } elseif ('Check' === $k) { @@ -244,15 +225,19 @@ public function jsonSerialize(): \stdClass $out->ID = $this->ID; $out->Node = $this->Node; $out->Address = $this->Address; - $out->TaggedAddresses = $this->TaggedAddresses; - $out->NodeMeta = $this->NodeMeta; + $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; - $out->Partition = $this->Partition; - $out->Locality = $this->Locality; + 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 1bfd1254..1ce777eb 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -23,23 +23,30 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig; use DCarbone\PHPConsulAPI\Health\HealthChecks; +use DCarbone\PHPConsulAPI\NodeMetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; +use DCarbone\PHPConsulAPI\ServiceMetaContainer; +use DCarbone\PHPConsulAPI\TaggedAddressContainer; class CatalogService extends AbstractModel { + use TaggedAddressContainer; + use NodeMetaContainer; + use ServiceMetaContainer; + public string $ID; public string $Node; public string $Address; public string $Datacenter; - public null|\stdClass $TaggedAddresses; - public null|\stdClass $NodeMeta; + /** @var array */ + public array $NodeMeta; public string $ServiceID; public string $ServiceName; public string $ServiceAddress; - public null|\stdClass $ServiceTaggedAddresses; + /** @var array */ + public array $ServiceTaggedAddresses; /** @var array */ public array $ServiceTags; - public null|\stdClass $ServiceMeta; public int $ServicePort; public Weights $ServiceWeights; public bool $ServiceEnableTagOverride; @@ -52,21 +59,25 @@ class CatalogService extends AbstractModel 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 = '', - null|\stdclass $TaggedAddresses = null, - null|\stdclass $NodeMeta = null, + array $TaggedAddresses = [], + array $NodeMeta = [], string $ServiceID = '', string $ServiceName = '', string $ServiceAddress = '', - null|\stdclass $ServiceTaggedAddresses = null, + array $ServiceTaggedAddresses = [], array $ServiceTags = [], - null|\stdclass $ServiceMeta = null, + array $ServiceMeta = [], int $ServicePort = 0, null|Weights $ServiceWeights = null, bool $ServiceEnableTagOverride = false, @@ -82,15 +93,14 @@ public function __construct( $this->Node = $Node; $this->Address = $Address; $this->Datacenter = $Datacenter; - $this->TaggedAddresses = $TaggedAddresses; - $this->NodeMeta = $NodeMeta; + $this->setTaggedAddresses($TaggedAddresses); + $this->setNodeMeta($NodeMeta); $this->ServiceID = $ServiceID; $this->ServiceName = $ServiceName; $this->ServiceAddress = $ServiceAddress; - $this->ServiceTaggedAddresses = $ServiceTaggedAddresses; $this->setServiceTags(...$ServiceTags); $this->setServiceTaggedAddresses($ServiceTaggedAddresses); - $this->ServiceMeta = $ServiceMeta; + $this->setServiceMeta($ServiceMeta); $this->ServicePort = $ServicePort; $this->ServiceWeights = $ServiceWeights ?? new Weights(); $this->ServiceEnableTagOverride = $ServiceEnableTagOverride; @@ -101,7 +111,7 @@ public function __construct( $this->ModifyIndex = $ModifyIndex; $this->Namespace = $Namespace; $this->Partition = $Partition; -} + } public function getID(): string { @@ -147,28 +157,6 @@ public function setDatacenter(string $Datacenter): self return $this; } - public function getTaggedAddresses(): null|\stdClass - { - return $this->TaggedAddresses; - } - - public function setTaggedAddresses(null|\stdClass $TaggedAddresses): self - { - $this->TaggedAddresses = $TaggedAddresses; - return $this; - } - - public function getNodeMeta(): \stdClass - { - return $this->NodeMeta; - } - - public function setNodeMeta(null|\stdClass $NodeMeta): self - { - $this->NodeMeta = $NodeMeta; - return $this; - } - public function getServiceID(): string { return $this->ServiceID; @@ -202,30 +190,41 @@ public function setServiceAddress(string $ServiceAddress): self return $this; } - public function getServiceTaggedAddresses(): \stdClass + /** + * @return array|null + */ + public function getServiceTaggedAddresses(): null|array + { + return $this->ServiceTaggedAddresses ?? null; + } + + public function setServiceTaggedAddress(string $Tag, ServiceAddress $ServiceAddress): self { - return $this->ServiceTaggedAddresses; + if (!isset($this->ServiceTaggedAddresses)) { + $this->ServiceTaggedAddresses = []; + } + $this->ServiceTaggedAddresses[$Tag] = $ServiceAddress; + return $this; } - public function setServiceTaggedAddresses(null|\stdClass $ServiceTaggedAddresses): self + /** + * @param array|null $ServiceTaggedAddresses + */ + public function setServiceTaggedAddresses(null|array $ServiceTaggedAddresses): self { if (null === $ServiceTaggedAddresses) { - $this->ServiceTaggedAddresses = null; + unset($this->TaggedAddresses); return $this; } - $this->ServiceTaggedAddresses = new \stdClass(); + $this->TaggedAddresses = []; foreach ($ServiceTaggedAddresses as $k => $v) { - if ($v instanceof ServiceAddress) { - $this->ServiceTaggedAddresses->{$k} = $v; - } else { - $this->ServiceTaggedAddresses->{$k} = ServiceAddress::jsonUnserialize((object)$v); - } + $this->setServiceTaggedAddress($k, $v); } return $this; } /** - * @return string[] + * @return array */ public function getServiceTags(): array { @@ -238,17 +237,6 @@ public function setServiceTags(string ...$ServiceTags): self return $this; } - public function getServiceMeta(): \stdClass - { - return $this->ServiceMeta; - } - - public function setServiceMeta(null|\stdClass $ServiceMeta): self - { - $this->ServiceMeta = $ServiceMeta; - return $this; - } - public function getServicePort(): int { return $this->ServicePort; @@ -368,7 +356,9 @@ public static function jsonUnserialize(\stdClass $decoded): self } elseif ('NodeMeta' === $k) { $n->setnodemeta($v); } elseif ('ServiceTaggedAddresses' === $k) { - $n->setservicetaggedaddresses($v); + foreach ($v as $kk => $vv) { + $n->setServiceTaggedAddress($kk, ServiceAddress::jsonUnserialize($vv)); + } } elseif ('Weights' === $k) { $n->ServiceWeights = Weights::jsonUnserialize($v); } elseif ('ServiceProxy' === $k) { @@ -383,6 +373,8 @@ public static function jsonUnserialize(\stdClass $decoded): self if (null !== $v) { $n->Checks = HealthChecks::jsonUnserialize($v); } + } elseif ('ServiceMeta' === $k) { + $n->setServiceMeta($v); } else { $n->{$k} = $v; } @@ -397,14 +389,14 @@ public function jsonSerialize(): \stdClass $out->Node = $this->Node; $out->Address = $this->Address; $out->Datacenter = $this->Datacenter; - $out->TaggedAddresses = $this->TaggedAddresses; - $out->NodeMeta = $this->NodeMeta; + $out->TaggedAddresses = $this->getTaggedAddresses(); + $out->NodeMeta = $this->getNodeMeta(); $out->ServiceID = $this->ServiceID; $out->ServiceName = $this->ServiceName; $out->ServiceAddress = $this->ServiceAddress; - $out->ServiceTaggedAddresses = $this->ServiceTaggedAddresses; + $out->ServiceTaggedAddresses = $this->getServiceTaggedAddresses(); $out->ServiceTags = $this->ServiceTags; - $out->ServiceMeta = $this->ServiceMeta; + $out->ServiceMeta = $this->getServiceMeta(); $out->ServicePort = $this->ServicePort; $out->ServiceWeights = $this->ServiceWeights; $out->ServiceEnableTagOverride = $this->ServiceEnableTagOverride; diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index 47499562..f4c88432 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -32,12 +32,11 @@ public function __construct( string $Name = '', string $Namespace = '', string $Partition = '', - ) - { + ) { $this->Name = $Name; $this->Namespace = $Namespace; $this->Partition = $Partition; -} + } public function getName(): string { diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 3773cbc6..11d87a24 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -39,7 +39,6 @@ class GatewayService extends AbstractModel public string $FromWildCard; public function __construct( - null|array $data = [], // Deprecated, will be removed. null|CompoundServiceName $Gateway = null, null|CompoundServiceName $Service = null, string|ServiceKind $GatewayKind = '', @@ -51,8 +50,7 @@ public function __construct( 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); @@ -64,7 +62,7 @@ public function __construct( $this->KeyFile = $KeyFile; $this->SNI = $SNI; $this->FromWildCard = $FromWildCard; -} + } public function getGateway(): CompoundServiceName { @@ -196,11 +194,11 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($decoded as $k => $v) { if ('Gateway' === $k) { $n->Gateway = CompoundServiceName::jsonUnserialize($v); - } else if ('Service' === $k) { + } elseif ('Service' === $k) { $n->Service = CompoundServiceName::jsonUnserialize($v); - } else if ('GatewayKind' === $k) { + } elseif ('GatewayKind' === $k) { $n->GatewayKind = ServiceKind::from($v); - } else if ('Hosts' === $k) { + } elseif ('Hosts' === $k) { $n->setHosts(...$v); } else { $n->{$k} = $v; diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index 7cdfecd2..b5a092f7 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -23,17 +23,17 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\MetaContainer; use DCarbone\PHPConsulAPI\Peering\Locality; +use DCarbone\PHPConsulAPI\TaggedAddressContainer; class Node extends AbstractModel { use MetaContainer; + use TaggedAddressContainer; public string $ID; public string $Node; public string $Address; public string $Datacenter; - /** @var array */ - public array $TaggedAddresses; public int $CreateIndex; public int $ModifyIndex; public string $Partition; @@ -41,16 +41,16 @@ class Node extends AbstractModel public null|Locality $Locality; /** - * @param \stdClass|array|null $TaggedAddresses - * @param \stdClass|array|null $Meta + * @param array $TaggedAddresses + * @param array $Meta */ public function __construct( string $ID = '', string $Node = '', string $Address = '', string $Datacenter = '', - null|\stdClass|array $TaggedAddresses = null, - null|\stdClass|array $Meta = null, + array $TaggedAddresses = [], + array $Meta = [], int $CreateIndex = 0, int $ModifyIndex = 0, string $Partition = '', @@ -114,31 +114,6 @@ public function setDatacenter(string $Datacenter): self return $this; } - /** - * @return array|null - */ - public function getTaggedAddresses(): null|array - { - return $this->TaggedAddresses; - } - - /** - * @param \stdClass|array|null $TaggedAddresses - * @return $this - */ - public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self - { - if (null === $TaggedAddresses) { - unset($this->TaggedAddresses); - return $this; - } - $this->TaggedAddresses = []; - foreach ($TaggedAddresses as $k => $v) { - $this->TaggedAddresses[$k] = $v; - } - return $this; - } - public function getCreateIndex(): int { return $this->CreateIndex; diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index a204bdc7..c6184f90 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -27,16 +27,11 @@ class ServiceAddress extends AbstractModel public string $Address; public int $Port; - /** - * @param array|null $data - */ - public function __construct( - string $address = '', - int $port = 0, - ) { + public function __construct(string $address = '', int $port = 0) + { $this->Address = $address; $this->Port = $port; -} + } public function getAddress(): string { diff --git a/src/Catalog/Weights.php b/src/Catalog/Weights.php index 58fbfb52..452e92d3 100644 --- a/src/Catalog/Weights.php +++ b/src/Catalog/Weights.php @@ -27,16 +27,11 @@ class Weights extends AbstractModel public int $Passing; public int $Warning; - /** - * @param array|null $data - */ - public function __construct( - int $Passing = 0, - int $Warning = 0 - ) { + public function __construct(int $Passing = 0, int $Warning = 0) + { $this->Passing = $Passing; $this->Warning = $Warning; -} + } public function getPassing(): int { diff --git a/src/MetaContainer.php b/src/MetaContainer.php index c00214ff..20e6524c 100644 --- a/src/MetaContainer.php +++ b/src/MetaContainer.php @@ -33,9 +33,17 @@ public function getMeta(): null|array return $this->Meta ?? null; } + public function setMetaValue(string $k, string $v): self + { + if (!isset($this->Meta)) { + $this->Meta = []; + } + $this->Meta[$k] = $v; + return $this; + } + /** * @param null|\stdClass|array $Meta - * @return self */ public function setMeta(null|\stdClass|array $Meta): self { @@ -45,7 +53,7 @@ public function setMeta(null|\stdClass|array $Meta): self } $this->Meta = []; foreach ($Meta as $k => $v) { - $this->Meta[$k] = $v; + $this->setMetaValue($k, $v); } return $this; } diff --git a/src/NodeMetaContainer.php b/src/NodeMetaContainer.php new file mode 100644 index 00000000..8467496d --- /dev/null +++ b/src/NodeMetaContainer.php @@ -0,0 +1,61 @@ + */ + public array $NodeMeta; + + /** + * @return null|array + */ + public function getNodeMeta(): null|array + { + return $this->NodeMeta ?? null; + } + + public function setNodeMetaValue(string $k, string $v): self + { + if (!isset($this->NodeMeta)) { + $this->NodeMeta = []; + } + $this->NodeMeta[$k] = $v; + return $this; + } + + /** + * @param \stdClass|array|null $NodeMeta + * @return $this + */ + public function setNodeMeta(null|\stdClass|array $NodeMeta): self + { + if (null === $NodeMeta) { + unset($this->NodeMeta); + return $this; + } + $this->NodeMeta = []; + foreach ($NodeMeta as $k => $v) { + $this->setNodeMetaValue($k, $v); + } + return $this; + } +} diff --git a/src/ServiceMetaContainer.php b/src/ServiceMetaContainer.php new file mode 100644 index 00000000..d2e7f1a4 --- /dev/null +++ b/src/ServiceMetaContainer.php @@ -0,0 +1,60 @@ + */ + public array $ServiceMeta; + + /** + * @return null|array + */ + public function getServiceMeta(): null|array + { + return $this->ServiceMeta ?? null; + } + + public function setServiceMetaValue(string $k, string $v): self + { + if (!isset($this->ServiceMeta)) { + $this->ServiceMeta = []; + } + $this->ServiceMeta[$k] = $v; + return $this; + } + + /** + * @param \stdClass|array|null $ServiceMeta + */ + public function setServiceMeta(null|\stdClass|array $ServiceMeta): self + { + if (null === $ServiceMeta) { + unset($this->ServiceMeta); + return $this; + } + $this->ServiceMeta = []; + foreach ($ServiceMeta as $k => $v) { + $this->setServiceMetaValue($k, $v); + } + return $this; + } +} diff --git a/src/TaggedAddressContainer.php b/src/TaggedAddressContainer.php new file mode 100644 index 00000000..328badb7 --- /dev/null +++ b/src/TaggedAddressContainer.php @@ -0,0 +1,60 @@ + */ + public array $TaggedAddresses; + + /** + * @return null|array + */ + public function getTaggedAddresses(): null|array + { + return $this->TaggedAddresses ?? null; + } + + public function setTaggedAddress(string $k, string $v): self + { + if (!isset($this->TaggedAddresses)) { + $this->TaggedAddresses = []; + } + $this->TaggedAddresses[$k] = $v; + return $this; + } + + /** + * @param \stdClass|array|null $TaggedAddresses + */ + public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self + { + if (null === $TaggedAddresses) { + unset($this->TaggedAddresses); + return $this; + } + $this->TaggedAddresses = []; + foreach ($TaggedAddresses as $k => $v) { + $this->setTaggedAddress($k, $v); + } + return $this; + } +} From d344914bd90cc4f2acf26792ad8851c9c2529e57 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Wed, 1 Oct 2025 21:23:34 -0500 Subject: [PATCH 77/79] more work, kinda sideways --- src/Agent/AgentService.php | 8 +-- src/Agent/AgentServiceCheck.php | 4 +- src/Agent/AgentServiceConnectProxyConfig.php | 5 +- src/Agent/AgentServiceRegistration.php | 28 +++++--- src/Agent/ConnectProxyConfig.php | 4 +- src/Agent/GaugeValue.php | 4 +- src/Agent/SampledValue.php | 4 +- src/Agent/Upstream.php | 4 +- src/ConfigEntry/EnvoyExtension.php | 47 +++++++++--- src/ConfigEntry/GatewayServiceTLSConfig.php | 5 +- src/ConfigEntry/HTTPHeaderModifiers.php | 32 +++++---- src/ConfigEntry/IngressGatewayConfigEntry.php | 4 +- src/ConfigEntry/LeastRequestConfig.php | 5 +- src/ConfigEntry/MeshConfigEntry.php | 4 +- src/ConfigEntry/ProxyConfigEntry.php | 8 +-- src/ConfigEntry/ServiceConfigEntry.php | 4 +- .../ServiceIntentionsConfigEntry.php | 4 +- .../ServiceResolverConfigEntry.php | 58 +++++++-------- src/ConfigEntry/ServiceRouterConfigEntry.php | 4 +- src/Event/UserEvent.php | 2 +- src/MetaContainer.php | 7 +- src/NodeMetaContainer.php | 8 +-- src/QueryOptions.php | 71 +++++++++++-------- src/TaggedAddressContainer.php | 3 +- src/funcs.php | 2 +- 25 files changed, 189 insertions(+), 140 deletions(-) diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 06d78cb7..2108e587 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -53,8 +53,8 @@ class AgentService extends AbstractModel /** * @param array $Tags - * @param null|\stdClass|array $Meta - * @param null|\stdClass|array $TaggedAddresses + * @param array $Meta + * @param array $TaggedAddresses */ public function __construct( string|ServiceKind $Kind = '', @@ -62,10 +62,10 @@ public function __construct( string $Service = '', string $SocketPath = '', array $Tags = [], - null|\stdClass|array $Meta = null, + array $Meta = [], int $Port = 0, string $Address = '', - null|\stdClass|array $TaggedAddresses = null, + array $TaggedAddresses = [], null|AgentWeights $Weights = null, bool $EnableTagOverride = false, int $CreateIndex = 0, diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 5a75a08e..9123dc9f 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -53,7 +53,7 @@ class AgentServiceCheck extends AbstractModel /** * @param array $Args - * @param null|\stdClass|array>|\DCarbone\PHPConsulAPI\Values $Header + * @param null|array>|\DCarbone\PHPConsulAPI\Values $Header */ public function __construct( string $CheckID = '', @@ -65,7 +65,7 @@ public function __construct( string $Timeout = '', string $TTL = '', string $HTTP = '', - null|array|\stdClass|Values $Header = null, + null|array|Values $Header = null, string $Method = '', string $TCP = '', string $Status = '', diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index e7258dce..98cdd27e 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -39,6 +39,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel public string $LocalServiceSocketPath; public ProxyMode $Mode; public null|TransparentProxyConfig $TransparentProxy; + /** @var array */ public array $Config; /** @var \DCarbone\PHPConsulAPI\Agent\Upstream[] */ public array $Upstreams; @@ -48,7 +49,7 @@ class AgentServiceConnectProxyConfig extends AbstractModel /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions - * @param null|\stdClass|array $Config + * @param array $Config * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams */ public function __construct( @@ -60,7 +61,7 @@ public function __construct( string $LocalServiceSocketPath = '', string|ProxyMode $Mode = ProxyMode::Default, null|TransparentProxyConfig $TransparentProxy = null, - null|\stdClass|array $Config = null, + array $Config = [], iterable $Upstreams = [], null|MeshGatewayConfig $MeshGateway = null, null|ExposeConfig $Expose = null, diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index cdd404aa..24b6f0f6 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -50,8 +50,8 @@ class AgentServiceRegistration extends AbstractModel /** * @param array $Tags - * @param null|\stdClass|array $TaggedAddresses - * @param null|\stdClass|array $Meta + * @param array $TaggedAddresses + * @param array $Meta */ public function __construct( string|ServiceKind $Kind = ServiceKind::Typical, @@ -60,9 +60,9 @@ public function __construct( array $Tags = [], int $Port = 0, string $Address = '', - null|\stdClass|array $TaggedAddresses = null, + array $TaggedAddresses = [], bool $EnableTagOverride = false, - null|\stdClass|array $Meta = null, + array $Meta = [], null|AgentWeights $Weights = null, null|AgentServiceCheck $Check = null, null|AgentServiceChecks $Checks = null, @@ -168,11 +168,20 @@ public function getTaggedAddresses(): null|array return $this->TaggedAddresses ?? null; } + public function setTaggedAddress(string $Tag, ServiceAddress $Address): self + { + if (!isset($this->TaggedAddresses)) { + $this->TaggedAddresses = []; + } + $this->TaggedAddresses[$Tag] = $Address; + return $this; + } + /** - * @param \stdClass|array|null $TaggedAddresses + * @param array|null $TaggedAddresses * @return $this */ - public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self + public function setTaggedAddresses(null|array $TaggedAddresses): self { if (null === $TaggedAddresses) { unset($this->TaggedAddresses); @@ -180,7 +189,7 @@ public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self } $this->TaggedAddresses = []; foreach ($TaggedAddresses as $k => $v) { - $this->TaggedAddresses[$k] = $v; + $this->setTaggedAddress($k, $v); } return $this; } @@ -293,7 +302,10 @@ public static function jsonUnserialize(\stdClass $decoded): self } elseif ('Tags' === $k) { $n->setTags(...$v); } elseif ('TaggedAddresses' === $k) { - $n->setTaggedAddresses($v); + $n->TaggedAddresses = []; + foreach ($v as $kk => $vv) { + $n->TaggedAddresses[$kk] = ServiceAddress::jsonUnserialize($vv); + } } elseif ('Weights' === $k) { $n->Weights = AgentWeights::jsonUnserialize($v); } elseif ('Check' === $k) { diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php index 366374c3..71338e66 100644 --- a/src/Agent/ConnectProxyConfig.php +++ b/src/Agent/ConnectProxyConfig.php @@ -34,7 +34,7 @@ class ConnectProxyConfig extends AbstractModel public array $Upstreams; /** - * @param array|\stdClass|null $Config + * @param array $Config * @param array<\DCarbone\PHPConsulAPI\Agent\Upstream> $Upstreams */ public function __construct( @@ -42,7 +42,7 @@ public function __construct( string $TargetServiceID = '', string $TargetServiceName = '', string $ContentHash = '', - null|\stdClass|array $Config = null, + array $Config = [], array $Upstreams = [], ) { $this->ProxyServiceID = $ProxyServiceID; diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index 765e55b0..f5bdad93 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -30,12 +30,12 @@ class GaugeValue extends AbstractModel public array $Labels; /** - * @param array|\stdClass|null $Labels + * @param array $Labels */ public function __construct( string $Name = '', float $Value = 0.0, - null|\stdClass|array $Labels = null, + array $Labels = [], ) { $this->Name = $Name; $this->Value = $Value; diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index e9b66663..db09c0b9 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -35,7 +35,7 @@ class SampledValue extends AbstractModel public array $Labels; /** - * @param \stdClass|array|null $Labels + * @param array $Labels */ public function __construct( string $Name = '', @@ -45,7 +45,7 @@ public function __construct( float $Max = 0.0, float $Mean = 0.0, float $Stddev = 0.0, - null|\stdClass|array $Labels = null, + array $Labels = [], ) { $this->Name = $Name; $this->Count = $Count; diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index c13b8e4c..7cd3744a 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -41,7 +41,7 @@ class Upstream extends AbstractModel public bool $CentrallyConfigured; /** - * @param \stdClass|array|null $Config + * @param array $Config */ public function __construct( string|UpstreamDestType $DestinationType = UpstreamDestType::UNDEFINED, @@ -54,7 +54,7 @@ public function __construct( int $LocalBindPort = 0, string $LocalBindSocketPath = '', string $LocalBindSocketMode = '', - null|\stdClass|array $Config = null, + array $Config = [], null|MeshGatewayConfig $MeshGateway = null, bool $CentrallyConfigured = false, ) { diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 4d7a17db..002bb8e4 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -26,23 +26,24 @@ class EnvoyExtension extends AbstractModel { public string $Name; public bool $Required; - public null|\stdClass $Arguments; + /** @var array */ + public array $Arguments; public string $ConsulVersion; public string $EnvoyVersion; /** - * @param array|null $data + * @param array $Arguments */ public function __construct( string $Name = '', bool $Required = false, - null|\stdClass $Arguments = null, + array $Arguments = [], string $ConsulVersion = '', string $EnvoyVersion = '', ) { $this->Name = $Name; $this->Required = $Required; - $this->Arguments = $Arguments; + $this->setArguments($Arguments); $this->ConsulVersion = $ConsulVersion; $this->EnvoyVersion = $EnvoyVersion; } @@ -69,14 +70,36 @@ public function setRequired(bool $Required): self return $this; } - public function getArguments(): null|\stdClass + /** + * @return null|array + */ + public function getArguments(): null|array { - return $this->Arguments; + return $this->Arguments ?? null; } - public function setArguments(null|\stdClass $Arguments): self + public function setArgument(string $k, mixed $v): self { - $this->Arguments = $Arguments; + if (!isset($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) { + unset($this->Arguments); + return $this; + } + $this->Arguments = []; + foreach ($Arguments as $k => $v) { + $this->setArgument($k, $v); + } return $this; } @@ -106,7 +129,11 @@ public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { - $n->{$k} = $v; + if ('Arguments' === $k) { + $n->setArguments($v); + } else { + $n->{$k} = $v; + } } return $n; } @@ -116,7 +143,7 @@ public function jsonSerialize(): \stdClass $out = $this->_startJsonSerialize(); $out->Name = $this->Name; $out->Required = $this->Required; - $out->Arguments = $this->Arguments; + $out->Arguments = $this->getArguments(); $out->ConsulVersion = $this->ConsulVersion; $out->EnvoyVersion = $this->EnvoyVersion; return $out; diff --git a/src/ConfigEntry/GatewayServiceTLSConfig.php b/src/ConfigEntry/GatewayServiceTLSConfig.php index d334c1e6..e9de413b 100644 --- a/src/ConfigEntry/GatewayServiceTLSConfig.php +++ b/src/ConfigEntry/GatewayServiceTLSConfig.php @@ -57,10 +57,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (null !== $this->SDS) { $out->SDS = $this->SDS->jsonSerialize(); } diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php index 6bd361cf..887e1dbd 100644 --- a/src/ConfigEntry/HTTPHeaderModifiers.php +++ b/src/ConfigEntry/HTTPHeaderModifiers.php @@ -37,8 +37,8 @@ class HTTPHeaderModifiers extends AbstractModel * @param array $Remove */ public function __construct( - null|array|\stdClass $Add = null, - null|array|\stdClass $Set = null, + array $Add = [], + array $Set = [], array $Remove = [] ) { $this->setAdd($Add); @@ -56,15 +56,16 @@ public function getAdd(): array /** * @param null|\stdClass|array $Add - * @return $this */ public function setAdd(null|\stdClass|array $Add): self { + if (null === $Add) { + unset($this->Add); + return $this; + } $this->Add = []; - if (null !== $Add) { - foreach ($Add as $k => $v) { - $this->Add[$k] = $v; - } + foreach ($Add as $k => $v) { + $this->Add[$k] = $v; } return $this; } @@ -79,15 +80,16 @@ public function getSet(): array /** * @param null|\stdClass|array $Set - * @return $this */ public function setSet(null|\stdClass|array $Set): self { + if (null === $Set) { + unset($this->Set); + return $this; + } $this->Set = []; - if (null !== $Set) { - foreach ($Set as $k => $v) { - $this->Set[$k] = $v; - } + foreach ($Set as $k => $v) { + $this->Set[$k] = $v; } return $this; } @@ -114,6 +116,8 @@ public static function jsonUnserialize(\stdClass $decoded): self $n->setSet($v); } elseif ('Add' === $k) { $n->setAdd($v); + } elseif ('Remove' === $k) { + $n->setRemove(...$v); } else { $n->{$k} = $v; } @@ -124,10 +128,10 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { $out = $this->_startJsonSerialize(); - if ([] !== $this->Add) { + if (isset($this->Add)) { $out->Add = $this->Add; } - if ([] !== $this->Set) { + if (isset($this->Set)) { $out->Set = $this->Set; } if ([] !== $this->Remove) { diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index 09971213..49f16994 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -36,7 +36,7 @@ class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\IngressListener> $Listeners - * @param null|\stdClass|array $Meta + * @param array $Meta */ public function __construct( string $Kind = '', @@ -45,7 +45,7 @@ public function __construct( string $Namespace = '', null|GatewayTLSConfig $TLS = null, array $Listeners = [], - null|\stdClass|array $Meta = null, + array $Meta = [], null|IngressServiceConfig $Defaults = null, int $CreateIndex = 0, int $ModifyIndex = 0, diff --git a/src/ConfigEntry/LeastRequestConfig.php b/src/ConfigEntry/LeastRequestConfig.php index 9484b8dc..a9d55f4b 100644 --- a/src/ConfigEntry/LeastRequestConfig.php +++ b/src/ConfigEntry/LeastRequestConfig.php @@ -57,10 +57,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new \stdClass(); - foreach($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); if (0 !== $this->ChoiceCount) { $out->ChoiceCount = $this->ChoiceCount; } diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index 0f026444..b05a8743 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -35,7 +35,7 @@ class MeshConfigEntry extends AbstractModel implements ConfigEntry public null|PeeringMeshConfig $Peering; /** - * @param \stdClass|array|null $Meta + * @param array $Meta */ public function __construct( string $Partition = '', @@ -45,7 +45,7 @@ public function __construct( null|MeshTLSConfig $TLS = null, null|MeshHTTPConfig $HTTP = null, null|PeeringMeshConfig $Peering = null, - null|\stdClass|array $Meta = null, + array $Meta = [], int $CreateIndex = 0, int $ModifyIndex = 0 ) { diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index 7b45a48b..59316869 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -46,9 +46,9 @@ class ProxyConfigEntry extends AbstractModel implements ConfigEntry public null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality; /** - * @param null|\stdClass|array $Config + * @param array $Config * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> $EnvoyExtensions - * @param null|\stdClass|array $Meta + * @param array $Meta */ public function __construct( string $Kind = '', @@ -57,7 +57,7 @@ public function __construct( string|ProxyMode $Mode = ProxyMode::Default, null|TransparentProxyConfig $TransparentProxy = null, string|MutualTLSMode $MutualTLSMode = MutualTLSMode::Default, - null|\stdClass|array $Config = null, + array $Config = [], null|MeshGatewayConfig $MeshGateway = null, null|ExposeConfig $Expose = null, null|AccessLogsConfig $AccessLogs = null, @@ -65,7 +65,7 @@ public function __construct( null|ServiceResolverFailoverPolicy $FailoverPolicy = null, null|ServiceResolverPrioritizeByLocality $PrioritizeByLocality = null, string $Namespace = '', - null|\stdClass|array $Meta = null, + array $Meta = [], int $CreateIndex = 0, int $ModifyIndex = 0, ) { diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index e0f41c0e..0b449552 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -73,7 +73,7 @@ public function __construct( string $BalanceInboundConnections = '', null|RateLimits $RateLimits = null, array $EnvoyExtensions = [], - null|\stdClass|array $Meta = null, + array $Meta = [], int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -336,6 +336,8 @@ public static function jsonUnserialize(\stdClass $decoded): self foreach ($v as $ext) { $n->EnvoyExtensions[] = EnvoyExtension::jsonUnserialize($ext); } + } elseif ('Meta' === $k) { + $n->setMeta($v); } else { $n->{$k} = $v; } diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php index 05c7a566..4f0b34bb 100644 --- a/src/ConfigEntry/ServiceIntentionsConfigEntry.php +++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php @@ -36,7 +36,7 @@ class ServiceIntentionsConfigEntry extends AbstractModel implements ConfigEntry /** * @param array $Sources - * @param null|\stdClass|array $Meta + * @param array $Meta */ public function __construct( string $Kind = '', @@ -45,7 +45,7 @@ public function __construct( string $Namespace = '', array $Sources = [], null|IntentionJWTRequirement $JWT = null, - null|\stdClass|array $Meta = null, + array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index e031b0cc..fd895dee 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -45,9 +45,9 @@ class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry public null|LoadBalancer $LoadBalancer; /** - * @param null|\stdClass|array $Subsets - * @param null|\stdClass|array $Failover - * @param null|\stdClass|array $Meta + * @param null|array $Subsets + * @param null|array $Failover + * @param null|array $Meta */ public function __construct( string $Kind = '', @@ -55,14 +55,14 @@ public function __construct( string $Partition = '', string $Namespace = '', string $DefaultSubnet = '', - null|\stdClass|array $Subsets = null, + null|array $Subsets = null, null|ServiceResolverRedirect $Redirect = null, - null|\stdClass|array $Failover = 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|\stdClass|array $Meta = null, + null|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { @@ -138,21 +138,24 @@ public function getSubsets(): array public function setSubsetKey(string $key, ServiceResolverSubset $subset): self { + if (!isset($this->Subsets)) { + $this->Subsets = []; + } $this->Subsets[$key] = $subset; return $this; } /** - * @param null|\stdClass|array $Subsets - * @return $this + * @param null|array $Subsets */ - public function setSubsets(null|\stdClass|array $Subsets): self + public function setSubsets(null|array $Subsets): self { - $this->Subsets = []; - if (null !== $Subsets) { - foreach ($Subsets as $k => $v) { - $this->setSubsetKey($k, $v); - } + unset($this->Subsets); + if (null === $Subsets) { + return $this; + } + foreach ($Subsets as $k => $v) { + $this->setSubsetKey($k, $v); } return $this; } @@ -183,16 +186,16 @@ public function setFailoverKey(string $key, ServiceResolverFailover $failover): } /** - * @param null|\stdClass|array $Failover - * @return $this + * @param null|array $Failover */ - public function setFailover(null|\stdClass|array $Failover): self + public function setFailover(null|array $Failover): self { - $this->Failover = []; - if (null !== $Failover) { - foreach ($Failover as $k => $v) { - $this->setFailoverKey($k, $v); - } + unset($this->Failover); + if (null === $Failover) { + return $this; + } + foreach ($Failover as $k => $v) { + $this->setFailoverKey($k, $v); } return $this; } @@ -276,10 +279,7 @@ public static function jsonUnserialize(\stdClass $decoded): self public function jsonSerialize(): \stdClass { - $out = new stdClass(); - foreach ($this->_getDynamicFields() as $k => $v) { - $out->{$k} = $v; - } + $out = $this->_startJsonSerialize(); $out->Kind = $this->Kind; $out->Name = $this->Name; if ('' !== $this->Partition) { @@ -291,13 +291,13 @@ public function jsonSerialize(): \stdClass if ('' !== $this->DefaultSubset) { $out->DefaultSubset = $this->DefaultSubset; } - if ([] !== $this->Subsets) { + if (isset($this->Subsets)) { $out->Subsets = $this->Subsets; } if (null !== $this->Redirect) { $out->Redirect = $this->Redirect; } - if ([] !== $this->Failover) { + if (isset($this->Failover)) { $out->Failover = $this->Failover; } if (0 !== $this->ConnectTimeout->Nanoseconds()) { @@ -312,7 +312,7 @@ public function jsonSerialize(): \stdClass if (null !== $this->LoadBalancer) { $out->LoadBalancer = $this->LoadBalancer; } - if ([] !== $this->Meta) { + if (isset($this->Meta)) { $out->Meta = $this->Meta; } $out->CreateIndex = $this->CreateIndex; diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 4c79c22e..6e27cbe5 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -34,7 +34,7 @@ class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry /** * @param array<\DCarbone\PHPConsulAPI\ConfigEntry\ServiceRoute> $Routes - * @param null|\stdClass|array $Meta + * @param null|array $Meta */ public function __construct( string $Kind = '', @@ -42,7 +42,7 @@ public function __construct( string $Partition = '', string $Namespace = '', array $Routes = [], - null|\stdClass|array $Meta = null, + null|array $Meta = null, int $CreateIndex = 0, int $ModifyIndex = 0, ) { diff --git a/src/Event/UserEvent.php b/src/Event/UserEvent.php index 1035527b..169f681a 100644 --- a/src/Event/UserEvent.php +++ b/src/Event/UserEvent.php @@ -93,7 +93,7 @@ public function getLTime(): int return $this->LTime; } - public static function jsonUnserialize(\stdclass $decoded): self + public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); foreach ($decoded as $k => $v) { diff --git a/src/MetaContainer.php b/src/MetaContainer.php index 20e6524c..12fc24ad 100644 --- a/src/MetaContainer.php +++ b/src/MetaContainer.php @@ -33,7 +33,7 @@ public function getMeta(): null|array return $this->Meta ?? null; } - public function setMetaValue(string $k, string $v): self + public function setMetaKey(string $k, string $v): self { if (!isset($this->Meta)) { $this->Meta = []; @@ -47,13 +47,12 @@ public function setMetaValue(string $k, string $v): self */ public function setMeta(null|\stdClass|array $Meta): self { + unset($this->Meta); if (null === $Meta) { - unset($this->Meta); return $this; } - $this->Meta = []; foreach ($Meta as $k => $v) { - $this->setMetaValue($k, $v); + $this->setMetaKey($k, $v); } return $this; } diff --git a/src/NodeMetaContainer.php b/src/NodeMetaContainer.php index 8467496d..c4a8e17a 100644 --- a/src/NodeMetaContainer.php +++ b/src/NodeMetaContainer.php @@ -33,7 +33,7 @@ public function getNodeMeta(): null|array return $this->NodeMeta ?? null; } - public function setNodeMetaValue(string $k, string $v): self + public function setNodeMetaKey(string $k, string $v): self { if (!isset($this->NodeMeta)) { $this->NodeMeta = []; @@ -44,17 +44,15 @@ public function setNodeMetaValue(string $k, string $v): self /** * @param \stdClass|array|null $NodeMeta - * @return $this */ public function setNodeMeta(null|\stdClass|array $NodeMeta): self { + unset($this->NodeMeta); if (null === $NodeMeta) { - unset($this->NodeMeta); return $this; } - $this->NodeMeta = []; foreach ($NodeMeta as $k => $v) { - $this->setNodeMetaValue($k, $v); + $this->setNodeMetaKey($k, $v); } return $this; } diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 62576cb0..92ecc7c6 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -48,7 +48,7 @@ class QueryOptions implements RequestOptions public bool $Pretty; /** - * @param null|\stdClass|array $NodeMeta + * @param array $NodeMeta */ public function __construct( string $Namespace = '', @@ -64,7 +64,7 @@ public function __construct( string $Token = '', string $Near = '', string $Filter = '', - null|\stdClass|array $NodeMeta = null, + array $NodeMeta = [], int $RelayFactor = 0, bool $LocalOnly = false, bool $Connect = false, @@ -97,9 +97,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 getDatacenter(): string @@ -107,9 +108,10 @@ public function getDatacenter(): string return $this->Datacenter; } - public function setDatacenter(string $datacenter): void + public function setDatacenter(string $datacenter): self { $this->Datacenter = $datacenter; + return $this; } public function isAllowStale(): bool @@ -117,9 +119,10 @@ public function isAllowStale(): bool return $this->AllowStale; } - public function setAllowStale(bool $allowStale): void + public function setAllowStale(bool $allowStale): self { $this->AllowStale = $allowStale; + return $this; } public function isRequireConsistent(): bool @@ -127,9 +130,10 @@ public function isRequireConsistent(): bool return $this->RequireConsistent; } - public function setRequireConsistent(bool $requireConsistent): void + public function setRequireConsistent(bool $requireConsistent): self { $this->RequireConsistent = $requireConsistent; + return $this; } public function isUseCache(): bool @@ -137,9 +141,10 @@ public function isUseCache(): bool return $this->UseCache; } - public function setUseCache(bool $useCache): void + public function setUseCache(bool $useCache): self { $this->UseCache = $useCache; + return $this; } public function getMaxAge(): Time\Duration @@ -147,9 +152,10 @@ public function getMaxAge(): Time\Duration return $this->MaxAge; } - public function setMaxAge(null|int|float|string|\DateInterval|Time\Duration $maxAge): void + public function setMaxAge(null|int|float|string|\DateInterval|Time\Duration $maxAge): self { $this->MaxAge = Time::Duration($maxAge); + return $this; } public function getStaleIfError(): Time\Duration @@ -157,9 +163,10 @@ public function getStaleIfError(): Time\Duration return $this->StaleIfError; } - public function setStaleIfError(null|int|float|string|\DateInterval|Time\Duration $staleIfError): void + public function setStaleIfError(null|int|float|string|\DateInterval|Time\Duration $staleIfError): self { $this->StaleIfError = Time::Duration($staleIfError); + return $this; } public function getWaitIndex(): int @@ -167,9 +174,10 @@ public function getWaitIndex(): int return $this->WaitIndex; } - public function setWaitIndex(int $waitIndex): void + public function setWaitIndex(int $waitIndex): self { $this->WaitIndex = $waitIndex; + return $this; } public function getWaitTime(): Time\Duration @@ -177,9 +185,10 @@ public function getWaitTime(): Time\Duration return $this->WaitTime; } - public function setWaitTime(null|int|float|string|\DateInterval|Time\Duration $waitTime): void + public function setWaitTime(null|int|float|string|\DateInterval|Time\Duration $waitTime): self { $this->WaitTime = Time::Duration($waitTime); + return $this; } public function getWaitHash(): string @@ -187,9 +196,10 @@ public function getWaitHash(): string return $this->WaitHash; } - public function setWaitHash(string $waitHash): void + public function setWaitHash(string $waitHash): self { $this->WaitHash = $waitHash; + return $this; } public function getToken(): string @@ -197,9 +207,10 @@ public function getToken(): string return $this->Token; } - public function setToken(string $token): void + public function setToken(string $token): self { $this->Token = $token; + return $this; } public function getNear(): string @@ -207,9 +218,10 @@ public function getNear(): string return $this->Near; } - public function setNear(string $near): void + public function setNear(string $near): self { $this->Near = $near; + return $this; } public function getFilter(): string @@ -217,9 +229,10 @@ public function getFilter(): string return $this->Filter; } - public function setFilter(string $filter): void + public function setFilter(string $filter): self { $this->Filter = $filter; + return $this; } /** @@ -231,17 +244,12 @@ public function getNodeMeta(): array } /** - * @param null|\stdClass|array $nodeMeta - * @return void + * @param array $nodeMeta */ - public function setNodeMeta(null|\stdClass|array $nodeMeta): void + public function setNodeMeta(array $nodeMeta): self { - $this->NodeMeta = []; - if (null !== $nodeMeta) { - foreach ($nodeMeta as $k => $v) { - $this->NodeMeta[$k] = $v; - } - } + $this->NodeMeta = $nodeMeta; + return $this; } public function getRelayFactor(): int @@ -249,9 +257,10 @@ public function getRelayFactor(): int return $this->RelayFactor; } - public function setRelayFactor(int $relayFactor): void + public function setRelayFactor(int $relayFactor): self { $this->RelayFactor = $relayFactor; + return $this; } public function isLocalOnly(): bool @@ -259,9 +268,10 @@ public function isLocalOnly(): bool return $this->LocalOnly; } - public function setLocalOnly(bool $localOnly): void + public function setLocalOnly(bool $localOnly): self { $this->LocalOnly = $localOnly; + return $this; } public function isConnect(): bool @@ -269,9 +279,10 @@ public function isConnect(): bool return $this->Connect; } - public function setConnect(bool $connect): void + public function setConnect(bool $connect): self { $this->Connect = $connect; + return $this; } public function getTimeout(): Time\Duration @@ -279,9 +290,10 @@ public function getTimeout(): Time\Duration return $this->Timeout; } - public function setTimeout(null|int|float|string|\DateInterval|Time\Duration $timeout): void + public function setTimeout(null|int|float|string|\DateInterval|Time\Duration $timeout): self { $this->Timeout = Time::Duration($timeout); + return $this; } public function isPretty(): bool @@ -289,9 +301,10 @@ public function isPretty(): bool return $this->Pretty; } - public function setPretty(bool $pretty): void + public function setPretty(bool $pretty): self { $this->Pretty = $pretty; + return $this; } public function apply(Request $r): void diff --git a/src/TaggedAddressContainer.php b/src/TaggedAddressContainer.php index 328badb7..eebec1b3 100644 --- a/src/TaggedAddressContainer.php +++ b/src/TaggedAddressContainer.php @@ -47,11 +47,10 @@ public function setTaggedAddress(string $k, string $v): self */ public function setTaggedAddresses(null|\stdClass|array $TaggedAddresses): self { + unset($this->TaggedAddresses); if (null === $TaggedAddresses) { - unset($this->TaggedAddresses); return $this; } - $this->TaggedAddresses = []; foreach ($TaggedAddresses as $k => $v) { $this->setTaggedAddress($k, $v); } diff --git a/src/funcs.php b/src/funcs.php index f952131e..14185a00 100644 --- a/src/funcs.php +++ b/src/funcs.php @@ -34,7 +34,7 @@ function dur_to_millisecond(Time\Duration $dur): string return "${ms}ms"; } -$_zeroObject = new \stdclass(); +$_zeroObject = new \stdClass(); function _enc_obj_if_valued(\stdClass &$out, string $field, \JsonSerializable $obj): void { From fd6e8315777265d1c996518a5855ed17186b8c02 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 2 Oct 2025 15:14:43 -0500 Subject: [PATCH 78/79] little bit of refactoring --- composer.json | 2 +- .../ACLAuthMethodListEntryQueryResponse.php | 4 +- src/ACL/ACLAuthMethodQueryResponse.php | 4 +- src/ACL/ACLAuthMethodWriteResponse.php | 4 +- src/ACL/ACLBindingRuleQueryResponse.php | 4 +- src/ACL/ACLBindingRuleWriteResponse.php | 4 +- src/ACL/ACLBindingRulesQueryResponse.php | 4 +- src/ACL/ACLClient.php | 4 +- src/ACL/ACLEntriesResponse.php | 4 +- src/ACL/ACLLoginParams.php | 4 +- src/ACL/ACLOIDCAuthURLParams.php | 4 +- src/ACL/ACLPolicyListEntryQueryResponse.php | 4 +- src/ACL/ACLPolicyQueryResponse.php | 4 +- src/ACL/ACLPolicyWriteResponse.php | 4 +- src/ACL/ACLReplicationStatusResponse.php | 4 +- src/ACL/ACLRoleQueryResponse.php | 4 +- src/ACL/ACLRoleWriteResponse.php | 4 +- src/ACL/ACLRolesQueryResponse.php | 4 +- src/ACL/ACLTokenExpandedQueryResponse.php | 4 +- src/ACL/ACLTokenListEntryQueryResponse.php | 4 +- src/ACL/ACLTokenQueryResponse.php | 4 +- src/ACL/ACLTokenWriteResponse.php | 4 +- src/AbstractClient.php | 10 +- src/Agent/AgentChecksResponse.php | 4 +- src/Agent/AgentClient.php | 2 +- src/Agent/AgentHealthServiceResponse.php | 6 +- src/Agent/AgentHealthServicesResponse.php | 6 +- src/Agent/AgentMembersResponse.php | 4 +- src/Agent/AgentService.php | 4 +- src/Agent/AgentServiceRegistration.php | 4 +- src/Agent/AgentServiceResponse.php | 4 +- src/Agent/AgentServicesResponse.php | 4 +- src/Agent/MetricsInfoResponse.php | 4 +- src/Catalog/CatalogClient.php | 6 +- src/Catalog/CatalogNodeResponse.php | 4 +- .../CatalogNodeServicesListResponse.php | 4 +- src/Catalog/CatalogRegistration.php | 8 +- src/Catalog/CatalogService.php | 12 +- src/Catalog/CatalogServicesResponse.php | 4 +- src/Catalog/GatewayServicesResponse.php | 4 +- src/Catalog/Node.php | 8 +- src/Catalog/NodesResponse.php | 4 +- src/ConfigEntry/ConfigEntryTrait.php | 4 +- .../IntentionHTTPHeaderPermission.php | 2 +- .../IntentionJWTClaimVerification.php | 2 +- src/ConfigEntry/ProxyConfigEntry.php | 2 +- src/ConfigEntry/ServiceConfigEntry.php | 2 +- .../ServiceResolverConfigEntry.php | 2 +- src/ConfigEntry/UpstreamConfig.php | 2 +- src/Coordinate/CoordinateClient.php | 2 +- .../CoordinateDatacentersResponse.php | 4 +- src/Coordinate/CoordinateEntriesResponse.php | 4 +- src/Debug/DebugClient.php | 2 +- src/DecodedBody.php | 4 +- src/Event/UserEventResponse.php | 4 +- src/Event/UserEventsResponse.php | 4 +- src/Health/HealthChecksResponse.php | 4 +- src/Health/ServiceEntriesResponse.php | 4 +- src/KV/KVClient.php | 6 +- src/KV/KVPairResponse.php | 4 +- src/KV/KVPairsResponse.php | 4 +- src/KV/KVTxnAPIResponse.php | 8 +- src/MapResponse.php | 3 + src/Operator/AutopilotServer.php | 4 +- src/Operator/AutopilotStateResponse.php | 4 +- src/Operator/OperatorAreaJoinResponse.php | 4 +- src/Operator/OperatorAreasResponse.php | 4 +- ...OperatorAutopilotConfigurationResponse.php | 4 +- src/Operator/OperatorClient.php | 6 +- src/Operator/OperatorHealthReplyResponse.php | 4 +- .../OperatorRaftConfigurationResponse.php | 4 +- src/Operator/OperatorSerfMembersResponse.php | 4 +- .../OperatorServerHealthsResponse.php | 4 +- .../Encoding}/SimpleJsonUnserializeTrait.php | 2 +- .../Response}/AbstractResponse.php | 2 +- .../Response}/AbstractValuedQueryResponse.php | 6 +- .../Response}/AbstractValuedResponse.php | 4 +- .../Response}/AbstractValuedWriteResponse.php | 6 +- .../Response/BoolValueField.php} | 4 +- .../Response/ErrorField.php} | 6 +- .../Response/QueryMetaField.php} | 6 +- .../Response}/QueryResponseInterface.php | 4 +- .../Response/StringValueField.php} | 4 +- .../Response/StringsValueField.php} | 4 +- .../UnmarshalledResponseInterface.php | 2 +- .../Response}/ValuedBoolResponse.php | 4 +- .../Response}/ValuedQueryBoolResponse.php | 4 +- .../Response}/ValuedQueryStringResponse.php | 4 +- .../Response}/ValuedQueryStringsResponse.php | 4 +- .../Response}/ValuedResponseInterface.php | 2 +- .../Response}/ValuedStringResponse.php | 4 +- .../Response}/ValuedStringsResponse.php | 4 +- .../Response}/ValuedWriteBoolResponse.php | 4 +- .../Response}/ValuedWriteStringResponse.php | 4 +- .../Response/WriteMetaField.php} | 6 +- src/{ => PHPLib/Response}/WriteResponse.php | 9 +- .../Response}/WriteResponseInterface.php | 4 +- .../Types/MetaField.php} | 4 +- .../Types/NodeMetaField.php} | 4 +- .../Types/ServiceMetaField.php} | 7 +- .../Types/TaggedAddressField.php} | 4 +- src/{ => PHPLib}/funcs.php | 2 +- src/PreparedQuery/PreparedQueryClient.php | 4 +- .../PreparedQueryDefinitionsResponse.php | 4 +- .../PreparedQueryExecuteResponseResponse.php | 4 +- src/QueryOptions.php | 1 + src/Request.php | 1 + src/Session/SessionClient.php | 4 +- src/Session/SessionEntriesQueryResponse.php | 4 +- src/Session/SessionEntriesWriteResponse.php | 4 +- src/Session/SessionEntry.php | 2 - src/Status/StatusClient.php | 4 +- tools/php-cs-fixer/composer.lock | 277 ++++++++++-------- 113 files changed, 406 insertions(+), 334 deletions(-) rename src/{ => PHPLib/Encoding}/SimpleJsonUnserializeTrait.php (94%) rename src/{ => PHPLib/Response}/AbstractResponse.php (96%) rename src/{ => PHPLib/Response}/AbstractValuedQueryResponse.php (93%) rename src/{ => PHPLib/Response}/AbstractValuedResponse.php (94%) rename src/{ => PHPLib/Response}/AbstractValuedWriteResponse.php (93%) rename src/{ResponseValueBoolTrait.php => PHPLib/Response/BoolValueField.php} (94%) rename src/{ErrorContainer.php => PHPLib/Response/ErrorField.php} (88%) rename src/{QueryMetaContainer.php => PHPLib/Response/QueryMetaField.php} (88%) rename src/{ => PHPLib/Response}/QueryResponseInterface.php (89%) rename src/{ResponseValueStringTrait.php => PHPLib/Response/StringValueField.php} (93%) rename src/{ResponseValueStringsTrait.php => PHPLib/Response/StringsValueField.php} (92%) rename src/{ => PHPLib/Response}/UnmarshalledResponseInterface.php (93%) rename src/{ => PHPLib/Response}/ValuedBoolResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedQueryBoolResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedQueryStringResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedQueryStringsResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedResponseInterface.php (93%) rename src/{ => PHPLib/Response}/ValuedStringResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedStringsResponse.php (90%) rename src/{ => PHPLib/Response}/ValuedWriteBoolResponse.php (91%) rename src/{ => PHPLib/Response}/ValuedWriteStringResponse.php (91%) rename src/{WriteMetaContainer.php => PHPLib/Response/WriteMetaField.php} (88%) rename src/{ => PHPLib/Response}/WriteResponse.php (87%) rename src/{ => PHPLib/Response}/WriteResponseInterface.php (89%) rename src/{MetaContainer.php => PHPLib/Types/MetaField.php} (95%) rename src/{NodeMetaContainer.php => PHPLib/Types/NodeMetaField.php} (95%) rename src/{ServiceMetaContainer.php => PHPLib/Types/ServiceMetaField.php} (91%) rename src/{TaggedAddressContainer.php => PHPLib/Types/TaggedAddressField.php} (95%) rename src/{ => PHPLib}/funcs.php (96%) diff --git a/composer.json b/composer.json index 57c8434c..99e80eb8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "autoload": { "files": [ - "src/funcs.php" + "src/PHPLib/funcs.php" ], "psr-4": { "DCarbone\\PHPConsulAPI\\": "src/" diff --git a/src/ACL/ACLAuthMethodListEntryQueryResponse.php b/src/ACL/ACLAuthMethodListEntryQueryResponse.php index 268e6554..c5612997 100644 --- a/src/ACL/ACLAuthMethodListEntryQueryResponse.php +++ b/src/ACL/ACLAuthMethodListEntryQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLAuthMethodListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLAuthMethodQueryResponse.php b/src/ACL/ACLAuthMethodQueryResponse.php index 5c51602f..81b1b258 100644 --- a/src/ACL/ACLAuthMethodQueryResponse.php +++ b/src/ACL/ACLAuthMethodQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLAuthMethodQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLAuthMethodWriteResponse.php b/src/ACL/ACLAuthMethodWriteResponse.php index 61f17997..3d17c080 100644 --- a/src/ACL/ACLAuthMethodWriteResponse.php +++ b/src/ACL/ACLAuthMethodWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLAuthMethodWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLBindingRuleQueryResponse.php b/src/ACL/ACLBindingRuleQueryResponse.php index 73381657..b56e53c2 100644 --- a/src/ACL/ACLBindingRuleQueryResponse.php +++ b/src/ACL/ACLBindingRuleQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLBindingRuleQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLBindingRuleWriteResponse.php b/src/ACL/ACLBindingRuleWriteResponse.php index 471cb66c..86a26782 100644 --- a/src/ACL/ACLBindingRuleWriteResponse.php +++ b/src/ACL/ACLBindingRuleWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLBindingRuleWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLBindingRulesQueryResponse.php b/src/ACL/ACLBindingRulesQueryResponse.php index cf6d7d59..10746c9c 100644 --- a/src/ACL/ACLBindingRulesQueryResponse.php +++ b/src/ACL/ACLBindingRulesQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLBindingRulesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLClient.php b/src/ACL/ACLClient.php index af9c7531..385f1ff7 100644 --- a/src/ACL/ACLClient.php +++ b/src/ACL/ACLClient.php @@ -23,9 +23,9 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\Error; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedWriteStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteStringResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class ACLClient extends AbstractClient { diff --git a/src/ACL/ACLEntriesResponse.php b/src/ACL/ACLEntriesResponse.php index e4bd298a..dcc7acf4 100644 --- a/src/ACL/ACLEntriesResponse.php +++ b/src/ACL/ACLEntriesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index f560aa6b..f291dad9 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -21,11 +21,11 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; class ACLLoginParams extends AbstractModel { - use MetaContainer; + use MetaField; public string $AuthMethod; public string $BearerToken; diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index d29749d4..84140981 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -21,11 +21,11 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; class ACLOIDCAuthURLParams extends AbstractModel { - use MetaContainer; + use MetaField; public string $AuthMethod; public string $RedirectURI; diff --git a/src/ACL/ACLPolicyListEntryQueryResponse.php b/src/ACL/ACLPolicyListEntryQueryResponse.php index 0fd2ac10..ab72d7f1 100644 --- a/src/ACL/ACLPolicyListEntryQueryResponse.php +++ b/src/ACL/ACLPolicyListEntryQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLPolicyListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLPolicyQueryResponse.php b/src/ACL/ACLPolicyQueryResponse.php index 50895ba5..5833463c 100644 --- a/src/ACL/ACLPolicyQueryResponse.php +++ b/src/ACL/ACLPolicyQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLPolicyQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLPolicyWriteResponse.php b/src/ACL/ACLPolicyWriteResponse.php index a9b74b46..3074612b 100644 --- a/src/ACL/ACLPolicyWriteResponse.php +++ b/src/ACL/ACLPolicyWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLPolicyWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLReplicationStatusResponse.php b/src/ACL/ACLReplicationStatusResponse.php index 51438d44..750593f8 100644 --- a/src/ACL/ACLReplicationStatusResponse.php +++ b/src/ACL/ACLReplicationStatusResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLReplicationStatusResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLRoleQueryResponse.php b/src/ACL/ACLRoleQueryResponse.php index 9106283e..699e164a 100644 --- a/src/ACL/ACLRoleQueryResponse.php +++ b/src/ACL/ACLRoleQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLRoleQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLRoleWriteResponse.php b/src/ACL/ACLRoleWriteResponse.php index 0827b545..464ecafc 100644 --- a/src/ACL/ACLRoleWriteResponse.php +++ b/src/ACL/ACLRoleWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLRoleWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLRolesQueryResponse.php b/src/ACL/ACLRolesQueryResponse.php index d07d6036..66c8bd4e 100644 --- a/src/ACL/ACLRolesQueryResponse.php +++ b/src/ACL/ACLRolesQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLRolesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLTokenExpandedQueryResponse.php b/src/ACL/ACLTokenExpandedQueryResponse.php index 09e6c9f6..eaddb4fd 100644 --- a/src/ACL/ACLTokenExpandedQueryResponse.php +++ b/src/ACL/ACLTokenExpandedQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLTokenExpandedQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLTokenListEntryQueryResponse.php b/src/ACL/ACLTokenListEntryQueryResponse.php index 350bf618..e4ab6845 100644 --- a/src/ACL/ACLTokenListEntryQueryResponse.php +++ b/src/ACL/ACLTokenListEntryQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLTokenListEntryQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLTokenQueryResponse.php b/src/ACL/ACLTokenQueryResponse.php index c9d0c160..e108e4cd 100644 --- a/src/ACL/ACLTokenQueryResponse.php +++ b/src/ACL/ACLTokenQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLTokenQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ACL/ACLTokenWriteResponse.php b/src/ACL/ACLTokenWriteResponse.php index 6a654d55..9ff6f8d1 100644 --- a/src/ACL/ACLTokenWriteResponse.php +++ b/src/ACL/ACLTokenWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ACLTokenWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/AbstractClient.php b/src/AbstractClient.php index 99ebe77d..8c08d2f2 100644 --- a/src/AbstractClient.php +++ b/src/AbstractClient.php @@ -22,6 +22,14 @@ use DCarbone\Go\HTTP; use DCarbone\Go\Time; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\QueryResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedQueryStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedQueryStringsResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponseInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\RequestOptions as GuzzleRequestOptions; use Psr\Http\Message\ResponseInterface; @@ -297,7 +305,7 @@ protected function _executeGetValuedStrs(string $path, null|QueryOptions $opts): * todo: move into Unmarshaller? * * @param \DCarbone\PHPConsulAPI\RequestResponse $resp - * @param \DCarbone\PHPConsulAPI\AbstractResponse $ret + * @param \DCarbone\PHPConsulAPI\PHPLib\Response\AbstractResponse $ret * @throws \Exception */ protected function _unmarshalResponse(RequestResponse $resp, AbstractResponse $ret): void diff --git a/src/Agent/AgentChecksResponse.php b/src/Agent/AgentChecksResponse.php index dc4bdc67..2ca5b1f2 100644 --- a/src/Agent/AgentChecksResponse.php +++ b/src/Agent/AgentChecksResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class AgentChecksResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Agent/AgentClient.php b/src/Agent/AgentClient.php index b7a520fa..2570079e 100644 --- a/src/Agent/AgentClient.php +++ b/src/Agent/AgentClient.php @@ -27,7 +27,7 @@ use DCarbone\PHPConsulAPI\MapResponse; use DCarbone\PHPConsulAPI\QueryOptions; use DCarbone\PHPConsulAPI\Request; -use DCarbone\PHPConsulAPI\ValuedStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedStringResponse; class AgentClient extends AbstractClient { diff --git a/src/Agent/AgentHealthServiceResponse.php b/src/Agent/AgentHealthServiceResponse.php index 5ada9735..b9c317dc 100644 --- a/src/Agent/AgentHealthServiceResponse.php +++ b/src/Agent/AgentHealthServiceResponse.php @@ -20,13 +20,13 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractResponse; use DCarbone\PHPConsulAPI\Error; -use DCarbone\PHPConsulAPI\ErrorContainer; +use DCarbone\PHPConsulAPI\PHPLib\Response\ErrorField; class AgentHealthServiceResponse extends AbstractResponse { - use ErrorContainer; + use ErrorField; public string $AggregatedStatus; public null|AgentServiceChecksInfo $AgentServiceChecksInfo; diff --git a/src/Agent/AgentHealthServicesResponse.php b/src/Agent/AgentHealthServicesResponse.php index f529be51..1ef372e5 100644 --- a/src/Agent/AgentHealthServicesResponse.php +++ b/src/Agent/AgentHealthServicesResponse.php @@ -20,13 +20,13 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractResponse; use DCarbone\PHPConsulAPI\Error; -use DCarbone\PHPConsulAPI\ErrorContainer; +use DCarbone\PHPConsulAPI\PHPLib\Response\ErrorField; class AgentHealthServicesResponse extends AbstractResponse { - use ErrorContainer; + use ErrorField; public string $AggregatedStatus; /** @var \DCarbone\PHPConsulAPI\Agent\AgentServiceChecksInfo[] */ diff --git a/src/Agent/AgentMembersResponse.php b/src/Agent/AgentMembersResponse.php index 6005c021..6e3d5f2e 100644 --- a/src/Agent/AgentMembersResponse.php +++ b/src/Agent/AgentMembersResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class AgentMembersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 2108e587..086d7b20 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -21,12 +21,12 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; class AgentService extends AbstractModel { - use MetaContainer; + use MetaField; public ServiceKind $Kind; public string $ID; diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 24b6f0f6..4389e3ea 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -22,12 +22,12 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Catalog\ServiceAddress; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; class AgentServiceRegistration extends AbstractModel { - use MetaContainer; + use MetaField; public ServiceKind $Kind; public string $ID; diff --git a/src/Agent/AgentServiceResponse.php b/src/Agent/AgentServiceResponse.php index 49d31f14..ad671fe7 100644 --- a/src/Agent/AgentServiceResponse.php +++ b/src/Agent/AgentServiceResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class AgentServiceResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Agent/AgentServicesResponse.php b/src/Agent/AgentServicesResponse.php index 48d44523..82f86708 100644 --- a/src/Agent/AgentServicesResponse.php +++ b/src/Agent/AgentServicesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class AgentServicesResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Agent/MetricsInfoResponse.php b/src/Agent/MetricsInfoResponse.php index 82fbe9f7..37ac5ea2 100644 --- a/src/Agent/MetricsInfoResponse.php +++ b/src/Agent/MetricsInfoResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class MetricsInfoResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Catalog/CatalogClient.php b/src/Catalog/CatalogClient.php index 8bce4c74..babe674c 100644 --- a/src/Catalog/CatalogClient.php +++ b/src/Catalog/CatalogClient.php @@ -22,10 +22,10 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedQueryStringsResponse; -use DCarbone\PHPConsulAPI\ValuedStringsResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedQueryStringsResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedStringsResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class CatalogClient extends AbstractClient { diff --git a/src/Catalog/CatalogNodeResponse.php b/src/Catalog/CatalogNodeResponse.php index 362f38e0..423934e7 100644 --- a/src/Catalog/CatalogNodeResponse.php +++ b/src/Catalog/CatalogNodeResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class CatalogNodeResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Catalog/CatalogNodeServicesListResponse.php b/src/Catalog/CatalogNodeServicesListResponse.php index 30126820..4f7d6ea0 100644 --- a/src/Catalog/CatalogNodeServicesListResponse.php +++ b/src/Catalog/CatalogNodeServicesListResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class CatalogNodeServicesListResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index f1cf92e9..173a4fc9 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -24,14 +24,14 @@ use DCarbone\PHPConsulAPI\Agent\AgentCheck; use DCarbone\PHPConsulAPI\Agent\AgentService; use DCarbone\PHPConsulAPI\Health\HealthChecks; -use DCarbone\PHPConsulAPI\NodeMetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\NodeMetaField; use DCarbone\PHPConsulAPI\Peering\Locality; -use DCarbone\PHPConsulAPI\TaggedAddressContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; class CatalogRegistration extends AbstractModel { - use TaggedAddressContainer; - use NodeMetaContainer; + use TaggedAddressField; + use NodeMetaField; public string $ID; public string $Node; diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 1ce777eb..2ad8b883 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -23,16 +23,16 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig; use DCarbone\PHPConsulAPI\Health\HealthChecks; -use DCarbone\PHPConsulAPI\NodeMetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\NodeMetaField; use DCarbone\PHPConsulAPI\Peering\Locality; -use DCarbone\PHPConsulAPI\ServiceMetaContainer; -use DCarbone\PHPConsulAPI\TaggedAddressContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\ServiceMetaField; +use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; class CatalogService extends AbstractModel { - use TaggedAddressContainer; - use NodeMetaContainer; - use ServiceMetaContainer; + use TaggedAddressField; + use NodeMetaField; + use ServiceMetaField; public string $ID; public string $Node; diff --git a/src/Catalog/CatalogServicesResponse.php b/src/Catalog/CatalogServicesResponse.php index 6758043e..fa36e858 100644 --- a/src/Catalog/CatalogServicesResponse.php +++ b/src/Catalog/CatalogServicesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class CatalogServicesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Catalog/GatewayServicesResponse.php b/src/Catalog/GatewayServicesResponse.php index 127a92b9..9d8c688f 100644 --- a/src/Catalog/GatewayServicesResponse.php +++ b/src/Catalog/GatewayServicesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class GatewayServicesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index b5a092f7..de08185f 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -21,14 +21,14 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; -use DCarbone\PHPConsulAPI\TaggedAddressContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; class Node extends AbstractModel { - use MetaContainer; - use TaggedAddressContainer; + use MetaField; + use TaggedAddressField; public string $ID; public string $Node; diff --git a/src/Catalog/NodesResponse.php b/src/Catalog/NodesResponse.php index a56b77bb..bb75b998 100644 --- a/src/Catalog/NodesResponse.php +++ b/src/Catalog/NodesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class NodesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/ConfigEntry/ConfigEntryTrait.php b/src/ConfigEntry/ConfigEntryTrait.php index d06c4fc6..66425712 100644 --- a/src/ConfigEntry/ConfigEntryTrait.php +++ b/src/ConfigEntry/ConfigEntryTrait.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; trait ConfigEntryTrait { - use MetaContainer; + use MetaField; public string $Namespace; public int $CreateIndex; diff --git a/src/ConfigEntry/IntentionHTTPHeaderPermission.php b/src/ConfigEntry/IntentionHTTPHeaderPermission.php index 976ba85d..59cccb05 100644 --- a/src/ConfigEntry/IntentionHTTPHeaderPermission.php +++ b/src/ConfigEntry/IntentionHTTPHeaderPermission.php @@ -21,7 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\SimpleJsonUnserializeTrait; +use DCarbone\PHPConsulAPI\PHPLib\Encoding\SimpleJsonUnserializeTrait; class IntentionHTTPHeaderPermission extends AbstractModel { diff --git a/src/ConfigEntry/IntentionJWTClaimVerification.php b/src/ConfigEntry/IntentionJWTClaimVerification.php index 169e0bfd..ccd0521d 100644 --- a/src/ConfigEntry/IntentionJWTClaimVerification.php +++ b/src/ConfigEntry/IntentionJWTClaimVerification.php @@ -21,7 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\SimpleJsonUnserializeTrait; +use DCarbone\PHPConsulAPI\PHPLib\Encoding\SimpleJsonUnserializeTrait; class IntentionJWTClaimVerification extends AbstractModel { diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index 59316869..23a7265d 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -22,7 +22,7 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Consul; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; +use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; class ProxyConfigEntry extends AbstractModel implements ConfigEntry { diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index 0b449552..edaf286d 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -22,7 +22,7 @@ use DCarbone\PHPConsulAPI\AbstractModel; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; +use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; class ServiceConfigEntry extends AbstractModel implements ConfigEntry { diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index fd895dee..1bf01531 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -24,7 +24,7 @@ use DCarbone\Go\Time; use stdClass; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; +use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry { diff --git a/src/ConfigEntry/UpstreamConfig.php b/src/ConfigEntry/UpstreamConfig.php index a8b18acb..05e0f9c3 100644 --- a/src/ConfigEntry/UpstreamConfig.php +++ b/src/ConfigEntry/UpstreamConfig.php @@ -21,7 +21,7 @@ */ use DCarbone\PHPConsulAPI\AbstractModel; -use function DCarbone\PHPConsulAPI\_enc_obj_if_valued; +use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; class UpstreamConfig extends AbstractModel { diff --git a/src/Coordinate/CoordinateClient.php b/src/Coordinate/CoordinateClient.php index 8759c496..7a49f628 100644 --- a/src/Coordinate/CoordinateClient.php +++ b/src/Coordinate/CoordinateClient.php @@ -23,7 +23,7 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\QueryOptions; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class CoordinateClient extends AbstractClient { diff --git a/src/Coordinate/CoordinateDatacentersResponse.php b/src/Coordinate/CoordinateDatacentersResponse.php index 031fc260..723e7410 100644 --- a/src/Coordinate/CoordinateDatacentersResponse.php +++ b/src/Coordinate/CoordinateDatacentersResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class CoordinateDatacentersResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Coordinate/CoordinateEntriesResponse.php b/src/Coordinate/CoordinateEntriesResponse.php index 8ecefa28..69f1f6b0 100644 --- a/src/Coordinate/CoordinateEntriesResponse.php +++ b/src/Coordinate/CoordinateEntriesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class CoordinateEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Debug/DebugClient.php b/src/Debug/DebugClient.php index a96f89aa..3688536b 100644 --- a/src/Debug/DebugClient.php +++ b/src/Debug/DebugClient.php @@ -23,7 +23,7 @@ use DCarbone\Go\HTTP; use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\Error; -use DCarbone\PHPConsulAPI\ValuedStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedStringResponse; class DebugClient extends AbstractClient { diff --git a/src/DecodedBody.php b/src/DecodedBody.php index 068a2ac0..cc00a599 100644 --- a/src/DecodedBody.php +++ b/src/DecodedBody.php @@ -20,9 +20,11 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\PHPLib\Response\ErrorField; + final class DecodedBody { - use ErrorContainer; + use ErrorField; public mixed $Decoded = null; diff --git a/src/Event/UserEventResponse.php b/src/Event/UserEventResponse.php index a71a354e..8176bd72 100644 --- a/src/Event/UserEventResponse.php +++ b/src/Event/UserEventResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class UserEventResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/Event/UserEventsResponse.php b/src/Event/UserEventsResponse.php index d3c56eca..72c18138 100644 --- a/src/Event/UserEventsResponse.php +++ b/src/Event/UserEventsResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class UserEventsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Health/HealthChecksResponse.php b/src/Health/HealthChecksResponse.php index 14081f1e..174b3605 100644 --- a/src/Health/HealthChecksResponse.php +++ b/src/Health/HealthChecksResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class HealthChecksResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Health/ServiceEntriesResponse.php b/src/Health/ServiceEntriesResponse.php index 9223803b..14a98835 100644 --- a/src/Health/ServiceEntriesResponse.php +++ b/src/Health/ServiceEntriesResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class ServiceEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/KV/KVClient.php b/src/KV/KVClient.php index 8adcd094..1e3f04d0 100644 --- a/src/KV/KVClient.php +++ b/src/KV/KVClient.php @@ -24,10 +24,10 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\Error; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedQueryStringsResponse; -use DCarbone\PHPConsulAPI\ValuedWriteBoolResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedQueryStringsResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteBoolResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class KVClient extends AbstractClient { diff --git a/src/KV/KVPairResponse.php b/src/KV/KVPairResponse.php index 89d95eb9..d29c03c3 100644 --- a/src/KV/KVPairResponse.php +++ b/src/KV/KVPairResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class KVPairResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/KV/KVPairsResponse.php b/src/KV/KVPairsResponse.php index ddd34cdb..51e3e0cd 100644 --- a/src/KV/KVPairsResponse.php +++ b/src/KV/KVPairsResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class KVPairsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/KV/KVTxnAPIResponse.php b/src/KV/KVTxnAPIResponse.php index 05221fe1..fa3dd639 100644 --- a/src/KV/KVTxnAPIResponse.php +++ b/src/KV/KVTxnAPIResponse.php @@ -20,13 +20,13 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\ErrorContainer; -use DCarbone\PHPConsulAPI\QueryMetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Response\ErrorField; +use DCarbone\PHPConsulAPI\PHPLib\Response\QueryMetaField; class KVTxnAPIResponse { - use QueryMetaContainer; - use ErrorContainer; + use QueryMetaField; + use ErrorField; public bool $OK = false; public null|KVTxnResponse $KVTxnResponse = null; diff --git a/src/MapResponse.php b/src/MapResponse.php index 02c4cbd3..14ac9932 100644 --- a/src/MapResponse.php +++ b/src/MapResponse.php @@ -20,6 +20,9 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; + /** * @template T */ diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index bb666ec2..a14a5d25 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -22,11 +22,11 @@ use DCarbone\Go\Time; use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\MetaContainer; +use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; class AutopilotServer extends AbstractModel implements \JsonSerializable { - use MetaContainer; + use MetaField; public string $ID; public string $Name; diff --git a/src/Operator/AutopilotStateResponse.php b/src/Operator/AutopilotStateResponse.php index 0e35370d..da0eb151 100644 --- a/src/Operator/AutopilotStateResponse.php +++ b/src/Operator/AutopilotStateResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class AutopilotStateResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorAreaJoinResponse.php b/src/Operator/OperatorAreaJoinResponse.php index 77ebcc77..4def6370 100644 --- a/src/Operator/OperatorAreaJoinResponse.php +++ b/src/Operator/OperatorAreaJoinResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorAreaJoinResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorAreasResponse.php b/src/Operator/OperatorAreasResponse.php index fd436b00..26c08cbc 100644 --- a/src/Operator/OperatorAreasResponse.php +++ b/src/Operator/OperatorAreasResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorAreasResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorAutopilotConfigurationResponse.php b/src/Operator/OperatorAutopilotConfigurationResponse.php index 384d04e0..c7a20f87 100644 --- a/src/Operator/OperatorAutopilotConfigurationResponse.php +++ b/src/Operator/OperatorAutopilotConfigurationResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorAutopilotConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorClient.php b/src/Operator/OperatorClient.php index 3d477621..80256534 100644 --- a/src/Operator/OperatorClient.php +++ b/src/Operator/OperatorClient.php @@ -24,10 +24,10 @@ use DCarbone\PHPConsulAPI\Error; use DCarbone\PHPConsulAPI\QueryOptions; use DCarbone\PHPConsulAPI\RequestResponse; -use DCarbone\PHPConsulAPI\ValuedBoolResponse; -use DCarbone\PHPConsulAPI\ValuedWriteStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedBoolResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteStringResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class OperatorClient extends AbstractClient { diff --git a/src/Operator/OperatorHealthReplyResponse.php b/src/Operator/OperatorHealthReplyResponse.php index 2fa54b27..e3bd9c3e 100644 --- a/src/Operator/OperatorHealthReplyResponse.php +++ b/src/Operator/OperatorHealthReplyResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorHealthReplyResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorRaftConfigurationResponse.php b/src/Operator/OperatorRaftConfigurationResponse.php index 35d164db..1cc3f910 100644 --- a/src/Operator/OperatorRaftConfigurationResponse.php +++ b/src/Operator/OperatorRaftConfigurationResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorRaftConfigurationResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorSerfMembersResponse.php b/src/Operator/OperatorSerfMembersResponse.php index 15abdfb2..2a6f33a9 100644 --- a/src/Operator/OperatorSerfMembersResponse.php +++ b/src/Operator/OperatorSerfMembersResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorSerfMembersResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Operator/OperatorServerHealthsResponse.php b/src/Operator/OperatorServerHealthsResponse.php index 608a6be9..649e5273 100644 --- a/src/Operator/OperatorServerHealthsResponse.php +++ b/src/Operator/OperatorServerHealthsResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class OperatorServerHealthsResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { diff --git a/src/SimpleJsonUnserializeTrait.php b/src/PHPLib/Encoding/SimpleJsonUnserializeTrait.php similarity index 94% rename from src/SimpleJsonUnserializeTrait.php rename to src/PHPLib/Encoding/SimpleJsonUnserializeTrait.php index 9642616f..3d540cc0 100644 --- a/src/SimpleJsonUnserializeTrait.php +++ b/src/PHPLib/Encoding/SimpleJsonUnserializeTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Encoding; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) diff --git a/src/AbstractResponse.php b/src/PHPLib/Response/AbstractResponse.php similarity index 96% rename from src/AbstractResponse.php rename to src/PHPLib/Response/AbstractResponse.php index 914bacd4..9007fc93 100644 --- a/src/AbstractResponse.php +++ b/src/PHPLib/Response/AbstractResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) diff --git a/src/AbstractValuedQueryResponse.php b/src/PHPLib/Response/AbstractValuedQueryResponse.php similarity index 93% rename from src/AbstractValuedQueryResponse.php rename to src/PHPLib/Response/AbstractValuedQueryResponse.php index a2ab90d9..736eecf1 100644 --- a/src/AbstractValuedQueryResponse.php +++ b/src/PHPLib/Response/AbstractValuedQueryResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,8 +22,8 @@ abstract class AbstractValuedQueryResponse extends AbstractResponse implements QueryResponseInterface, ValuedResponseInterface { - use QueryMetaContainer; - use ErrorContainer; + use QueryMetaField; + use ErrorField; public function offsetExists(mixed $offset): bool { diff --git a/src/AbstractValuedResponse.php b/src/PHPLib/Response/AbstractValuedResponse.php similarity index 94% rename from src/AbstractValuedResponse.php rename to src/PHPLib/Response/AbstractValuedResponse.php index 1e8fc823..ef468167 100644 --- a/src/AbstractValuedResponse.php +++ b/src/PHPLib/Response/AbstractValuedResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,7 +22,7 @@ abstract class AbstractValuedResponse extends AbstractResponse implements ValuedResponseInterface { - use ErrorContainer; + use ErrorField; public function offsetExists(mixed $offset): bool { diff --git a/src/AbstractValuedWriteResponse.php b/src/PHPLib/Response/AbstractValuedWriteResponse.php similarity index 93% rename from src/AbstractValuedWriteResponse.php rename to src/PHPLib/Response/AbstractValuedWriteResponse.php index c380bcd0..4c5bd193 100644 --- a/src/AbstractValuedWriteResponse.php +++ b/src/PHPLib/Response/AbstractValuedWriteResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,8 +22,8 @@ abstract class AbstractValuedWriteResponse extends AbstractResponse implements ValuedResponseInterface { - use WriteMetaContainer; - use ErrorContainer; + use WriteMetaField; + use ErrorField; public function offsetExists(mixed $offset): bool { diff --git a/src/ResponseValueBoolTrait.php b/src/PHPLib/Response/BoolValueField.php similarity index 94% rename from src/ResponseValueBoolTrait.php rename to src/PHPLib/Response/BoolValueField.php index 8741df78..817a62df 100644 --- a/src/ResponseValueBoolTrait.php +++ b/src/PHPLib/Response/BoolValueField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait ResponseValueBoolTrait +trait BoolValueField { public bool $Value = false; diff --git a/src/ErrorContainer.php b/src/PHPLib/Response/ErrorField.php similarity index 88% rename from src/ErrorContainer.php rename to src/PHPLib/Response/ErrorField.php index bfd17fbf..460d0048 100644 --- a/src/ErrorContainer.php +++ b/src/PHPLib/Response/ErrorField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,9 @@ limitations under the License. */ -trait ErrorContainer +use DCarbone\PHPConsulAPI\Error; + +trait ErrorField { public null|Error $Err = null; diff --git a/src/QueryMetaContainer.php b/src/PHPLib/Response/QueryMetaField.php similarity index 88% rename from src/QueryMetaContainer.php rename to src/PHPLib/Response/QueryMetaField.php index 8c513435..f42fc22d 100644 --- a/src/QueryMetaContainer.php +++ b/src/PHPLib/Response/QueryMetaField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,9 @@ limitations under the License. */ -trait QueryMetaContainer +use DCarbone\PHPConsulAPI\QueryMeta; + +trait QueryMetaField { public null|QueryMeta $QueryMeta = null; diff --git a/src/QueryResponseInterface.php b/src/PHPLib/Response/QueryResponseInterface.php similarity index 89% rename from src/QueryResponseInterface.php rename to src/PHPLib/Response/QueryResponseInterface.php index 389a2e26..25f02733 100644 --- a/src/QueryResponseInterface.php +++ b/src/PHPLib/Response/QueryResponseInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,6 +20,8 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\QueryMeta; + interface QueryResponseInterface { public function getQueryMeta(): null|QueryMeta; diff --git a/src/ResponseValueStringTrait.php b/src/PHPLib/Response/StringValueField.php similarity index 93% rename from src/ResponseValueStringTrait.php rename to src/PHPLib/Response/StringValueField.php index bfdbf8ac..5069c3b4 100644 --- a/src/ResponseValueStringTrait.php +++ b/src/PHPLib/Response/StringValueField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait ResponseValueStringTrait +trait StringValueField { public string $Value = ''; diff --git a/src/ResponseValueStringsTrait.php b/src/PHPLib/Response/StringsValueField.php similarity index 92% rename from src/ResponseValueStringsTrait.php rename to src/PHPLib/Response/StringsValueField.php index f996b53c..9ab730d3 100644 --- a/src/ResponseValueStringsTrait.php +++ b/src/PHPLib/Response/StringsValueField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait ResponseValueStringsTrait +trait StringsValueField { public array $Value = []; diff --git a/src/UnmarshalledResponseInterface.php b/src/PHPLib/Response/UnmarshalledResponseInterface.php similarity index 93% rename from src/UnmarshalledResponseInterface.php rename to src/PHPLib/Response/UnmarshalledResponseInterface.php index c379cf6f..8fb3cac0 100644 --- a/src/UnmarshalledResponseInterface.php +++ b/src/PHPLib/Response/UnmarshalledResponseInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) diff --git a/src/ValuedBoolResponse.php b/src/PHPLib/Response/ValuedBoolResponse.php similarity index 91% rename from src/ValuedBoolResponse.php rename to src/PHPLib/Response/ValuedBoolResponse.php index a0db756d..08617eb7 100644 --- a/src/ValuedBoolResponse.php +++ b/src/PHPLib/Response/ValuedBoolResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedBoolResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - use ResponseValueBoolTrait; + use BoolValueField; } diff --git a/src/ValuedQueryBoolResponse.php b/src/PHPLib/Response/ValuedQueryBoolResponse.php similarity index 91% rename from src/ValuedQueryBoolResponse.php rename to src/PHPLib/Response/ValuedQueryBoolResponse.php index 52efc008..43b77705 100644 --- a/src/ValuedQueryBoolResponse.php +++ b/src/PHPLib/Response/ValuedQueryBoolResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedQueryBoolResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - use ResponseValueBoolTrait; + use BoolValueField; } diff --git a/src/ValuedQueryStringResponse.php b/src/PHPLib/Response/ValuedQueryStringResponse.php similarity index 91% rename from src/ValuedQueryStringResponse.php rename to src/PHPLib/Response/ValuedQueryStringResponse.php index e8edb1a3..d8dedd44 100644 --- a/src/ValuedQueryStringResponse.php +++ b/src/PHPLib/Response/ValuedQueryStringResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedQueryStringResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - use ResponseValueStringTrait; + use StringValueField; } diff --git a/src/ValuedQueryStringsResponse.php b/src/PHPLib/Response/ValuedQueryStringsResponse.php similarity index 91% rename from src/ValuedQueryStringsResponse.php rename to src/PHPLib/Response/ValuedQueryStringsResponse.php index afa3ccaf..b67105a6 100644 --- a/src/ValuedQueryStringsResponse.php +++ b/src/PHPLib/Response/ValuedQueryStringsResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedQueryStringsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { - use ResponseValueStringsTrait; + use StringsValueField; } diff --git a/src/ValuedResponseInterface.php b/src/PHPLib/Response/ValuedResponseInterface.php similarity index 93% rename from src/ValuedResponseInterface.php rename to src/PHPLib/Response/ValuedResponseInterface.php index ec14dc77..decd2ed7 100644 --- a/src/ValuedResponseInterface.php +++ b/src/PHPLib/Response/ValuedResponseInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) diff --git a/src/ValuedStringResponse.php b/src/PHPLib/Response/ValuedStringResponse.php similarity index 91% rename from src/ValuedStringResponse.php rename to src/PHPLib/Response/ValuedStringResponse.php index c7a680d8..28f198ff 100644 --- a/src/ValuedStringResponse.php +++ b/src/PHPLib/Response/ValuedStringResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedStringResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - use ResponseValueStringTrait; + use StringValueField; } diff --git a/src/ValuedStringsResponse.php b/src/PHPLib/Response/ValuedStringsResponse.php similarity index 90% rename from src/ValuedStringsResponse.php rename to src/PHPLib/Response/ValuedStringsResponse.php index 9baf33d2..0655d03b 100644 --- a/src/ValuedStringsResponse.php +++ b/src/PHPLib/Response/ValuedStringsResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedStringsResponse extends AbstractValuedResponse implements UnmarshalledResponseInterface { - use ResponseValueStringsTrait; + use StringsValueField; } diff --git a/src/ValuedWriteBoolResponse.php b/src/PHPLib/Response/ValuedWriteBoolResponse.php similarity index 91% rename from src/ValuedWriteBoolResponse.php rename to src/PHPLib/Response/ValuedWriteBoolResponse.php index 0236ca1f..fcbe2a15 100644 --- a/src/ValuedWriteBoolResponse.php +++ b/src/PHPLib/Response/ValuedWriteBoolResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedWriteBoolResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { - use ResponseValueBoolTrait; + use BoolValueField; } diff --git a/src/ValuedWriteStringResponse.php b/src/PHPLib/Response/ValuedWriteStringResponse.php similarity index 91% rename from src/ValuedWriteStringResponse.php rename to src/PHPLib/Response/ValuedWriteStringResponse.php index d9ec5bbf..31024ad9 100644 --- a/src/ValuedWriteStringResponse.php +++ b/src/PHPLib/Response/ValuedWriteStringResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -22,5 +22,5 @@ class ValuedWriteStringResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { - use ResponseValueStringTrait; + use StringValueField; } diff --git a/src/WriteMetaContainer.php b/src/PHPLib/Response/WriteMetaField.php similarity index 88% rename from src/WriteMetaContainer.php rename to src/PHPLib/Response/WriteMetaField.php index 0c13ba78..002c39b0 100644 --- a/src/WriteMetaContainer.php +++ b/src/PHPLib/Response/WriteMetaField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,9 @@ limitations under the License. */ -trait WriteMetaContainer +use DCarbone\PHPConsulAPI\WriteMeta; + +trait WriteMetaField { public null|WriteMeta $WriteMeta = null; diff --git a/src/WriteResponse.php b/src/PHPLib/Response/WriteResponse.php similarity index 87% rename from src/WriteResponse.php rename to src/PHPLib/Response/WriteResponse.php index 592e7586..d652c0b1 100644 --- a/src/WriteResponse.php +++ b/src/PHPLib/Response/WriteResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,10 +20,13 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\Error; +use DCarbone\PHPConsulAPI\WriteMeta; + class WriteResponse extends AbstractResponse implements WriteResponseInterface { - use WriteMetaContainer; - use ErrorContainer; + use WriteMetaField; + use ErrorField; public function offsetExists(mixed $offset): bool { diff --git a/src/WriteResponseInterface.php b/src/PHPLib/Response/WriteResponseInterface.php similarity index 89% rename from src/WriteResponseInterface.php rename to src/PHPLib/Response/WriteResponseInterface.php index c3218f94..132d6608 100644 --- a/src/WriteResponseInterface.php +++ b/src/PHPLib/Response/WriteResponseInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Response; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,6 +20,8 @@ limitations under the License. */ +use DCarbone\PHPConsulAPI\WriteMeta; + interface WriteResponseInterface { public function getWriteMeta(): null|WriteMeta; diff --git a/src/MetaContainer.php b/src/PHPLib/Types/MetaField.php similarity index 95% rename from src/MetaContainer.php rename to src/PHPLib/Types/MetaField.php index 12fc24ad..80160bdf 100644 --- a/src/MetaContainer.php +++ b/src/PHPLib/Types/MetaField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Types; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait MetaContainer +trait MetaField { /** @var array */ public array $Meta; diff --git a/src/NodeMetaContainer.php b/src/PHPLib/Types/NodeMetaField.php similarity index 95% rename from src/NodeMetaContainer.php rename to src/PHPLib/Types/NodeMetaField.php index c4a8e17a..ccd1bbfa 100644 --- a/src/NodeMetaContainer.php +++ b/src/PHPLib/Types/NodeMetaField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Types; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait NodeMetaContainer +trait NodeMetaField { /** @var array */ public array $NodeMeta; diff --git a/src/ServiceMetaContainer.php b/src/PHPLib/Types/ServiceMetaField.php similarity index 91% rename from src/ServiceMetaContainer.php rename to src/PHPLib/Types/ServiceMetaField.php index d2e7f1a4..ddc9d54c 100644 --- a/src/ServiceMetaContainer.php +++ b/src/PHPLib/Types/ServiceMetaField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Types; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait ServiceMetaContainer +trait ServiceMetaField { /** @var array */ public array $ServiceMeta; @@ -47,11 +47,10 @@ public function setServiceMetaValue(string $k, string $v): self */ public function setServiceMeta(null|\stdClass|array $ServiceMeta): self { + unset($this->ServiceMeta); if (null === $ServiceMeta) { - unset($this->ServiceMeta); return $this; } - $this->ServiceMeta = []; foreach ($ServiceMeta as $k => $v) { $this->setServiceMetaValue($k, $v); } diff --git a/src/TaggedAddressContainer.php b/src/PHPLib/Types/TaggedAddressField.php similarity index 95% rename from src/TaggedAddressContainer.php rename to src/PHPLib/Types/TaggedAddressField.php index eebec1b3..7ec21e25 100644 --- a/src/TaggedAddressContainer.php +++ b/src/PHPLib/Types/TaggedAddressField.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Types; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -trait TaggedAddressContainer +trait TaggedAddressField { /** @var array */ public array $TaggedAddresses; diff --git a/src/funcs.php b/src/PHPLib/funcs.php similarity index 96% rename from src/funcs.php rename to src/PHPLib/funcs.php index 14185a00..f90910bb 100644 --- a/src/funcs.php +++ b/src/PHPLib/funcs.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) diff --git a/src/PreparedQuery/PreparedQueryClient.php b/src/PreparedQuery/PreparedQueryClient.php index 27e3d187..8505304c 100644 --- a/src/PreparedQuery/PreparedQueryClient.php +++ b/src/PreparedQuery/PreparedQueryClient.php @@ -22,9 +22,9 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedWriteStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteStringResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class PreparedQueryClient extends AbstractClient { diff --git a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php index 595e93f6..f21d28f3 100644 --- a/src/PreparedQuery/PreparedQueryDefinitionsResponse.php +++ b/src/PreparedQuery/PreparedQueryDefinitionsResponse.php @@ -20,8 +20,8 @@ namespace DCarbone\PHPConsulAPI\PreparedQuery; -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class PreparedQueryDefinitionsResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php b/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php index 3fe9b80c..99fc47a3 100644 --- a/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php +++ b/src/PreparedQuery/PreparedQueryExecuteResponseResponse.php @@ -20,8 +20,8 @@ namespace DCarbone\PHPConsulAPI\PreparedQuery; -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class PreparedQueryExecuteResponseResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/QueryOptions.php b/src/QueryOptions.php index 92ecc7c6..75f79f87 100644 --- a/src/QueryOptions.php +++ b/src/QueryOptions.php @@ -21,6 +21,7 @@ */ use DCarbone\Go\Time; +use function DCarbone\PHPConsulAPI\PHPLib\dur_to_millisecond; class QueryOptions implements RequestOptions { diff --git a/src/Request.php b/src/Request.php index 06540d40..510743d8 100644 --- a/src/Request.php +++ b/src/Request.php @@ -25,6 +25,7 @@ use GuzzleHttp\Psr7\Uri; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; +use function DCarbone\PHPConsulAPI\PHPLib\dur_to_millisecond; class Request { diff --git a/src/Session/SessionClient.php b/src/Session/SessionClient.php index 00e51fe1..8cd2ec83 100644 --- a/src/Session/SessionClient.php +++ b/src/Session/SessionClient.php @@ -24,9 +24,9 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\Error; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedWriteStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedWriteStringResponse; use DCarbone\PHPConsulAPI\WriteOptions; -use DCarbone\PHPConsulAPI\WriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\WriteResponse; class SessionClient extends AbstractClient { diff --git a/src/Session/SessionEntriesQueryResponse.php b/src/Session/SessionEntriesQueryResponse.php index 08a25a10..19aa369a 100644 --- a/src/Session/SessionEntriesQueryResponse.php +++ b/src/Session/SessionEntriesQueryResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedQueryResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedQueryResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class SessionEntriesQueryResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { diff --git a/src/Session/SessionEntriesWriteResponse.php b/src/Session/SessionEntriesWriteResponse.php index 4e7f13a9..a05f188b 100644 --- a/src/Session/SessionEntriesWriteResponse.php +++ b/src/Session/SessionEntriesWriteResponse.php @@ -20,8 +20,8 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractValuedWriteResponse; -use DCarbone\PHPConsulAPI\UnmarshalledResponseInterface; +use DCarbone\PHPConsulAPI\PHPLib\Response\AbstractValuedWriteResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\UnmarshalledResponseInterface; class SessionEntriesWriteResponse extends AbstractValuedWriteResponse implements UnmarshalledResponseInterface { diff --git a/src/Session/SessionEntry.php b/src/Session/SessionEntry.php index fe6490e7..282901bb 100644 --- a/src/Session/SessionEntry.php +++ b/src/Session/SessionEntry.php @@ -24,8 +24,6 @@ use DCarbone\PHPConsulAPI\AbstractModel; use DCarbone\PHPConsulAPI\Transcoding; -use function DCarbone\PHPConsulAPI\dur_to_millisecond; - class SessionEntry extends AbstractModel { protected const FIELDS = [ diff --git a/src/Status/StatusClient.php b/src/Status/StatusClient.php index 6659c958..0014b6fc 100644 --- a/src/Status/StatusClient.php +++ b/src/Status/StatusClient.php @@ -22,8 +22,8 @@ use DCarbone\PHPConsulAPI\AbstractClient; use DCarbone\PHPConsulAPI\QueryOptions; -use DCarbone\PHPConsulAPI\ValuedStringResponse; -use DCarbone\PHPConsulAPI\ValuedStringsResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedStringResponse; +use DCarbone\PHPConsulAPI\PHPLib\Response\ValuedStringsResponse; class StatusClient extends AbstractClient { diff --git a/tools/php-cs-fixer/composer.lock b/tools/php-cs-fixer/composer.lock index 312dd7fe..fc8b95ef 100644 --- a/tools/php-cs-fixer/composer.lock +++ b/tools/php-cs-fixer/composer.lock @@ -196,16 +196,16 @@ }, { "name": "composer/semver", - "version": "3.4.3", + "version": "3.4.4", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12" + "reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", - "reference": "4313d26ada5e0c4edfbd1dc481a92ff7bff91f12", + "url": "https://api.github.com/repos/composer/semver/zipball/198166618906cb2de69b95d7d47e5fa8aa1b2b95", + "reference": "198166618906cb2de69b95d7d47e5fa8aa1b2b95", "shasum": "" }, "require": { @@ -257,7 +257,7 @@ "support": { "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.4.3" + "source": "https://github.com/composer/semver/tree/3.4.4" }, "funding": [ { @@ -267,13 +267,9 @@ { "url": "https://github.com/composer", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" } ], - "time": "2024-09-19T14:15:21+00:00" + "time": "2025-08-20T19:15:30+00:00" }, { "name": "composer/xdebug-handler", @@ -390,16 +386,16 @@ }, { "name": "fidry/cpu-core-counter", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "8520451a140d3f46ac33042715115e290cf5785f" + "reference": "db9508f7b1474469d9d3c53b86f817e344732678" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", - "reference": "8520451a140d3f46ac33042715115e290cf5785f", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678", + "reference": "db9508f7b1474469d9d3c53b86f817e344732678", "shasum": "" }, "require": { @@ -409,10 +405,10 @@ "fidry/makefile": "^0.2.0", "fidry/php-cs-fixer-config": "^1.1.2", "phpstan/extension-installer": "^1.2.0", - "phpstan/phpstan": "^1.9.2", - "phpstan/phpstan-deprecation-rules": "^1.0.0", - "phpstan/phpstan-phpunit": "^1.2.2", - "phpstan/phpstan-strict-rules": "^1.4.4", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^8.5.31 || ^9.5.26", "webmozarts/strict-phpunit": "^7.5" }, @@ -439,7 +435,7 @@ ], "support": { "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" + "source": "https://github.com/theofidry/cpu-core-counter/tree/1.3.0" }, "funding": [ { @@ -447,7 +443,7 @@ "type": "github" } ], - "time": "2024-08-06T10:04:20+00:00" + "time": "2025-08-14T07:29:31+00:00" }, { "name": "friendsofphp/php-cs-fixer", @@ -1003,23 +999,23 @@ }, { "name": "react/promise", - "version": "v3.2.0", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63" + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63", + "url": "https://api.github.com/repos/reactphp/promise/zipball/23444f53a813a3296c1368bb104793ce8d88f04a", + "reference": "23444f53a813a3296c1368bb104793ce8d88f04a", "shasum": "" }, "require": { "php": ">=7.1.0" }, "require-dev": { - "phpstan/phpstan": "1.10.39 || 1.4.10", + "phpstan/phpstan": "1.12.28 || 1.4.10", "phpunit/phpunit": "^9.6 || ^7.5" }, "type": "library", @@ -1064,7 +1060,7 @@ ], "support": { "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v3.2.0" + "source": "https://github.com/reactphp/promise/tree/v3.3.0" }, "funding": [ { @@ -1072,7 +1068,7 @@ "type": "open_collective" } ], - "time": "2024-05-24T10:39:05+00:00" + "time": "2025-08-19T18:57:03+00:00" }, { "name": "react/socket", @@ -1301,16 +1297,16 @@ }, { "name": "symfony/console", - "version": "v6.4.20", + "version": "v6.4.26", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36" + "reference": "492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/2e4af9c952617cc3f9559ff706aee420a8464c36", - "reference": "2e4af9c952617cc3f9559ff706aee420a8464c36", + "url": "https://api.github.com/repos/symfony/console/zipball/492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f", + "reference": "492de6dfd93910d7d7a729c5a04ddcd2b9e99c4f", "shasum": "" }, "require": { @@ -1375,7 +1371,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.20" + "source": "https://github.com/symfony/console/tree/v6.4.26" }, "funding": [ { @@ -1386,25 +1382,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-03-03T17:16:38+00:00" + "time": "2025-09-26T12:13:46+00:00" }, { "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": { @@ -1417,7 +1417,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -1442,7 +1442,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": [ { @@ -1458,20 +1458,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v6.4.13", + "version": "v6.4.25", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e" + "reference": "b0cf3162020603587363f0551cd3be43958611ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e", - "reference": "0ffc48080ab3e9132ea74ef4e09d8dcf26bf897e", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b0cf3162020603587363f0551cd3be43958611ff", + "reference": "b0cf3162020603587363f0551cd3be43958611ff", "shasum": "" }, "require": { @@ -1522,7 +1522,7 @@ "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v6.4.13" + "source": "https://github.com/symfony/event-dispatcher/tree/v6.4.25" }, "funding": [ { @@ -1533,25 +1533,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-25T14:18:03+00:00" + "time": "2025-08-13T09:41:44+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "7642f5e970b672283b7823222ae8ef8bbc160b9f" + "reference": "59eb412e93815df44f05f342958efa9f46b1e586" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/7642f5e970b672283b7823222ae8ef8bbc160b9f", - "reference": "7642f5e970b672283b7823222ae8ef8bbc160b9f", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586", + "reference": "59eb412e93815df44f05f342958efa9f46b1e586", "shasum": "" }, "require": { @@ -1565,7 +1569,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -1598,7 +1602,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0" }, "funding": [ { @@ -1614,20 +1618,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2024-09-25T14:21:43+00:00" }, { "name": "symfony/filesystem", - "version": "v6.4.13", + "version": "v6.4.24", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "4856c9cf585d5a0313d8d35afd681a526f038dd3" + "reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/4856c9cf585d5a0313d8d35afd681a526f038dd3", - "reference": "4856c9cf585d5a0313d8d35afd681a526f038dd3", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/75ae2edb7cdcc0c53766c30b0a2512b8df574bd8", + "reference": "75ae2edb7cdcc0c53766c30b0a2512b8df574bd8", "shasum": "" }, "require": { @@ -1664,7 +1668,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.4.13" + "source": "https://github.com/symfony/filesystem/tree/v6.4.24" }, "funding": [ { @@ -1675,25 +1679,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-10-25T15:07:50+00:00" + "time": "2025-07-10T08:14:14+00:00" }, { "name": "symfony/finder", - "version": "v6.4.17", + "version": "v6.4.24", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7" + "reference": "73089124388c8510efb8d2d1689285d285937b08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7", - "reference": "1d0e8266248c5d9ab6a87e3789e6dc482af3c9c7", + "url": "https://api.github.com/repos/symfony/finder/zipball/73089124388c8510efb8d2d1689285d285937b08", + "reference": "73089124388c8510efb8d2d1689285d285937b08", "shasum": "" }, "require": { @@ -1728,7 +1736,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v6.4.17" + "source": "https://github.com/symfony/finder/tree/v6.4.24" }, "funding": [ { @@ -1739,25 +1747,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-12-29T13:51:37+00:00" + "time": "2025-07-15T12:02:45+00:00" }, { "name": "symfony/options-resolver", - "version": "v6.4.16", + "version": "v6.4.25", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "368128ad168f20e22c32159b9f761e456cec0c78" + "reference": "d28e7e2db8a73e9511df892d36445f61314bbebe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/368128ad168f20e22c32159b9f761e456cec0c78", - "reference": "368128ad168f20e22c32159b9f761e456cec0c78", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/d28e7e2db8a73e9511df892d36445f61314bbebe", + "reference": "d28e7e2db8a73e9511df892d36445f61314bbebe", "shasum": "" }, "require": { @@ -1795,7 +1807,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v6.4.16" + "source": "https://github.com/symfony/options-resolver/tree/v6.4.25" }, "funding": [ { @@ -1806,16 +1818,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-20T10:57:02+00:00" + "time": "2025-08-04T17:06:28+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", @@ -1874,7 +1890,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.33.0" }, "funding": [ { @@ -1885,6 +1901,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -1894,16 +1914,16 @@ }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70", + "reference": "380872130d3a5dd3ace2f4010d95125fde5d5c70", "shasum": "" }, "require": { @@ -1952,7 +1972,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.33.0" }, "funding": [ { @@ -1963,16 +1983,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-06-27T09:58:17+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -2033,7 +2057,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.33.0" }, "funding": [ { @@ -2044,6 +2068,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -2133,16 +2161,16 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", "shasum": "" }, "require": { @@ -2193,7 +2221,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0" }, "funding": [ { @@ -2204,16 +2232,20 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2025-01-02T08:10:11+00:00" }, { "name": "symfony/polyfill-php81", - "version": "v1.31.0", + "version": "v1.33.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php81.git", @@ -2269,7 +2301,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php81/tree/v1.33.0" }, "funding": [ { @@ -2280,6 +2312,10 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" @@ -2289,16 +2325,16 @@ }, { "name": "symfony/process", - "version": "v6.4.20", + "version": "v6.4.26", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "e2a61c16af36c9a07e5c9906498b73e091949a20" + "reference": "48bad913268c8cafabbf7034b39c8bb24fbc5ab8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e2a61c16af36c9a07e5c9906498b73e091949a20", - "reference": "e2a61c16af36c9a07e5c9906498b73e091949a20", + "url": "https://api.github.com/repos/symfony/process/zipball/48bad913268c8cafabbf7034b39c8bb24fbc5ab8", + "reference": "48bad913268c8cafabbf7034b39c8bb24fbc5ab8", "shasum": "" }, "require": { @@ -2330,7 +2366,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v6.4.20" + "source": "https://github.com/symfony/process/tree/v6.4.26" }, "funding": [ { @@ -2341,25 +2377,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-03-10T17:11:00+00:00" + "time": "2025-09-11T09:57:09+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.5.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0" + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/e53260aabf78fb3d63f8d79d69ece59f80d5eda0", - "reference": "e53260aabf78fb3d63f8d79d69ece59f80d5eda0", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4", + "reference": "f021b05a130d35510bd6b25fe9053c2a8a15d5d4", "shasum": "" }, "require": { @@ -2377,7 +2417,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.5-dev" + "dev-main": "3.6-dev" } }, "autoload": { @@ -2413,7 +2453,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.5.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.6.0" }, "funding": [ { @@ -2429,20 +2469,20 @@ "type": "tidelift" } ], - "time": "2024-09-25T14:20:29+00:00" + "time": "2025-04-25T09:37:31+00:00" }, { "name": "symfony/stopwatch", - "version": "v6.4.19", + "version": "v6.4.24", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c" + "reference": "b67e94e06a05d9572c2fa354483b3e13e3cb1898" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c", - "reference": "dfe1481c12c06266d0c3d58c0cb4b09bd497ab9c", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/b67e94e06a05d9572c2fa354483b3e13e3cb1898", + "reference": "b67e94e06a05d9572c2fa354483b3e13e3cb1898", "shasum": "" }, "require": { @@ -2475,7 +2515,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v6.4.19" + "source": "https://github.com/symfony/stopwatch/tree/v6.4.24" }, "funding": [ { @@ -2486,25 +2526,29 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2025-02-21T10:06:30+00:00" + "time": "2025-07-10T08:14:14+00:00" }, { "name": "symfony/string", - "version": "v6.4.15", + "version": "v6.4.26", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f" + "reference": "5621f039a71a11c87c106c1c598bdcd04a19aeea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", - "reference": "73a5e66ea2e1677c98d4449177c5a9cf9d8b4c6f", + "url": "https://api.github.com/repos/symfony/string/zipball/5621f039a71a11c87c106c1c598bdcd04a19aeea", + "reference": "5621f039a71a11c87c106c1c598bdcd04a19aeea", "shasum": "" }, "require": { @@ -2518,7 +2562,6 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/error-handler": "^5.4|^6.0|^7.0", "symfony/http-client": "^5.4|^6.0|^7.0", "symfony/intl": "^6.2|^7.0", "symfony/translation-contracts": "^2.5|^3.0", @@ -2561,7 +2604,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.4.15" + "source": "https://github.com/symfony/string/tree/v6.4.26" }, "funding": [ { @@ -2572,12 +2615,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-11-13T13:31:12+00:00" + "time": "2025-09-11T14:32:46+00:00" } ], "packages-dev": [], From 18ce19a38b875eebab714785cbf4b44374b86306 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 2 Oct 2025 20:04:35 -0500 Subject: [PATCH 79/79] more stuff and stuff --- src/ACL/ACLAuthMethod.php | 4 +- src/ACL/ACLAuthMethodListEntry.php | 4 +- src/ACL/ACLAuthMethodNamespaceRule.php | 4 +- src/ACL/ACLBindingRule.php | 4 +- src/ACL/ACLEntry.php | 4 +- src/ACL/ACLLink.php | 4 +- src/ACL/ACLLoginParams.php | 4 +- src/ACL/ACLNodeIdentity.php | 4 +- src/ACL/ACLOIDCAuthURLParams.php | 4 +- src/ACL/ACLOIDCCallbackParams.php | 4 +- src/ACL/ACLPolicy.php | 4 +- src/ACL/ACLPolicyListEntry.php | 4 +- src/ACL/ACLReplicationStatus.php | 4 +- src/ACL/ACLRole.php | 4 +- src/ACL/ACLServiceIdentity.php | 4 +- src/ACL/ACLTemplatedPolicy.php | 4 +- src/ACL/ACLTemplatedPolicyVariables.php | 4 +- src/ACL/ACLToken.php | 4 +- src/ACL/ACLTokenListEntry.php | 4 +- src/ACL/KubernetesAuthMethodConfig.php | 4 +- src/ACL/OIDCAuthMethodConfig.php | 4 +- src/Agent/AgentCheck.php | 4 +- src/Agent/AgentCheckUpdate.php | 4 +- src/Agent/AgentMember.php | 4 +- src/Agent/AgentService.php | 4 +- src/Agent/AgentServiceCheck.php | 4 +- src/Agent/AgentServiceChecks.php | 2 +- src/Agent/AgentServiceChecksInfo.php | 4 +- src/Agent/AgentServiceConnect.php | 4 +- src/Agent/AgentServiceConnectProxyConfig.php | 4 +- src/Agent/AgentServiceRegistration.php | 4 +- src/Agent/AgentToken.php | 4 +- src/Agent/AgentWeights.php | 4 +- src/Agent/ConnectProxyConfig.php | 4 +- src/Agent/GaugeValue.php | 4 +- src/Agent/MemberOpts.php | 4 +- src/Agent/MetricsInfo.php | 4 +- src/Agent/PointValue.php | 4 +- src/Agent/SampledValue.php | 4 +- src/Agent/ServiceRegisterOpts.php | 4 +- src/Agent/Upstream.php | 4 +- src/Catalog/CatalogDeregistration.php | 4 +- src/Catalog/CatalogNode.php | 4 +- src/Catalog/CatalogNodeServiceList.php | 4 +- src/Catalog/CatalogRegistration.php | 4 +- src/Catalog/CatalogService.php | 4 +- src/Catalog/CompoundServiceName.php | 4 +- src/Catalog/GatewayService.php | 4 +- src/Catalog/Node.php | 4 +- src/Catalog/ServiceAddress.php | 4 +- src/Catalog/Weights.php | 4 +- src/ConfigEntry/AccessLogsConfig.php | 4 +- src/ConfigEntry/CookieConfig.php | 4 +- src/ConfigEntry/DestinationConfig.php | 4 +- src/ConfigEntry/EnvoyExtension.php | 4 +- src/ConfigEntry/ExposeConfig.php | 4 +- src/ConfigEntry/ExposePath.php | 4 +- src/ConfigEntry/GatewayServiceTLSConfig.php | 4 +- src/ConfigEntry/GatewayTLSConfig.php | 4 +- src/ConfigEntry/GatewayTLSSDSConfig.php | 4 +- src/ConfigEntry/HTTPHeaderModifiers.php | 54 ++++--- src/ConfigEntry/HashPolicy.php | 4 +- src/ConfigEntry/IngressGatewayConfigEntry.php | 4 +- src/ConfigEntry/IngressListener.php | 4 +- src/ConfigEntry/IngressService.php | 4 +- src/ConfigEntry/IngressServiceConfig.php | 4 +- src/ConfigEntry/InstanceLevelRateLimits.php | 4 +- .../InstanceLevelRouteRateLimits.php | 4 +- .../IntentionHTTPHeaderPermission.php | 4 +- src/ConfigEntry/IntentionHTTPPermission.php | 4 +- .../IntentionJWTClaimVerification.php | 4 +- src/ConfigEntry/IntentionJWTRequirement.php | 4 +- src/ConfigEntry/IntentionPermission.php | 4 +- src/ConfigEntry/LeastRequestConfig.php | 4 +- src/ConfigEntry/LinkedService.php | 4 +- src/ConfigEntry/LoadBalancer.php | 22 +-- src/ConfigEntry/MeshConfigEntry.php | 4 +- src/ConfigEntry/MeshDirectionalTLSConfig.php | 4 +- src/ConfigEntry/MeshGatewayConfig.php | 4 +- src/ConfigEntry/MeshHTTPConfig.php | 4 +- src/ConfigEntry/MeshTLSConfig.php | 4 +- src/ConfigEntry/PassiveHealthCheck.php | 4 +- src/ConfigEntry/PeeringMeshConfig.php | 4 +- src/ConfigEntry/ProxyConfigEntry.php | 4 +- src/ConfigEntry/RateLimits.php | 4 +- src/ConfigEntry/RingHashConfig.php | 4 +- src/ConfigEntry/ServiceConfigEntry.php | 4 +- .../ServiceIntentionsConfigEntry.php | 4 +- .../ServiceResolverConfigEntry.php | 4 +- src/ConfigEntry/ServiceResolverFailover.php | 4 +- .../ServiceResolverFailoverPolicy.php | 4 +- .../ServiceResolverFailoverTarget.php | 4 +- .../ServiceResolverPrioritizeByLocality.php | 4 +- src/ConfigEntry/ServiceResolverRedirect.php | 4 +- src/ConfigEntry/ServiceResolverSubset.php | 4 +- src/ConfigEntry/ServiceRoute.php | 4 +- src/ConfigEntry/ServiceRouteDestination.php | 4 +- src/ConfigEntry/ServiceRouteHTTPMatch.php | 4 +- .../ServiceRouteHTTPMatchHeader.php | 4 +- .../ServiceRouteHTTPMatchQueryParam.php | 4 +- src/ConfigEntry/ServiceRouteMatch.php | 4 +- src/ConfigEntry/ServiceRouterConfigEntry.php | 4 +- src/ConfigEntry/ServiceSplit.php | 4 +- .../ServiceSplitterConfigEntry.php | 4 +- src/ConfigEntry/SourceIntention.php | 4 +- .../TerminatingGatewayConfigEntry.php | 4 +- src/ConfigEntry/TransparentProxyConfig.php | 4 +- .../TransparentProxyMeshConfig.php | 4 +- src/ConfigEntry/UpstreamConfig.php | 4 +- src/ConfigEntry/UpstreamConfiguration.php | 4 +- src/ConfigEntry/UpstreamLimits.php | 4 +- src/Coordinate/Coordinate.php | 4 +- src/Coordinate/CoordinateConfig.php | 4 +- src/Coordinate/CoordinateDatacenterMap.php | 4 +- src/Coordinate/CoordinateEntry.php | 4 +- src/Error.php | 20 +-- src/Event/UserEvent.php | 4 +- src/Health/HealthCheck.php | 140 +++++++++++++----- src/Health/HealthCheckDefinition.php | 4 +- src/Health/HealthChecks.php | 4 +- src/Health/ServiceEntriesResponse.php | 2 +- src/Health/ServiceEntry.php | 9 +- src/KV/CheckTxnOp.php | 34 +++-- src/KV/KVPair.php | 4 +- src/KV/KVPairs.php | 4 +- src/KV/KVTxnOp.php | 4 +- src/KV/KVTxnOps.php | 4 +- src/KV/KVTxnResponse.php | 4 +- src/KV/NodeTxnOp.php | 4 +- src/KV/ServiceTxnOp.php | 4 +- src/KV/TxnError.php | 4 +- src/KV/TxnErrors.php | 4 +- src/KV/TxnOp.php | 4 +- src/KV/TxnOps.php | 4 +- src/KV/TxnResponse.php | 4 +- src/KV/TxnResult.php | 4 +- src/KV/TxnResults.php | 4 +- src/Metrics/Label.php | 4 +- src/Operator/Area.php | 4 +- src/Operator/AreaJoinResponse.php | 4 +- src/Operator/AutopilotConfiguration.php | 4 +- src/Operator/AutopilotServer.php | 4 +- src/Operator/AutopilotState.php | 4 +- src/Operator/AutopilotUpgrade.php | 4 +- src/Operator/AutopilotZone.php | 4 +- src/Operator/AutopilotZoneUpgradeVersions.php | 4 +- src/Operator/OperatorHealthReply.php | 4 +- src/Operator/RaftConfiguration.php | 4 +- src/Operator/RaftServer.php | 4 +- src/Operator/SerfMember.php | 4 +- src/Operator/ServerHealth.php | 4 +- .../Types/AbstractType.php} | 4 +- src/Peering/Locality.php | 4 +- src/PreparedQuery/PreparedQueryDefinition.php | 4 +- .../PreparedQueryExecuteResponse.php | 4 +- src/PreparedQuery/QueryDNSOptions.php | 4 +- src/PreparedQuery/QueryDatacenterOptions.php | 4 +- src/PreparedQuery/QueryTemplate.php | 4 +- src/PreparedQuery/ServiceQuery.php | 4 +- src/Session/ServiceCheck.php | 4 +- src/Session/SessionEntry.php | 4 +- 161 files changed, 495 insertions(+), 400 deletions(-) rename src/{AbstractModel.php => PHPLib/Types/AbstractType.php} (93%) diff --git a/src/ACL/ACLAuthMethod.php b/src/ACL/ACLAuthMethod.php index 97949ace..47981ad3 100644 --- a/src/ACL/ACLAuthMethod.php +++ b/src/ACL/ACLAuthMethod.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLAuthMethod extends AbstractModel +class ACLAuthMethod extends AbstractType { public string $Name; public string $Type; diff --git a/src/ACL/ACLAuthMethodListEntry.php b/src/ACL/ACLAuthMethodListEntry.php index 8b5e5fb6..55d0f235 100644 --- a/src/ACL/ACLAuthMethodListEntry.php +++ b/src/ACL/ACLAuthMethodListEntry.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLAuthMethodListEntry extends AbstractModel +class ACLAuthMethodListEntry extends AbstractType { public string $Name; public string $Type; diff --git a/src/ACL/ACLAuthMethodNamespaceRule.php b/src/ACL/ACLAuthMethodNamespaceRule.php index 620c2533..0ceacfce 100644 --- a/src/ACL/ACLAuthMethodNamespaceRule.php +++ b/src/ACL/ACLAuthMethodNamespaceRule.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLAuthMethodNamespaceRule extends AbstractModel +class ACLAuthMethodNamespaceRule extends AbstractType { public string $Selector; public string $BindNamespace; diff --git a/src/ACL/ACLBindingRule.php b/src/ACL/ACLBindingRule.php index 5af47e1d..c950b5a0 100644 --- a/src/ACL/ACLBindingRule.php +++ b/src/ACL/ACLBindingRule.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLBindingRule extends AbstractModel +class ACLBindingRule extends AbstractType { public string $ID; public string $Description; diff --git a/src/ACL/ACLEntry.php b/src/ACL/ACLEntry.php index dd55e409..0b24e167 100644 --- a/src/ACL/ACLEntry.php +++ b/src/ACL/ACLEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLEntry extends AbstractModel +class ACLEntry extends AbstractType { public int $CreateIndex; public int $ModifyIndex; diff --git a/src/ACL/ACLLink.php b/src/ACL/ACLLink.php index ff5a0104..d9164623 100644 --- a/src/ACL/ACLLink.php +++ b/src/ACL/ACLLink.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLLink extends AbstractModel +class ACLLink extends AbstractType { public string $ID; public string $Name; diff --git a/src/ACL/ACLLoginParams.php b/src/ACL/ACLLoginParams.php index f291dad9..48723ec0 100644 --- a/src/ACL/ACLLoginParams.php +++ b/src/ACL/ACLLoginParams.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; -class ACLLoginParams extends AbstractModel +class ACLLoginParams extends AbstractType { use MetaField; diff --git a/src/ACL/ACLNodeIdentity.php b/src/ACL/ACLNodeIdentity.php index 852b79c4..216b8c11 100644 --- a/src/ACL/ACLNodeIdentity.php +++ b/src/ACL/ACLNodeIdentity.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLNodeIdentity extends AbstractModel +class ACLNodeIdentity extends AbstractType { public string $NodeName; public string $Datacenter; diff --git a/src/ACL/ACLOIDCAuthURLParams.php b/src/ACL/ACLOIDCAuthURLParams.php index 84140981..c2975c9f 100644 --- a/src/ACL/ACLOIDCAuthURLParams.php +++ b/src/ACL/ACLOIDCAuthURLParams.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; -class ACLOIDCAuthURLParams extends AbstractModel +class ACLOIDCAuthURLParams extends AbstractType { use MetaField; diff --git a/src/ACL/ACLOIDCCallbackParams.php b/src/ACL/ACLOIDCCallbackParams.php index 8242fa7a..3671e79e 100644 --- a/src/ACL/ACLOIDCCallbackParams.php +++ b/src/ACL/ACLOIDCCallbackParams.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLOIDCCallbackParams extends AbstractModel +class ACLOIDCCallbackParams extends AbstractType { public string $AuthMethod; public string $State; diff --git a/src/ACL/ACLPolicy.php b/src/ACL/ACLPolicy.php index 705012fb..48443c10 100644 --- a/src/ACL/ACLPolicy.php +++ b/src/ACL/ACLPolicy.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLPolicy extends AbstractModel +class ACLPolicy extends AbstractType { public string $ID; public string $Name; diff --git a/src/ACL/ACLPolicyListEntry.php b/src/ACL/ACLPolicyListEntry.php index 9bac385a..1db8b8d4 100644 --- a/src/ACL/ACLPolicyListEntry.php +++ b/src/ACL/ACLPolicyListEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLPolicyListEntry extends AbstractModel +class ACLPolicyListEntry extends AbstractType { public string $ID; public string $Name; diff --git a/src/ACL/ACLReplicationStatus.php b/src/ACL/ACLReplicationStatus.php index 6a8b82d4..ef2dcc27 100644 --- a/src/ACL/ACLReplicationStatus.php +++ b/src/ACL/ACLReplicationStatus.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLReplicationStatus extends AbstractModel +class ACLReplicationStatus extends AbstractType { public bool $Enabled; public bool $Running; diff --git a/src/ACL/ACLRole.php b/src/ACL/ACLRole.php index 6af27890..6962bcfe 100644 --- a/src/ACL/ACLRole.php +++ b/src/ACL/ACLRole.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLRole extends AbstractModel +class ACLRole extends AbstractType { public string $ID; public string $Name; diff --git a/src/ACL/ACLServiceIdentity.php b/src/ACL/ACLServiceIdentity.php index 153806e7..e09a7003 100644 --- a/src/ACL/ACLServiceIdentity.php +++ b/src/ACL/ACLServiceIdentity.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLServiceIdentity extends AbstractModel +class ACLServiceIdentity extends AbstractType { public string $ServiceName; /** @var string[] */ diff --git a/src/ACL/ACLTemplatedPolicy.php b/src/ACL/ACLTemplatedPolicy.php index 04d90697..4edc1dff 100644 --- a/src/ACL/ACLTemplatedPolicy.php +++ b/src/ACL/ACLTemplatedPolicy.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLTemplatedPolicy extends AbstractModel +class ACLTemplatedPolicy extends AbstractType { public string $TemplateName; public null|ACLTemplatedPolicyVariables $TemplateVariables; diff --git a/src/ACL/ACLTemplatedPolicyVariables.php b/src/ACL/ACLTemplatedPolicyVariables.php index 3e43c433..337fb175 100644 --- a/src/ACL/ACLTemplatedPolicyVariables.php +++ b/src/ACL/ACLTemplatedPolicyVariables.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLTemplatedPolicyVariables extends AbstractModel +class ACLTemplatedPolicyVariables extends AbstractType { public string $Name; diff --git a/src/ACL/ACLToken.php b/src/ACL/ACLToken.php index d94a5459..7b1480e0 100644 --- a/src/ACL/ACLToken.php +++ b/src/ACL/ACLToken.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLToken extends AbstractModel +class ACLToken extends AbstractType { use ACLTokenFields; diff --git a/src/ACL/ACLTokenListEntry.php b/src/ACL/ACLTokenListEntry.php index 88a9f3d3..2dc556d7 100644 --- a/src/ACL/ACLTokenListEntry.php +++ b/src/ACL/ACLTokenListEntry.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ACLTokenListEntry extends AbstractModel +class ACLTokenListEntry extends AbstractType { public int $CreateIndex; public int $ModifyIndex; diff --git a/src/ACL/KubernetesAuthMethodConfig.php b/src/ACL/KubernetesAuthMethodConfig.php index b8aff5e6..5492c296 100644 --- a/src/ACL/KubernetesAuthMethodConfig.php +++ b/src/ACL/KubernetesAuthMethodConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class KubernetesAuthMethodConfig extends AbstractModel +class KubernetesAuthMethodConfig extends AbstractType { public string $Host; public string $CACert; diff --git a/src/ACL/OIDCAuthMethodConfig.php b/src/ACL/OIDCAuthMethodConfig.php index c8f5effc..579b14ad 100644 --- a/src/ACL/OIDCAuthMethodConfig.php +++ b/src/ACL/OIDCAuthMethodConfig.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class OIDCAuthMethodConfig extends AbstractModel +class OIDCAuthMethodConfig extends AbstractType { /** @var array */ public array $JWTSupportedAlgs; diff --git a/src/Agent/AgentCheck.php b/src/Agent/AgentCheck.php index 847cfd79..e82afaf5 100644 --- a/src/Agent/AgentCheck.php +++ b/src/Agent/AgentCheck.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Health\HealthCheckDefinition; -class AgentCheck extends AbstractModel +class AgentCheck extends AbstractType { public string $Node; public string $CheckID; diff --git a/src/Agent/AgentCheckUpdate.php b/src/Agent/AgentCheckUpdate.php index bfa1eabe..74a4dd48 100644 --- a/src/Agent/AgentCheckUpdate.php +++ b/src/Agent/AgentCheckUpdate.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AgentCheckUpdate extends AbstractModel +class AgentCheckUpdate extends AbstractType { public string $Status; public string $Output; diff --git a/src/Agent/AgentMember.php b/src/Agent/AgentMember.php index 5083c02b..fe3dfb49 100644 --- a/src/Agent/AgentMember.php +++ b/src/Agent/AgentMember.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Consul; -class AgentMember extends AbstractModel +class AgentMember extends AbstractType { public string $Name; public string $Addr; diff --git a/src/Agent/AgentService.php b/src/Agent/AgentService.php index 086d7b20..9872478b 100644 --- a/src/Agent/AgentService.php +++ b/src/Agent/AgentService.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; -class AgentService extends AbstractModel +class AgentService extends AbstractType { use MetaField; diff --git a/src/Agent/AgentServiceCheck.php b/src/Agent/AgentServiceCheck.php index 9123dc9f..aff08e3a 100644 --- a/src/Agent/AgentServiceCheck.php +++ b/src/Agent/AgentServiceCheck.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Values; -class AgentServiceCheck extends AbstractModel +class AgentServiceCheck extends AbstractType { public string $CheckID; public string $Name; diff --git a/src/Agent/AgentServiceChecks.php b/src/Agent/AgentServiceChecks.php index 78684b5d..72b210c5 100644 --- a/src/Agent/AgentServiceChecks.php +++ b/src/Agent/AgentServiceChecks.php @@ -20,7 +20,7 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; class AgentServiceChecks implements \JsonSerializable, \Countable, \ArrayAccess { diff --git a/src/Agent/AgentServiceChecksInfo.php b/src/Agent/AgentServiceChecksInfo.php index b8718962..e6feb015 100644 --- a/src/Agent/AgentServiceChecksInfo.php +++ b/src/Agent/AgentServiceChecksInfo.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Health\HealthChecks; -class AgentServiceChecksInfo extends AbstractModel +class AgentServiceChecksInfo extends AbstractType { public string $AggregatedStatus; public null|AgentService $Service; diff --git a/src/Agent/AgentServiceConnect.php b/src/Agent/AgentServiceConnect.php index 53184d18..5554bf2e 100644 --- a/src/Agent/AgentServiceConnect.php +++ b/src/Agent/AgentServiceConnect.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AgentServiceConnect extends AbstractModel +class AgentServiceConnect extends AbstractType { public bool $Native; public null|AgentServiceRegistration $SidecarService; diff --git a/src/Agent/AgentServiceConnectProxyConfig.php b/src/Agent/AgentServiceConnectProxyConfig.php index 98cdd27e..01225f89 100644 --- a/src/Agent/AgentServiceConnectProxyConfig.php +++ b/src/Agent/AgentServiceConnectProxyConfig.php @@ -20,7 +20,7 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\ConfigEntry\AccessLogsConfig; use DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension; use DCarbone\PHPConsulAPI\ConfigEntry\ExposeConfig; @@ -28,7 +28,7 @@ use DCarbone\PHPConsulAPI\ConfigEntry\ProxyMode; use DCarbone\PHPConsulAPI\ConfigEntry\TransparentProxyConfig; -class AgentServiceConnectProxyConfig extends AbstractModel +class AgentServiceConnectProxyConfig extends AbstractType { /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\EnvoyExtension> */ public array $EnvoyExtensions; diff --git a/src/Agent/AgentServiceRegistration.php b/src/Agent/AgentServiceRegistration.php index 4389e3ea..a0e40a6f 100644 --- a/src/Agent/AgentServiceRegistration.php +++ b/src/Agent/AgentServiceRegistration.php @@ -20,12 +20,12 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Catalog\ServiceAddress; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; -class AgentServiceRegistration extends AbstractModel +class AgentServiceRegistration extends AbstractType { use MetaField; diff --git a/src/Agent/AgentToken.php b/src/Agent/AgentToken.php index 8b68ecab..61c880c1 100644 --- a/src/Agent/AgentToken.php +++ b/src/Agent/AgentToken.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AgentToken extends AbstractModel +class AgentToken extends AbstractType { public string $Token; diff --git a/src/Agent/AgentWeights.php b/src/Agent/AgentWeights.php index b3c68414..bd3f6f72 100644 --- a/src/Agent/AgentWeights.php +++ b/src/Agent/AgentWeights.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AgentWeights extends AbstractModel +class AgentWeights extends AbstractType { public int $Passing; public int $Warning; diff --git a/src/Agent/ConnectProxyConfig.php b/src/Agent/ConnectProxyConfig.php index 71338e66..5e9eff8c 100644 --- a/src/Agent/ConnectProxyConfig.php +++ b/src/Agent/ConnectProxyConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ConnectProxyConfig extends AbstractModel +class ConnectProxyConfig extends AbstractType { public string $ProxyServiceID; public string $TargetServiceID; diff --git a/src/Agent/GaugeValue.php b/src/Agent/GaugeValue.php index f5bdad93..d708fbcd 100644 --- a/src/Agent/GaugeValue.php +++ b/src/Agent/GaugeValue.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class GaugeValue extends AbstractModel +class GaugeValue extends AbstractType { public string $Name; public float $Value; diff --git a/src/Agent/MemberOpts.php b/src/Agent/MemberOpts.php index 3f65af10..573e3141 100644 --- a/src/Agent/MemberOpts.php +++ b/src/Agent/MemberOpts.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MemberOpts extends AbstractModel +class MemberOpts extends AbstractType { public bool $WAN; public string $Segment; diff --git a/src/Agent/MetricsInfo.php b/src/Agent/MetricsInfo.php index 6e17f26f..4d71ca8a 100644 --- a/src/Agent/MetricsInfo.php +++ b/src/Agent/MetricsInfo.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MetricsInfo extends AbstractModel +class MetricsInfo extends AbstractType { public string $Timestamp; /** @var \DCarbone\PHPConsulAPI\Agent\GaugeValue[] */ diff --git a/src/Agent/PointValue.php b/src/Agent/PointValue.php index 7bb0a659..a226147b 100644 --- a/src/Agent/PointValue.php +++ b/src/Agent/PointValue.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class PointValue extends AbstractModel +class PointValue extends AbstractType { public string $Name; /** @var float[] */ diff --git a/src/Agent/SampledValue.php b/src/Agent/SampledValue.php index db09c0b9..3fd7f589 100644 --- a/src/Agent/SampledValue.php +++ b/src/Agent/SampledValue.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class SampledValue extends AbstractModel +class SampledValue extends AbstractType { public string $Name; public int $Count; diff --git a/src/Agent/ServiceRegisterOpts.php b/src/Agent/ServiceRegisterOpts.php index 49cb5ccb..e55e6291 100644 --- a/src/Agent/ServiceRegisterOpts.php +++ b/src/Agent/ServiceRegisterOpts.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRegisterOpts extends AbstractModel +class ServiceRegisterOpts extends AbstractType { public bool $ReplaceExistingChecks; public string $Token; diff --git a/src/Agent/Upstream.php b/src/Agent/Upstream.php index 7cd3744a..e61a371a 100644 --- a/src/Agent/Upstream.php +++ b/src/Agent/Upstream.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\ConfigEntry\MeshGatewayConfig; -class Upstream extends AbstractModel +class Upstream extends AbstractType { public UpstreamDestType $DestinationType; public string $DestinationPartition; diff --git a/src/Catalog/CatalogDeregistration.php b/src/Catalog/CatalogDeregistration.php index a0b1d83a..9e5eac83 100644 --- a/src/Catalog/CatalogDeregistration.php +++ b/src/Catalog/CatalogDeregistration.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class CatalogDeregistration extends AbstractModel +class CatalogDeregistration extends AbstractType { public string $Node; public string $Address; diff --git a/src/Catalog/CatalogNode.php b/src/Catalog/CatalogNode.php index dc504e04..f0a441d4 100644 --- a/src/Catalog/CatalogNode.php +++ b/src/Catalog/CatalogNode.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentService; -class CatalogNode extends AbstractModel +class CatalogNode extends AbstractType { public null|Node $Node; /** @var array */ diff --git a/src/Catalog/CatalogNodeServiceList.php b/src/Catalog/CatalogNodeServiceList.php index 4061e865..03d6020e 100644 --- a/src/Catalog/CatalogNodeServiceList.php +++ b/src/Catalog/CatalogNodeServiceList.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentService; -class CatalogNodeServiceList extends AbstractModel +class CatalogNodeServiceList extends AbstractType { public null|Node $Node; /** @var array<\DCarbone\PHPConsulAPI\Agent\AgentService> */ diff --git a/src/Catalog/CatalogRegistration.php b/src/Catalog/CatalogRegistration.php index 173a4fc9..fd826197 100644 --- a/src/Catalog/CatalogRegistration.php +++ b/src/Catalog/CatalogRegistration.php @@ -20,7 +20,7 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentCheck; use DCarbone\PHPConsulAPI\Agent\AgentService; use DCarbone\PHPConsulAPI\Health\HealthChecks; @@ -28,7 +28,7 @@ use DCarbone\PHPConsulAPI\Peering\Locality; use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; -class CatalogRegistration extends AbstractModel +class CatalogRegistration extends AbstractType { use TaggedAddressField; use NodeMetaField; diff --git a/src/Catalog/CatalogService.php b/src/Catalog/CatalogService.php index 2ad8b883..82c97ec1 100644 --- a/src/Catalog/CatalogService.php +++ b/src/Catalog/CatalogService.php @@ -20,7 +20,7 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentServiceConnectProxyConfig; use DCarbone\PHPConsulAPI\Health\HealthChecks; use DCarbone\PHPConsulAPI\PHPLib\Types\NodeMetaField; @@ -28,7 +28,7 @@ use DCarbone\PHPConsulAPI\PHPLib\Types\ServiceMetaField; use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; -class CatalogService extends AbstractModel +class CatalogService extends AbstractType { use TaggedAddressField; use NodeMetaField; diff --git a/src/Catalog/CompoundServiceName.php b/src/Catalog/CompoundServiceName.php index f4c88432..c16e8221 100644 --- a/src/Catalog/CompoundServiceName.php +++ b/src/Catalog/CompoundServiceName.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class CompoundServiceName extends AbstractModel +class CompoundServiceName extends AbstractType { public string $Name; public string $Namespace; diff --git a/src/Catalog/GatewayService.php b/src/Catalog/GatewayService.php index 11d87a24..47183eae 100644 --- a/src/Catalog/GatewayService.php +++ b/src/Catalog/GatewayService.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\ServiceKind; -class GatewayService extends AbstractModel +class GatewayService extends AbstractType { public CompoundServiceName $Gateway; public CompoundServiceName $Service; diff --git a/src/Catalog/Node.php b/src/Catalog/Node.php index de08185f..9f0f6944 100644 --- a/src/Catalog/Node.php +++ b/src/Catalog/Node.php @@ -20,12 +20,12 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; use DCarbone\PHPConsulAPI\Peering\Locality; use DCarbone\PHPConsulAPI\PHPLib\Types\TaggedAddressField; -class Node extends AbstractModel +class Node extends AbstractType { use MetaField; use TaggedAddressField; diff --git a/src/Catalog/ServiceAddress.php b/src/Catalog/ServiceAddress.php index c6184f90..38223276 100644 --- a/src/Catalog/ServiceAddress.php +++ b/src/Catalog/ServiceAddress.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceAddress extends AbstractModel +class ServiceAddress extends AbstractType { public string $Address; public int $Port; diff --git a/src/Catalog/Weights.php b/src/Catalog/Weights.php index 452e92d3..73ceba2a 100644 --- a/src/Catalog/Weights.php +++ b/src/Catalog/Weights.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class Weights extends AbstractModel +class Weights extends AbstractType { public int $Passing; public int $Warning; diff --git a/src/ConfigEntry/AccessLogsConfig.php b/src/ConfigEntry/AccessLogsConfig.php index ac5de3dc..46096bec 100644 --- a/src/ConfigEntry/AccessLogsConfig.php +++ b/src/ConfigEntry/AccessLogsConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AccessLogsConfig extends AbstractModel +class AccessLogsConfig extends AbstractType { public bool $Enabled; public bool $DisableListenerLogs; diff --git a/src/ConfigEntry/CookieConfig.php b/src/ConfigEntry/CookieConfig.php index dc4be06f..3020622c 100644 --- a/src/ConfigEntry/CookieConfig.php +++ b/src/ConfigEntry/CookieConfig.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class CookieConfig extends AbstractModel +class CookieConfig extends AbstractType { public bool $Session; public Time\Duration $TTL; diff --git a/src/ConfigEntry/DestinationConfig.php b/src/ConfigEntry/DestinationConfig.php index ec2d89a8..f2f37085 100644 --- a/src/ConfigEntry/DestinationConfig.php +++ b/src/ConfigEntry/DestinationConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class DestinationConfig extends AbstractModel +class DestinationConfig extends AbstractType { /** @var array */ public array $Addresses; diff --git a/src/ConfigEntry/EnvoyExtension.php b/src/ConfigEntry/EnvoyExtension.php index 002bb8e4..935003c3 100644 --- a/src/ConfigEntry/EnvoyExtension.php +++ b/src/ConfigEntry/EnvoyExtension.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class EnvoyExtension extends AbstractModel +class EnvoyExtension extends AbstractType { public string $Name; public bool $Required; diff --git a/src/ConfigEntry/ExposeConfig.php b/src/ConfigEntry/ExposeConfig.php index ecc79264..090581df 100644 --- a/src/ConfigEntry/ExposeConfig.php +++ b/src/ConfigEntry/ExposeConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ExposeConfig extends AbstractModel +class ExposeConfig extends AbstractType { public bool $Checks; /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\ExposePath> */ diff --git a/src/ConfigEntry/ExposePath.php b/src/ConfigEntry/ExposePath.php index 4ac4994a..80f039c9 100644 --- a/src/ConfigEntry/ExposePath.php +++ b/src/ConfigEntry/ExposePath.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ExposePath extends AbstractModel +class ExposePath extends AbstractType { public int $ListenerPort; public string $Path; diff --git a/src/ConfigEntry/GatewayServiceTLSConfig.php b/src/ConfigEntry/GatewayServiceTLSConfig.php index e9de413b..a75bed5a 100644 --- a/src/ConfigEntry/GatewayServiceTLSConfig.php +++ b/src/ConfigEntry/GatewayServiceTLSConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class GatewayServiceTLSConfig extends AbstractModel +class GatewayServiceTLSConfig extends AbstractType { public null|GatewayTLSSDSConfig $SDS; diff --git a/src/ConfigEntry/GatewayTLSConfig.php b/src/ConfigEntry/GatewayTLSConfig.php index 18b1b316..c9cef188 100644 --- a/src/ConfigEntry/GatewayTLSConfig.php +++ b/src/ConfigEntry/GatewayTLSConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class GatewayTLSConfig extends AbstractModel +class GatewayTLSConfig extends AbstractType { public bool $Enabled; public null|GatewayTLSSDSConfig $SDS; diff --git a/src/ConfigEntry/GatewayTLSSDSConfig.php b/src/ConfigEntry/GatewayTLSSDSConfig.php index 46e506de..5dcdabac 100644 --- a/src/ConfigEntry/GatewayTLSSDSConfig.php +++ b/src/ConfigEntry/GatewayTLSSDSConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class GatewayTLSSDSConfig extends AbstractModel +class GatewayTLSSDSConfig extends AbstractType { public string $ClusterName; public string $CertResource; diff --git a/src/ConfigEntry/HTTPHeaderModifiers.php b/src/ConfigEntry/HTTPHeaderModifiers.php index 887e1dbd..6a72a0f2 100644 --- a/src/ConfigEntry/HTTPHeaderModifiers.php +++ b/src/ConfigEntry/HTTPHeaderModifiers.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class HTTPHeaderModifiers extends AbstractModel +class HTTPHeaderModifiers extends AbstractType { /** @var array */ public array $Add; @@ -32,18 +32,20 @@ class HTTPHeaderModifiers extends AbstractModel public array $Remove; /** - * @param array $Add - * @param array $Set - * @param array $Remove + * @param null|array $Add + * @param null|array $Set + * @param null|array $Remove */ public function __construct( - array $Add = [], - array $Set = [], - array $Remove = [] + null|array $Add = null, + null|array $Set = null, + null|array $Remove = null, ) { $this->setAdd($Add); $this->setSet($Set); - $this->setRemove(...$Remove); + if (null !== $Remove) { + $this->setRemove(...$Remove); + } } /** @@ -54,18 +56,26 @@ public function getAdd(): array return $this->Add; } + public function setAddKey(string $k, string $v): self + { + if (!isset($this->Add)) { + $this->Add = []; + } + $this->Add[$k] = $v; + return $this; + } + /** * @param null|\stdClass|array $Add */ public function setAdd(null|\stdClass|array $Add): self { + unset($this->Add); if (null === $Add) { - unset($this->Add); return $this; } - $this->Add = []; foreach ($Add as $k => $v) { - $this->Add[$k] = $v; + $this->setAddKey($k, $v); } return $this; } @@ -78,18 +88,26 @@ public function getSet(): array return $this->Set; } + public function setSetKey(string $k, string $v): self + { + if (!isset($this->Set)) { + $this->Set = []; + } + $this->Set[$k] = $v; + return $this; + } + /** * @param null|\stdClass|array $Set */ public function setSet(null|\stdClass|array $Set): self { + unset($this->Set); if (null === $Set) { - unset($this->Set); return $this; } - $this->Set = []; foreach ($Set as $k => $v) { - $this->Set[$k] = $v; + $this->setSetKey($k, $v); } return $this; } @@ -117,7 +135,9 @@ public static function jsonUnserialize(\stdClass $decoded): self } elseif ('Add' === $k) { $n->setAdd($v); } elseif ('Remove' === $k) { - $n->setRemove(...$v); + if (null !== $v) { + $n->setRemove(...$v); + } } else { $n->{$k} = $v; } @@ -134,7 +154,7 @@ public function jsonSerialize(): \stdClass if (isset($this->Set)) { $out->Set = $this->Set; } - if ([] !== $this->Remove) { + if (isset($this->Remove)) { $out->Remove = $this->Remove; } return $out; diff --git a/src/ConfigEntry/HashPolicy.php b/src/ConfigEntry/HashPolicy.php index 7525ff63..5f504eb5 100644 --- a/src/ConfigEntry/HashPolicy.php +++ b/src/ConfigEntry/HashPolicy.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class HashPolicy extends AbstractModel +class HashPolicy extends AbstractType { public string $Field; public string $FieldValue; diff --git a/src/ConfigEntry/IngressGatewayConfigEntry.php b/src/ConfigEntry/IngressGatewayConfigEntry.php index 49f16994..23a5cd96 100644 --- a/src/ConfigEntry/IngressGatewayConfigEntry.php +++ b/src/ConfigEntry/IngressGatewayConfigEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IngressGatewayConfigEntry extends AbstractModel implements ConfigEntry +class IngressGatewayConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/IngressListener.php b/src/ConfigEntry/IngressListener.php index 3a1a3914..d024d9f2 100644 --- a/src/ConfigEntry/IngressListener.php +++ b/src/ConfigEntry/IngressListener.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IngressListener extends AbstractModel +class IngressListener extends AbstractType { public int $Port; public string $Protocol; diff --git a/src/ConfigEntry/IngressService.php b/src/ConfigEntry/IngressService.php index 65e06ddd..1c3e33c8 100644 --- a/src/ConfigEntry/IngressService.php +++ b/src/ConfigEntry/IngressService.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IngressService extends AbstractModel +class IngressService extends AbstractType { public string $Name; /** @var array */ diff --git a/src/ConfigEntry/IngressServiceConfig.php b/src/ConfigEntry/IngressServiceConfig.php index 80e4c27b..fdd386f9 100644 --- a/src/ConfigEntry/IngressServiceConfig.php +++ b/src/ConfigEntry/IngressServiceConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IngressServiceConfig extends AbstractModel +class IngressServiceConfig extends AbstractType { public null|int $MaxConnections; public null|int $MaxPendingRequests; diff --git a/src/ConfigEntry/InstanceLevelRateLimits.php b/src/ConfigEntry/InstanceLevelRateLimits.php index e05de6c3..c59e9977 100644 --- a/src/ConfigEntry/InstanceLevelRateLimits.php +++ b/src/ConfigEntry/InstanceLevelRateLimits.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class InstanceLevelRateLimits extends AbstractModel +class InstanceLevelRateLimits extends AbstractType { public int $RequestsPerSecond; public int $RequestsMaxBurst; diff --git a/src/ConfigEntry/InstanceLevelRouteRateLimits.php b/src/ConfigEntry/InstanceLevelRouteRateLimits.php index 4dcddb5c..20aca99e 100644 --- a/src/ConfigEntry/InstanceLevelRouteRateLimits.php +++ b/src/ConfigEntry/InstanceLevelRouteRateLimits.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class InstanceLevelRouteRateLimits extends AbstractModel +class InstanceLevelRouteRateLimits extends AbstractType { public string $PathExact; public string $PathPrefix; diff --git a/src/ConfigEntry/IntentionHTTPHeaderPermission.php b/src/ConfigEntry/IntentionHTTPHeaderPermission.php index 59cccb05..942075e9 100644 --- a/src/ConfigEntry/IntentionHTTPHeaderPermission.php +++ b/src/ConfigEntry/IntentionHTTPHeaderPermission.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Encoding\SimpleJsonUnserializeTrait; -class IntentionHTTPHeaderPermission extends AbstractModel +class IntentionHTTPHeaderPermission extends AbstractType { use SimpleJsonUnserializeTrait; diff --git a/src/ConfigEntry/IntentionHTTPPermission.php b/src/ConfigEntry/IntentionHTTPPermission.php index ab77b5f7..130bdd7b 100644 --- a/src/ConfigEntry/IntentionHTTPPermission.php +++ b/src/ConfigEntry/IntentionHTTPPermission.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IntentionHTTPPermission extends AbstractModel +class IntentionHTTPPermission extends AbstractType { public string $PathExact; public string $PathPrefix; diff --git a/src/ConfigEntry/IntentionJWTClaimVerification.php b/src/ConfigEntry/IntentionJWTClaimVerification.php index ccd0521d..ea7bb603 100644 --- a/src/ConfigEntry/IntentionJWTClaimVerification.php +++ b/src/ConfigEntry/IntentionJWTClaimVerification.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Encoding\SimpleJsonUnserializeTrait; -class IntentionJWTClaimVerification extends AbstractModel +class IntentionJWTClaimVerification extends AbstractType { use SimpleJsonUnserializeTrait; diff --git a/src/ConfigEntry/IntentionJWTRequirement.php b/src/ConfigEntry/IntentionJWTRequirement.php index c4d754fc..eb07cd9d 100644 --- a/src/ConfigEntry/IntentionJWTRequirement.php +++ b/src/ConfigEntry/IntentionJWTRequirement.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IntentionJWTRequirement extends AbstractModel +class IntentionJWTRequirement extends AbstractType { public string $Name; /** @var array<\DCarbone\PHPConsulAPI\ConfigEntry\IntentionJWTClaimVerification> */ diff --git a/src/ConfigEntry/IntentionPermission.php b/src/ConfigEntry/IntentionPermission.php index 374dfa7c..d322e89e 100644 --- a/src/ConfigEntry/IntentionPermission.php +++ b/src/ConfigEntry/IntentionPermission.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class IntentionPermission extends AbstractModel +class IntentionPermission extends AbstractType { public IntentionAction $Action; public null|IntentionHTTPPermission $HTTP; diff --git a/src/ConfigEntry/LeastRequestConfig.php b/src/ConfigEntry/LeastRequestConfig.php index a9d55f4b..41369010 100644 --- a/src/ConfigEntry/LeastRequestConfig.php +++ b/src/ConfigEntry/LeastRequestConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class LeastRequestConfig extends AbstractModel +class LeastRequestConfig extends AbstractType { public int $ChoiceCount; diff --git a/src/ConfigEntry/LinkedService.php b/src/ConfigEntry/LinkedService.php index 3035a496..06c4ce6e 100644 --- a/src/ConfigEntry/LinkedService.php +++ b/src/ConfigEntry/LinkedService.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class LinkedService extends AbstractModel +class LinkedService extends AbstractType { public string $Namespace; public string $Name; diff --git a/src/ConfigEntry/LoadBalancer.php b/src/ConfigEntry/LoadBalancer.php index 4eb04358..b455be54 100644 --- a/src/ConfigEntry/LoadBalancer.php +++ b/src/ConfigEntry/LoadBalancer.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class LoadBalancer extends AbstractModel +class LoadBalancer extends AbstractType { public string $Policy; public null|RingHashConfig $RingHashConfig; @@ -37,12 +37,14 @@ public function __construct( string $Policy = '', null|RingHashConfig $RingHashConfig = null, null|LeastRequestConfig $LeastRequestConfig = null, - array $HashPolicies = [] + null|array $HashPolicies = null ) { $this->Policy = $Policy; $this->RingHashConfig = $RingHashConfig; $this->LeastRequestConfig = $LeastRequestConfig; - $this->setHashPolicies(...$HashPolicies); + if (null !== $HashPolicies) { + $this->setHashPolicies(...$HashPolicies); + } } public function getPolicy(): string @@ -98,14 +100,16 @@ public function setHashPolicies(HashPolicy ...$HashPolicies): self public static function jsonUnserialize(\stdClass $decoded): self { $n = new self(); - foreach($decoded as $k => $v) { + foreach ($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) { - foreach ($v as $hp) { - $n->HashPolicies[] = HashPolicy::jsonUnserialize($hp); + if (null !== $v) { + foreach ($v as $hp) { + $n->HashPolicies[] = HashPolicy::jsonUnserialize($hp); + } } } else { $n->{$k} = $v; @@ -126,9 +130,9 @@ public function jsonSerialize(): \stdClass if (null !== $this->LeastRequestConfig) { $out->LeastRequestConfig = $this->LeastRequestConfig; } - if ([] !== $this->HashPolicies) { + if (isset($this->HashPolicies)) { $out->HashPolicies = $this->HashPolicies; } return $out; } -} \ No newline at end of file +} diff --git a/src/ConfigEntry/MeshConfigEntry.php b/src/ConfigEntry/MeshConfigEntry.php index b05a8743..9e499e81 100644 --- a/src/ConfigEntry/MeshConfigEntry.php +++ b/src/ConfigEntry/MeshConfigEntry.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Consul; -class MeshConfigEntry extends AbstractModel implements ConfigEntry +class MeshConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/MeshDirectionalTLSConfig.php b/src/ConfigEntry/MeshDirectionalTLSConfig.php index 405e5abc..9585cd97 100644 --- a/src/ConfigEntry/MeshDirectionalTLSConfig.php +++ b/src/ConfigEntry/MeshDirectionalTLSConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MeshDirectionalTLSConfig extends AbstractModel +class MeshDirectionalTLSConfig extends AbstractType { public string $TLSMinVersion; public string $TLSMaxVersion; diff --git a/src/ConfigEntry/MeshGatewayConfig.php b/src/ConfigEntry/MeshGatewayConfig.php index 8ed4a1f2..87569428 100644 --- a/src/ConfigEntry/MeshGatewayConfig.php +++ b/src/ConfigEntry/MeshGatewayConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MeshGatewayConfig extends AbstractModel +class MeshGatewayConfig extends AbstractType { public MeshGatewayMode $Mode; diff --git a/src/ConfigEntry/MeshHTTPConfig.php b/src/ConfigEntry/MeshHTTPConfig.php index 5f658b25..48712196 100644 --- a/src/ConfigEntry/MeshHTTPConfig.php +++ b/src/ConfigEntry/MeshHTTPConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MeshHTTPConfig extends AbstractModel +class MeshHTTPConfig extends AbstractType { public bool $SanitizeXForwardClientCert; diff --git a/src/ConfigEntry/MeshTLSConfig.php b/src/ConfigEntry/MeshTLSConfig.php index cfddc757..9077a21e 100644 --- a/src/ConfigEntry/MeshTLSConfig.php +++ b/src/ConfigEntry/MeshTLSConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class MeshTLSConfig extends AbstractModel +class MeshTLSConfig extends AbstractType { public null|MeshDirectionalTLSConfig $Incoming; public null|MeshDirectionalTLSConfig $Outgoing; diff --git a/src/ConfigEntry/PassiveHealthCheck.php b/src/ConfigEntry/PassiveHealthCheck.php index 8b412604..af75279d 100644 --- a/src/ConfigEntry/PassiveHealthCheck.php +++ b/src/ConfigEntry/PassiveHealthCheck.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class PassiveHealthCheck extends AbstractModel +class PassiveHealthCheck extends AbstractType { public Time\Duration $Interval; public int $MaxFailures; diff --git a/src/ConfigEntry/PeeringMeshConfig.php b/src/ConfigEntry/PeeringMeshConfig.php index 7628a858..d18a581f 100644 --- a/src/ConfigEntry/PeeringMeshConfig.php +++ b/src/ConfigEntry/PeeringMeshConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class PeeringMeshConfig extends AbstractModel +class PeeringMeshConfig extends AbstractType { public bool $PeerThroughMeshGateways; diff --git a/src/ConfigEntry/ProxyConfigEntry.php b/src/ConfigEntry/ProxyConfigEntry.php index 23a7265d..a43c86ab 100644 --- a/src/ConfigEntry/ProxyConfigEntry.php +++ b/src/ConfigEntry/ProxyConfigEntry.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Consul; use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; -class ProxyConfigEntry extends AbstractModel implements ConfigEntry +class ProxyConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/RateLimits.php b/src/ConfigEntry/RateLimits.php index 43714f5d..7310516a 100644 --- a/src/ConfigEntry/RateLimits.php +++ b/src/ConfigEntry/RateLimits.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class RateLimits extends AbstractModel +class RateLimits extends AbstractType { public InstanceLevelRateLimits $InstanceLevel; diff --git a/src/ConfigEntry/RingHashConfig.php b/src/ConfigEntry/RingHashConfig.php index 53d1e9b4..03ad50e7 100644 --- a/src/ConfigEntry/RingHashConfig.php +++ b/src/ConfigEntry/RingHashConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class RingHashConfig extends AbstractModel +class RingHashConfig extends AbstractType { public int $MinimumRingSize = 0; public int $MaximumRingSize = 0; diff --git a/src/ConfigEntry/ServiceConfigEntry.php b/src/ConfigEntry/ServiceConfigEntry.php index edaf286d..8ad7e011 100644 --- a/src/ConfigEntry/ServiceConfigEntry.php +++ b/src/ConfigEntry/ServiceConfigEntry.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; -class ServiceConfigEntry extends AbstractModel implements ConfigEntry +class ServiceConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/ServiceIntentionsConfigEntry.php b/src/ConfigEntry/ServiceIntentionsConfigEntry.php index 4f0b34bb..445711bf 100644 --- a/src/ConfigEntry/ServiceIntentionsConfigEntry.php +++ b/src/ConfigEntry/ServiceIntentionsConfigEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceIntentionsConfigEntry extends AbstractModel implements ConfigEntry +class ServiceIntentionsConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/ServiceResolverConfigEntry.php b/src/ConfigEntry/ServiceResolverConfigEntry.php index 1bf01531..58f3f000 100644 --- a/src/ConfigEntry/ServiceResolverConfigEntry.php +++ b/src/ConfigEntry/ServiceResolverConfigEntry.php @@ -20,13 +20,13 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\Go\Time; use stdClass; use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; -class ServiceResolverConfigEntry extends AbstractModel implements ConfigEntry +class ServiceResolverConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/ServiceResolverFailover.php b/src/ConfigEntry/ServiceResolverFailover.php index 4e84cfd5..ac731575 100644 --- a/src/ConfigEntry/ServiceResolverFailover.php +++ b/src/ConfigEntry/ServiceResolverFailover.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverFailover extends AbstractModel +class ServiceResolverFailover extends AbstractType { public string $Service; public string $ServiceSubset; diff --git a/src/ConfigEntry/ServiceResolverFailoverPolicy.php b/src/ConfigEntry/ServiceResolverFailoverPolicy.php index 629af612..e65f124f 100644 --- a/src/ConfigEntry/ServiceResolverFailoverPolicy.php +++ b/src/ConfigEntry/ServiceResolverFailoverPolicy.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverFailoverPolicy extends AbstractModel +class ServiceResolverFailoverPolicy extends AbstractType { public string $Mode; /** @var array */ diff --git a/src/ConfigEntry/ServiceResolverFailoverTarget.php b/src/ConfigEntry/ServiceResolverFailoverTarget.php index 6e14972d..bb4b01f3 100644 --- a/src/ConfigEntry/ServiceResolverFailoverTarget.php +++ b/src/ConfigEntry/ServiceResolverFailoverTarget.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverFailoverTarget extends AbstractModel +class ServiceResolverFailoverTarget extends AbstractType { public string $Service; public string $ServiceSubset; diff --git a/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php index b7060f7f..4fe169ed 100644 --- a/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php +++ b/src/ConfigEntry/ServiceResolverPrioritizeByLocality.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverPrioritizeByLocality extends AbstractModel +class ServiceResolverPrioritizeByLocality extends AbstractType { public string $Mode; diff --git a/src/ConfigEntry/ServiceResolverRedirect.php b/src/ConfigEntry/ServiceResolverRedirect.php index ec766ce9..157adc48 100644 --- a/src/ConfigEntry/ServiceResolverRedirect.php +++ b/src/ConfigEntry/ServiceResolverRedirect.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverRedirect extends AbstractModel +class ServiceResolverRedirect extends AbstractType { public string $Service; public string $ServiceSubset; diff --git a/src/ConfigEntry/ServiceResolverSubset.php b/src/ConfigEntry/ServiceResolverSubset.php index a9a68717..cf726371 100644 --- a/src/ConfigEntry/ServiceResolverSubset.php +++ b/src/ConfigEntry/ServiceResolverSubset.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceResolverSubset extends AbstractModel +class ServiceResolverSubset extends AbstractType { public string $Filter; public bool $OnlyPassing; diff --git a/src/ConfigEntry/ServiceRoute.php b/src/ConfigEntry/ServiceRoute.php index 182ded2c..a7cc12e5 100644 --- a/src/ConfigEntry/ServiceRoute.php +++ b/src/ConfigEntry/ServiceRoute.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRoute extends AbstractModel +class ServiceRoute extends AbstractType { public null|ServiceRouteMatch $Match; public null|ServiceRouteDestination $Destination; diff --git a/src/ConfigEntry/ServiceRouteDestination.php b/src/ConfigEntry/ServiceRouteDestination.php index e7db78f9..20e46052 100644 --- a/src/ConfigEntry/ServiceRouteDestination.php +++ b/src/ConfigEntry/ServiceRouteDestination.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouteDestination extends AbstractModel +class ServiceRouteDestination extends AbstractType { public string $Service; public string $ServiceSubset; diff --git a/src/ConfigEntry/ServiceRouteHTTPMatch.php b/src/ConfigEntry/ServiceRouteHTTPMatch.php index c4ca1f6e..a9d0b6c6 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatch.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatch.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouteHTTPMatch extends AbstractModel +class ServiceRouteHTTPMatch extends AbstractType { public string $PathExact; public string $PathPrefix; diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php index 751acb45..e01f0f85 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchHeader.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouteHTTPMatchHeader extends AbstractModel +class ServiceRouteHTTPMatchHeader extends AbstractType { public string $Name; public bool $Present; diff --git a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php index af9bad16..875c35a3 100644 --- a/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php +++ b/src/ConfigEntry/ServiceRouteHTTPMatchQueryParam.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouteHTTPMatchQueryParam extends AbstractModel +class ServiceRouteHTTPMatchQueryParam extends AbstractType { public string $Name; public bool $Present; diff --git a/src/ConfigEntry/ServiceRouteMatch.php b/src/ConfigEntry/ServiceRouteMatch.php index f77ce860..5ff49bbb 100644 --- a/src/ConfigEntry/ServiceRouteMatch.php +++ b/src/ConfigEntry/ServiceRouteMatch.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouteMatch extends AbstractModel +class ServiceRouteMatch extends AbstractType { public null|ServiceRouteHTTPMatch $HTTP = null; diff --git a/src/ConfigEntry/ServiceRouterConfigEntry.php b/src/ConfigEntry/ServiceRouterConfigEntry.php index 6e27cbe5..eb9b17d3 100644 --- a/src/ConfigEntry/ServiceRouterConfigEntry.php +++ b/src/ConfigEntry/ServiceRouterConfigEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceRouterConfigEntry extends AbstractModel implements ConfigEntry +class ServiceRouterConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/ServiceSplit.php b/src/ConfigEntry/ServiceSplit.php index 5ef784bf..297686f2 100644 --- a/src/ConfigEntry/ServiceSplit.php +++ b/src/ConfigEntry/ServiceSplit.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceSplit extends AbstractModel +class ServiceSplit extends AbstractType { public float $Weight; public string $Service; diff --git a/src/ConfigEntry/ServiceSplitterConfigEntry.php b/src/ConfigEntry/ServiceSplitterConfigEntry.php index 3fa62ad2..01a03280 100644 --- a/src/ConfigEntry/ServiceSplitterConfigEntry.php +++ b/src/ConfigEntry/ServiceSplitterConfigEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceSplitterConfigEntry extends AbstractModel implements ConfigEntry +class ServiceSplitterConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/SourceIntention.php b/src/ConfigEntry/SourceIntention.php index 1bc15f4e..b460ba32 100644 --- a/src/ConfigEntry/SourceIntention.php +++ b/src/ConfigEntry/SourceIntention.php @@ -21,9 +21,9 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class SourceIntention extends AbstractModel +class SourceIntention extends AbstractType { public string $Name; public string $Peer; diff --git a/src/ConfigEntry/TerminatingGatewayConfigEntry.php b/src/ConfigEntry/TerminatingGatewayConfigEntry.php index 664a956a..afd2ae71 100644 --- a/src/ConfigEntry/TerminatingGatewayConfigEntry.php +++ b/src/ConfigEntry/TerminatingGatewayConfigEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class TerminatingGatewayConfigEntry extends AbstractModel implements ConfigEntry +class TerminatingGatewayConfigEntry extends AbstractType implements ConfigEntry { use ConfigEntryTrait; diff --git a/src/ConfigEntry/TransparentProxyConfig.php b/src/ConfigEntry/TransparentProxyConfig.php index 1111924f..260ab493 100644 --- a/src/ConfigEntry/TransparentProxyConfig.php +++ b/src/ConfigEntry/TransparentProxyConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class TransparentProxyConfig extends AbstractModel +class TransparentProxyConfig extends AbstractType { public int $OutboundListenerPort; public bool $DialedDirectly; diff --git a/src/ConfigEntry/TransparentProxyMeshConfig.php b/src/ConfigEntry/TransparentProxyMeshConfig.php index 9b1901eb..9cb1493b 100644 --- a/src/ConfigEntry/TransparentProxyMeshConfig.php +++ b/src/ConfigEntry/TransparentProxyMeshConfig.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class TransparentProxyMeshConfig extends AbstractModel +class TransparentProxyMeshConfig extends AbstractType { public bool $MeshDestinationsOnly; diff --git a/src/ConfigEntry/UpstreamConfig.php b/src/ConfigEntry/UpstreamConfig.php index 05e0f9c3..19a16b13 100644 --- a/src/ConfigEntry/UpstreamConfig.php +++ b/src/ConfigEntry/UpstreamConfig.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use function DCarbone\PHPConsulAPI\PHPLib\_enc_obj_if_valued; -class UpstreamConfig extends AbstractModel +class UpstreamConfig extends AbstractType { public string $Name; public string $Partition; diff --git a/src/ConfigEntry/UpstreamConfiguration.php b/src/ConfigEntry/UpstreamConfiguration.php index c01e76b6..41551b81 100644 --- a/src/ConfigEntry/UpstreamConfiguration.php +++ b/src/ConfigEntry/UpstreamConfiguration.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class UpstreamConfiguration extends AbstractModel +class UpstreamConfiguration extends AbstractType { /** @var array */ public array $Overrides; diff --git a/src/ConfigEntry/UpstreamLimits.php b/src/ConfigEntry/UpstreamLimits.php index 2bb867d4..fdcb816e 100644 --- a/src/ConfigEntry/UpstreamLimits.php +++ b/src/ConfigEntry/UpstreamLimits.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class UpstreamLimits extends AbstractModel +class UpstreamLimits extends AbstractType { public null|int $MaxConnections = null; public null|int $MaxPendingRequests = null; diff --git a/src/Coordinate/Coordinate.php b/src/Coordinate/Coordinate.php index c85d7159..926d5411 100644 --- a/src/Coordinate/Coordinate.php +++ b/src/Coordinate/Coordinate.php @@ -21,14 +21,14 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; /** * Class Coordinate * * From github.com/hashicorp/serf/coordinate/coordinate.go */ -class Coordinate extends AbstractModel +class Coordinate extends AbstractType { public const ZeroThreshold = 1.0e-6; private const secondsToNanoseconds = 1.0e9; diff --git a/src/Coordinate/CoordinateConfig.php b/src/Coordinate/CoordinateConfig.php index 1a53735e..be7dfe4e 100644 --- a/src/Coordinate/CoordinateConfig.php +++ b/src/Coordinate/CoordinateConfig.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Metrics\Label; -class CoordinateConfig extends AbstractModel +class CoordinateConfig extends AbstractType { public const DefaultDimensionality = 8; public const DefaultVivaldiErrorMax = 1.5; diff --git a/src/Coordinate/CoordinateDatacenterMap.php b/src/Coordinate/CoordinateDatacenterMap.php index d317582a..b4eadbfc 100644 --- a/src/Coordinate/CoordinateDatacenterMap.php +++ b/src/Coordinate/CoordinateDatacenterMap.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class CoordinateDatacenterMap extends AbstractModel +class CoordinateDatacenterMap extends AbstractType { public string $Datacenter = ''; public string $AreaID = ''; diff --git a/src/Coordinate/CoordinateEntry.php b/src/Coordinate/CoordinateEntry.php index 183222d6..ae04fbc5 100644 --- a/src/Coordinate/CoordinateEntry.php +++ b/src/Coordinate/CoordinateEntry.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class CoordinateEntry extends AbstractModel +class CoordinateEntry extends AbstractType { public string $Node; public string $Segment; diff --git a/src/Error.php b/src/Error.php index d84620aa..3bd6fbe0 100644 --- a/src/Error.php +++ b/src/Error.php @@ -22,11 +22,6 @@ use DCarbone\Go\Time; -/** - * TODO: Make this better... - * - * Class Error - */ class Error implements \JsonSerializable { private Time\Time $time; @@ -35,19 +30,18 @@ class Error implements \JsonSerializable public function __construct(string $message) { - $this->time = Time::Now(); + $this->time = Time::Now(); $this->message = $message; } public static function unexpectedResponseCodeError(RequestResponse $resp): self { - return new static( + return new self( sprintf( 'unexpected response code: %d (%s)', $resp->Response->getStatusCode(), $resp->Response->getBody()->getContents(), ) - ); } @@ -61,12 +55,12 @@ public function getMessage(): string return $this->message; } - public function jsonSerialize(): array + public function jsonSerialize(): \stdClass { - return [ - 'message' => $this->message, - 'timestamp' => $this->time, - ]; + $out = new \stdClass(); + $out->message = $this->message; + $out->timestamp = $this->time; + return $out; } public function __toString(): string diff --git a/src/Event/UserEvent.php b/src/Event/UserEvent.php index 169f681a..d6fa00d0 100644 --- a/src/Event/UserEvent.php +++ b/src/Event/UserEvent.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class UserEvent extends AbstractModel +class UserEvent extends AbstractType { public string $ID; public string $Name; diff --git a/src/Health/HealthCheck.php b/src/Health/HealthCheck.php index 6b6e88c1..7273929f 100644 --- a/src/Health/HealthCheck.php +++ b/src/Health/HealthCheck.php @@ -20,43 +20,66 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; -use DCarbone\PHPConsulAPI\Transcoding; +use DCarbone\PHPConsulAPI\PHPLib\Types\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 $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->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 +170,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; @@ -212,4 +238,48 @@ public function setModifyIndex(int $ModifyIndex): self $this->ModifyIndex = $ModifyIndex; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new self(); + foreach ($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 b74ff618..56b8f01e 100644 --- a/src/Health/HealthCheckDefinition.php +++ b/src/Health/HealthCheckDefinition.php @@ -21,10 +21,10 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Values; -class HealthCheckDefinition extends AbstractModel implements \JsonSerializable +class HealthCheckDefinition extends AbstractType implements \JsonSerializable { public string $HTTP; public Values $Header; diff --git a/src/Health/HealthChecks.php b/src/Health/HealthChecks.php index 3bcb06fb..f4c4c649 100644 --- a/src/Health/HealthChecks.php +++ b/src/Health/HealthChecks.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Consul; /** * @implements \ArrayAccess * @implements \IteratorAggregate */ -class HealthChecks extends AbstractModel implements \IteratorAggregate, \Countable, \ArrayAccess +class HealthChecks extends AbstractType implements \IteratorAggregate, \Countable, \ArrayAccess { /** @var \DCarbone\PHPConsulAPI\Health\HealthCheck[] */ protected array $Checks = []; diff --git a/src/Health/ServiceEntriesResponse.php b/src/Health/ServiceEntriesResponse.php index 14a98835..cd2eada1 100644 --- a/src/Health/ServiceEntriesResponse.php +++ b/src/Health/ServiceEntriesResponse.php @@ -26,7 +26,7 @@ class ServiceEntriesResponse extends AbstractValuedQueryResponse implements UnmarshalledResponseInterface { /** @var \DCarbone\PHPConsulAPI\Health\ServiceEntry[] */ - public array $ServiceEntries = []; + public array $ServiceEntries; /** * @return \DCarbone\PHPConsulAPI\Health\ServiceEntry[] diff --git a/src/Health/ServiceEntry.php b/src/Health/ServiceEntry.php index 96773463..4a2a4d7c 100644 --- a/src/Health/ServiceEntry.php +++ b/src/Health/ServiceEntry.php @@ -20,12 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentService; use DCarbone\PHPConsulAPI\Catalog\Node; -use DCarbone\PHPConsulAPI\Transcoding; -class ServiceEntry extends AbstractModel +class ServiceEntry extends AbstractType { protected const FIELDS = [ self::FIELD_NODE => [ @@ -48,8 +47,8 @@ class ServiceEntry extends AbstractModel private const FIELD_SERVICE = 'Service'; private const FIELD_CHECKS = 'Checks'; - public ?Node $Node = null; - public ?AgentService $Service = null; + public ?Node $Node; + public ?AgentService $Service; public HealthChecks $Checks; public function __construct(?array $data = []) diff --git a/src/KV/CheckTxnOp.php b/src/KV/CheckTxnOp.php index 0ffce250..a30c5a5b 100644 --- a/src/KV/CheckTxnOp.php +++ b/src/KV/CheckTxnOp.php @@ -20,22 +20,12 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Health\HealthCheck; -use DCarbone\PHPConsulAPI\Transcoding; -class CheckTxnOp extends AbstractModel +class CheckTxnOp extends AbstractType { - protected const FIELDS = [ - self::FIELD_CHECK => [ - Transcoding::FIELD_TYPE => Transcoding::OBJECT, - Transcoding::FIELD_CLASS => HealthCheck::class, - ], - ]; - - private const FIELD_CHECK = 'Check'; - - public string $Verb = ''; + public string $Verb = ''; public HealthCheck $Check; public function __construct(?array $data = []) @@ -67,4 +57,22 @@ public function setCheck(HealthCheck $Check): self $this->Check = $Check; return $this; } + + public static function jsonUnserialize(\stdClass $decoded): self + { + $n = new self(); + foreach ($decoded as $k => $v) { + if ('Check' === $k) { + $n->Check = HealthCheck::jsonUnserialize($v); + } else { + $n->{$k} = $v; + } + } + return $n; + } + + public function jsonSerialize(): mixed + { + // TODO: Implement jsonSerialize() method. + } } diff --git a/src/KV/KVPair.php b/src/KV/KVPair.php index 91452569..e8b5542c 100644 --- a/src/KV/KVPair.php +++ b/src/KV/KVPair.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class KVPair extends AbstractModel +class KVPair extends AbstractType { protected const FIELDS = [ self::FIELD_NAMESPACE => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/KV/KVPairs.php b/src/KV/KVPairs.php index 1003b6aa..f5f8dbc0 100644 --- a/src/KV/KVPairs.php +++ b/src/KV/KVPairs.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\FakeSlice; class KVPairs extends FakeSlice { protected string $containedClass = KVPair::class; - protected function newChild(array $data): AbstractModel + protected function newChild(array $data): AbstractType { return new KVPair($data, true); } diff --git a/src/KV/KVTxnOp.php b/src/KV/KVTxnOp.php index e3824339..adddc0ed 100644 --- a/src/KV/KVTxnOp.php +++ b/src/KV/KVTxnOp.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class KVTxnOp extends AbstractModel +class KVTxnOp extends AbstractType { public string $Verb = ''; public string $Key = ''; diff --git a/src/KV/KVTxnOps.php b/src/KV/KVTxnOps.php index a1c1ac8f..f061f452 100644 --- a/src/KV/KVTxnOps.php +++ b/src/KV/KVTxnOps.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\FakeSlice; class KVTxnOps extends FakeSlice { protected string $containedClass = KVTxnOp::class; - protected function newChild(array $data): AbstractModel + protected function newChild(array $data): AbstractType { return new KVTxnOp($data); } diff --git a/src/KV/KVTxnResponse.php b/src/KV/KVTxnResponse.php index dfd2d9f1..df3b7fd6 100644 --- a/src/KV/KVTxnResponse.php +++ b/src/KV/KVTxnResponse.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class KVTxnResponse extends AbstractModel +class KVTxnResponse extends AbstractType { protected const FIELDS = [ self::FIELD_RESULTS => [ diff --git a/src/KV/NodeTxnOp.php b/src/KV/NodeTxnOp.php index 872f7d5d..07587f80 100644 --- a/src/KV/NodeTxnOp.php +++ b/src/KV/NodeTxnOp.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Catalog\Node; use DCarbone\PHPConsulAPI\Transcoding; -class NodeTxnOp extends AbstractModel +class NodeTxnOp extends AbstractType { protected const FIELDS = [ self::FIELD_NODE => [ diff --git a/src/KV/ServiceTxnOp.php b/src/KV/ServiceTxnOp.php index 52c50964..f21a994c 100644 --- a/src/KV/ServiceTxnOp.php +++ b/src/KV/ServiceTxnOp.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Agent\AgentService; use DCarbone\PHPConsulAPI\Transcoding; -class ServiceTxnOp extends AbstractModel +class ServiceTxnOp extends AbstractType { protected const FIELDS = [ self::FIELD_SERVICE => [ diff --git a/src/KV/TxnError.php b/src/KV/TxnError.php index d0add265..b81df0b7 100644 --- a/src/KV/TxnError.php +++ b/src/KV/TxnError.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class TxnError extends AbstractModel +class TxnError extends AbstractType { public int $OpIndex = 0; public string $What = ''; diff --git a/src/KV/TxnErrors.php b/src/KV/TxnErrors.php index e09430bb..fa33534b 100644 --- a/src/KV/TxnErrors.php +++ b/src/KV/TxnErrors.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\FakeSlice; class TxnErrors extends FakeSlice { protected string $containedClass = TxnError::class; - protected function newChild(array $data): AbstractModel + protected function newChild(array $data): AbstractType { return new TxnError($data); } diff --git a/src/KV/TxnOp.php b/src/KV/TxnOp.php index f5f50a44..2d47cf26 100644 --- a/src/KV/TxnOp.php +++ b/src/KV/TxnOp.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class TxnOp extends AbstractModel +class TxnOp extends AbstractType { protected const FIELDS = [ self::FIELD_KV => [ diff --git a/src/KV/TxnOps.php b/src/KV/TxnOps.php index 28a37cc1..5a62d013 100644 --- a/src/KV/TxnOps.php +++ b/src/KV/TxnOps.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\FakeSlice; class TxnOps extends FakeSlice { protected string $containedClass = TxnOp::class; - protected function newChild(array $data): AbstractModel + protected function newChild(array $data): AbstractType { return new TxnOp($data); } diff --git a/src/KV/TxnResponse.php b/src/KV/TxnResponse.php index 7bcdfd9c..99c2b424 100644 --- a/src/KV/TxnResponse.php +++ b/src/KV/TxnResponse.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class TxnResponse extends AbstractModel +class TxnResponse extends AbstractType { protected const FIELDS = [ self::FIELD_RESULTS => [ diff --git a/src/KV/TxnResult.php b/src/KV/TxnResult.php index 1f7af537..1f34032f 100644 --- a/src/KV/TxnResult.php +++ b/src/KV/TxnResult.php @@ -20,13 +20,13 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Catalog\CatalogService; use DCarbone\PHPConsulAPI\Catalog\Node; use DCarbone\PHPConsulAPI\Health\HealthCheck; use DCarbone\PHPConsulAPI\Transcoding; -class TxnResult extends AbstractModel +class TxnResult extends AbstractType { protected const FIELDS = [ self::FIELD_KV => [ diff --git a/src/KV/TxnResults.php b/src/KV/TxnResults.php index d4a87fb5..f98e819b 100644 --- a/src/KV/TxnResults.php +++ b/src/KV/TxnResults.php @@ -20,14 +20,14 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\FakeSlice; class TxnResults extends FakeSlice { protected string $containedClass = TxnResult::class; - protected function newChild(array $data): AbstractModel + protected function newChild(array $data): AbstractType { return new TxnResult($data); } diff --git a/src/Metrics/Label.php b/src/Metrics/Label.php index cc5d6f86..29453017 100644 --- a/src/Metrics/Label.php +++ b/src/Metrics/Label.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class Label extends AbstractModel +class Label extends AbstractType { public string $Name; public string $Value; diff --git a/src/Operator/Area.php b/src/Operator/Area.php index 51821ec5..7db9dcdc 100644 --- a/src/Operator/Area.php +++ b/src/Operator/Area.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class Area extends AbstractModel +class Area extends AbstractType { public string $ID; public string $PeerDatacenter; diff --git a/src/Operator/AreaJoinResponse.php b/src/Operator/AreaJoinResponse.php index 8ff3af60..f103e4a6 100644 --- a/src/Operator/AreaJoinResponse.php +++ b/src/Operator/AreaJoinResponse.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AreaJoinResponse extends AbstractModel +class AreaJoinResponse extends AbstractType { public string $Address; public bool $Joined; diff --git a/src/Operator/AutopilotConfiguration.php b/src/Operator/AutopilotConfiguration.php index 24740ddc..fa276660 100644 --- a/src/Operator/AutopilotConfiguration.php +++ b/src/Operator/AutopilotConfiguration.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class AutopilotConfiguration extends AbstractModel +class AutopilotConfiguration extends AbstractType { protected const FIELDS = [ self::FIELD_LAST_CONTACT_THRESHOLD => [ diff --git a/src/Operator/AutopilotServer.php b/src/Operator/AutopilotServer.php index a14a5d25..953a84ca 100644 --- a/src/Operator/AutopilotServer.php +++ b/src/Operator/AutopilotServer.php @@ -21,10 +21,10 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\PHPLib\Types\MetaField; -class AutopilotServer extends AbstractModel implements \JsonSerializable +class AutopilotServer extends AbstractType implements \JsonSerializable { use MetaField; diff --git a/src/Operator/AutopilotState.php b/src/Operator/AutopilotState.php index d4545ef4..dfc81505 100644 --- a/src/Operator/AutopilotState.php +++ b/src/Operator/AutopilotState.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class AutopilotState extends AbstractModel +class AutopilotState extends AbstractType { protected const FIELDS = [ self::FIELD_SERVERS => [ diff --git a/src/Operator/AutopilotUpgrade.php b/src/Operator/AutopilotUpgrade.php index 9d232f5d..9348f638 100644 --- a/src/Operator/AutopilotUpgrade.php +++ b/src/Operator/AutopilotUpgrade.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class AutopilotUpgrade extends AbstractModel +class AutopilotUpgrade extends AbstractType { protected const FIELDS = [ self::FIELD_TARGET_VERSION => Transcoding::OMITEMPTY_STRING_FIELD, diff --git a/src/Operator/AutopilotZone.php b/src/Operator/AutopilotZone.php index 801ed9fe..e79c96b9 100644 --- a/src/Operator/AutopilotZone.php +++ b/src/Operator/AutopilotZone.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class AutopilotZone extends AbstractModel +class AutopilotZone extends AbstractType { public array $Servers; public array $Voters; diff --git a/src/Operator/AutopilotZoneUpgradeVersions.php b/src/Operator/AutopilotZoneUpgradeVersions.php index 43f087db..e46863af 100644 --- a/src/Operator/AutopilotZoneUpgradeVersions.php +++ b/src/Operator/AutopilotZoneUpgradeVersions.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class AutopilotZoneUpgradeVersions extends AbstractModel +class AutopilotZoneUpgradeVersions extends AbstractType { protected const FIELDS = [ self::FIELD_TARGET_VERSION_VOTERS => Transcoding::OMITEMPTY_STRING_ARRAY_FIELD, diff --git a/src/Operator/OperatorHealthReply.php b/src/Operator/OperatorHealthReply.php index f60e8abb..9a389bad 100644 --- a/src/Operator/OperatorHealthReply.php +++ b/src/Operator/OperatorHealthReply.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class OperatorHealthReply extends AbstractModel +class OperatorHealthReply extends AbstractType { protected const FIELDS = [ self::FIELD_SERVERS => [ diff --git a/src/Operator/RaftConfiguration.php b/src/Operator/RaftConfiguration.php index c9f4dc6b..f352c541 100644 --- a/src/Operator/RaftConfiguration.php +++ b/src/Operator/RaftConfiguration.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class RaftConfiguration extends AbstractModel +class RaftConfiguration extends AbstractType { protected const FIELDS = [ self::FIELD_SERVERS => [ diff --git a/src/Operator/RaftServer.php b/src/Operator/RaftServer.php index f83d894b..16989a7e 100644 --- a/src/Operator/RaftServer.php +++ b/src/Operator/RaftServer.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class RaftServer extends AbstractModel +class RaftServer extends AbstractType { public string $ID; public string $Node; diff --git a/src/Operator/SerfMember.php b/src/Operator/SerfMember.php index a3857188..61d09cc2 100644 --- a/src/Operator/SerfMember.php +++ b/src/Operator/SerfMember.php @@ -21,10 +21,10 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class SerfMember extends AbstractModel +class SerfMember extends AbstractType { protected const FIELDS = [ self::FIELD_RTT => [ diff --git a/src/Operator/ServerHealth.php b/src/Operator/ServerHealth.php index 029fb82c..0758a24a 100644 --- a/src/Operator/ServerHealth.php +++ b/src/Operator/ServerHealth.php @@ -21,10 +21,10 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class ServerHealth extends AbstractModel +class ServerHealth extends AbstractType { protected const FIELDS = [ self::FIELD_LAST_CONTACT => [ diff --git a/src/AbstractModel.php b/src/PHPLib/Types/AbstractType.php similarity index 93% rename from src/AbstractModel.php rename to src/PHPLib/Types/AbstractType.php index 55c85808..eff77ed6 100644 --- a/src/AbstractModel.php +++ b/src/PHPLib/Types/AbstractType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DCarbone\PHPConsulAPI; +namespace DCarbone\PHPConsulAPI\PHPLib\Types; /* Copyright 2016-2025 Daniel Carbone (daniel.p.carbone@gmail.com) @@ -20,7 +20,7 @@ limitations under the License. */ -abstract class AbstractModel implements \JsonSerializable +abstract class AbstractType implements \JsonSerializable { /** @var array */ private array $_dyn = []; diff --git a/src/Peering/Locality.php b/src/Peering/Locality.php index 2b50af25..8c1a93de 100644 --- a/src/Peering/Locality.php +++ b/src/Peering/Locality.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class Locality extends AbstractModel +class Locality extends AbstractType { public string $Region; public string $Zone; diff --git a/src/PreparedQuery/PreparedQueryDefinition.php b/src/PreparedQuery/PreparedQueryDefinition.php index 236b1ca1..f188c776 100644 --- a/src/PreparedQuery/PreparedQueryDefinition.php +++ b/src/PreparedQuery/PreparedQueryDefinition.php @@ -20,10 +20,10 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class PreparedQueryDefinition extends AbstractModel +class PreparedQueryDefinition extends AbstractType { protected const FIELDS = [ self::FIELD_SERVICE => [ diff --git a/src/PreparedQuery/PreparedQueryExecuteResponse.php b/src/PreparedQuery/PreparedQueryExecuteResponse.php index 1a28093b..d935d733 100644 --- a/src/PreparedQuery/PreparedQueryExecuteResponse.php +++ b/src/PreparedQuery/PreparedQueryExecuteResponse.php @@ -20,11 +20,11 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Health\ServiceEntry; use DCarbone\PHPConsulAPI\Transcoding; -class PreparedQueryExecuteResponse extends AbstractModel +class PreparedQueryExecuteResponse extends AbstractType { protected const FIELDS = [ self::FIELD_NODES => [ diff --git a/src/PreparedQuery/QueryDNSOptions.php b/src/PreparedQuery/QueryDNSOptions.php index 729f29b8..a11ae7a4 100644 --- a/src/PreparedQuery/QueryDNSOptions.php +++ b/src/PreparedQuery/QueryDNSOptions.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class QueryDNSOptions extends AbstractModel +class QueryDNSOptions extends AbstractType { public string $TTL = ''; diff --git a/src/PreparedQuery/QueryDatacenterOptions.php b/src/PreparedQuery/QueryDatacenterOptions.php index f8d67967..4b995458 100644 --- a/src/PreparedQuery/QueryDatacenterOptions.php +++ b/src/PreparedQuery/QueryDatacenterOptions.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class QueryDatacenterOptions extends AbstractModel +class QueryDatacenterOptions extends AbstractType { public int $NearestN = 0; public array $Datacenters = []; diff --git a/src/PreparedQuery/QueryTemplate.php b/src/PreparedQuery/QueryTemplate.php index b6ddbada..5f33bd9e 100644 --- a/src/PreparedQuery/QueryTemplate.php +++ b/src/PreparedQuery/QueryTemplate.php @@ -20,9 +20,9 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class QueryTemplate extends AbstractModel +class QueryTemplate extends AbstractType { public string $Type = ''; public string $Regexp = ''; diff --git a/src/PreparedQuery/ServiceQuery.php b/src/PreparedQuery/ServiceQuery.php index f3c9f612..6b30efa8 100644 --- a/src/PreparedQuery/ServiceQuery.php +++ b/src/PreparedQuery/ServiceQuery.php @@ -20,12 +20,12 @@ limitations under the License. */ -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\HasSettableStringTags; use DCarbone\PHPConsulAPI\HasStringTags; use DCarbone\PHPConsulAPI\Transcoding; -class ServiceQuery extends AbstractModel +class ServiceQuery extends AbstractType { use HasSettableStringTags; use HasStringTags; diff --git a/src/Session/ServiceCheck.php b/src/Session/ServiceCheck.php index 8aa2f823..35b931ea 100644 --- a/src/Session/ServiceCheck.php +++ b/src/Session/ServiceCheck.php @@ -20,9 +20,9 @@ namespace DCarbone\PHPConsulAPI\Session; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; -class ServiceCheck extends AbstractModel +class ServiceCheck extends AbstractType { public string $ID = ''; public string $Namespace = ''; diff --git a/src/Session/SessionEntry.php b/src/Session/SessionEntry.php index 282901bb..394fa28f 100644 --- a/src/Session/SessionEntry.php +++ b/src/Session/SessionEntry.php @@ -21,10 +21,10 @@ */ use DCarbone\Go\Time; -use DCarbone\PHPConsulAPI\AbstractModel; +use DCarbone\PHPConsulAPI\PHPLib\Types\AbstractType; use DCarbone\PHPConsulAPI\Transcoding; -class SessionEntry extends AbstractModel +class SessionEntry extends AbstractType { protected const FIELDS = [ self::FIELD_LOCK_DELAY => [