mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
Add more precise types for the registration of safe classes
Safe classes only impact the auto-escaping of the string casting of instance of those classes. By defining that this method only expects names of stringable classes, it allows static analysis tools to report non-working configurations (for instance for people thinking this would impact the auto-escaping for values returned by getters of a safe class).
This commit is contained in:
committed by
GitHub
parent
c8bb3b1b69
commit
8330936415
@@ -52,6 +52,9 @@ final class EscaperRuntime implements RuntimeExtensionInterface
|
||||
return $this->escapers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<class-string<\Stringable>, string[]> $safeClasses
|
||||
*/
|
||||
public function setSafeClasses(array $safeClasses = [])
|
||||
{
|
||||
$this->safeClasses = [];
|
||||
@@ -61,6 +64,10 @@ final class EscaperRuntime implements RuntimeExtensionInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<\Stringable> $class
|
||||
* @param string[] $strategies
|
||||
*/
|
||||
public function addSafeClass(string $class, array $strategies)
|
||||
{
|
||||
$class = ltrim($class, '\\');
|
||||
|
||||
Reference in New Issue
Block a user