protected function extractClosureCode(\ReflectionFunction $ref)
	{
		$file = $ref->getFileName();
		$lines = file($file, FILE_IGNORE_NEW_LINES);
		
		if(isset($this->namespaceContextCache[$file]))
		{
			$namespaceContext = $this->namespaceContextCache[$file];
		}
		else
		{
			$tokens = token_get_all(implode("\n", $lines));
			$namespaceContext = $this->namespaceContextCache[$file] = $this->generateNamespaceContext($tokens);
		}
		
		// Extract closure code from file source.
		$funcLines = array_slice($lines, $ref->getStartLine() - 1, $ref->getEndLine() - $ref->getStartLine() + 1);
		$snippet = implode("\n", array_map('trim', $funcLines));
		$snippet = preg_replace("'^.*\{'", '', $snippet);
		$snippet = preg_replace("'\}.*$'", '', $snippet);
		
		// Parse closure code snippet and expand unqualified names.
		$tokens = array_slice(token_get_all('<?php ' . $snippet), 1);
		$buffer = $this->expandNames($tokens, $namespaceContext);
		
		return str_replace("\n", "\n\t\t", "\n" . trim($buffer));
	}
protected function extractClosureCode(\ReflectionFunction $ref)
	{
		$file = $ref->getFileName();
		$lines = file($file, FILE_IGNORE_NEW_LINES);
		
		if(isset($this->namespaceContextCache[$file]))
		{
			$namespaceContext = $this->namespaceContextCache[$file];
		}
		else
		{
			$tokens = token_get_all(implode("\n", $lines));
			$namespaceContext = $this->namespaceContextCache[$file] = $this->generateNamespaceContext($tokens);
		}
		
		// Extract closure code from file source.
		$funcLines = array_slice($lines, $ref->getStartLine() - 1, $ref->getEndLine() - $ref->getStartLine() + 1);
		$snippet = implode("\n", array_map('trim', $funcLines));
		$snippet = preg_replace("'^.*\{'", '', $snippet);
		$snippet = preg_replace("'\}.*$'", '', $snippet);
		
		// Parse closure code snippet and expand unqualified names.
		$tokens = array_slice(token_get_all('<?php ' . $snippet), 1);
		$buffer = $this->expandNames($tokens, $namespaceContext);
		
		return str_replace("\n", "\n\t\t", "\n" . trim($buffer));
	}
protected function extractClosureCode ( \ ReflectionFunction $ ref ) { $ file = $ ref -> getFileName ( ) ; $ lines = file ( $ file , FILE_IGNORE_NEW_LINES ) ; if ( isset ( $ this -> namespaceContextCache [ $ file ] ) ) { $ namespaceContext = $ this -> namespaceContextCache [ $ file ] ; } else { $ tokens = token_get_all ( implode ( "\n" , $ lines ) ) ; $ namespaceContext = $ this -> namespaceContextCache [ $ file ] = $ this -> generateNamespaceContext ( $ tokens ) ; } // Extract closure code from file source. $ funcLines = array_slice ( $ lines , $ ref -> getStartLine ( ) - 1 , $ ref -> getEndLine ( ) - $ ref -> getStartLine ( ) + 1 ) ; $ snippet = implode ( "\n" , array_map ( 'trim' , $ funcLines ) ) ; $ snippet = preg_replace ( "'^.*\{'" , '' , $ snippet ) ; $ snippet = preg_replace ( "'\}.*$'" , '' , $ snippet ) ; // Parse closure code snippet and expand unqualified names. $ tokens = array_slice ( token_get_all ( '<?php ' . $ snippet ) , 1 ) ; $ buffer = $ this -> expandNames ( $ tokens , $ namespaceContext ) ; return str_replace ( "\n" , "\n\t\t" , "\n" . trim ( $ buffer ) ) ; }
Extract code of the given closure and process it for use in a replacement method.

@param \ReflectionFunction $ref
@return string
Extract code of the given closure and process it for use in a replacement method .