예제 #1
0
 protected static function checkAutoLoadConf()
 {
     global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP;
     $supportsParsekit = function_exists('parsekit_compile_file');
     // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
     $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses;
     $actual = array();
     $files = array_unique($expected);
     foreach ($files as $file) {
         // Only prefix $IP if it doesn't have it already.
         // Generally local classes don't have it, and those from extensions and test suites do.
         if (substr($file, 0, 1) != '/' && substr($file, 1, 1) != ':') {
             $filePath = "{$IP}/{$file}";
         } else {
             $filePath = $file;
         }
         if ($supportsParsekit) {
             $parseInfo = parsekit_compile_file("{$filePath}");
             $classes = array_keys($parseInfo['class_table']);
         } else {
             $contents = file_get_contents("{$filePath}");
             $m = array();
             preg_match_all('/\\n\\s*(?:final)?\\s*(?:abstract)?\\s*(?:class|interface)\\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER);
             $classes = $m[1];
         }
         foreach ($classes as $class) {
             $actual[$class] = $file;
         }
     }
     return array('expected' => $expected, 'actual' => $actual);
 }
 public function execute()
 {
     global $wgAutoloadLocalClasses, $IP;
     $files = array_unique($wgAutoloadLocalClasses);
     foreach ($files as $file) {
         if (function_exists('parsekit_compile_file')) {
             $parseInfo = parsekit_compile_file("{$IP}/{$file}");
             $classes = array_keys($parseInfo['class_table']);
         } else {
             $contents = file_get_contents("{$IP}/{$file}");
             $m = array();
             preg_match_all('/\\n\\s*class\\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER);
             $classes = $m[1];
         }
         foreach ($classes as $class) {
             if (!isset($wgAutoloadLocalClasses[$class])) {
                 // printf( "%-50s Unlisted, in %s\n", $class, $file );
                 $this->output("\t'{$class}' => '{$file}',\n");
             } elseif ($wgAutoloadLocalClasses[$class] !== $file) {
                 $this->output("{$class}: Wrong file: found in {$file}, listed in " . $wgAutoloadLocalClasses[$class] . "\n");
             }
         }
     }
 }
예제 #3
0
 /**
  * Check a file for syntax errors using Parsekit. Shamelessly stolen
  * from tools/lint.php by TimStarling
  * @param $file String Path to a file to check for syntax errors
  * @return boolean
  */
 private function checkFileWithParsekit($file)
 {
     static $okErrors = array('Redefining already defined constructor', 'Assigning the return value of new by reference is deprecated');
     $errors = array();
     parsekit_compile_file($file, $errors, PARSEKIT_SIMPLE);
     $ret = true;
     if ($errors) {
         foreach ($errors as $error) {
             foreach ($okErrors as $okError) {
                 if (substr($error['errstr'], 0, strlen($okError)) == $okError) {
                     continue 2;
                 }
             }
             $ret = false;
             $this->output("Error in {$file} line {$error['lineno']}: {$error['errstr']}\n");
             $this->mFailures[$file] = $errors;
         }
     }
     return $ret;
 }
예제 #4
0
<?php

if (php_sapi_name() != 'cli') {
    exit;
}
$IP = dirname(__FILE__) . '/..';
require "{$IP}/includes/AutoLoader.php";
$files = array_unique($wgAutoloadLocalClasses);
foreach ($files as $file) {
    if (function_exists('parsekit_compile_file')) {
        $parseInfo = parsekit_compile_file("{$IP}/{$file}");
        $classes = array_keys($parseInfo['class_table']);
    } else {
        $contents = file_get_contents("{$IP}/{$file}");
        $m = array();
        preg_match_all('/\\n\\s*class\\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER);
        $classes = $m[1];
    }
    foreach ($classes as $class) {
        if (!isset($wgAutoloadLocalClasses[$class])) {
            //printf( "%-50s Unlisted, in %s\n", $class, $file );
            echo "\t\t'{$class}' => '{$file}',\n";
        } elseif ($wgAutoloadLocalClasses[$class] !== $file) {
            echo "{$class}: Wrong file: found in {$file}, listed in " . $wgAutoloadLocalClasses[$class] . "\n";
        }
    }
}
    if (array_key_exists('function_table', $tree)) {
        foreach ($tree['function_table'] as $item) {
            $ret = array_merge($ret, $self($item));
        }
    }
    return $ret;
}
function get_locally_declared_functions($tree)
{
    $self = __FUNCTION__;
    $ret = array();
    if (array_key_exists('function_table', $tree)) {
        foreach ($tree['function_table'] as $funcname => $item) {
            $ret = array_merge($ret, array($funcname), $self($item));
        }
    }
    return $ret;
}
function get_foreign_function_calls($tree)
{
    $ret = array();
    $localnames = get_locally_declared_functions($tree);
    foreach (array_unique(get_all_function_calls($tree)) as $func_call) {
        if (!in_array($func_call, $localnames) and !function_exists($func_call)) {
            $ret[] = $func_call;
        }
    }
    return $ret;
}
$tree = parsekit_compile_file('local.php');
print_r(get_foreign_function_calls($tree));