public static function genFile($str, $name, $ext = null) { return new static(function () use($str, $name) { if (!$ext) { preg_match("/[^\\.]+\$/", $name, $matches); $ext = $matches[0]; } Response::mimeType("application/{$ext}"); Response::attachmentName("{$name}"); return $str; }); }