• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter Get List all Classes and Methods

#1
Photo 
Hello CI patrons. 

I am just creating a simple library to get list all classes and methods on HMVC structure, i called the function on MY_Controller but here something wrong to get methods
and when i var_dump it got result like this 
[Image: image.png]

,there's something wrong with my code ? 

Thank you


PHP Code:
[color=#333333]public static function get_class_and_methods()
[/color]
    {

        // $classes = get_declared_classes();



        $appdir     APPPATH."modules";

        $appdirScan array_diff(scandir($appdir), array('.''..'));

        echo "<pre>";

        $arrAllModules = [];

    

        
foreach ($appdirScan as $keyParent => $module) {

            $scanperModule array_diff(preg_grep('~\.(php|phtml)$~'scandir($appdir."/".$module."/controllers")), array('.''..'));

            $arrAllModules[] = $scanperModule;



            foreach ($scanperModule as $keyFChild => $value) {

                // $a = file_get_contents($appdir."/".$module."/controllers/".$value);

                $classes self::getClassNameFromFile($appdir."/".$module."/controllers/".$value);

                $methods get_class_methods($classes);

                var_dump ($methods);

                // $aUserMethods = array();

                // if(is_array($methods)){

                    // foreach($methods as $method) {

                        // var_dump ($method);

                        // if($method != '__construct' && $method != 'get_instance' && $method != $classes && $method != "setOutput" && $method != "checkAjaxSession" && $method != "setDeniedPage" && $method != "debug" && $method != "__get") {

                        //     $aUserMethods[] = $method;

                        // }

                    // }

                // }

            }

        }

        // $flatten = array_flatten(array_merge($arrAllModules));



        die();



    }



    private static function getClassNameFromFile($filePathName)

    {

        $php_code file_get_contents($filePathName);



        $classes = array();

        $tokens token_get_all($php_code);

        $count count($tokens);

        for ($i 2$i $count$i++) {

            if ($tokens[$i 2][0] == T_CLASS

                
&& $tokens[$i 1][0] == T_WHITESPACE

                
&& $tokens[$i][0] == T_STRING

            
) {



                $class_name $tokens[$i][1];

                $classes[] = $class_name;

            }

        }



        return $classes[0];

    }





    function array_flatten($array) { 

        
if (!is_array($array)) { 

            
return FALSE; 

        
} 

          

        $result 
= array(); 

        
foreach ($array as $key => $value) { 

            
if (is_array($value)) { 

              $result 
array_merge($resultarray_flatten($value)); 

            
} 

            
else { 

              $result
[$key] = $value; 

            
} 

        
} 

          
return $result;
[
color=#333333]    } 
[/color
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.