diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f141532..02fa1991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ Please read about the future of the Firebase Admin PHP SDK on the ## [Unreleased] +### Added + +* Added support for [rollout parameter values](https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfig#RolloutValue) + in Remote Config Templates. + ([#923](https://github.com/kreait/firebase-php/pull/923)) + ## [7.14.0] - 2024-08-21 ### Added diff --git a/src/Firebase/RemoteConfig/ParameterValue.php b/src/Firebase/RemoteConfig/ParameterValue.php index b6b3d093..cd302f1e 100644 --- a/src/Firebase/RemoteConfig/ParameterValue.php +++ b/src/Firebase/RemoteConfig/ParameterValue.php @@ -10,12 +10,16 @@ /** * @phpstan-import-type RemoteConfigPersonalizationValueShape from PersonalizationValue + * @phpstan-import-type RemoteConfigRolloutValueShape from RolloutValue * * @phpstan-type RemoteConfigParameterValueShape array{ * value?: string, * useInAppDefault?: bool, - * personalizationValue?: RemoteConfigPersonalizationValueShape + * personalizationValue?: RemoteConfigPersonalizationValueShape, + * rolloutValue?: RemoteConfigRolloutValueShape * } + * + * @see https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfig#remoteconfigparametervalue */ final class ParameterValue implements JsonSerializable { @@ -23,6 +27,7 @@ private function __construct( private readonly ?string $value = null, private readonly ?bool $useInAppDefault = null, private readonly ?PersonalizationValue $personalizationValue = null, + private readonly ?RolloutValue $rolloutValue = null, ) { } @@ -41,6 +46,11 @@ public static function withPersonalizationValue(PersonalizationValue $value): se return new self(personalizationValue: $value); } + public static function withRolloutValue(RolloutValue $value): self + { + return new self(rolloutValue: $value); + } + /** * @param RemoteConfigParameterValueShape $data */ @@ -58,6 +68,10 @@ public static function fromArray(array $data): self return self::withPersonalizationValue(PersonalizationValue::fromArray($data['personalizationValue'])); } + if (array_key_exists('rolloutValue', $data)) { + return self::withRolloutValue(RolloutValue::fromArray($data['rolloutValue'])); + } + return new self(); } @@ -78,6 +92,10 @@ public function toArray(): array return ['personalizationValue' => $this->personalizationValue->toArray()]; } + if ($this->rolloutValue !== null) { + return ['rolloutValue' => $this->rolloutValue->toArray()]; + } + return []; } diff --git a/src/Firebase/RemoteConfig/PersonalizationValue.php b/src/Firebase/RemoteConfig/PersonalizationValue.php index 14175998..5d37903e 100644 --- a/src/Firebase/RemoteConfig/PersonalizationValue.php +++ b/src/Firebase/RemoteConfig/PersonalizationValue.php @@ -10,6 +10,8 @@ * @phpstan-type RemoteConfigPersonalizationValueShape array{ * personalizationId: string * } + * + * @see https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfig#personalizationvalue */ final class PersonalizationValue implements JsonSerializable { diff --git a/src/Firebase/RemoteConfig/RolloutValue.php b/src/Firebase/RemoteConfig/RolloutValue.php new file mode 100644 index 00000000..7173c70f --- /dev/null +++ b/src/Firebase/RemoteConfig/RolloutValue.php @@ -0,0 +1,50 @@ + + * } + * + * @see https://firebase.google.com/docs/reference/remote-config/rest/v1/RemoteConfig#rolloutvalue + */ +final class RolloutValue implements JsonSerializable +{ + /** + * @param RemoteConfigRolloutValueShape $data + */ + private function __construct(private readonly array $data) + { + } + + /** + * @param RemoteConfigRolloutValueShape $data + */ + public static function fromArray(array $data): self + { + return new self($data); + } + + /** + * @return RemoteConfigRolloutValueShape + */ + public function toArray(): array + { + return $this->data; + } + + /** + * @return RemoteConfigRolloutValueShape + */ + public function jsonSerialize(): array + { + return $this->data; + } +} diff --git a/tests/Integration/RemoteConfigTest.php b/tests/Integration/RemoteConfigTest.php index 71a6eba6..03e82294 100644 --- a/tests/Integration/RemoteConfigTest.php +++ b/tests/Integration/RemoteConfigTest.php @@ -41,6 +41,11 @@ final class RemoteConfigTest extends IntegrationTestCase "name": "lang_french", "expression": "device.language in ['fr', 'fr_CA', 'fr_CH']", "tagColor": "GREEN" + }, + { + "name": "user_exists", + "expression": "true", + "tagColor": "TEAL" } ], "parameters": { @@ -63,7 +68,7 @@ final class RemoteConfigTest extends IntegrationTestCase }, "unspecified_value_type": { "defaultValue": "1", - "valueType": "STRING" + "valueType": "PARAMETER_VALUE_TYPE_UNSPECIFIED" }, "string_value_type": { "defaultValue": "1", @@ -80,6 +85,20 @@ final class RemoteConfigTest extends IntegrationTestCase "json_value_type": { "defaultValue": "{\"key\": \"value\"}", "valueType": "JSON" + }, + "is_ready_for_rollout": { + "defaultValue": "false", + "valueType": "BOOLEAN", + "conditionalValues": { + "lang_german": { + "value": "false" + }, + "user_exists": { + "rollout_id": "rollout_2", + "value": "true", + "percent": 50 + } + } } }, "parameterGroups": {