Habari\Utils::php_check_file_syntax PHP Method

php_check_file_syntax() public static method

Check the PHP syntax of (and execute) the specified file.
See also: Utils::php_check_syntax()
public static php_check_file_syntax ( $file, &$error = null )
    public static function php_check_file_syntax($file, &$error = null)
    {
        // Prepend and append PHP opening tags to prevent eval() failures.
        $plugin_code = file_get_contents($file);
        $replacements = array('#^<\\?(php)?\\s#A' => '', '#\\?>$#' => '', '#(?<!\\w)namespace [^;]+;#' => 'namespace HabariSandBox\\Plugin;');
        foreach ($replacements as $search => $replacement) {
            if (preg_match($search, $plugin_code)) {
                $plugin_code = trim(preg_replace($search, $replacement, $plugin_code));
            }
        }
        return self::php_check_syntax($plugin_code, $error);
    }