-
-
Save Spriz/efa8a9a774bf20fd3b7737eff679e2bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Api\Controller\Traits; | |
use App\Exception\NoAccountSelected; | |
use Cake\Event\Event; | |
/** | |
* Trait RequiresActiveAccountTrait | |
* | |
* @package Api\Controller\Traits | |
*/ | |
trait RequiresActiveAccountTrait | |
{ | |
/** | |
* @return array | |
*/ | |
public function implementedEvents(): array | |
{ | |
return ['Controller.initialize' => 'checkForAccount'] + parent::implementedEvents(); | |
} | |
/** | |
* @param \Cake\Event\Event $e | |
*/ | |
public function checkForAccount(Event $e) | |
{ | |
if (empty($this->Auth->user('active_account_id'))) { | |
throw new NoAccountSelected(); | |
} | |
parent::beforeFilter($e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment