You appear to be a bot. Output may be restricted
Description
Extract the source of a function or method to a temporary fileIf the function is an abstract method then it will contain no code This is detectable by the end line being null. Rather than load the first line we just create an empty function. Notes: We may use namespace oikscloa in the future.
Usage
oiksc_function_loader::extract_to_tmp();
Parameters
Returns
voidSource
File name: oik-shortcodes/classes/class-oiksc-function-loader.phpLines:
1 to 43 of 43
function extract_to_tmp() { // We need to specify the file name and component type here $contents_arr = oiksc_load_file( null, $this->component_type, $this->plugin ); $this->tempnam = tempnam( sys_get_temp_dir(), "oikscloa"); $start = $this->function_obj->getStartLine(); $start--; $end = $this->function_obj->getEndLine(); $line = "<?php //" . $this->function_obj->methodname . "\n" ; $this->write( $line ); for ( $i = $start ; $i< $end; $i++ ) { //$line = strip_for_fun( $contents[$i] ); $line = $contents_arr[$i]; /** * Since we're loading this as a function we need to eliminate keywords that are applicable to methods but not functions. * Handling abstract is belt and braces - since there shouldn't be any code. * * @TODO - this is still messy. For JetPack it converted func and caused a fatal error. * This current version alters variable names as well * Would it not be better to tokenize the line, find the first literal and replace that? * Answer: Yes. As demonstrated by [bw_api] public static protected function func( $func [/bw_api] * being handled correctly. * */ if ( $i == $start ) { $line = $this->create_dummy_function_line( $line ); //$line = str_replace( "::", "__", $line ); $line = str_replace( "self", "Telf", $line ); } else { $line = str_replace( "parent::", "Quarent::", $line ); $line = str_replace( "self", "Telf", $line ); $line = str_replace( "new static", "new Ttatic", $line ); $line = str_replace( "static::", "Ttatic::", $line ); //$line = str_replace( "Telf::", 'self__', $line ); } $this->write( $line ); } if ( !$end ) { $this->write( "function " . $this->dummy_function_name . "(){}" ); } }View on GitHub