lithium\core\Adaptable::applyStrategies()
Applies strategies configured in $name for $method on $data.
Parameters
-
string
$methodThe strategy method to be applied.
-
string
$nameThe named configuration
-
mixed
$dataThe data to which the strategies will be applied.
-
array
$optionsIf
modeis set to 'LIFO', the strategies are applied in reverse. order of their definition.
Returns
mixedResult of application of strategies to data. If no strategies have been configured, this method will simply return the original data.
Source
public static function applyStrategies($method, $name, $data, array $options = []) {
$options += ['mode' => null];
if (!$strategies = static::strategies($name)) {
return $data;
}
if (!count($strategies)) {
return $data;
}
if (isset($options['mode']) && ($options['mode'] === 'LIFO')) {
$strategies->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);
unset($options['mode']);
}
foreach ($strategies as $strategy) {
if (method_exists($strategy, $method)) {
$data = $strategy->{$method}($data, $options);
}
}
return $data;
}