Xao / Technical Fieldnotes

Framework Reference · Issue 1.0.0-dev · 4 min read

Core API Reference

Reference for Xao\\Runtime, Xao\\XaoRoot, Xao\\DomDoc, Xao\\DomFactory, Xao\\AppDoc, Xao\\Http\\Response, and Xao\\Exceptions.

Audience: PHP 8 developers building on XaoWords: 666Source: content/core-api.md
Open library index (12 documents)

All framework classes under src/ declare strict_types=1, require zero Composer packages, and pass phc check plus PHP 8.4 parity tests.

Xao\Runtime

Source: src/Runtime.php

  • public const VERSION = '1.0.0-dev' (targeting v1.0.0)

  • public const NAME = 'Xao'

  • public static function health(): array — returns ['framework' => string, 'version' => string, 'status' => string].

Xao\XaoRoot

Source: src/XaoRoot.php

Base class providing structured, inspectable error tracking without silent failures:

  • addError(string $message, string $errorCode = 'XAO_ERROR', array $context = []): void

  • addException(XaoException $exception): void

  • hasErrors(): bool

  • getErrors(): array

  • getLastError(): ?array

  • clearErrors(): void

  • throwError(string $message, string $errorCode = 'XAO_ERROR', array $context = []): void

Xao\DomDoc (extends XaoRoot)

Source: src/DomDoc.php

Core XML Application Object wrapping DOMDocument and DOMXPath:

  • __construct(string|DOMDocument $root = 'root', string $version = '1.0', string $encoding = 'UTF-8')

  • getDocument(): DOMDocument / getRoot(): DOMNode

  • toXml(bool $formatOutput = false): string / xmlGetDoc(bool $formatOutput = false): string

  • ndAppendToNode(DOMNode $target, string $name, ?string $value = null, array $attributes = []): DOMElement

  • ndAppendToRoot(string $name, ?string $value = null, array $attributes = []): DOMElement

  • ndConsumeNode(DOMNode $node, ?DOMNode $target = null): DOMNode

  • ndConsumeDoc(DomDoc $source, ?DOMNode $target = null): DOMElement

  • ndConsumeXml(string $xml, ?DOMNode $target = null): DOMElement

  • ndConsumeFile(string $filePath, ?DOMNode $target = null, ?string $baseDir = null): DOMElement

  • ndAppendToNodeNS(DOMNode $parent, string $namespaceUri, string $qualifiedName, ?string $text = null, array $attributes = []): DOMElement

  • ndAppendToRootNS(string $namespaceUri, string $qualifiedName, ?string $text = null, array $attributes = []): DOMElement

  • arrGetElementsByTagNameNS(string $namespaceUri, string $localName): array

  • ndImportNode(DOMNode $node, bool $deep = true, ?DOMNode $target = null): DOMNode

  • toCanonicalXml(bool $exclusive = false, bool $withComments = false): string

  • xpath(array $namespaces = []): DOMXPath

  • arrGetByXpath(string $query, ?DOMNode $contextNode = null, array $namespaces = []): array

  • evaluateXpath(string $expression, ?DOMNode $contextNode = null, array $namespaces = []): mixed

  • ndGetOneByXpath(string $query, ?DOMNode $contextNode = null, array $namespaces = []): ?DOMNode

  • ndAppendError(string $message, string $errorCode = 'XAO_ERROR', array $context = [], ?DOMNode $target = null): DOMElement

  • ndAppendException(XaoException $exception, ?DOMNode $target = null): DOMElement

  • static parseXmlToDomDocument(string $xml): DOMDocument — rejects empty XML and <!DOCTYPE / <!ENTITY declarations.

  • static resolveSafeFilePath(string $filePath, ?string $baseDir = null): string — enforces realpath() base-directory containment.

Content Callbacks

Register PHP callables on the document being assembled. Use onElement(string $localName, callable $handler, string $namespaceUri = '') for an element name and onXPath(string $selector, callable $handler, array $namespaces = []) for a node selection. Namespace matching uses the URI, so the author can choose a different prefix in each imported fragment.

Call processContentCallbacks() after importing the fragments and before the XSLT transformation. It selects all matches first, then invokes each handler with one matched node in registration order. Elements added by a handler become eligible on a subsequent explicit pass. Select the owning element for portable edits, since PHC can store leaf text directly on its element.

Xao\DomFactory

Source: src/DomFactory.php

  • static fromXml(string $xml): DomDoc

  • static fromFile(string $filePath, ?string $baseDir = null): DomDoc

  • static fromRoot(string $rootTag, string $version = '1.0', string $encoding = 'UTF-8'): DomDoc

Xao\AppDoc

Source: src/AppDoc.php

Stateless, worker-mode-safe front controller:

  • __construct(Transformer $transformer, bool $debug = false)

  • isDebugEnabled(): bool

  • registerRoute(string $path, callable $handler, string $stylesheet, string $contentType = 'text/html; charset=utf-8'): void

  • handle(string $rawPath, array $query = []): Response — validates paths, gates ?xao:XML=1 / ?xao:Text=1 behind $debug === true, transforms via Transformer, and returns an immutable Response.

Xao\Http\Response

Source: src/Http/Response.php

  • __construct(int $status, string $contentType, string $body, array $headers = [])

  • getStatus(): int, getContentType(): string, getBody(): string, getHeaders(): array, emit(): void

Xao\Exceptions\*

All exceptions extend Xao\Exceptions\XaoException (getErrorCode(), getContext(), toErrorArray()):

  • Xao\Exceptions\DomDocException

  • Xao\Exceptions\XmlParseException

  • Xao\Exceptions\DbToXmlException

  • Xao\Exceptions\TransformException (adds getHttpStatus(): int)

  • Xao\Exceptions\XsltTransformException (extends TransformException for native/driver XSLT errors)

  • Xao\Exceptions\InvalidSlugException (adds getHttpStatus(): int)