mirror of
https://github.com/elyby/accounts.git
synced 2024-12-02 19:50:46 +05:30
28 lines
531 B
PHP
28 lines
531 B
PHP
|
<?php
|
||
|
namespace api\traits;
|
||
|
|
||
|
use common\models\Account;
|
||
|
|
||
|
trait AccountFinder {
|
||
|
|
||
|
private $account;
|
||
|
|
||
|
public abstract function getLogin();
|
||
|
|
||
|
/**
|
||
|
* @return Account|null
|
||
|
*/
|
||
|
public function getAccount() {
|
||
|
if ($this->account === null) {
|
||
|
$this->account = Account::findOne([$this->getLoginAttribute() => $this->getLogin()]);
|
||
|
}
|
||
|
|
||
|
return $this->account;
|
||
|
}
|
||
|
|
||
|
public function getLoginAttribute() {
|
||
|
return strpos($this->getLogin(), '@') ? 'email' : 'username';
|
||
|
}
|
||
|
|
||
|
}
|