attachments[$attachment->id] = $attachment; } /** * @return Attachment[] */ public function getAttachments() { return $this->attachments; } /** * Get array of internal HTML links placeholders. * * @return array attachmentId => link placeholder */ public function getInternalLinksPlaceholders(): array { return preg_match_all('/=["\'](ci?d:([\w\.%*@-]+))["\']/i', $this->textHtml, $matches) ? array_combine($matches[2], $matches[1]) : []; } /** * @return mixed */ public function replaceInternalLinks($baseUri) { $baseUri = rtrim($baseUri, '\\/').'/'; $fetchedHtml = $this->textHtml; foreach ($this->getInternalLinksPlaceholders() as $attachmentId => $placeholder) { if (isset($this->attachments[$attachmentId])) { $fetchedHtml = str_replace($placeholder, $baseUri.basename($this->attachments[$attachmentId]->filePath), $fetchedHtml); } } return $fetchedHtml; } }