API / Minn\Rest / FontSettings

FontSettings final class

Minn\Rest\FontSettings · public/minn/src/Minn/Rest/FontSettings.php · 221 lines

The settings a font family or face is written with, judged and cleaned as the reference does (probe font-writes). A POST sends them as a JSON string: one that is not a string is refused by type, one that is not JSON (or is null) as not "a valid JSON string", and what it holds is held to the settings' schema (required keys first, then each key in the order sent: its type, or that it is not a property), then each key that must not be empty. A family's update names no slug and needs none of the rest; a face's sources must each be an address the site may fetch or a file the request uploads, and every file it uploads must be one of them. Only the first refusal is answered, under the settings' name, its own data moved under additional_data beside a 400 status. A PUT or a PATCH reads the settings as the object itself, which the reference cannot save (it fails with a fatal error); here such an update saves as a POST would.

Constants and properties

privateFAMILY = 'font_family_settings'
privateFACE = 'font_face_settings'
privateFAMILY_SCHEMA = array ( 'type' => 'object', 'properties' => array ( 'name' => array ( 'type' => 'string', ), 'slug' => array ( 'type' => 'string', ), 'fontFamily' => array ( 'type' => 'string', ), 'preview' => array ( 'type' => 'string', ), ), 'additionalProperties' => false, )
privateFACE_SCHEMA = array ( 'type' => 'object', 'properties' => array ( 'fontFamily' => array ( 'type' => 'string', ), 'fontStyle' => array ( 'type' => 'string', ), 'fontWeight' => array ( 'type' => array ( 0 => 'string', 1 => 'integer', ), ), 'fontDisplay' => array ( 'type' => 'string', 'enum' => array ( 0 => 'auto', 1 => 'block', 2 => 'fallback', 3 => 'swap', 4 => 'optional', ), ), 'src' => array ( 'anyOf' => array ( 0 => array ( 'type' => 'string', ), 1 => array ( 'type' => 'array', 'items' => array ( 'type' => 'string', ), ), ), ), 'fontStretch' => array ( 'type' => 'string', ), 'ascentOverride' => array ( 'type' => 'string', ), 'descentOverride' => array ( 'type' => 'string', ), 'fontVariant' => array ( 'type' => 'string', ), 'fontFeatureSettings' => array ( 'type' => 'string', ), 'fontVariationSettings' => array ( 'type' => 'string', ), 'lineGapOverride' => array ( 'type' => 'string', ), 'sizeAdjust' => array ( 'type' => 'string', ), 'unicodeRange' => array ( 'type' => 'string', ), 'preview' => array ( 'type' => 'string', ), ), 'required' => array ( 0 => 'fontFamily', 1 => 'src', ), 'additionalProperties' => false, )

Public

staticnewFamily(Minn\Http\Request $request): array#

A new family's settings, judged. @return array<string, mixed>

@return array<string, mixed>
staticfamilyChanges(Minn\Http\Request $request): array#

An update's settings, judged: what it names replaces what is stored, and the slug cannot change. @return array<string, mixed>

@return array<string, mixed>
staticnewFace(Minn\Http\Request $request): array#

A new face's settings, judged, its sources against the files the request uploads. @return array<string, mixed>

@return array<string, mixed>
staticversion(Minn\Http\Request $request): void#

The theme.json version a write names, when it names one: an integer from 2 to 3, refused as any argument is.

staticsources(mixed $src): array#

The sources a face names, each as text, in order. @return list<string>

@return list<string>
staticcleanFamily(array $settings): array#

A family's settings as stored: the name as plain text, the slug as a slug, the font-family list quoted name by name, the preview a clean address; in the order sent.

$settingsarray<string, mixed>
@return array<string, mixed>
staticcleanFace(array $settings): array#

A face's settings as stored, in the order sent: the font-family list quoted name by name, the preview a clean address, the sources left for the upload to resolve, every other value as plain text (a weight given as a number becomes its text).

$settingsarray<string, mixed>
@return array<string, mixed>

Internals 6

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatedecoded(Minn\Http\Request $request, string $param, array $schema): array#

The settings a write sends, decoded and held to the schema.

$schemaarray<string, mixed>
@return array<string, mixed>
privateobject(mixed $value, string $param, array $schema): array#

Settings a PUT or a PATCH sends, read as the object itself and held to the schema as any argument is (none of its keys required).

$schemaarray<string, mixed>
@return array<string, mixed>
privatefilled(array $settings, string $param, array $keys, string $message): void#

Each key the settings name that must not be empty, in order.

$settingsarray<string, mixed>
$keyslist<string>
privaterefused(string $param, Minn\Runtime\Refusal $refusal): Minn\RestError#

The settings' refusal as the reference answers it: a 400 status, any data of the refusal's own under additional_data.

privatetopLevel(string $param, Minn\Runtime\Refusal $refusal): Minn\RestError#

A refusal of the argument itself, as any argument is refused.

privatevalues(Minn\Http\Request $request): array#

What a write names: its body's fields over the query's. @return array<string, mixed>

@return array<string, mixed>