SettingContext
extends SmartObject
in package
Holds the settings for the current request in two layers.
- client layer (setSettings()): what the presenter brought along; on the front end
only the public subset (
getPublicMerged), - server layer (setServerSettings()): the full map (neon
%params%+%publicParams%- all database rows), filled by SettingManager in its constructor. It never travels over the wire.
The context is a DI singleton shared by the front presenter and by Api managers called in the
same request through ApiBridge::internalCall() (their startup()
does not run). Server code reads SMTP credentials, appTempDir, emailTemplatePath or
feedsDir from it; narrowing the context to the public subset would break e-mail sending and
dropzone uploads. The boundary is the HTTP response (guarded getPublicMerged endpoint and
the Latte variable $settings), not server process memory.
See SettingInitTrait.
An optional SettingReadProbe records which keys are read (get()) and who reads the
whole map (getSettings()). It only observes: return values and layer order are unchanged,
and a disabled probe (the default) does nothing.
Table of Contents
Properties
- $probe : SettingReadProbe|null
- $serverSettings : array<int, array<string, mixed>>
- $settings : array<int, array<string, mixed>>
Methods
- __construct() : mixed
- get() : mixed
- Reads one value. The server layer wins because it is complete; the client layer is the fallback for contexts where the server layer was not filled.
- getPublicSettings() : array<int, array<string, mixed>>
- Returns the public subset, the only part allowed into a template or over the wire.
- getSettings() : array<int, array<string, mixed>>
- Returns the server view: the full map when it was filled, otherwise the client layer.
- path() : string
- Returns a path from the path settings (value shaped `['abs' => …, 'rel' => …]`); a missing key yields `''`.
- setServerSettings() : self
- Sets the full server map. Only the Api `SettingManager` calls it (server side, from config and database); nobody else should.
- setSettings() : self
- callerOf() : string
- Returns the class (or file) of the first caller outside `SettingContext` and the `SettingsTrait` wrappers; used by the probe only.
- hasKey() : bool
- Tells whether the key exists in any layer, so the probe can tell a null/empty value from a missing key. Called only while the probe is enabled.
Properties
$probe read-only
private
SettingReadProbe|null
$probe
= null
$serverSettings
private
array<int, array<string, mixed>>
$serverSettings
= []
server layer, never leaves the process
$settings
private
array<int, array<string, mixed>>
$settings
= []
client layer (the public subset on the front end)
Methods
__construct()
public
__construct([SettingReadProbe|null $probe = null ]) : mixed
Parameters
- $probe : SettingReadProbe|null = null
get()
Reads one value. The server layer wins because it is complete; the client layer is the fallback for contexts where the server layer was not filled.
public
get([int|null $module = null ][, string|null $key = null ]) : mixed
Parameters
- $module : int|null = null
- $key : string|null = null
getPublicSettings()
Returns the public subset, the only part allowed into a template or over the wire.
public
getPublicSettings() : array<int, array<string, mixed>>
It never touches the server layer.
Return values
array<int, array<string, mixed>>getSettings()
Returns the server view: the full map when it was filled, otherwise the client layer.
public
getSettings() : array<int, array<string, mixed>>
Managers read this through SettingsTrait::getSettings().
Return values
array<int, array<string, mixed>>path()
Returns a path from the path settings (value shaped `['abs' => …, 'rel' => …]`); a missing key yields `''`.
public
path(int $module, string $key[, string $variant = 'abs' ]) : string
Parameters
- $module : int
- $key : string
- $variant : string = 'abs'
Return values
stringsetServerSettings()
Sets the full server map. Only the Api `SettingManager` calls it (server side, from config and database); nobody else should.
public
setServerSettings(array<int, array<string, mixed>> $settings) : self
Parameters
- $settings : array<int, array<string, mixed>>
Return values
selfsetSettings()
public
setSettings(array<int, array<string, mixed>> $settings) : self
Parameters
- $settings : array<int, array<string, mixed>>
Return values
selfcallerOf()
Returns the class (or file) of the first caller outside `SettingContext` and the `SettingsTrait` wrappers; used by the probe only.
private
static callerOf(array<int, string> $wrappers) : string
Parameters
- $wrappers : array<int, string>
-
names of wrapper methods to skip
Return values
stringhasKey()
Tells whether the key exists in any layer, so the probe can tell a null/empty value from a missing key. Called only while the probe is enabled.
private
hasKey(int $module, string $key) : bool
Parameters
- $module : int
- $key : string