LightnCandy\Exporter::closure PHP Méthode

closure() protected static méthode

Get PHP code string from a closure of function as string
protected static closure ( array\arraystring | integer> $context, object $closure ) : string
$context array\arraystring | integer>
$closure object Closure object
Résultat string
    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)));
    }