mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 07:35:55 +08:00
Fixing indentation
This commit is contained in:
parent
1c63287243
commit
6919a6a34f
2
.editorconfig
Normal file
2
.editorconfig
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[*.php]
|
||||||
|
indent_style = tab
|
File diff suppressed because it is too large
Load diff
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,9 +173,9 @@ 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);
|
||||||
|
@ -201,13 +186,13 @@ trait Accounts
|
||||||
// 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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,44 +53,44 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -131,10 +131,9 @@ class Identity implements JsonSerializable
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FromJSON(array $aData, bool $bAjax = false) : bool
|
public function FromJSON(array $aData, bool $bAjax = false): bool
|
||||||
{
|
|
||||||
if (!empty($aData['Email']))
|
|
||||||
{
|
{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ class Identities extends AbstractProvider
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -32,33 +32,35 @@ class Identities extends AbstractProvider
|
||||||
* @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
|
// Find all identities stored in the system
|
||||||
$identities = $this->MergeIdentitiesPerDriver($this->GetIdentiesPerDriver($account));
|
$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
|
// Find all identities in the system
|
||||||
$identities = &$this->GetIdentiesPerDriver($account);
|
$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
|
||||||
|
@ -69,9 +71,9 @@ class Identities extends AbstractProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -80,35 +82,37 @@ class Identities extends AbstractProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
// On deletion, we remove the identity from all drivers if they are writeable.
|
||||||
$identities = &$this->GetIdentiesPerDriver($account);
|
$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()]))
|
{
|
||||||
|
if (isset($this->identitiesPerDriverPerAccount[$account->Email()]))
|
||||||
return $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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +124,13 @@ class Identities extends AbstractProvider
|
||||||
* @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
|
// Merge logic for the identities
|
||||||
$identities = [];
|
$identities = [];
|
||||||
foreach($this->drivers as $driver) {
|
foreach ($this->drivers as $driver) {
|
||||||
// Merge and replace by key
|
// Merge and replace by key
|
||||||
foreach($identitiesPerDriver[$driver->Name()] as $identity)
|
foreach ($identitiesPerDriver[$driver->Name()] as $identity)
|
||||||
$identities[$identity->Id(true)] = $identity;
|
$identities[$identity->Id(true)] = $identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,18 +27,18 @@ class FileIdentities implements IIdentities
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +50,16 @@ class FileIdentities implements IIdentities
|
||||||
*/
|
*/
|
||||||
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) {
|
||||||
|
return $identity->ToSimpleJSON();
|
||||||
|
}, $identities);
|
||||||
$this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', json_encode($jsons));
|
$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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ interface IIdentities
|
||||||
*
|
*
|
||||||
* @return Identity[]
|
* @return Identity[]
|
||||||
*/
|
*/
|
||||||
public function GetIdentities(Account $account) : array;
|
public function GetIdentities(Account $account): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
@ -25,10 +25,10 @@ interface IIdentities
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function SupportsStore() : bool;
|
public function SupportsStore(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Name() : string;
|
public function Name(): string;
|
||||||
}
|
}
|
|
@ -35,10 +35,13 @@ class TestIdentities implements IIdentities
|
||||||
/**
|
/**
|
||||||
* @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";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue