• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

[oik] plugins.com

WordPress plugins and themes

  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

_oiksc_list_classes2() – List the classes/functions implemented within the source file

You appear to be a bot. Output may be restricted

Description

List the classes/functions implemented within the source file

At 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 instances

TO 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.php
Lines:
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;
 
[1][2]Next »
 View on GitHub

Published: March 11, 2017 | Last updated: March 11, 2017

Primary Sidebar

Information

Function name: _oiksc_list_classes2
Plugin ref: oik block shortcode and API server
Version: 1.41.5
Sourcefile: classes/oik-listapis2.php
File ref: classes/oik-listapis2.php
API type: private
Deprecated?: No
API Letters: C,L,O,_

Recent plugin updates

oik-fields v1.55.1
oik-fields v1.55.1 oik-fields v1.55.1 has been tested with WordPress 7.1. ...
oik v4.16.0
oik v4.16.0 Upgrade to oik v4.16.0 for many accessibility (a11y) improvements for both the front end and admin areas, plus a security fix. ...
oik-fields v1.55.0
oik-fields v1.55.0 Upgrade to oik-fields v1.55.0 for accessibility improvements to the featured image virtual field. ...
oik-css v2.4.0
oik-css v2.4.0 Upgrade to oik-css v2.4.0 for accessibility improvements for Low Color Contrast errors. ...
oik-unloader v0.4.0
oik-unloader v0.4.0 Update to oik-unloader v0.4.0 for improved accessibility of the active-plugins shortcode. Tested with WordPress 6.9 and PHP 8.4 ...

Footer

Plugins

  • All Plugins
  • oik base plugin
  • FREE oik plugins
  • WordPress plugins
  • Premium oik plugins

Themes

  • FREE themes
  • Bespoke themes
  • Premium themes

Blocks

  • All Blocks
  • Block examples
  • About Blocks

Shortcodes

  • All Shortcodes
  • Shortcode examples
  • About Shortcodes

Reference

  • About APIs
  • All APIs
  • All Classes
  • All Files
  • All Hooks

Support

  • Contact
  • Cookies policy
  • Get API key
  • Privacy
  • Request support
  • Sitemap
  • Stay informed
  • Terms and Conditions
oik-plugins
Email: herb@bobbingwide.com

Weight shipping plugins

Find out which cart weight shipping plugin you need for your WooCommerce site.
Which cart weight based plugin do I need?

Site:  www.oik-plugins.com
© Copyright oik-plugins 2011-2026. All rights reserved.


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins

WordPress version: 7.1.2

Gutenberg version: 24.0.0

PHP version: 8.2.35