Fixing indentation

This commit is contained in:
Floris Westerman 2020-11-10 11:52:21 +01:00
parent 1c63287243
commit 6919a6a34f
No known key found for this signature in database
GPG key ID: E2AED138B92702B0
8 changed files with 903 additions and 1234 deletions

2
.editorconfig Normal file
View file

@ -0,0 +1,2 @@
[*.php]
indent_style = tab

File diff suppressed because it is too large Load diff

View file

@ -2,11 +2,11 @@
namespace RainLoop\Actions; namespace RainLoop\Actions;
use \RainLoop\Enumerations\Capa; use RainLoop\Enumerations\Capa;
use \RainLoop\Exceptions\ClientException; use RainLoop\Exceptions\ClientException;
use \RainLoop\Model\Account; use RainLoop\Model\Account;
use \RainLoop\Model\Identity; use RainLoop\Model\Identity;
use \RainLoop\Notifications; use RainLoop\Notifications;
use RainLoop\Providers\Storage\Enumerations\StorageType; use RainLoop\Providers\Storage\Enumerations\StorageType;
use function trim; use function trim;
@ -16,12 +16,11 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoAccountSetup() : array public function DoAccountSetup(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) if (!$this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
{
return $this->FalseResponse(__FUNCTION__); return $this->FalseResponse(__FUNCTION__);
} }
@ -31,15 +30,12 @@ trait Accounts
$sEmail = trim($this->GetActionParam('Email', '')); $sEmail = trim($this->GetActionParam('Email', ''));
$sPassword = $this->GetActionParam('Password', ''); $sPassword = $this->GetActionParam('Password', '');
$bNew = '1' === (string) $this->GetActionParam('New', '1'); $bNew = '1' === (string)$this->GetActionParam('New', '1');
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true); $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
if ($bNew && ($oAccount->Email() === $sEmail || $sParentEmail === $sEmail || isset($aAccounts[$sEmail]))) if ($bNew && ($oAccount->Email() === $sEmail || $sParentEmail === $sEmail || isset($aAccounts[$sEmail]))) {
{
throw new ClientException(Notifications::AccountAlreadyExists); throw new ClientException(Notifications::AccountAlreadyExists);
} } else if (!$bNew && !isset($aAccounts[$sEmail])) {
else if (!$bNew && !isset($aAccounts[$sEmail]))
{
throw new ClientException(Notifications::AccountDoesNotExist); throw new ClientException(Notifications::AccountDoesNotExist);
} }
@ -47,8 +43,7 @@ trait Accounts
$oNewAccount->SetParentEmail($sParentEmail); $oNewAccount->SetParentEmail($sParentEmail);
$aAccounts[$oNewAccount->Email()] = $oNewAccount->GetAuthToken(); $aAccounts[$oNewAccount->Email()] = $oNewAccount->GetAuthToken();
if (!$oAccount->IsAdditionalAccount()) if (!$oAccount->IsAdditionalAccount()) {
{
$aAccounts[$oAccount->Email()] = $oAccount->GetAuthToken(); $aAccounts[$oAccount->Email()] = $oAccount->GetAuthToken();
} }
@ -59,12 +54,11 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoAccountDelete() : array public function DoAccountDelete(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) if (!$this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
{
return $this->FalseResponse(__FUNCTION__); return $this->FalseResponse(__FUNCTION__);
} }
@ -74,16 +68,13 @@ trait Accounts
$aAccounts = $this->GetAccounts($oAccount); $aAccounts = $this->GetAccounts($oAccount);
if (0 < \strlen($sEmailToDelete) && $sEmailToDelete !== $sParentEmail && isset($aAccounts[$sEmailToDelete])) if (0 < \strlen($sEmailToDelete) && $sEmailToDelete !== $sParentEmail && isset($aAccounts[$sEmailToDelete])) {
{
unset($aAccounts[$sEmailToDelete]); unset($aAccounts[$sEmailToDelete]);
$oAccountToChange = null; $oAccountToChange = null;
if ($oAccount->Email() === $sEmailToDelete && !empty($aAccounts[$sParentEmail])) if ($oAccount->Email() === $sEmailToDelete && !empty($aAccounts[$sParentEmail])) {
{
$oAccountToChange = $this->GetAccountFromCustomToken($aAccounts[$sParentEmail], false, false); $oAccountToChange = $this->GetAccountFromCustomToken($aAccounts[$sParentEmail], false, false);
if ($oAccountToChange) if ($oAccountToChange) {
{
$this->AuthToken($oAccountToChange); $this->AuthToken($oAccountToChange);
} }
} }
@ -98,13 +89,12 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoIdentityUpdate() : array public function DoIdentityUpdate(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
$oIdentity = new \RainLoop\Model\Identity(); $oIdentity = new \RainLoop\Model\Identity();
if (!$oIdentity->FromJSON($this->GetActionParams(), true)) if (!$oIdentity->FromJSON($this->GetActionParams(), true)) {
{
throw new ClientException(Notifications::InvalidInputArgument); throw new ClientException(Notifications::InvalidInputArgument);
} }
@ -115,18 +105,16 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoIdentityDelete() : array public function DoIdentityDelete(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(false, false, Capa::IDENTITIES, $oAccount)) if (!$this->GetCapa(false, false, Capa::IDENTITIES, $oAccount)) {
{
return $this->FalseResponse(__FUNCTION__); return $this->FalseResponse(__FUNCTION__);
} }
$sId = trim($this->GetActionParam('IdToDelete', '')); $sId = trim($this->GetActionParam('IdToDelete', ''));
if (empty($sId)) if (empty($sId)) {
{
throw new ClientException(Notifications::UnknownError); throw new ClientException(Notifications::UnknownError);
} }
@ -137,15 +125,14 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoAccountsAndIdentitiesSortOrder() : array public function DoAccountsAndIdentitiesSortOrder(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
$aAccounts = $this->GetActionParam('Accounts', null); $aAccounts = $this->GetActionParam('Accounts', null);
$aIdentities = $this->GetActionParam('Identities', null); $aIdentities = $this->GetActionParam('Identities', null);
if (!\is_array($aAccounts) && !\is_array($aIdentities)) if (!\is_array($aAccounts) && !\is_array($aIdentities)) {
{
return $this->FalseResponse(__FUNCTION__); return $this->FalseResponse(__FUNCTION__);
} }
@ -161,19 +148,17 @@ trait Accounts
/** /**
* @throws \MailSo\Base\Exceptions\Exception * @throws \MailSo\Base\Exceptions\Exception
*/ */
public function DoAccountsAndIdentities() : array public function DoAccountsAndIdentities(): array
{ {
$oAccount = $this->getAccountFromToken(); $oAccount = $this->getAccountFromToken();
$mAccounts = false; $mAccounts = false;
if ($this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) if ($this->GetCapa(false, false, Capa::ADDITIONAL_ACCOUNTS, $oAccount)) {
{
$mAccounts = $this->GetAccounts($oAccount); $mAccounts = $this->GetAccounts($oAccount);
$mAccounts = \array_keys($mAccounts); $mAccounts = \array_keys($mAccounts);
foreach ($mAccounts as $iIndex => $sName) foreach ($mAccounts as $iIndex => $sName) {
{
$mAccounts[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sName); $mAccounts[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sName);
} }
} }
@ -184,35 +169,35 @@ trait Accounts
)); ));
} }
/** /**
* @param Account $account * @param Account $account
* @return Identity[] * @return Identity[]
*/ */
public function GetIdentities(Account $account) : array public function GetIdentities(Account $account): array
{ {
if(!$account) return []; if (!$account) return [];
// A custom name for a single identity is also stored in this system // A custom name for a single identity is also stored in this system
$allowMultipleIdentities = $this->GetCapa(false, false, Capa::IDENTITIES, $account); $allowMultipleIdentities = $this->GetCapa(false, false, Capa::IDENTITIES, $account);
// Get all identities // Get all identities
$identities = $this->IdentitiesProvider()->GetIdentities($account, $allowMultipleIdentities); $identities = $this->IdentitiesProvider()->GetIdentities($account, $allowMultipleIdentities);
// Sort identities // Sort identities
$orderString = $this->StorageProvider()->Get($account, StorageType::CONFIG, 'accounts_identities_order'); $orderString = $this->StorageProvider()->Get($account, StorageType::CONFIG, 'accounts_identities_order');
$order = json_decode($orderString, true) ?? []; $order = json_decode($orderString, true) ?? [];
if(isset($order['Identities']) && is_array($order['Identities']) && count($order['Identities']) > 1) { if (isset($order['Identities']) && is_array($order['Identities']) && count($order['Identities']) > 1) {
$list = array_map(function($item) { $list = array_map(function ($item) {
if('' === $item) $item = '---'; if ('' === $item) $item = '---';
return $item; return $item;
}, $order['Identities']); }, $order['Identities']);
usort($identities, function($a, $b) use ($list) { usort($identities, function ($a, $b) use ($list) {
return array_search($a->Id(true), $list) < array_search($b->Id(true), $list) ? -1 : 1; return array_search($a->Id(true), $list) < array_search($b->Id(true), $list) ? -1 : 1;
}); });
} }
return $identities; return $identities;
} }
} }

View file

@ -7,40 +7,40 @@ use MailSo\Base\Utils;
class Identity implements JsonSerializable class Identity implements JsonSerializable
{ {
/** /**
* @var string * @var string
*/ */
private $sId; private $sId;
/** /**
* @var string * @var string
*/ */
private $sEmail; private $sEmail;
/** /**
* @var string * @var string
*/ */
private $sName; private $sName;
/** /**
* @var string * @var string
*/ */
private $sReplyTo; private $sReplyTo;
/** /**
* @var string * @var string
*/ */
private $sBcc; private $sBcc;
/** /**
* @var string * @var string
*/ */
private $sSignature; private $sSignature;
/** /**
* @var bool * @var bool
*/ */
private $bSignatureInsertBefore; private $bSignatureInsertBefore;
function __construct(string $sId = '', string $sEmail = '') function __construct(string $sId = '', string $sEmail = '')
{ {
@ -53,88 +53,87 @@ class Identity implements JsonSerializable
$this->bSignatureInsertBefore = false; $this->bSignatureInsertBefore = false;
} }
public function Id(bool $bFillOnEmpty = false) : string public function Id(bool $bFillOnEmpty = false): string
{ {
return $bFillOnEmpty ? ('' === $this->sId ? '---' : $this->sId) : $this->sId; return $bFillOnEmpty ? ('' === $this->sId ? '---' : $this->sId) : $this->sId;
} }
public function Email() : string public function Email(): string
{ {
return $this->sEmail; return $this->sEmail;
} }
public function SetEmail(string $sEmail) : self public function SetEmail(string $sEmail): self
{ {
$this->sEmail = $sEmail; $this->sEmail = $sEmail;
return $this; return $this;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function ReplyTo() : string public function ReplyTo(): string
{ {
return $this->sReplyTo; return $this->sReplyTo;
} }
public function Bcc() : string public function Bcc(): string
{ {
return $this->sBcc; return $this->sBcc;
} }
public function Signature() : string public function Signature(): string
{ {
return $this->sSignature; return $this->sSignature;
} }
public function SignatureInsertBefore() : bool public function SignatureInsertBefore(): bool
{ {
return $this->bSignatureInsertBefore; return $this->bSignatureInsertBefore;
} }
public function SetId(string $sId): Identity public function SetId(string $sId): Identity
{
$this->sId = $sId;
return $this;
}
public function SetName(string $sName): Identity
{
$this->sName = $sName;
return $this;
}
public function SetReplyTo(string $sReplyTo): Identity
{
$this->sReplyTo = $sReplyTo;
return $this;
}
public function SetBcc(string $sBcc): Identity
{
$this->sBcc = $sBcc;
return $this;
}
public function SetSignature(string $sSignature): Identity
{
$this->sSignature = $sSignature;
return $this;
}
public function SetSignatureInsertBefore(bool $bSignatureInsertBefore): Identity
{
$this->bSignatureInsertBefore = $bSignatureInsertBefore;
return $this;
}
public function FromJSON(array $aData, bool $bAjax = false) : bool
{ {
if (!empty($aData['Email'])) $this->sId = $sId;
{ return $this;
}
public function SetName(string $sName): Identity
{
$this->sName = $sName;
return $this;
}
public function SetReplyTo(string $sReplyTo): Identity
{
$this->sReplyTo = $sReplyTo;
return $this;
}
public function SetBcc(string $sBcc): Identity
{
$this->sBcc = $sBcc;
return $this;
}
public function SetSignature(string $sSignature): Identity
{
$this->sSignature = $sSignature;
return $this;
}
public function SetSignatureInsertBefore(bool $bSignatureInsertBefore): Identity
{
$this->bSignatureInsertBefore = $bSignatureInsertBefore;
return $this;
}
public function FromJSON(array $aData, bool $bAjax = false): bool
{
if (!empty($aData['Email'])) {
$this->sId = !empty($aData['Id']) ? $aData['Id'] : ''; $this->sId = !empty($aData['Id']) ? $aData['Id'] : '';
$this->sEmail = $bAjax ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email']; $this->sEmail = $bAjax ? Utils::IdnToAscii($aData['Email'], true) : $aData['Email'];
$this->sName = isset($aData['Name']) ? $aData['Name'] : ''; $this->sName = isset($aData['Name']) ? $aData['Name'] : '';
@ -150,7 +149,7 @@ class Identity implements JsonSerializable
return false; return false;
} }
public function ToSimpleJSON() : array public function ToSimpleJSON(): array
{ {
return array( return array(
'Id' => $this->Id(), 'Id' => $this->Id(),
@ -176,12 +175,12 @@ class Identity implements JsonSerializable
); );
} }
public function Validate() : bool public function Validate(): bool
{ {
return !empty($this->sEmail); return !empty($this->sEmail);
} }
public function IsAccountIdentities() : bool public function IsAccountIdentities(): bool
{ {
return '' === $this->Id(); return '' === $this->Id();
} }

View file

@ -8,127 +8,132 @@ use RainLoop\Providers\Identities\IIdentities;
class Identities extends AbstractProvider class Identities extends AbstractProvider
{ {
/** @var IIdentities[] */ /** @var IIdentities[] */
private $drivers; private $drivers;
/** @var Identity[][][] */ /** @var Identity[][][] */
private $identitiesPerDriverPerAccount; private $identitiesPerDriverPerAccount;
/** /**
* Identities constructor. * Identities constructor.
* @param IIdentities[] $drivers * @param IIdentities[] $drivers
*/ */
public function __construct(?array $drivers = null) public function __construct(?array $drivers = null)
{ {
if($drivers === null) $drivers = []; if ($drivers === null) $drivers = [];
$this->drivers = array_filter($drivers, function($driver) { $this->drivers = array_filter($drivers, function ($driver) {
return $driver instanceof IIdentities; return $driver instanceof IIdentities;
}); });
} }
/** /**
* @param Account $account * @param Account $account
* @param bool $allowMultipleIdentities * @param bool $allowMultipleIdentities
* @return Identity[] * @return Identity[]
*/ */
public function GetIdentities(Account $account, bool $allowMultipleIdentities) : array { public function GetIdentities(Account $account, bool $allowMultipleIdentities): array
// Find all identities stored in the system {
$identities = $this->MergeIdentitiesPerDriver($this->GetIdentiesPerDriver($account)); // Find all identities stored in the system
$identities = $this->MergeIdentitiesPerDriver($this->GetIdentiesPerDriver($account));
// Find the primary identity // Find the primary identity
$primaryIdentity = current(array_filter($identities, function($identity) { $primaryIdentity = current(array_filter($identities, function ($identity) {
return $identity->IsAccountIdentities(); return $identity->IsAccountIdentities();
})); }));
// If no primary identity is found, generate default one from account info // If no primary identity is found, generate default one from account info
if($primaryIdentity === null || $primaryIdentity === false) if ($primaryIdentity === null || $primaryIdentity === false)
$identities[] = $primaryIdentity = new Identity('', $account->Email()); $identities[] = $primaryIdentity = new Identity('', $account->Email());
// Return only primary identity or all identities // Return only primary identity or all identities
return $allowMultipleIdentities ? $identities : [$primaryIdentity]; return $allowMultipleIdentities ? $identities : [$primaryIdentity];
} }
public function UpdateIdentity(Account $account, Identity $identity) { public function UpdateIdentity(Account $account, Identity $identity)
// Find all identities in the system {
$identities = &$this->GetIdentiesPerDriver($account); // Find all identities in the system
$identities = &$this->GetIdentiesPerDriver($account);
$isNew = true; $isNew = true;
foreach($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if(!$driver->SupportsStore()) continue; if (!$driver->SupportsStore()) continue;
$driverIdentities = &$identities[$driver->Name()]; $driverIdentities = &$identities[$driver->Name()];
if(!isset($driverIdentities[$identity->Id(true)])) if (!isset($driverIdentities[$identity->Id(true)]))
continue; continue;
// We update the identity in all writeable stores // We update the identity in all writeable stores
$driverIdentities[$identity->Id(true)] = $identity; $driverIdentities[$identity->Id(true)] = $identity;
$isNew = false; $isNew = false;
$driver->SetIdentities($account, $driverIdentities); $driver->SetIdentities($account, $driverIdentities);
} }
// If it is a new identity we add it to any storage driver // If it is a new identity we add it to any storage driver
if($isNew) { if ($isNew) {
// Pick any storage driver to store the result, typically only file storage // Pick any storage driver to store the result, typically only file storage
$storageDriver = current(array_filter($this->drivers, function($driver) { $storageDriver = current(array_filter($this->drivers, function ($driver) {
return $driver->SupportsStore(); return $driver->SupportsStore();
})); }));
$identities[$storageDriver->Name()][$identity->Id(true)] = $identity; $identities[$storageDriver->Name()][$identity->Id(true)] = $identity;
$storageDriver->SetIdentities($account, $identities[$storageDriver->Name()]); $storageDriver->SetIdentities($account, $identities[$storageDriver->Name()]);
} }
} }
public function DeleteIdentity(Account $account, string $identityId) { public function DeleteIdentity(Account $account, string $identityId)
// On deletion, we remove the identity from all drivers if they are writeable. {
$identities = &$this->GetIdentiesPerDriver($account); // On deletion, we remove the identity from all drivers if they are writeable.
$identities = &$this->GetIdentiesPerDriver($account);
foreach($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if(!$driver->SupportsStore()) continue; if (!$driver->SupportsStore()) continue;
$driverIdentities = &$identities[$driver->Name()]; $driverIdentities = &$identities[$driver->Name()];
if(!isset($driverIdentities[$identityId])) if (!isset($driverIdentities[$identityId]))
continue; continue;
// We found it, so remove and update storage if relevant // We found it, so remove and update storage if relevant
$identity = $driverIdentities[$identityId]; $identity = $driverIdentities[$identityId];
if($identity->IsAccountIdentities()) continue; // never remove the primary identity if ($identity->IsAccountIdentities()) continue; // never remove the primary identity
unset($driverIdentities[$identityId]); unset($driverIdentities[$identityId]);
$driver->SetIdentities($account, $driverIdentities); $driver->SetIdentities($account, $driverIdentities);
} }
} }
private function &GetIdentiesPerDriver(Account $account) : array { private function &GetIdentiesPerDriver(Account $account): array
if(isset($this->identitiesPerDriverPerAccount[$account->Email()])) {
return $this->identitiesPerDriverPerAccount[$account->Email()]; if (isset($this->identitiesPerDriverPerAccount[$account->Email()]))
return $this->identitiesPerDriverPerAccount[$account->Email()];
$identitiesPerDriver = []; $identitiesPerDriver = [];
foreach($this->drivers as $driver) { foreach ($this->drivers as $driver) {
$driverIdentities = $driver->GetIdentities($account); $driverIdentities = $driver->GetIdentities($account);
foreach($driverIdentities as $identity) foreach ($driverIdentities as $identity)
$identitiesPerDriver[$driver->Name()][$identity->Id(true)] = $identity; $identitiesPerDriver[$driver->Name()][$identity->Id(true)] = $identity;
} }
$this->identitiesPerDriverPerAccount[$account->Email()] = $identitiesPerDriver; $this->identitiesPerDriverPerAccount[$account->Email()] = $identitiesPerDriver;
return $this->identitiesPerDriverPerAccount[$account->Email()]; return $this->identitiesPerDriverPerAccount[$account->Email()];
} }
/** /**
* @param Identity[][] $identitiesPerDriver * @param Identity[][] $identitiesPerDriver
* @return Identity[] * @return Identity[]
*/ */
private function MergeIdentitiesPerDriver(array $identitiesPerDriver) : array { private function MergeIdentitiesPerDriver(array $identitiesPerDriver): array
// Merge logic for the identities {
$identities = []; // Merge logic for the identities
foreach($this->drivers as $driver) { $identities = [];
// Merge and replace by key foreach ($this->drivers as $driver) {
foreach($identitiesPerDriver[$driver->Name()] as $identity) // Merge and replace by key
$identities[$identity->Id(true)] = $identity; foreach ($identitiesPerDriver[$driver->Name()] as $identity)
} $identities[$identity->Id(true)] = $identity;
}
return array_values($identities); return array_values($identities);
} }
} }

View file

@ -8,62 +8,64 @@ use RainLoop\Providers\Storage;
class FileIdentities implements IIdentities class FileIdentities implements IIdentities
{ {
/** /**
* @var Storage * @var Storage
*/ */
private $localStorageProvider; private $localStorageProvider;
/** /**
* FileIdentities constructor. * FileIdentities constructor.
* @param Storage $localStorageProvider * @param Storage $localStorageProvider
*/ */
public function __construct(Storage $localStorageProvider) public function __construct(Storage $localStorageProvider)
{ {
$this->localStorageProvider = $localStorageProvider; $this->localStorageProvider = $localStorageProvider;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function GetIdentities(Account $account): array public function GetIdentities(Account $account): array
{ {
if(!$account) return []; if (!$account) return [];
$data = $this->localStorageProvider->Get($account, Storage\Enumerations\StorageType::CONFIG, 'identities'); $data = $this->localStorageProvider->Get($account, Storage\Enumerations\StorageType::CONFIG, 'identities');
$subIdentities = json_decode($data, true) ?? []; $subIdentities = json_decode($data, true) ?? [];
$result = []; $result = [];
foreach($subIdentities as $subIdentity) { foreach ($subIdentities as $subIdentity) {
$identity = new Identity(); $identity = new Identity();
$identity->FromJSON($subIdentity); $identity->FromJSON($subIdentity);
if(!$identity->Validate()) continue; if (!$identity->Validate()) continue;
if($identity->IsAccountIdentities()) $identity->SetEmail($account->Email()); if ($identity->IsAccountIdentities()) $identity->SetEmail($account->Email());
$result[] = $identity; $result[] = $identity;
} }
return $result; return $result;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function SetIdentities(Account $account, array $identities) public function SetIdentities(Account $account, array $identities)
{ {
$jsons = array_map(function($identity) { return $identity->ToSimpleJSON(); }, $identities); $jsons = array_map(function ($identity) {
$this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', json_encode($jsons)); return $identity->ToSimpleJSON();
} }, $identities);
$this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', json_encode($jsons));
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function SupportsStore() : bool public function SupportsStore(): bool
{ {
return true; return true;
} }
public function Name(): string public function Name(): string
{ {
return "File"; return "File";
} }
} }

View file

@ -7,28 +7,28 @@ use RainLoop\Model\Identity;
interface IIdentities interface IIdentities
{ {
/** /**
* @param Account $account * @param Account $account
* *
* @return Identity[] * @return Identity[]
*/ */
public function GetIdentities(Account $account) : array; public function GetIdentities(Account $account): array;
/** /**
* @param Account $account * @param Account $account
* @param Identity[] $identities * @param Identity[] $identities
* *
* @return void * @return void
*/ */
public function SetIdentities(Account $account, array $identities); public function SetIdentities(Account $account, array $identities);
/** /**
* @return bool * @return bool
*/ */
public function SupportsStore() : bool; public function SupportsStore(): bool;
/** /**
* @return string * @return string
*/ */
public function Name() : string; public function Name(): string;
} }

View file

@ -8,37 +8,40 @@ use RainLoop\Model\Identity;
class TestIdentities implements IIdentities class TestIdentities implements IIdentities
{ {
/** /**
* @param Account $account * @param Account $account
* @return Identity[] * @return Identity[]
*/ */
public function GetIdentities(Account $account): array public function GetIdentities(Account $account): array
{ {
$oIdentity = new Identity('', $account->Email()); $oIdentity = new Identity('', $account->Email());
$oIdentity->SetName("Test Name"); $oIdentity->SetName("Test Name");
return [$oIdentity]; return [$oIdentity];
} }
/** /**
* @param Account $account * @param Account $account
* @param Identity[] $identities * @param Identity[] $identities
* *
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function SetIdentities(Account $account, array $identities) public function SetIdentities(Account $account, array $identities)
{ {
throw new Exception("Not implemented"); throw new Exception("Not implemented");
} }
/** /**
* @return bool * @return bool
*/ */
public function SupportsStore() : bool public function SupportsStore(): bool
{ {
return false; return false;
} }
public function Name() : string { return "Test"; } public function Name(): string
{
return "Test";
}
} }