slugger = $slugger; } /** * {@inheritDoc} * * @throws RuntimeException */ public function __invoke(string $filename): string { // Dot files are renamed regardless of security settings. $filename = trim($filename, '.'); // Remove any null bytes. See // http://php.net/manual/security.filesystem.nullbytes.php $filename = str_replace(chr(0), '', $filename); $ext = pathinfo($filename, PATHINFO_EXTENSION); if (empty($ext)) { throw new RuntimeException('Cannot sanitize dot files'); } $original = pathinfo($filename, PATHINFO_FILENAME); return $this->slugger->slug($original)->lower() . ".$ext"; } }