Description
List the classes/functions implemented within the source fileAt the moment we don't need to know much about the classes since we're not particularly interested in the properties more the methods. So now we need to find the methods for each class? BUT HOW? We don't want to attempt to use Reflection functions since we may not be able to load the class So do we extract the class and then search for functions using this logic? OR do we just extend this loop to look for methods within classes.
Usage
$array = _oiksc_list_classes2( $tokens, $get_token );Parameters
- $tokens
- ( array ) required – array of PHP tokens
- $get_token
- ( string ) optional default: T_CLASS – the token type we're looking for T_CLASS/T_FUNCTION
Returns
array of oiksc_token_object instancesTO DO
Now that we're also storing the token for the docblock do we need to stored the docblock contents as well?Source
File name: oik-shortcodes/classes/oik-listapis2.phpLines:
1 to 100 of 115
function _oiksc_list_classes2( $tokens, $get_token=T_CLASS ) { $functions = array(); // set an arbitrary end point past which we won't validly find a class due to there not being enough tokens // allowing us to increment $t without any worries // Actually we cheat and add 3 dummy white space tokens $count = count( $tokens ); $tokens[$count] = T_WHITESPACE; $tokens[$count+1] = T_WHITESPACE; $tokens[$count+2] = T_WHITESPACE; $t = 0; $thisclass = null; $thismethod = null; $methods = array(); $docblock = null; $docblock_token = null; $open_curlies = 0; while ( $t < $count ) { $new_docblock = _oiksc_get_token( $tokens, $t, T_DOC_COMMENT ); if ( $new_docblock ) { $docblock = $new_docblock; $docblock_token = $tokens[$t]; } $class = _oiksc_get_token_object( $tokens, $t, $get_token ); if ( $class ) { $t += 2; $class->classname = _oiksc_get_token( $tokens, $t, T_STRING ); if ( $class->classname ) { if ( $get_token === T_CLASS ) { $t2 = $t + 2; $class->extends = _oiksc_get_token( $tokens, $t2, T_EXTENDS ); if ( $class->extends ) { $class->extended = _oiksc_get_token( $tokens, $t2+2, T_STRING ); } $class->implements = _oiksc_get_token( $tokens, $t2, T_IMPLEMENTS ); if ( $class->implements ) { // $functions[] = "$function $extends$implements $extended_or_implemented"; $class->implemented = _oiksc_get_token( $tokens, $t2+2, T_STRING ); // @TODO - continue for other implemented classes } } $class->open_curlies = $open_curlies; $class->docblock = $docblock; $class->docblock_token = $docblock_token; $thisclass = $class; //print_r( $thisclass ); $functions[] = $thisclass; $docblock = null; } else { bw_trace2( "program error", "Expecting class name after 'class' token" ); } } $function = _oiksc_get_token_object( $tokens, $t, T_FUNCTION ); if ( $function ) { $t += 2; $function->methodname = _oiksc_get_token( $tokens, $t, T_STRING ); if ( $function->methodname ) { $function->open_curlies = $open_curlies; $function->docblock = $docblock; $function->docblock_token = $docblock_token; if ( $thisclass && $thisclass->classname ) { $function->classname = $thisclass->classname; } $thismethod = $function; array_push( $methods, $thismethod ); // print_r( $thismethod ); $functions[] = $thismethod; $docblock = null; } else { bw_trace2( "program error", "Expecting function name after 'function' token" ); } } /* Keep track of curly braces so that we know where the class / function starts and ends */ if ( $tokens[$t] == '{' ) { $open_curlies++; //echo "{ $open_curlies" . PHP_EOL; } if ( _oiksc_get_token( $tokens, $t, T_DOLLAR_OPEN_CURLY_BRACES ) ) { $open_curlies++; //echo "{ $open_curlies" . PHP_EOL; } if ( _oiksc_get_token( $tokens, $t, T_CURLY_OPEN ) ) { $open_curlies++; //echo "{ $open_curlies" . PHP_EOL; } if ( $tokens[$t] == '}' ) { $open_curlies--; //echo "} $open_curlies" . PHP_EOL; //print_r( $thisclass ); //print_r( $thisclass->open_curlies ); if ( $thisclass && $thisclass->open_curlies == $open_curlies ) { $thisclass->endline = _oiksc_get_endline( $tokens, $t ); $thisclass = null;View on GitHub
Invoked by
Calls
1 to 4 of 4
