lithium\core\Adaptable::applyStrategies PHP Méthode

applyStrategies() public static méthode

Applies strategies configured in $name for $method on $data.
public static applyStrategies ( string $method, string $name, mixed $data, array $options = [] ) : mixed
$method string The strategy method to be applied.
$name string The named configuration
$data mixed The data to which the strategies will be applied.
$options array If `mode` is set to 'LIFO', the strategies are applied in reverse. order of their definition.
Résultat mixed Result of application of strategies to data. If no strategies have been configured, this method will simply return the original data.
    public static function applyStrategies($method, $name, $data, array $options = array())
    {
        $options += array('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;
    }