json_encode($this->policyRegistry->getMutationCollections()), 'HashCollection' => json_encode($this->directiveHashCollection), ]; } public function updateState(array $state): void { foreach ($state as $name => $value) { switch ($name) { case 'PolicyRegistry::$mutationCollections': $this->updatePolicyRegistryMutationCollections($value); break; case 'HashCollection': $this->updateHashCollection($value); break; } } } private function updatePolicyRegistryMutationCollections(mixed $value): void { $array = $this->decodeJsonString($value); if (is_array($array)) { $this->policyRegistry->setMutationsCollections( ...array_map($this->modelService->buildMutationCollectionFromArray(...), $array) ); } } private function updateHashCollection(mixed $value): void { $array = $this->decodeJsonString($value); if (is_array($array)) { $this->directiveHashCollection->updateFromJson($array); } } private function decodeJsonString(mixed $value): ?array { if (!is_string($value) || $value === '') { return null; } try { $array = json_decode($value, true, 512, \JSON_THROW_ON_ERROR); } catch (\JsonException) { return null; } return is_array($array) ? $array : null; } }