Aller au contenu

omnisense/omnidocs Référence de l’API

Étage
Famille
Version
1.x
Suite de conformité
branchée, CI rouge
Vérifié en réel
Vérifié en partie
Licence
MIT
composer require omnisense/omnidocs:1.x-dev

Lue dans les fichiers PHP du paquet au commit 9ce91ac82a80 : ses espaces de noms, classes, interfaces et énumérations, leurs constantes, propriétés et méthodes publiques avec leur PHPDoc, et les options que prennent ses fabriques. Rien n’en est exécuté.

Omnidocs

  • Config class

    A source's options while its factory builds it: the options given, the factory's defaults under them, the keys that must be filled. Options come as configuration and environment variables give them: strings too.

    8 methods

  • LinkerInterface interface

    Where a site publishes what a page links to. A source turns every link it reads into one of three: another page of the manual (page()), another file of the repository (file(): the source tree on its forge, at the commit read), a picture (image()). An address that is absolute, or only an anchor, is left as it was written.

    3 methods

  • OnePage class

    A version of a manual read as one page: every page in reading order, one after the other, so that a package's whole documentation is one address - read straight away, searched with the browser's own find in page, its table of contents in a sidebar.

    10 methods · 2 properties

  • OnePart class

    A page of a manual as a part of its one page (OnePage): where it starts, its HTML there, the file to edit.

    2 methods · 8 properties

  • Registry class

    The application's sources by name, each built once from its factory and options:

    6 methods

  • SourceFactory class

    What a provider's factory has in common: its defaults set under the options given, the options it requires checked, then the source built.

    1 method

  • SourceFactoryInterface interface

    Builds a source from its options (the folder it reads, the repository it comes from...).

    2 methods

  • SourceInterface interface

    One version of a manual, as one format wrote it: a folder of Markdown, the output of Sphinx's JSON builder, Doxygen's XML, the JSON JSDoc explains.

    4 methods

Omnidocs\Exception

  • ExceptionInterface interface

    Every exception omnidocs and its sources throw.

  • InvalidConfigException class

    A source asked for with options it cannot work with: a folder that is not there, an option missing.

  • SourceException class

    What a source reads cannot be read: a file that is not the tool's output, a JSON or XML that does not parse.

Omnidocs\Html

  • Conventions class

    The HTML every format renders to, so that one stylesheet and one script read a manual whatever wrote it - the conventions of symfony.com/doc:

    9 methods · 2 constants

  • Headings class

    The headings of an HTML fragment that carry an id - on the heading, or on the element that wraps it (Sphinx's <section id>) - for "on this page" and the search index; and ids for texts that have none.

    3 methods

  • Links class

    The addresses of a page's links and pictures, rewritten: every <a href> and <img src> of an HTML fragment is handed to $rewrite (the address as written, decoded, and whether it is a picture), which answers the address to print or null to keep it. For the formats whose tool writes HTML (Sphinx's JSON builder); a Markdown source rewrites its links before rendering, on the document.

    1 method

  • Prose class

    A comment's prose as HTML - a PHPDoc's, a JSDoc's description: paragraphs at blank lines, a block indented by four spaces or more as code, lines that start with "-" or "*" as a list, `code` as code; everything else escaped.

    1 method

  • Text class

    The plain text of an HTML fragment: what a reader reads, for a search index and a description.

    1 method

Omnidocs\Linking

  • RepositoryLinker class

    The links of a manual read from a GitHub repository at a commit: a page goes where the site's closure says, another file of the repository to github.com at that commit (never a moving branch), a picture to raw.githubusercontent.com at that commit - or wherever the closures given say.

    5 methods

Omnidocs\Model

  • Heading class

    A heading of a page: its level (1 to 6), the id it carries in the page's HTML - the anchor "on this page" and the search link to - and its text.

    2 methods · 3 properties

  • Manual class

    A manual: its key in the site's addresses, its title, the repository it is read from ("glitchr-studio/flowjs"), its versions by name and the one read by default - the current one; the others are older (or newer) series a site shows with a notice.

    5 methods · 5 properties

  • Node class

    A place in a manual's contents: a page, or a section that holds pages (a folder of Markdown files, a Sphinx toctree caption, a group of API entries). Its path is its address inside the manual ("" for the home, "sticky", "guides/install"); a page knows the file it is read from, relative to the repository ("docs/sticky.md"), a section has none.

    5 methods · 5 properties

  • Page class

    A page of a manual, ready for a template: its path in the manual, its title, its contents (HTML, headings, metadata, plain text), the file it is read from relative to the repository - what "edit this page" opens - and the API entries it documents.

    6 methods · 5 properties

  • Rendered class

    A text once rendered to HTML: the HTML (without its first-level title when the format gives one, which the page prints itself), that title, the headings for "on this page", the metadata the source carried (a Markdown front matter), and its plain text for a search index and a description.

    2 methods · 5 properties

  • Symbol class

    An entry of an API reference: a class, a function, a method, an option, a member... as the format names it. Its name is the one a reader searches and a cross-reference gives ("StickyStops.attach", "requests.get", "tinyxml2::XMLDocument::Parse"); it lives on a page of the manual, at an anchor of that page.

    2 methods · 8 properties

  • Version class

    One version of a manual ("1.x", "4.x", "main"): its source, the branch it follows and the commit it is read at, whether it has reached its end of life. Reads its pages in reading order - the home first, then the tree depth first - for the previous and next links.

    10 methods · 5 properties

Omnidocs\Search

  • Entry class

    One record of a search index: what a hit shows and where it leads. Written with short keys, the index being downloaded whole by the reader's browser:

    3 methods · 8 properties

  • SearchIndex class

    The search index of a static site: one JSON file, written with the site, that the reader's browser downloads once and searches (assets/omnidocs.js): the pages of each version given, a record per heading so that a hit lands on its section, a record per API entry, and whatever the site adds of its own (its guides, its news). Records keep the order they were added in, so that two builds write the same file.

    6 methods

Omnidocs\Support

  • Path class

    Paths inside a repository or a tool's output, written with "/".

    7 methods

Omnidocs\Testing

  • ArraySource class

    A manual written out in PHP, for an application's tests or a page that is no file: pages as [path => ['title' => ..., 'html' => ...]] (the order given is the reading order; "" is the home), symbols as Symbol objects.

    5 methods

  • ArraySourceFactory class

    The "array" factory: an ArraySource from its 'pages' option, for an application's tests.

    2 options · 1 method

  • RecordingLinker class

    A linker for tests: pages at "/<path>", files at "repo:<path>", pictures at "img:<path>", and every request kept, so a test can check what a source linked to.

    3 methods · 3 properties

  • SourceContractTests trait

    What every source does, as PHPUnit tests: a provider's test case (or an application's, for a source of its own) uses this trait and gives the source, read from a real tool's output.

    6 methods

Omnidocs

Config class

final class Config extends ArrayObject Config.php:14

A source's options while its factory builds it: the options given, the factory's defaults under them, the keys that must be filled. Options come as configuration and environment variables give them: strings too.

Config::defaults()

public function defaults(array $defaults): self

Config::validateNotEmpty()

public function validateNotEmpty(array $keys, string $source): void

Config::get()

public function get(string $key, mixed $default = null): mixed

Config::string()

public function string(string $key): ?string

A string option; null when it is empty.

Config::bool()

public function bool(string $key, bool $default = false): bool

A boolean option, as an environment variable gives it too: "1", "true", "yes", "on".

Config::list()

public function list(string $key): array

A list; one given as an environment variable is a comma-separated string.

Config::map()

public function map(string $key): array

A map of strings ("note" => "Remarque").

Config::directory()

public function directory(string $key, string $source): string

A folder that must exist, without its trailing slash.

LinkerInterface interface

interface LinkerInterface LinkerInterface.php:12

Where a site publishes what a page links to. A source turns every link it reads into one of three: another page of the manual (page()), another file of the repository (file(): the source tree on its forge, at the commit read), a picture (image()). An address that is absolute, or only an anchor, is left as it was written.

LinkerInterface::page()

public function page(string $path, ?string $fragment = null): string

A page of the manual, by its path ("" the home), with its anchor.

LinkerInterface::file()

public function file(string $path, ?string $fragment = null): ?string

A file of the repository that is not a page ("src/js/stops.js"); null leaves the link as written.

LinkerInterface::image()

public function image(string $path): ?string

A picture, by its path in the repository or in the tool's output; null leaves it as written.

OnePage class

final class OnePage OnePage.php:40

A version of a manual read as one page: every page in reading order, one after the other, so that a package's whole documentation is one address - read straight away, searched with the browser's own find in page, its table of contents in a sidebar.

  • the home comes first, as it is; every other page is a part: a section whose title is a second-level heading (its anchor, "sticky", from its path), its own headings one level down (its h2 becomes an h3), its ids prefixed with the part's anchor ("keys" becomes "sticky-keys"), so that no two ids of the page meet;
  • a link from a page to another page of the manual goes to that part, in the page (#sticky, #sticky-keys); the linker given keeps the files of the repository and the pictures;
  • the former addresses, one per page, are listed with the part they became and the prefix their anchors took (redirects()), for a static redirection that carries the visitor's #fragment over.

$one = new OnePage($manual->version(), $links, '/docs/flowjs/1.x'); $one->parts(); // the home, then each page: title, anchor, HTML, the file to edit $one->toc(); // the headings down to the third level, nested: the sidebar

With $groups, the manual's top-level sections (a folder, a toctree caption, a group of API entries) group its parts: the table of contents lists each section with its pages under it, and the page puts the section's title before its first part (div.doc-group, its own anchor). A section of a single page that bears its name is that page alone, not a group of one.

public readonly Version $version
public readonly string $url

The page's own address: what search records and redirections lead to.

OnePage::__construct()

public function __construct(public readonly Version $version, readonly LinkerInterface $links, public readonly string $url, readonly int $tocLevel = 3, readonly bool $groups = false)

OnePage::anchor()

public function anchor(string $path, ?string $fragment = null): string

The anchor a page of the manual, or one of its headings, has in the one page; "" for the home's top.

OnePage::urlOf()

public function urlOf(string $path, ?string $fragment = null): string

The address of a page of the manual, or one of its headings, in the one page.

OnePage::parts()

public function parts(): array
Returns

the home first, then every page in reading order

OnePage::groups()

public function groups(): array

The groups of the parts (with $groups): each top-level section, its anchor, its title, its pages' paths - but a section of one page that bears its name.

OnePage::html()

public function html(): string

The parts' HTML, one after the other.

OnePage::headings()

public function headings(): array
Returns

every heading of the page, the parts' titles at the second level

OnePage::toc()

public function toc(): array

The table of contents: the second-level headings, each with its third-level ones (down to $tocLevel).

OnePage::text()

public function text(): string

The page's text, for a description.

OnePage::redirects()

public function redirects(): array

The former address of each page but the home: its path => the part's anchor, and the prefix a #fragment of that address takes in the one page.

OnePart class

final class OnePart OnePart.php:9

A page of a manual as a part of its one page (OnePage): where it starts, its HTML there, the file to edit.

public readonly string $path
public readonly string $title
public readonly string $anchor

Its anchor in the one page; "" for the home.

public readonly string $html
public readonly array $headings

its title first (but for the home), then its own, one level down

public readonly ?string $source

The file it is read from, relative to the repository: "edit this page".

public readonly string $text
public readonly Page $page

The page as its source rendered it, on its own.

OnePart::__construct()

public function __construct(public readonly string $path, public readonly string $title, public readonly string $anchor, public readonly string $html, public readonly array $headings, public readonly ?string $source, public readonly string $text, public readonly Page $page)
$headings

its title first (but for the home), then its own, one level down

OnePart::isHome()

public function isHome(): bool

Registry class

final class Registry Registry.php:18

The application's sources by name, each built once from its factory and options:

$docs = new Registry([new MarkdownSourceFactory(), new JsdocSourceFactory()], [ 'manual' => ['factory' => 'markdown', 'options' => ['root' => __DIR__.'/..', 'docs' => 'docs']], 'api' => ['factory' => 'jsdoc', 'options' => ['file' => __DIR__.'/var/jsdoc.json']], ]);

$docs->get('manual')->tree();

Registry::__construct()

public function __construct(iterable $factories, readonly array $config = [])

Registry::get()

public function get(string $name): SourceInterface

Registry::has()

public function has(string $name): bool

Registry::names()

public function names(): array

Registry::create()

public function create(string $factory, array $options = []): SourceInterface

A source built afresh by a factory, from options given here.

Registry::factories()

public function factories(): array
Returns

the factories installed: what factory: may name

SourceFactory class

abstract class SourceFactory implements SourceFactoryInterface SourceFactory.php:9

What a provider's factory has in common: its defaults set under the options given, the options it requires checked, then the source built.

SourceFactory::create()

final public function create(array $options = []): SourceInterface

SourceFactoryInterface interface

interface SourceFactoryInterface SourceFactoryInterface.php:6

Builds a source from its options (the folder it reads, the repository it comes from...).

SourceFactoryInterface::getName()

public function getName(): string

The name sources are configured with: "markdown", "sphinx", "doxygen", "jsdoc".

SourceFactoryInterface::create()

public function create(array $options = []): SourceInterface

SourceInterface interface

interface SourceInterface SourceInterface.php:18

One version of a manual, as one format wrote it: a folder of Markdown, the output of Sphinx's JSON builder, Doxygen's XML, the JSON JSDoc explains.

Every format answers the same three questions - the contents, a page, the API entries - so that a site renders any of them with the same templates.

A source reads files that already exist (a checkout, a build's output): it never runs the tool that wrote them, never reaches the network.

SourceInterface::home()

public function home(): ?Node

The manual's home page, when the source has one ("" is its path).

SourceInterface::tree()

public function tree(): array

The contents, in reading order: pages, and sections holding pages.

The home is not in it.

SourceInterface::page()

public function page(string $path, ?LinkerInterface $links = null): ?Page

A page rendered, by its path ("" for the home); null when there is none. Its links to other pages of the manual, to other files of the repository and its pictures go through $links: the site says where each one is published.

SourceInterface::symbols()

public function symbols(): array

The API entries the source documents, each on its page at its anchor; a manual of prose alone has none.

Omnidocs\Exception

ExceptionInterface interface

interface ExceptionInterface extends Throwable ExceptionInterface.php:6

Every exception omnidocs and its sources throw.

InvalidConfigException class

final class InvalidConfigException extends InvalidArgumentException implements ExceptionInterface InvalidConfigException.php:6

A source asked for with options it cannot work with: a folder that is not there, an option missing.

SourceException class

final class SourceException extends RuntimeException implements ExceptionInterface SourceException.php:6

What a source reads cannot be read: a file that is not the tool's output, a JSON or XML that does not parse.

Omnidocs\Html

Conventions class

final class Conventions Conventions.php:21

The HTML every format renders to, so that one stylesheet and one script read a manual whatever wrote it - the conventions of symfony.com/doc:

  • a callout: <blockquote class="doc-callout doc-callout-note" data-label="Note">, for note, tip, important, warning, caution, seealso; versionadded and deprecated carry their version (data-version) and say it in their label;
  • a version badge beside a heading: <span class="doc-version" data-version="1.4">;
  • a code block in its frame: <div class="doc-code" data-lang="js">, its caption (a file name) above it in <div class="doc-code-caption">;
  • code blocks side by side in tabs (YAML / PHP, npm / yarn): <div class="doc-tabs" data-doc-tabs>, a tab list of buttons and a panel each; without a script every panel shows, its title above it.

assets/omnidocs.js gives the tabs and a copy button to each frame.

const CALLOUTS = ['note', 'tip', 'important', 'warning', 'caution', 'seealso', 'versionadded', 'deprecated']
const LABELS = ['note' => 'Note', 'tip' => 'Tip', 'important' => 'Important', 'warning' => 'Warning', 'caution' => 'Caution', 'seealso' => 'See also', 'versionadded' => 'Ne…

The labels, in English; %version% is the callout's version.

Conventions::__construct()

public function __construct(readonly array $labels = [])

The words a reader reads, in their language: any of LABELS' keys.

Conventions::label()

public function label(string $type, ?string $version = null): string

Conventions::callout()

public function callout(string $type, string $inner, ?string $version = null): string

A callout around $inner (HTML).

Conventions::calloutAttributes()

public function calloutAttributes(string $type, ?string $version = null): array
Returns

the attributes of a callout's element, in their order

Conventions::versionBadge()

public function versionBadge(string $version, string $type = 'versionadded'): string

Conventions::code()

public function code(string $code, ?string $language = null, ?string $caption = null): string

A code block in its frame. $code is HTML already (escaped, or coloured by a highlighter).

Conventions::tabs()

public function tabs(array $panels, string $id): string

Panels side by side, one shown at a time: [title => HTML]. $id makes the ids of its tabs and panels unique in the page ("tabs-1").

Conventions::attributes()

public static function attributes(array $attributes): string

Conventions::escape()

public static function escape(string $text): string

Headings class

final class Headings Headings.php:12

The headings of an HTML fragment that carry an id - on the heading, or on the element that wraps it (Sphinx's <section id>) - for "on this page" and the search index; and ids for texts that have none.

Headings::of()

public static function of(string $html, int $from = 2, int $to = 4): array
$from

the first level kept

$to

the last level kept

public static function withoutPermalinks(string $html): string

A heading's text without the permalink a tool adds to it (¶, #).

Headings::id()

public static function id(string $text, array &$taken = []): string

An id for a text, unique among $taken (which it joins): "Scroll stops" → "scroll-stops", then "scroll-stops-1". Letters of any script are kept, as GitHub keeps them.

final class Links Links.php:13

The addresses of a page's links and pictures, rewritten: every <a href> and <img src> of an HTML fragment is handed to $rewrite (the address as written, decoded, and whether it is a picture), which answers the address to print or null to keep it. For the formats whose tool writes HTML (Sphinx's JSON builder); a Markdown source rewrites its links before rendering, on the document.

public static function rewrite(string $html, callable $rewrite): string

Prose class

final class Prose Prose.php:11

A comment's prose as HTML - a PHPDoc's, a JSDoc's description: paragraphs at blank lines, a block indented by four spaces or more as code, lines that start with "-" or "*" as a list, code as code; everything else escaped.

For the API references, whose tools give text, not Markdown.

Prose::toHtml()

public static function toHtml(string $text): string

Paragraphs at blank lines, a block indented by four spaces or more as code, lines starting with "-" or "*" as a list, code as code; everything else escaped.

Text class

final class Text Text.php:6

The plain text of an HTML fragment: what a reader reads, for a search index and a description.

Text::of()

public static function of(string $html): string

Omnidocs\Linking

RepositoryLinker class

final class RepositoryLinker implements LinkerInterface RepositoryLinker.php:19

The links of a manual read from a GitHub repository at a commit: a page goes where the site's closure says, another file of the repository to github.com at that commit (never a moving branch), a picture to raw.githubusercontent.com at that commit - or wherever the closures given say.

new RepositoryLinker( fn (string $path, ?string $fragment) => '/docs/'.$path.($fragment ? '#'.$fragment : ''), 'glitchr-studio/flowjs', 'c417356...', );

RepositoryLinker::__construct()

public function __construct(callable $page, readonly ?string $repository = null, readonly ?string $ref = null, ?callable $image = null, readonly string $forge = 'https://github.com', readonly string $raw = 'https://raw.githubusercontent.com')
$image

a picture's address; raw.githubusercontent.com by default

RepositoryLinker::page()

public function page(string $path, ?string $fragment = null): string

RepositoryLinker::file()

public function file(string $path, ?string $fragment = null): ?string

RepositoryLinker::image()

public function image(string $path): ?string

RepositoryLinker::edit()

public function edit(string $path, string $branch): ?string

Where a file is edited on the forge, at a branch: "edit this page".

Omnidocs\Model

Heading class

final class Heading Heading.php:9

A heading of a page: its level (1 to 6), the id it carries in the page's HTML - the anchor "on this page" and the search link to - and its text.

public readonly int $level
public readonly string $id
public readonly string $text

Heading::__construct()

public function __construct(public readonly int $level, public readonly string $id, public readonly string $text)

Heading::toArray()

public function toArray(): array

Manual class

final class Manual Manual.php:11

A manual: its key in the site's addresses, its title, the repository it is read from ("glitchr-studio/flowjs"), its versions by name and the one read by default - the current one; the others are older (or newer) series a site shows with a notice.

public readonly array $versions
public readonly string $default
public readonly string $key
public readonly string $title
public readonly ?string $repository

Manual::__construct()

public function __construct(public readonly string $key, public readonly string $title, iterable $versions, ?string $default = null, public readonly ?string $repository = null)

Manual::series()

public function series(): array

Manual::has()

public function has(string $series): bool

Manual::version()

public function version(?string $series = null): Version

Manual::isCurrent()

public function isCurrent(string $series): bool

Node class

final class Node Node.php:12

A place in a manual's contents: a page, or a section that holds pages (a folder of Markdown files, a Sphinx toctree caption, a group of API entries). Its path is its address inside the manual ("" for the home, "sticky", "guides/install"); a page knows the file it is read from, relative to the repository ("docs/sticky.md"), a section has none.

public readonly string $path
public readonly string $title
public readonly ?string $source
public readonly int $order
public readonly array $children

Node::__construct()

public function __construct(public readonly string $path, public readonly string $title, public readonly ?string $source = null, public readonly int $order = 100, public readonly array $children = [], readonly bool $section = false)

Node::section()

public static function section(string $path, string $title, array $children, int $order = 100): self

A section: a title over pages, not a page of its own.

Node::isSection()

public function isSection(): bool

Node::contains()

public function contains(string $path): bool

Whether this node, or a node under it, is the one at $path.

Node::flatten()

public static function flatten(array $tree): array

Every page of a tree, depth first, in reading order (sections left out).

Page class

final class Page Page.php:11

A page of a manual, ready for a template: its path in the manual, its title, its contents (HTML, headings, metadata, plain text), the file it is read from relative to the repository - what "edit this page" opens - and the API entries it documents.

public readonly string $path
public readonly string $title
public readonly Rendered $content
public readonly ?string $source
public readonly array $symbols

Page::__construct()

public function __construct(public readonly string $path, public readonly string $title, public readonly Rendered $content, public readonly ?string $source = null, public readonly array $symbols = [])

Page::html()

public function html(): string

Page::headings()

public function headings(): array

Page::meta()

public function meta(): array

Page::text()

public function text(): string

Page::excerpt()

public function excerpt(int $length = 220): string

Rendered class

final class Rendered Rendered.php:11

A text once rendered to HTML: the HTML (without its first-level title when the format gives one, which the page prints itself), that title, the headings for "on this page", the metadata the source carried (a Markdown front matter), and its plain text for a search index and a description.

public readonly string $html
public readonly ?string $title
public readonly array $headings
public readonly array $meta
public readonly string $text

Rendered::__construct()

public function __construct(public readonly string $html, public readonly ?string $title = null, public readonly array $headings = [], public readonly array $meta = [], public readonly string $text = '')

Rendered::excerpt()

public function excerpt(int $length = 220): string

The plain text, its spaces collapsed, cut at $length characters with an ellipsis.

Symbol class

final class Symbol Symbol.php:12

An entry of an API reference: a class, a function, a method, an option, a member... as the format names it. Its name is the one a reader searches and a cross-reference gives ("StickyStops.attach", "requests.get", "tinyxml2::XMLDocument::Parse"); it lives on a page of the manual, at an anchor of that page.

public readonly string $kind

What it is, in the format's words: "class", "function", "method", "member", "option", "py:function".

..

public readonly string $name
public readonly string $page

The page that documents it (its path in the manual).

public readonly ?string $anchor

Its id in that page's HTML; null: the page itself.

public readonly string $summary

Its first sentence or so, as plain text.

public readonly ?string $signature

How it is called or declared: "attach(scroller, options)".

public readonly ?string $parent

The entry it belongs to ("StickyStops" for "StickyStops.attach").

public readonly ?string $source

Where it is defined, relative to the repository: "src/js/stops.js#L1213".

Symbol::__construct()

public function __construct(public readonly string $kind, public readonly string $name, public readonly string $page, public readonly ?string $anchor = null, public readonly string $summary = '', public readonly ?string $signature = null, public readonly ?string $parent = null, public readonly ?string $source = null)

Symbol::toArray()

public function toArray(): array

Version class

final class Version Version.php:14

One version of a manual ("1.x", "4.x", "main"): its source, the branch it follows and the commit it is read at, whether it has reached its end of life. Reads its pages in reading order - the home first, then the tree depth first - for the previous and next links.

public readonly string $name
public readonly SourceInterface $source
public readonly ?string $branch
public readonly ?string $ref

The commit (or tag) it is read at.

public readonly bool $eol

Version::__construct()

public function __construct(public readonly string $name, public readonly SourceInterface $source, public readonly ?string $branch = null, public readonly ?string $ref = null, public readonly bool $eol = false)

Version::home()

public function home(): ?Node

Version::tree()

public function tree(): array

Version::pages()

public function pages(): array
Returns

every page, the home first, then the tree depth first

Version::node()

public function node(string $path): ?Node

The node of a page, by its path.

Version::page()

public function page(string $path, ?LinkerInterface $links = null): ?Page

A page rendered, kept for the next call with the same linker.

Version::previous()

public function previous(string $path): ?Node

Version::next()

public function next(string $path): ?Node

Version::symbols()

public function symbols(): array

Version::symbol()

public function symbol(string $name): ?Symbol

An API entry by its name ("StickyStops.attach").

Entry class

final class Entry Entry.php:22

One record of a search index: what a hit shows and where it leads. Written with short keys, the index being downloaded whole by the reader's browser:

k its kind: "page", "heading", "symbol" - or a site's own ("guide", "news"...) t its title (a page's title, a heading's text, a symbol's name) u its address (with the anchor of a heading or a symbol) d a short text: the page's first words, what follows a heading, a symbol's summary h the page's headings, " · " between them x words searched but not shown in the title: a symbol's kind, a manual's name and version p the page a heading or a symbol is on s a symbol's signature

An empty field is left out.

public readonly string $kind
public readonly string $title
public readonly string $url
public readonly string $text
public readonly array $headings
public readonly string $extra
public readonly string $page
public readonly string $signature

Entry::__construct()

public function __construct(public readonly string $kind, public readonly string $title, public readonly string $url, public readonly string $text = '', public readonly array $headings = [], public readonly string $extra = '', public readonly string $page = '', public readonly string $signature = '')

Entry::page()

public static function page(string $kind, string $title, string $url, string $text, array $headings = [], string $extra = '', int $maxLevel = 3): self

A page's entry, its headings down to $maxLevel listed.

Entry::toArray()

public function toArray(): array

SearchIndex class

final class SearchIndex SearchIndex.php:23

The search index of a static site: one JSON file, written with the site, that the reader's browser downloads once and searches (assets/omnidocs.js): the pages of each version given, a record per heading so that a hit lands on its section, a record per API entry, and whatever the site adds of its own (its guides, its news). Records keep the order they were added in, so that two builds write the same file.

$index = (new SearchIndex())->version($manual->version(), $links, extra: 'flowjs 1.x'); file_put_contents('search.json', $index->toJson('en'));

SearchIndex::add()

public function add(Entry ...$entries): self

SearchIndex::version()

public function version(Version $version, LinkerInterface $links, string $kind = 'page', string $extra = '', bool $headings = true, bool $symbols = true, int $headingLevel = 3, int $excerpt = 160, ?callable $title = null): self

Every page of a version, its headings (levels 2 to $headingLevel) and its API entries.

$title

a page's title in the index (the page's own by default)

SearchIndex::onePage()

public function onePage(OnePage $one, string $title, string $kind = 'page', string $extra = '', bool $headings = true, bool $symbols = true, int $headingLevel = 3, int $excerpt = 160): self

A manual read as one page (OnePage): a record for the page, one per part (the pages it is made of), one per heading and one per API entry, each leading to its anchor in the one page.

SearchIndex::entries()

public function entries(): array

SearchIndex::toArray()

public function toArray(?string $locale = null): array

SearchIndex::toJson()

public function toJson(?string $locale = null): string

Omnidocs\Support

Path class

final class Path Path.php:6

Paths inside a repository or a tool's output, written with "/".

Path::normalise()

public static function normalise(string $path): ?string

"docs/../src/./Foo.php" → "src/Foo.php"; null when it climbs out of its root.

Path::resolve()

public static function resolve(string $file, string $relative): ?string

$relative read from the folder of $file ("docs/a.md" + "../README.md" → "README.md"); null outside the root.

Path::isAbsolute()

public static function isAbsolute(string $url): bool

Whether a link is absolute (a scheme, "//host", "/path") or only an anchor: left as written.

Path::split()

public static function split(string $url): array

["guides/install.md", "intro"] from "guides/install.md#intro"; the query left out.

Path::order()

public static function order(string $name, int $default = 100): array

"10-getting-started" → [10, "getting-started"]; [100, $name] without a number.

Path::slug()

public static function slug(string $name): string

"Getting Started!" → "getting-started": lower case ASCII letters, digits and dashes.

Path::humanise()

public static function humanise(string $slug): string

"getting-started" → "Getting started".

Omnidocs\Testing

ArraySource class

final class ArraySource implements SourceInterface ArraySource.php:23

A manual written out in PHP, for an application's tests or a page that is no file: pages as [path => ['title' => ..., 'html' => ...]] (the order given is the reading order; "" is the home), symbols as Symbol objects.

A link written "page:<path>#<fragment>" in a page's HTML goes through the linker.

new ArraySource(['' => ['title' => 'Home', 'html' => '<p>Hi</p>'], 'install' => ['title' => 'Install', 'html' => '<h2 id="npm">npm</h2>']]);

ArraySource::__construct()

public function __construct(readonly array $pages, readonly array $symbols = [])

ArraySource::home()

public function home(): ?Node

ArraySource::tree()

public function tree(): array

ArraySource::page()

public function page(string $path, ?LinkerInterface $links = null): ?Page

ArraySource::symbols()

public function symbols(): array

ArraySourceFactory class

final class ArraySourceFactory extends SourceFactory ArraySourceFactory.php:10

The "array" factory: an ArraySource from its 'pages' option, for an application's tests.

Options

OptionDefault
pages[]required
symbols[]

ArraySourceFactory::getName()

public function getName(): string

RecordingLinker class

final class RecordingLinker implements LinkerInterface RecordingLinker.php:12

A linker for tests: pages at "/<path>", files at "repo:<path>", pictures at "img:<path>", and every request kept, so a test can check what a source linked to.

public array $pages = []
public array $files = []
public array $images = []

RecordingLinker::page()

public function page(string $path, ?string $fragment = null): string

RecordingLinker::file()

public function file(string $path, ?string $fragment = null): ?string

RecordingLinker::image()

public function image(string $path): ?string

SourceContractTests trait

trait SourceContractTests SourceContractTests.php:22

What every source does, as PHPUnit tests: a provider's test case (or an application's, for a source of its own) uses this trait and gives the source, read from a real tool's output.

final class SphinxSourceTest extends TestCase { use SourceContractTests;

    protected function source(): SourceInterface { return (new SphinxSourceFactory())->create(['dir' => __DIR__.'/Fixtures/requests']); }
}

Requires phpunit/phpunit (the application's, in require-dev).

SourceContractTests::testItsContentsAreNodesWithOnePathEach()

public function testItsContentsAreNodesWithOnePathEach(): void

SourceContractTests::testEveryPageRendersWithTheAnchorsItLists()

public function testEveryPageRendersWithTheAnchorsItLists(): void

SourceContractTests::testAPathThatIsNoPageGivesNone()

public function testAPathThatIsNoPageGivesNone(): void

SourceContractTests::testItsLinksToItsOwnPagesGoToPagesItHas()

public function testItsLinksToItsOwnPagesGoToPagesItHas(): void

SourceContractTests::testEveryApiEntryIsOnAPageAtItsAnchor()

public function testEveryApiEntryIsOnAPageAtItsAnchor(): void

SourceContractTests::testAPageReadTwiceIsTheSame()

public function testAPageReadTwiceIsTheSame(): void