diff options
author | Christopher Ng <chrng8@gmail.com> | 2022-03-08 00:49:00 +0000 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2022-03-17 16:33:19 +0000 |
commit | 2d9d0702f00410c5868482c0017fc93a06eaef90 (patch) | |
tree | 4ebe2bdf58abd10c6c08bd32ee2b3f3236aceff3 /lib | |
parent | 2a75c303b5ce01f809866a0afb326663b9f9d125 (diff) | |
download | nextcloud-server-2d9d0702f00410c5868482c0017fc93a06eaef90.tar.gz nextcloud-server-2d9d0702f00410c5868482c0017fc93a06eaef90.zip |
Add method to set all account properties from json
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Accounts/Account.php | 22 | ||||
-rw-r--r-- | lib/public/Accounts/IAccount.php | 9 |
2 files changed, 31 insertions, 0 deletions
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<int, IAccountProperty> $collectionProperties */ + $collectionProperties = []; + /** @var array<int, array<string, string>> $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<string, string> $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) { diff --git a/lib/public/Accounts/IAccount.php b/lib/public/Accounts/IAccount.php index 8d4d8b5c023..dcec17f9363 100644 --- a/lib/public/Accounts/IAccount.php +++ b/lib/public/Accounts/IAccount.php @@ -72,6 +72,15 @@ interface IAccount extends \JsonSerializable { public function getProperties(): array; /** + * Set all properties of an account + * + * @param array<string, array<string, string>>|array<string, array<int, array<string, string>>> $properties + * + * @since 24.0.0 + */ + public function setAllPropertiesFromJson(array $properties): IAccount; + + /** * Get all properties of an account. Array indices are numeric. To get * the property name, call getName() against the value. * |