Skip to content
Merged
Prev Previous commit
Next Next commit
add IAccountPropertyCollection with implementation
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jun 3, 2021
commit 0bade2747902b22002203c31e7e13f36256f42bc
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'OCP\\Accounts\\IAccount' => $baseDir . '/lib/public/Accounts/IAccount.php',
'OCP\\Accounts\\IAccountManager' => $baseDir . '/lib/public/Accounts/IAccountManager.php',
'OCP\\Accounts\\IAccountProperty' => $baseDir . '/lib/public/Accounts/IAccountProperty.php',
'OCP\\Accounts\\IAccountPropertyCollection' => $baseDir . '/lib/public/Accounts/IAccountPropertyCollection.php',
'OCP\\Accounts\\PropertyDoesNotExistException' => $baseDir . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Activity\\ActivitySettings' => $baseDir . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\IConsumer' => $baseDir . '/lib/public/Activity/IConsumer.php',
Expand Down Expand Up @@ -581,6 +582,7 @@
'OC\\Accounts\\Account' => $baseDir . '/lib/private/Accounts/Account.php',
'OC\\Accounts\\AccountManager' => $baseDir . '/lib/private/Accounts/AccountManager.php',
'OC\\Accounts\\AccountProperty' => $baseDir . '/lib/private/Accounts/AccountProperty.php',
'OC\\Accounts\\AccountPropertyCollection' => $baseDir . '/lib/private/Accounts/AccountPropertyCollection.php',
'OC\\Accounts\\Hooks' => $baseDir . '/lib/private/Accounts/Hooks.php',
'OC\\Activity\\ActivitySettingsAdapter' => $baseDir . '/lib/private/Activity/ActivitySettingsAdapter.php',
'OC\\Activity\\Event' => $baseDir . '/lib/private/Activity/Event.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Accounts\\IAccount' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccount.php',
'OCP\\Accounts\\IAccountManager' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountManager.php',
'OCP\\Accounts\\IAccountProperty' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountProperty.php',
'OCP\\Accounts\\IAccountPropertyCollection' => __DIR__ . '/../../..' . '/lib/public/Accounts/IAccountPropertyCollection.php',
'OCP\\Accounts\\PropertyDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Activity\\ActivitySettings' => __DIR__ . '/../../..' . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\IConsumer' => __DIR__ . '/../../..' . '/lib/public/Activity/IConsumer.php',
Expand Down Expand Up @@ -610,6 +611,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Accounts\\Account' => __DIR__ . '/../../..' . '/lib/private/Accounts/Account.php',
'OC\\Accounts\\AccountManager' => __DIR__ . '/../../..' . '/lib/private/Accounts/AccountManager.php',
'OC\\Accounts\\AccountProperty' => __DIR__ . '/../../..' . '/lib/private/Accounts/AccountProperty.php',
'OC\\Accounts\\AccountPropertyCollection' => __DIR__ . '/../../..' . '/lib/private/Accounts/AccountPropertyCollection.php',
'OC\\Accounts\\Hooks' => __DIR__ . '/../../..' . '/lib/private/Accounts/Hooks.php',
'OC\\Activity\\ActivitySettingsAdapter' => __DIR__ . '/../../..' . '/lib/private/Activity/ActivitySettingsAdapter.php',
'OC\\Activity\\Event' => __DIR__ . '/../../..' . '/lib/private/Activity/Event.php',
Expand Down
86 changes: 86 additions & 0 deletions lib/private/Accounts/AccountPropertyCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

namespace OC\Accounts;

use InvalidArgumentException;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;

class AccountPropertyCollection implements IAccountPropertyCollection {

/** @var string */
protected $collectionName = '';

/** @var IAccountProperty[] */
protected $properties = [];

public function __construct(string $collectionName) {
$this->collectionName = $collectionName;
}

public function setProperties(array $properties): IAccountPropertyCollection {
/** @var IAccountProperty $property */
$this->properties = [];
foreach ($properties as $property) {
$this->addProperty($property);
}
return $this;
}

public function getProperties(): array {
return $this->properties;
}

public function addProperty(IAccountProperty $property): IAccountPropertyCollection {
if ($property->getName() !== $this->collectionName) {
throw new InvalidArgumentException('Provided property does not match collection name');
}
$this->properties[] = $property;
return $this;
}

public function removeProperty(IAccountProperty $property): IAccountPropertyCollection {
$ref = array_search($property, $this->properties, true);
if ($ref !== false) {
unset($this->properties[$ref]);
}
return $this;
}

public function removePropertyByValue(string $value): IAccountPropertyCollection {
foreach ($this->properties as $i => $property) {
if ($property->getValue() === $value) {
unset($this->properties[$i]);
}
}
return $this;
}

public function jsonSerialize() {
return [$this->collectionName => $this->properties];
}
}
77 changes: 77 additions & 0 deletions lib/public/Accounts/IAccountPropertyCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

namespace OCP\Accounts;

use InvalidArgumentException;
use JsonSerializable;

/**
* Interface IAccountPropertyCollection
*
* @package OCP\Accounts
*
* @since 22.0.0
*/
interface IAccountPropertyCollection extends JsonSerializable {

/**
* set properties of this collection
*
* @param IAccountProperty[] $properties
* @throws InvalidArgumentException
* @since 22.0.0
*/
public function setProperties(array $properties): IAccountPropertyCollection;

/**
* @return IAccountProperty[]
* @since 22.0.0
*/
public function getProperties(): array;

/**
* adds a property to this collection
*
* @throws InvalidArgumentException
* @since 22.0.0
*/
public function addProperty(IAccountProperty $property): IAccountPropertyCollection;

/**
* removes a property of this collection
*
* @since 22.0.0
*/
public function removeProperty(IAccountProperty $property): IAccountPropertyCollection;

/**
* removes a property identified by its value
*
* @since 22.0.0
*/
public function removePropertyByValue(string $value): IAccountPropertyCollection;
}
Loading