sync(); } /** * Find plugin account data or create fresh one * * @param Account $account * @return AccountData|null */ public function resolvePluginAccountData(Account $account) { $accountData = $this->findAccountDataById($account->getId()); if (!$accountData) { $accountData = new AccountData(); // Set proper default values $accountData->setPath($account->getPath()); $accountData->setId($account->getId()); $accountData->setSecret($account->getClientSecret()); array_push($this->accounts, $accountData); } return $accountData; } /** * Should return account data by base path * * @param $basePath * @return AccountData */ public function getAccountDataByBasePath($basePath) { foreach ($this->accounts as $iterable) { $iterableBasePath = plugin_basename($iterable->getPath()); if ($iterableBasePath === $basePath) { return $iterable; } } return null; } /** * Return account by id * * @param $id * @return AccountData|null */ private function findAccountDataById($id) { foreach ($this->accounts as &$iterable) { if ($iterable->getId() === $id) { return $iterable; } } return null; } }