Oihana PHP System

PrepareSkin

Provides utilities to manage and prepare "skins" for controllers.

A "skin" represents a visual or behavioral variant of a controller's output.

This trait handles:

  • Default skin
  • Method-specific skin definitions
  • Enumeration of all available skins
  • Validation and preparation of skins from requests or initialization arrays

Table of Contents

Properties

$skinDefault  : string|null
The default skin for the controller.
$skinMethods  : array<string, string>|null
Method-specific skin definitions.
$skins  : array<string|int, string>|null
List of all available skins for the controller.

Methods

initializeSkins()  : static
Initialize the skin-related properties from an associative array.
isValidSkin()  : bool
Validate a given skin.
prepareSkin()  : string|null
Prepare and determine the effective skin for a request or method.

Properties

$skinDefault

The default skin for the controller.

public string|null $skinDefault = null

This skin is used when no specific skin is requested or defined.

$skinMethods

Method-specific skin definitions.

public array<string, string>|null $skinMethods = null

Array format: [ 'methodName' => 'skinName', ... ] Overrides the default skin for specific controller methods.

$skins

List of all available skins for the controller.

public array<string|int, string>|null $skins = null

Used to validate requested skins.

Methods

initializeSkins()

Initialize the skin-related properties from an associative array.

protected initializeSkins([array<string, mixed> $init = [] ]) : static

Example:

$this->initializeSkins([
    PrepareSkin::SKIN_DEFAULT => 'default',
    PrepareSkin::SKIN_METHODS => ['edit' => 'editor'],
    PrepareSkin::SKINS        => ['default', 'editor', 'compact']
]);
Parameters
$init : array<string, mixed> = []

Associative array of skin definitions.

Return values
static

Returns the current instance for method chaining.

isValidSkin()

Validate a given skin.

protected isValidSkin(string|null $skin) : bool

Checks if the skin is a string and exists in the defined skins list. Converts the skin name to lowercase before validation.

Parameters
$skin : string|null

Skin name to validate.

Return values
bool

True if the skin exists in the available skins list; false otherwise.

prepareSkin()

Prepare and determine the effective skin for a request or method.

protected prepareSkin(ServerRequestInterface|null $request[, array<string, mixed> $init = [] ][, array<string, mixed>|null &$params = null ][, string|null $method = null ]) : string|null

This method considers:

  • Initialization array
  • Method-specific skin overrides
  • Query parameter in the request
  • Default skin fallback
  • Validation against available skins

Example:

$skin = $this->prepareSkin($request, ['skinDefault' => 'main'], $params, 'edit');
Parameters
$request : ServerRequestInterface|null

Optional HTTP request to read query parameters from.

$init : array<string, mixed> = []

Optional initialization array.

$params : array<string, mixed>|null = null

Reference to an array where the chosen skin will be stored.

$method : string|null = null

Optional controller method name to apply method-specific skin.

Return values
string|null

Returns the prepared skin name in lowercase, or null if invalid or "main".


        
On this page

Search results