Index

ThemeController

MMO\client\controllers · 1 symbol · generated 30 Sep 2026

class

ThemeController

ThemeController.php:37

The http face of ThemeConfigurator: reads the theme's customizable surface, and writes a new one.

class MMO\client\controllers\ThemeController extends MMO\core\classes\aController
Namespace
MMO\client\controllers
Extends
aController
Four routes, three of which are what `<mmo-theme-config>` calls: - `GET theme/config.json` the model (every value the token sources declare) and the current overrides; - `POST theme/config/preview.json` compiles a candidate theme and answers the css, writing nothing; - `PUT theme/config.json` stores it, regenerates the `.scs` and recompiles the application's stylesheet; - `DELETE theme/config.json` drops every override. ### Who may call it Saving writes two files of the project and recompiles its css. That is a build step, not a user preference, so the controller answers 403 outside of development unless an application explicitly says otherwise ([`$devOnly`](https://mmoframework.fr/documentation/mmo.client/php/controllers/ThemeController.md#themecontroller-devonly)) -- and an application that opens it in production is expected to put it behind its own authentication, exactly as it would an admin screen. What a caller sends is never trusted: a value is re-parsed in the context of the entry it replaces and re-printed from the ast before it reaches a file ([`ThemeConfigurator::validate`](https://mmoframework.fr/documentation/mmo.client/php/ThemeConfigurator.md#themeconfigurator-validate)), so what is written is this package's own output rather than the request's text. ```json // PUT theme/config.json {"overrides": {"tokens:let::brand.s500": "#8B5CF6", "tokens:theme::radius.md": "20px"}} ```

Index

devOnly
configurator($route)
DefaultConfig() static
overrides($route)
payload($configurator)The payload every route answers: what can be changed, what is changed, and where it was written.
routeConfig($route)The whole customizable surface of the theme, and the values that currently override it.
routePreview($route)Compile a candidate theme and answer its css, without writing anything.
routeReset($route)Drop every override: the theme goes back to what its sources declare.
routeSave($route)Store a new configuration, regenerate the theme and recompile the application's stylesheet.

Properties1

devOnly

protected bool $devOnly = true
Type
bool

Methods8

configurator($route)

ThemeController.php:52
protected function configurator(MMO\core\server\Route $route): MMO\client\ThemeConfigurator
$routeRoute
returnsThemeConfiguratorthe configurator these routes drive
throwswhen the theme may not be configured over http here

overrides($route)

ThemeController.php:70
protected function overrides(MMO\core\server\Route $route): array
$routeRoute
returnsarraythe overrides of the request body
throwswhen the body is not an object of scalars

payload($configurator)

ThemeController.php:89

The payload every route answers: what can be changed, what is changed, and where it was written.

protected function payload(MMO\client\ThemeConfigurator $configurator): arrayThe css url carries the stylesheet's own timestamp, so a page that has just saved can reload the document's stylesheet instead of reloading the document.
$configuratorThemeConfigurator
returnsarray

routeConfig($route)

ThemeController.php:117

The whole customizable surface of the theme, and the values that currently override it.

#[MMO\core\attributes\APIRoute('GET|theme/config.json', […2 items], mediaTypes: ['json'])] function routeConfig(MMO\core\server\Route $route): array
$routeRoute
returnsarray

routePreview($route)

ThemeController.php:135

Compile a candidate theme and answer its css, without writing anything.

#[MMO\core\attributes\APIRoute('POST|theme/config/preview.json', […2 items], mediaTypes: ['json'])] function routePreview(MMO\core\server\Route $route): arrayThe generated token layer *is* the theme, so this css is the `:root` rule and the dark theme's rules and nothing else -- small enough for a page to append it to its head on every keystroke, which is how the configurator previews a change that no custom property can express on its own (a brand ramp moves every token derived from it, and only a compilation knows which).
$routeRoute
returnsarray

routeReset($route)

ThemeController.php:165

Drop every override: the theme goes back to what its sources declare.

#[MMO\core\attributes\APIRoute('DELETE|theme/config.json', ['title' => 'Reset the theme', 'description' => 'drop every override'], mediaTypes: ['json'])] function routeReset(MMO\core\server\Route $route): array
$routeRoute
returnsarraypayload

routeSave($route)

ThemeController.php:149

Store a new configuration, regenerate the theme and recompile the application's stylesheet.

#[MMO\core\attributes\APIRoute('PUT|theme/config.json', […2 items], mediaTypes: ['json'])] function routeSave(MMO\core\server\Route $route): array
$routeRoute
returnsarraypayload, with the css url carrying the new stylesheet's timestamp
Inherited members (55)
ConstantsDeclared byDescription
ALERTiLogLevelAlert: Action must be taken immediately.
ALLiLogLevelMask for all
ALL_PLUSiLogLeveldebug everything
BACKTRACEiLogLevel
CRITICALiLogLevelCritical: Critical conditions.
DEBUGiLogLevelDebug: Detailed debug information.
DEEPiLogLeveldebug everything with arguments
EMERGENCYiLogLevelEmergency: System is unusable.
ERRORiLogLevelError: Runtime errors that do not require immediate action but should typically be logged and monitored.
ERROR_PLUSiLogLevelMask for all error
FATALiLogLevelMask for all fatal error
INFOiLogLevelInfo: Interesting events.
INFO_PLUSiLogLevelMask for all errors/warning/notices/info
MEMORYiLogLevelinclude backtrace object
NOTICEiLogLevelNotice: Normal but significant events.
NOTICE_PLUSiLogLevelMask for all errors/warning/notices/info
TRACEiLogLevelinclude backtrace as origins
WARNINGiLogLevelWarning: Exceptional occurrences that are not errors.
WARNING_PLUSiLogLevelMask for all errors and warnings
PropertiesDeclared byDescription
verbosityaModule
MethodsDeclared byDescription
alert($message, $context)aModuleAction must be taken immediately.
backtraces($message, $context)aModuleForce-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it).
Configure($config)aModuleMerge $config into this module's configuration in the shared Configuration.
critical($message, $context)aModuleCritical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)aModuleDetailed debug information.
debugName()aModuleHuman-readable identifier used as the default {origin} in this instance's log messages.
emergency($message, $context)aModuleSystem is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
error($message, $context)aModuleRuntime errors that do not require immediate action but should typically be logged and monitored.
ExtractRoutes($config)aControllerExtract all the APIRoute from this class, regardless of the fact they are registered in the application
getVerbosity()aModule
HasRoutes()aControllerTells if any APIRoute are registered in the application
info($message, $context)aModuleInteresting events. No-op if INFO is currently filtered out by the verbosity mask.
Instantiate($config)aModule(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared()aModule
Link($method, $data)aControllerBuild a Link (URL + label/icon/description/title, taken from the route's APIRoute metadata) for a registered route.
log($level, $message, $context)aModuleLogs with an arbitrary level.
notice($message, $context)aModuleNormal but significant events.
offsetExists($key)aModule\ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access.
offsetGet($key)aModule\ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g.
offsetSet($key, $value)aModule\ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g.
offsetUnset($key)aModule\ArrayAccess::offsetUnset -- equivalent to $module[$key] = null.
onRoute($route)aControllerThis function is called before any api route declared.
Route($method)aControllerGet a registered APIRoute WARNING: if this class was not registered in the application, it will return null.
Routes()aControllerGet a list of registered APIRoutes (from this class) in the application WARNING: if this class was not registered in the application, it will return an empty array.
serialize($path, $serializer)aModule\MMO\core\interfaces\iSerializable::serialize -- exports every property (via
setVerbosity($verb)aModuleSet the current verbosity mask, replacing whatever it was before.
Shared()aModuleGet the shared instance, creating (and configuring) it on first call.
testVerbosity($level)aModuleTest whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
traitUnshare($serialize)aModuleRemove the shared instance, so the next Shared() call creates a fresh one.
unserialize($data, $path, $instances)aModule\MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via
Unshare($serialize)aModuleLike tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it.
Url($method, $data)aControllerBuild the URL for a registered route, filling in any {placeholder} from $data.
warning($message, $context)aModuleExceptional occurrences that are not errors.
__construct($config)aModuleprotected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.
__wakeup()aControllerCalled automatically right after the controller's shared instance is built (aModule::unserialize): registers onRoute as a Route listener with a low priority (-10), so it…