gossi\codegen\utils\ReflectionUtils::getFunctionBody PHP Method

getFunctionBody() public static method

public static getFunctionBody ( ReflectionFunctionAbstract $function )
$function ReflectionFunctionAbstract
    public static function getFunctionBody(\ReflectionFunctionAbstract $function)
    {
        $source = file($function->getFileName());
        $start = $function->getStartLine() - 1;
        $end = $function->getEndLine();
        $body = implode('', array_slice($source, $start, $end - $start));
        $open = strpos($body, '{');
        $close = strrpos($body, '}');
        return trim(substr($body, $open + 1, (strlen($body) - $close) * -1));
    }

Usage Example

 public function testFunctionBody()
 {
     $actual = ReflectionUtils::getFunctionBody(new \ReflectionFunction('wurst'));
     $expected = 'return \'wurst\';';
     $this->assertEquals($expected, $actual);
     $actual = ReflectionUtils::getFunctionBody(new \ReflectionFunction('inline'));
     $expected = 'return \'x\';';
     $this->assertEquals($expected, $actual);
 }
All Usage Examples Of gossi\codegen\utils\ReflectionUtils::getFunctionBody