'cover', self::ATTACH_STRETCH => 'stretch', self::ATTACH_TILE => 'tile', self::ATTACH_CONTAIN => 'contain', ]; public const ATTRIBUTE_STRINGS = [ self::ATTRIB_BLEND => 'blend', self::ATTRIB_SLIDE => 'slide', ]; public static function getAttachmentStringOptions(): array { return [ self::ATTACH_COVER => 'Cover', self::ATTACH_STRETCH => 'Stretch', self::ATTACH_TILE => 'Tile', self::ATTACH_CONTAIN => 'Contain', ]; } private int $settings; public function __construct(UserInfo $userInfo) { parent::__construct($userInfo); $this->settings = (int)$userInfo->getBackgroundSettings(); } public function getSettings(): int { return $this->settings; } public function getMaxWidth(): int { global $cfg; return $cfg->getInteger('background.max_width', self::MAX_WIDTH); } public function getMaxHeight(): int { global $cfg; return $cfg->getInteger('background.max_height', self::MAX_HEIGHT); } public function getMaxBytes(): int { global $cfg; return $cfg->getInteger('background.max_size', self::MAX_BYTES); } public function getFileName(): string { return sprintf('background-%1$d.%2$s', $this->getUserId(), $this->getFileExtension()); } public function getRelativePath(): string { return sprintf(self::FORMAT, $this->getUserId()); } public function getAttachment(): int { return $this->settings & 0x0F; } public function getAttachmentString(): string { return self::ATTACHMENT_STRINGS[$this->getAttachment()] ?? ''; } public function setAttachment(int $attach): self { $this->settings = $this->getAttributes() | ($attach & 0x0F); return $this; } public function setAttachmentString(string $attach): self { if(!in_array($attach, self::ATTACHMENT_STRINGS)) throw new InvalidArgumentException; $this->setAttachment(array_flip(self::ATTACHMENT_STRINGS)[$attach]); return $this; } public function getAttributes(): int { return $this->settings & 0xF0; } public function setAttributes(int $attrib): self { $this->settings = $this->getAttachment() | ($attrib & 0xF0); return $this; } public function isBlend(): bool { return ($this->getAttributes() & self::ATTRIB_BLEND) > 0; } public function setBlend(bool $blend): self { $this->settings = $blend ? ($this->settings | self::ATTRIB_BLEND) : ($this->settings & ~self::ATTRIB_BLEND); return $this; } public function isSlide(): bool { return ($this->getAttributes() & self::ATTRIB_SLIDE) > 0; } public function setSlide(bool $slide): self { $this->settings = $slide ? ($this->settings | self::ATTRIB_SLIDE) : ($this->settings & ~self::ATTRIB_SLIDE); return $this; } public function getClassNames(string $format = '%s'): array { $names = []; $attachment = $this->getAttachment(); $attributes = $this->getAttributes(); if(array_key_exists($attachment, self::ATTACHMENT_STRINGS)) $names[] = sprintf($format, self::ATTACHMENT_STRINGS[$attachment]); foreach(self::ATTRIBUTE_STRINGS as $flag => $name) if(($attributes & $flag) > 0) $names[] = sprintf($format, $name); return $names; } public function delete(): void { parent::delete(); $this->settings = 0; } }