container = $container; } /** * Whether an application is initialized as a portal. */ public function isPortal() : bool { return $this->container->has('portal'); } /** * Get portal ID (if an applicaition is portal). */ public function getPortalId() : string { if (!$this->isPortal()) throw new Error("Can't get portal ID for non-portal application."); return $this->getPortal()->id; } /** * Get a portal entity (if an applicaition is portal). */ public function getPortal() : PortalEntity { if (!$this->isPortal()) throw new Error("Can't get portal for non-portal application."); return $this->container->get('portal'); } /** * Whether any user is initialized. If not logged, it will also return TRUE, meaning the system used is used. */ public function hasUser() : bool { return $this->container->has('user'); } /** * Get current logged user. If no auth is applied, then system user will be returned. */ public function getUser() : UserEntity { if (!$this->hasUser()) throw new Error("User is not yet available."); return $this->container->get('user'); } /** * Whether a user is logged. */ public function isLogged() : bool { if (!$this->container->has('user')) return false; if ($this->getUser()->isSystem()) return false; return true; } /** * Whether logged as an admin. */ public function isAdmin() : bool { if (!$this->isLogged()) return false; return $this->getUser()->isAdmin(); } /** * Whether logged as an api user. */ public function isApi() : bool { if (!$this->isLogged()) return false; return $this->getUser()->isApi(); } }