class UserDocsManifest implements Flushable (View source)

A utility class which builds a manifest of where to find all user documentation and caches it.

It finds the following information:

  • The canonical location of the file for each documentation slug. If more than one module has a doc with the same slug, the module with the highest priority is used.
  • Metadata for each doc, such as its title, sort order and frontmatter.
  • Which pages have which localisations.
  • The tree structure used to display links to the documentation.

Traits

Provides extensions to this object to integrate it with standard config API methods.

A class that can be instantiated or replaced via DI

Constants

protected CACHE_KEY

private MODULE_NAME_PATTERN

Matches a composer package name, e.g. "silverstripe/admin" Refer to https://getcomposer.org/doc/04-schema.md#name

private UNINHERITED_FRONT_MATTER_KEYS

Frontmatter keys that only apply to the file they're in, so they're never filled in from another file.

The title has its own fallback, and "extends" decides if a file is a doc or an extension.

Config options

documentation_roots array

Paths to directories that contain user documentation.

Properties

protected array $cachedProperties

Array of properties to cache

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public static 
flush()

This function is triggered early in the request if the kernel gets flushed.

public static 
array
getLocalePriority()

Get the request locale and fallbacks in order of precedence.

public
void
init(bool $includeTests = false)

Initialise the documentation manifest

public
void
regenerate(array $validPaths, bool $includeTests)

Completely regenerates the manifest file.

public
void
handleFile(array $data, string $fileName, string $filePath, string $basePath)

Visit a file to inspect for user help documentation.

public
string|null
getRootPathInModule(string $module)

Get the path to the documentation root in the given module.

public
array
getDocData(string|null $locale = null)

Get the metadata about documentation, optionally for a single locale.

public
array
getLocalisedDocData()

Get all data about documentation for the current locale.

public
array
getBreadcrumbs(string $slug, string $baseUrl)

Get the title and link of each ancestor of the doc with the given slug, starting at the root.

public
array
getLocalisedTreeData()

Get the hierarchical-structured tree data for the current locale.

public
array
getLocalisedClassMap()

Get the slugs of the docs that name each class in their frontmatter, for the current locale.

public
array
getDocClasses(array $docDatum)

Get the classes that a doc names in the "classes" key of its frontmatter, including classes that its extensions add.

public
string
getSlugForPath(string $path, bool $isRootDir = false)

Get the URL slug for the given documentation file/folder path.

public static 
string
encodeSlug(string $slug)

Encode each segment of the slug so that it can be used in a URL.

public static 
string
getSlugFromUrlPath(string $path)

Get the slug from the path of a doc URL, relative to the URL of the docs action.

protected
bool
setManifestData(array $data)

Set the manifest properties from cached or newly built data, and clear the data worked out from them.

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

static flush()

This function is triggered early in the request if the kernel gets flushed.

Each class that implements Flushable implements this function which looks after it's own specific flushing functionality.

static array getLocalePriority()

Get the request locale and fallbacks in order of precedence.

Return Value

array

void init(bool $includeTests = false)

Initialise the documentation manifest

Parameters

bool $includeTests

Return Value

void

void regenerate(array $validPaths, bool $includeTests)

Completely regenerates the manifest file.

Parameters

array $validPaths

Absolute paths to directories that contain user documentation

bool $includeTests

Return Value

void

void handleFile(array $data, string $fileName, string $filePath, string $basePath)

Visit a file to inspect for user help documentation.

Updates the $data array in place, so that further transformations (e.g. sorting) can be done before storing the data as manifest state.

Parameters

array $data

The array the file's metadata will be added to

string $fileName
string $filePath
string $basePath

The path to the registered documentation folder this file comes from

Return Value

void

string|null getRootPathInModule(string $module)

Get the path to the documentation root in the given module.

Parameters

string $module

Return Value

string|null

The path relative to the module root, or null if the module has no docs

array getDocData(string|null $locale = null)

Get the metadata about documentation, optionally for a single locale.

For each locale, the doc from the module with the highest priority that has the doc in that locale is used. Note that this does not include the locale fallbacks - use getLocalisedDocData() if you need the data to be flowing through the locale cascade. Extensions are added to each doc in the same way as getLocalisedDocData().

Parameters

string|null $locale

Return Value

array

Doc data keyed by slug if a locale is given, otherwise keyed by locale then slug

array getLocalisedDocData()

Get all data about documentation for the current locale.

For each doc, the module with the highest priority that has the doc in any of the current locales is used. Within that module, the current locale falls back to the shortened locale and then to the default locale. For example pt_BR will fallback to pt which will then fallback to en_US which falls back to en.

Extensions are kept separately for each doc, keyed by their extension key. Each extension key uses the same rules as docs, and falls back separately from the doc it extends.

Frontmatter keys that a doc doesn't have are filled in from the docs it overrides or translates, except for keys in UNINHERITED_FRONT_MATTER_KEYS. See inheritFrontMatter().

Return Value

array

array getBreadcrumbs(string $slug, string $baseUrl)

Get the title and link of each ancestor of the doc with the given slug, starting at the root.

The link is null for ancestors without content.

Parameters

string $slug
string $baseUrl

The URL that doc slugs are relative to

Return Value

array

Exceptions

InvalidArgumentException

array getLocalisedTreeData()

Get the hierarchical-structured tree data for the current locale.

Uses the same docs as getLocalisedDocData().

Return Value

array

array getLocalisedClassMap()

Get the slugs of the docs that name each class in their frontmatter, for the current locale.

Only docs with content are included.

Docs that have the class in "primary_for" come first, and then docs are in the order of the navigation tree. The first doc for a class is its main doc.

Return Value

array

Lists of slugs keyed by lowercase class name

array getDocClasses(array $docDatum)

Get the classes that a doc names in the "classes" key of its frontmatter, including classes that its extensions add.

Names that aren't the name of a class are left out, because docs can be for classes from modules that aren't installed.

Parameters

array $docDatum

Doc data from getLocalisedDocData() or getDocData()

Return Value

array

Class names keyed by lowercase class name

string getSlugForPath(string $path, bool $isRootDir = false)

Get the URL slug for the given documentation file/folder path.

The slug for an index file with no directory, such as "index.md", is ".".

Parameters

string $path
bool $isRootDir

Return Value

string

static string encodeSlug(string $slug)

Encode each segment of the slug so that it can be used in a URL.

Dots are encoded so that the URL isn't read as having a file extension, except in "." and ".." segments.

Parameters

string $slug

Return Value

string

static string getSlugFromUrlPath(string $path)

Get the slug from the path of a doc URL, relative to the URL of the docs action.

This removes any query string or anchor, and decodes the path.

Parameters

string $path

Return Value

string

protected bool setManifestData(array $data)

Set the manifest properties from cached or newly built data, and clear the data worked out from them.

Properties that are missing or invalid in the data are reset, so empty data resets the manifest.

Parameters

array $data

Return Value

bool

True if the data was valid and the properties were set