/** * Get loaded object. If object is not loaded yet, then load it and save it * locally. Otherwise, just return the pre-loaded object. * * @return mixed Loaded object */ public function get() { if ($this->adminUser instanceof AdminUserInterface) { return $this->adminUser; } $token = $this->tokenStorage instanceof TokenStorageInterface ? $this->tokenStorage->getToken() : null; $this->adminUser = $token instanceof UsernamePasswordToken ? $token->getUser() : $this->adminUserFactory->create(); return $this->adminUser; }
/** * Load admin user method * * This method tries to load AdminUser stored in Session, using specific * session field name. * * If this AdminUser is found, stores it locally and uses it as "official" * adminUser object * * Otherwise, new AdminUser is created and stored (not flushed nor * persisted) * * @return AdminUserInterface Loaded admin user */ public function loadAdminUser() { if ($this->adminUser instanceof AdminUserInterface) { return $this->adminUser; } $token = $this->securityContext instanceof SecurityContextInterface ? $this->securityContext->getToken() : null; if ($token instanceof UsernamePasswordToken) { $this->adminUser = $token->getUser(); } else { $this->adminUser = $this->adminUserFactory->create(); } return $this->adminUser; }