\Drupal\strata\Capture\Classifier ClassificationProfile

A portable set of classification decisions.

Deciding what a site's ephemeral keyspace is for is real work, done once per site by someone who understands the modules on it. Two things make that work worth exporting: a staging site and a production site running the same modules need the same answers, and a module maintainer can ship the answers for their own namespaces so nobody has to rediscover them.

Only decisions travel. Observed key and byte counts are properties of one site's traffic and mean nothing on another, so they are left behind rather than carried across and believed.

An imported profile does not overwrite a local human decision by default. Someone who looked at their own site and chose an answer outranks a file, and a profile that silently reversed that would be worse than no profile at all.

Summary

Methods
Properties
Constants
__construct
fromRegistry
applyTo
count
jsonSerialize
fromArray
fromFile
decisions
label
version
VERSION
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

VERSION

VERSION = 1

Format version written into every profile.

Properties

$decisions

$decisions : array

Type

array<string|int, mixed>

$label

$label : string

Type

string

$version

$version : int

Type

int

Methods

__construct()

__construct(array  $decisions = [], string  $label = '', int  $version = \self::VERSION) : mixed

Constructs a profile.

Parameters

array $decisions

Pattern keyed to its classification.

string $label

What this profile is, such as "earth-app production" or "commerce defaults".

int $version

Format version.

Returns

mixed —

fromRegistry()

fromRegistry(\Drupal\strata\Capture\Classifier\ClassificationRegistry  $registry, string  $label = '', bool  $humanOnly = true) : self

Builds a profile from what a registry holds.

Parameters

\Drupal\strata\Capture\Classifier\ClassificationRegistry $registry

The registry to read.

string $label

What to call the profile.

bool $humanOnly

TRUE to export only what a person decided, which is the useful default: a heuristic's answer is re-derived on the target site anyway, and exporting it would freeze this release's rules into a file that outlives them.

Returns

self —

The profile.

applyTo()

applyTo(\Drupal\strata\Capture\Classifier\ClassificationRegistry  $registry, bool  $overwriteLocal = false) : array{applied: int, kept: int}

Applies this profile to a registry.

Parameters

\Drupal\strata\Capture\Classifier\ClassificationRegistry $registry

The registry to write into.

bool $overwriteLocal

TRUE to replace a decision a person made on this site. FALSE, the default, keeps it.

Returns

array{applied: int, kept: int} —

How many decisions were written and how many local ones were left alone.

count()

count() : int

How many decisions the profile carries.

Returns

int —

The count.

jsonSerialize()

jsonSerialize() : array<string,mixed>

{@inheritdoc}

Returns

array

The profile as a plain array, which is the form written to a file.

fromArray()

fromArray(array  $data) : self

Reads a profile back.

A pattern whose classification this release does not know is skipped rather than guessed at, so a profile written by a later version loads what it can and says nothing about the rest.

Parameters

array $data

The array produced by ClassificationProfile::jsonSerialize().

Throws

\InvalidArgumentException

When the version is one this release cannot read.

Returns

self —

The profile.

fromFile()

fromFile(string  $path) : self

Reads a profile from a JSON file.

Parameters

string $path

The file path.

Throws

\InvalidArgumentException

When the file cannot be read or does not hold a profile.

Returns

self —

The profile.