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:
Christophe Coevoet
2024-09-13 12:58:50 +02:00
committed by GitHub
parent c8bb3b1b69
commit 8330936415
+7
View File
@@ -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, '\\');