text = SharedText::toUTF8($text); } elseif ($text instanceof TextRun) { $this->text = $text; } else { throw new InvalidArgumentException('Invalid text, should be a string or a TextRun'); } $this->depth = $depth; $styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}"; if (array_key_exists($styleName, Style::getStyles())) { $this->style = str_replace('_', '', $styleName); } if ($pageNumber !== null) { $this->pageNumber = $pageNumber; } } /** * Get Title Text content. * * @return string|TextRun */ public function getText() { return $this->text; } /** * Get depth. * * @return int */ public function getDepth() { return $this->depth; } /** * Get Title style. * * @return ?string */ public function getStyle() { return $this->style; } /** * Get page number. */ public function getPageNumber(): ?int { return $this->pageNumber; } }