[oik] plugins.com

WordPress plugins and themes

  • Home
  • 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

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

Called by

1 to 1 of 1
  • oiksc_list_file_functions2() – List functions implemented in the file

Invoked by

    Calls

    1 to 4 of 4
    • bw_trace2() – Trace $value to the trace log file if tracing is active
    • _oiksc_get_endline() – Determine the end line number
    • _oiksc_get_token() – Return the token value at $index if it’s of type $type
    • _oiksc_get_token_object() – Return the token at $index if it’s of type $type

    Call hooks

    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,_

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

    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-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
    SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
    oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
    oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
    oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

    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-2025. All rights reserved.


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

    WordPress version: 6.8.3

    Gutenberg version: 21.7.0

    PHP version: 8.2.29