lithium\core\Adaptable::applyStrategies()

public static method

Applies strategies configured in $name for $method on $data.

Parameters

  • string $method

    The strategy method to be applied.

  • string $name

    The named configuration

  • mixed $data

    The data to which the strategies will be applied.

  • array $options

    If mode is set to 'LIFO', the strategies are applied in reverse. order of their definition.

Returns

mixed

Result 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;
	}