Commit 674a53f4 authored by Felix Flor's avatar Felix Flor

add two new functions to analyse files for they modules and they status of install

parent f2a005dc
......@@ -39,6 +39,8 @@ require_once __DIR__ . '/inc/func/isModuleForConstantInstalled.func.php';
require_once __DIR__ . '/inc/func/isModuleForConstantInstalledAsString.func.php';
require_once __DIR__ . '/inc/func/matchConstantToModule.func.php';
require_once __DIR__ . '/inc/func/isConstantInArray.func.php';
require_once __DIR__ . '/inc/func/getNeededModules.func.php';
require_once __DIR__ . '/inc/func/getModulesInstalledStatus.func.php';
/********************/
/* output functions */
......
<?php
namespace APHPBreakdown;
/**
* @return mixed[] $neddedModulesInstallStatus
*
* @param mixed[] $neededModules
*
* @throws \Exception - if $filesToCheck is not of type array
*
* this function chechs the install status of the needed modules
*
**/
function getModulesInstalledStatus($neededModules){
if(!is_array($neededModules))
throw new \Exception ("Invalid parameter type for \$neededModules! Must: array, Is: " . gettype($neededModules));
$neddedModulesInstallStatus = array();
echo "APHPBreakdown: Checking Modul Status ... ";
foreach ($neededModules as $neededModule) {
if($neededModule != "Core"){
if(!extension_loaded($neededModule)){
$neddedModulesInstallStatus[$neededModule] = false;
} else {
$neddedModulesInstallStatus[$neededModule] = true;
}
}
}
echo "Finished!\n\n";
return $neddedModulesInstallStatus;
}
<?php
namespace APHPBreakdown;
/**
* @return mixed[] $neededModules - a aplphabetical sorted array if all needed modules
*
* @param mixed[] $filesToCheck - contains all paths to files, one path per field
*
* @throws \Exception - if $filesToCheck is not of type array
*
* this functions checks all given files for functions, constants and classes which
* needed for the project you analize.
*
**/
function getNeededModules($filesToCheck){
if(!is_array($filesToCheck))
throw new \Exception ("Invalid parameter type for \$filesToCheck! Must: array, Is: " . gettype($filesToCheck));
$neededModules = array();
$countAllFiles = count($filesToCheck);
$i = 0;
foreach($filesToCheck as $fileToCheck){
system("clear");
echo "APHPBreakdown: Analyzing File [ ".++$i." / $countAllFiles ] \n";
$tokens = token_get_all(file_get_contents($fileToCheck['fullpath']));
foreach($tokens as $token){
if(is_array($token) && T_STRING == $token[0] && isset($token[1])){
/* check function */
if(in_array($token[1], $GLOBALS['php71_functions_list'])){
$functionToModule = matchFunctionToModule($token[1]);
if(null == $functionToModule)
$functionToModule = "UNKNOWN";
if(!in_array($functionToModule ,$neededModules))
$neededModules[] = $functionToModule;
}
/* check class */
if(in_array($token[1], $GLOBALS['php71_classes_list'])){
$classToModule = matchClassToModule($token[1]);
if(null == $classToModule)
$classToModule = "UNKNOWN";
if(!in_array($classToModule ,$neededModules))
$neededModules[] = $classToModule;
}
/* check constants */
if(isConstantInArray($token[1])){
$constantToModule = matchConstantToModule($token[1]);
if(null == $constantToModule)
$constantToModule = "UNKNOWN";
if(!in_array($constantToModule ,$neededModules))
$neededModules[] = $constantToModule;
}
}
}
}
sort($neededModules, SORT_STRING | SORT_FLAG_CASE);
return $neededModules;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment