protected static function closure($context, $closure)
{
if (is_string($closure) && preg_match('/(.+)::(.+)/', $closure, $matched)) {
$ref = new \ReflectionMethod($matched[1], $matched[2]);
} else {
$ref = new \ReflectionFunction($closure);
}
$fname = $ref->getFileName();
$lines = file_get_contents($fname);
$file = new \SplFileObject($fname);
$file->seek($ref->getStartLine() - 2);
$spos = $file->ftell();
$file->seek($ref->getEndLine() - 1);
$epos = $file->ftell();
return preg_replace('/^.*?function(\\s+[^\\s\\(]+?)?\\s*\\((.+)\\}.*?\\s*$/s', 'function($2}', static::replaceSafeString($context, substr($lines, $spos, $epos - $spos)));
}