From 2d9d0702f00410c5868482c0017fc93a06eaef90 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Tue, 8 Mar 2022 00:49:00 +0000 Subject: Add method to set all account properties from json Signed-off-by: Christopher Ng --- lib/private/Accounts/Account.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/private/Accounts') diff --git a/lib/private/Accounts/Account.php b/lib/private/Accounts/Account.php index 7d36af561ce..d3287b219d0 100644 --- a/lib/private/Accounts/Account.php +++ b/lib/private/Accounts/Account.php @@ -72,6 +72,28 @@ class Account implements IAccount { }); } + public function setAllPropertiesFromJson(array $properties): IAccount { + foreach ($properties as $propertyName => $propertyObject) { + if ($this->isCollection($propertyName)) { + $collection = new AccountPropertyCollection($propertyName); + /** @var array $collectionProperties */ + $collectionProperties = []; + /** @var array> $propertyObject */ + foreach ($propertyObject as ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData]) { + $collectionProperties[] = new AccountProperty($collection->getName(), $value, $scope, $verified, $verificationData); + } + $collection->setProperties($collectionProperties); + $this->setPropertyCollection($collection); + } else { + /** @var array $propertyObject */ + ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData] = $propertyObject; + $this->setProperty($propertyName, $value, $scope, $verified, $verificationData); + } + } + + return $this; + } + public function getAllProperties(): Generator { foreach ($this->properties as $propertyObject) { if ($propertyObject instanceof IAccountProperty) { -- cgit v1.2.3