function EscaperExtension::setEscaper
Defines a new escaper to be used via the escape filter.
Parameters
string $strategy The strategy name that should be used as a strategy in the escape call:
callable(Environment, string, string): string $callable A valid PHP callable:
Deprecated
since Twig 3.10
File
-
vendor/
twig/ twig/ src/ Extension/ EscaperExtension.php, line 127
Class
Namespace
Twig\ExtensionCode
public function setEscaper($strategy, callable $callable) {
trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\\Runtime\\EscaperRuntime::setEscaper()" method instead (be warned that Environment is not passed anymore to the callable).', __METHOD__);
if (!isset($this->environment)) {
throw new \LogicException(\sprintf('You must call "setEnvironment()" before calling "%s()".', __METHOD__));
}
$this->escapers[$strategy] = $callable;
$callable = function ($string, $charset) use ($callable) {
return $callable($this->environment, $string, $charset);
};
$this->escaper
->setEscaper($strategy, $callable);
}