MMOframework
Why AI Playground Libraries Developers Agency
FR EN
Build a project live
Index

Document

MMO\core\documents\docx · 1 symbol · generated 30 Nov 2026

class

Document

Document.php:15

Word document reader (.docx): what its text says, as Markdown (toMarkdown) -- headings (the Title and Heading 1..6 styles, or a paragraph's outline level), bold, italic and struck-through text, bulleted and numbered lists at their level, tables, links, images (named, not extracted) and footnotes. Reads the archive itself (Zip: no ext-zip needed); headers, footers, comments and tracked deletions are left out.

class MMO\core\documents\docx\Document
Namespace
MMO\core\documents\docx
echo \MMO\core\documents\docx\Document::File('report.docx')->toMarkdown();

Index

NS_A
NS_PKG_REL
NS_R
NS_W
NS_WP
counters
files
footnotes
mainThe main part's name, found through _rels/.rels.
notes
numbering
rels
styles
blocks($parent)
child($parent, $name)The first w: child named $name.
Elements($xpath, $query, $context) static
EscapeLineStart($text) staticA paragraph's text that would start a heading, a list or a quote, escaped.
File($filename) staticRead a .docx file from disk.
getFiles()
image($drawing)An image as ![its description](its file in the archive).
inline($parent)The text of a paragraph (or of a link...) with its emphasis, links, images and note references.
IsListItem($block) static
load($filename)Read a .docx file from disk.
loadData($data)Read a .docx file's raw bytes.
loadFiles($files)Read a .docx from its parts, already out of their archive (an unzipped folder, a test).
note($id)A footnote's reference, its text kept for the end of the document.
notesMarkdown()
on($rPr, $name)
paragraph($p)A paragraph as Markdown: a heading, a list item, or a line of text ('' when it has no text).
readNumbering($part)Each list's format by level (numbering.xml): numId => ilvl => numFmt.
readRels($part)
readStyles($part)The styles' headings, emphasis and lists (styles.xml).
run($r)A run: its text (escaped), its emphasis, and the markup it holds (an image, a note reference).
style($id)
table($tbl)A table as Markdown: its first row the header, a cell's paragraphs on one line (<br> between), a cell spread over several columns repeated in each, one merged down left empty below its first.
toMarkdown($title)The document as Markdown (GitHub's flavour).
val($el)An element's w:val.
Wrap($text, $bold, $italic, $strike) staticText wrapped in its emphasis, the spaces around it left outside ( a is no bold for Markdown).
xpath($name)

Constants5

NS_A

const NS_A = 'http://schemas.openxmlformats.org/drawingml/2006/main'

NS_PKG_REL

const NS_PKG_REL = 'http://schemas.openxmlformats.org/package/2006/relationships'

NS_R

const NS_R = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'

NS_W

const NS_W = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'

NS_WP

const NS_WP = 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing'

Properties8

counters

protected array $counters = []
Type
array

files

protected array $files = []
Type
array

footnotes

protected array $footnotes = []
Type
array

main

The main part's name, found through _rels/.rels.

protected string $main = 'word/document.xml'
Type
string

notes

protected array $notes = []
Type
array

numbering

protected array $numbering = []
Type
array

rels

protected array $rels = []
Type
array

styles

protected array $styles = []
Type
array

Methods26

blocks($parent)

Document.php:133
protected function blocks(DOMElement $parent): array
$parentDOMElement
returnsarraythe Markdown of each paragraph and table of $parent (the body, a cell, a content control).

Elements($xpath, $query, $context)

staticDocument.php:472
protected static function Elements(DOMXPath $xpath, string $query, ?DOMNode $context = null): array
$xpathDOMXPath
$querystring
$context = nullnull | DOMNode
returnsarraythe elements an XPath query finds.

EscapeLineStart($text)

staticDocument.php:487

A paragraph's text that would start a heading, a list or a quote, escaped.

protected static function EscapeLineStart(string $text): string
$textstring
returnsstring

File($filename)

staticDocument.php:43

Read a .docx file from disk.

static function File(string $filename): MMO\core\documents\docx\Document
$filenamestring
returnsDocument
throwsif it doesn't exist.

image($drawing)

Document.php:308

An image as ![its description](its file in the archive).

protected function image(DOMElement $drawing): string
$drawingDOMElement
returnsstring

inline($parent)

Document.php:203

The text of a paragraph (or of a link...) with its emphasis, links, images and note references.

protected function inline(DOMElement $parent): string
$parentDOMElement
returnsstring

IsListItem($block)

staticDocument.php:492
protected static function IsListItem(string $block): bool
$blockstring
returnsboolwhether a block of Markdown is a list item (they are kept on following lines).

loadData($data)

Document.php:59

Read a .docx file's raw bytes.

function loadData(string $data): void
$datastring
returnsvoid
throwsif it isn't a ZIP archive, or holds no Word document.

loadFiles($files)

Document.php:74

Read a .docx from its parts, already out of their archive (an unzipped folder, a test).

function loadFiles(array $files): void
$filesarray
returnsvoid
throwsif there's no Word document among them.
(new Document())->loadFiles(['word/document.xml' => '<w:document xmlns:w="...">...</w:document>']);

note($id)

Document.php:299

A footnote's reference, its text kept for the end of the document.

protected function note(string $id): string
$idstring
returnsstring

notesMarkdown()

Document.php:465
protected function notesMarkdown(): string
returnsstringthe footnotes referenced, [^id]: text each, '' when none was.

on($rPr, $name)

Document.php:459
protected function on(?DOMElement $rPr, string $name): ?bool
$rPrnull | DOMElement
$namestring
returnsnull | boola toggle of a run's properties (<w:b/>, <w:b w:val="0"/>), null when it isn't set.

paragraph($p)

Document.php:161

A paragraph as Markdown: a heading, a list item, or a line of text ('' when it has no text).

protected function paragraph(DOMElement $p): string

readNumbering($part)

Document.php:410

Each list's format by level (numbering.xml): numId => ilvl => numFmt.

protected function readNumbering(string $part): void
$partstring
returnsvoid

readRels($part)

Document.php:370
protected function readRels(string $part): array
$partstring
returnsarraystring> a part's relationships: id => its target (relative to the archive, or a url).

readStyles($part)

Document.php:384

The styles' headings, emphasis and lists (styles.xml).

protected function readStyles(string $part): void
$partstring
returnsvoid

run($r)

Document.php:256

A run: its text (escaped), its emphasis, and the markup it holds (an image, a note reference).

protected function run(DOMElement $r): array
$rDOMElement
returnsarrayarray{bool, bool, bool}, string}

style($id)

Document.php:427
protected function style(?string $id): array
$idnull | string
returnsarraystring, level: ?int, bold: bool, italic: bool, list: ?array, basedOn: ?string} a style with what it inherits.

table($tbl)

Document.php:325

A table as Markdown: its first row the header, a cell's paragraphs on one line (<br> between), a cell spread over several columns repeated in each, one merged down left empty below its first.

protected function table(DOMElement $tbl): string
$tblDOMElement
returnsstring

toMarkdown($title)

Document.php:111

The document as Markdown (GitHub's flavour).

function toMarkdown(?string $title = null): string
$title = nullnull | stringa # {title} above it (the file's name...).
returnsstring
echo Document::File('report.docx')->toMarkdown('report.docx');

Wrap($text, $bold, $italic, $strike)

staticDocument.php:478

Text wrapped in its emphasis, the spaces around it left outside ( a is no bold for Markdown).

protected static function Wrap(string $text, bool $bold, bool $italic, bool $strike): string
$textstring
$boldbool
$italicbool
$strikebool
returnsstring

xpath($name)

Document.php:353
protected function xpath(string $name): ?array
$namestring
returnsnull | array\DOMXPath}|null a part parsed, the w prefix registered; null when there's none.