src/Helper.php
/**
     * Dumps closure object to string.
     * Based on http://www.metashock.de/2013/05/dump-source-code-of-closure-in-php/
     * @param Closure $c 
     * @return string
     */
Dumps closure object to string.
Dumps closure object to string .
public static function dumpClosure(Closure $c) {
        $res = 'function (';
        $fun = new ReflectionFunction($c);
        $args = [];
        foreach($fun->getParameters() as $arg) {
            $str = '';
            if($arg->isArray()) {
                $str .= 'array ';
            } else if($arg->getClass()) {
                $str .= $arg->getClass()->name . ' ';
            }
            if($arg->isPassedByReference()){
                $str .= '&';
            }
            $str .= '$' . $arg->name;
            if ($arg->isOptional()) {
                $str .= ' = ' . var_export($arg->getDefaultValue(), true);
            }
            $args[] = $str;
        }
        $res .= implode(', ', $args);
        $res .= ') {' . PHP_EOL;
        $lines = file($fun->getFileName());
        for ($i = $fun->getStartLine(); $i < $fun->getEndLine(); $i++) {
            $res .= $lines[$i];
        }
        return rtrim($res, "\n ,");
    }
public static function dumpClosure ( Closure $ c ) { $ res = 'function (' ; $ fun = new ReflectionFunction ( $ c ) ; $ args = [ ] ; foreach ( $ fun -> getParameters ( ) as $ arg ) { $ str = '' ; if ( $ arg -> isArray ( ) ) { $ str .= 'array ' ; } else if ( $ arg -> getClass ( ) ) { $ str .= $ arg -> getClass ( ) -> name . ' ' ; } if ( $ arg -> isPassedByReference ( ) ) { $ str .= '&' ; } $ str .= '$' . $ arg -> name ; if ( $ arg -> isOptional ( ) ) { $ str .= ' = ' . var_export ( $ arg -> getDefaultValue ( ) , true ) ; } $ args [ ] = $ str ; } $ res .= implode ( ', ' , $ args ) ; $ res .= ') {' . PHP_EOL ; $ lines = file ( $ fun -> getFileName ( ) ) ; for ( $ i = $ fun -> getStartLine ( ) ; $ i < $ fun -> getEndLine ( ) ; $ i ++ ) { $ res .= $ lines [ $ i ] ; } return rtrim ( $ res , " \n  , " ) ; }
Dumps closure object to string.
Dumps closure object to string .