id = (string)$attachment['id']; $this->type = $type; $this->url = $url; $this->preview_url = $preview; $this->remote_url = $remote; $this->text_url = $this->remote_url ?? $this->url; $this->description = $attachment['description']; $this->blurhash = $attachment['blurhash']; if ($type === 'image') { if ((int) $attachment['width'] > 0 && (int) $attachment['height'] > 0) { $this->meta['original']['width'] = (int) $attachment['width']; $this->meta['original']['height'] = (int) $attachment['height']; $this->meta['original']['size'] = (int) $attachment['width'] . 'x' . (int) $attachment['height']; $this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']); } if (isset($attachment['preview-width']) && (int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) { $this->meta['small']['width'] = (int) $attachment['preview-width']; $this->meta['small']['height'] = (int) $attachment['preview-height']; $this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height']; $this->meta['small']['aspect'] = (float) ((int) $attachment['preview-width'] / (int) $attachment['preview-height']); } } } /** * Returns the current entity as an array * * @return array */ public function toArray(): array { $attachment = parent::toArray(); if (empty($attachment['remote_url'])) { $attachment['remote_url'] = null; } return $attachment; } }