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