Exemple #1
0
//-----------------------------------------------------------
// START
//-----------------------------------------------------------
_mkdir_m($packed_dir, 0777);
_mkdir_m($compiled_dir, 0777);
// Get files array
$files_to_compress = scan_dir($source_dir, 1, "#.*\\.(php)\$#");
//print_r($files_to_compress);
foreach ((array) $files_to_compress as $cur_file_path) {
    $compressed_file_path = $packed_dir . substr($cur_file_path, strlen($source_dir));
    $compressed_file_dir = dirname($compressed_file_path);
    if (!file_exists($compressed_file_dir)) {
        _mkdir_m($compressed_file_dir, 0777);
    }
    // Do compress
    _do_compress_php_file($cur_file_path, $compressed_file_path);
}
// Get classes names and paths
$new_files_to_compile = [];
foreach ((array) scan_dir($packed_dir, 1, "#.*\\.(php)\$#", $exclude_pattern_user) as $cur_file_path) {
    $class_name = str_replace("/", "_", str_replace("\\/", "/", substr($cur_file_path, strlen($packed_dir), -4)));
    $GLOBALS['CLASSES'][$class_name] = $class_name;
    $GLOBALS['CLASSES_PATHS'][$class_name] = $cur_file_path;
}
// Build inheritance tree
foreach ((array) $GLOBALS['CLASSES'] as $class_name) {
    $text = substr(file_get_contents($GLOBALS['CLASSES_PATHS'][$class_name]), 6) . "\r\n";
    $text = preg_replace($pattern_require, "", $text);
    if (preg_match("/abstract class ([a-z\\_]+)/ims", $text, $m)) {
        $GLOBALS["ABSTRACT_CLASSES"][$class_name] = $class_name;
    }
Exemple #2
0
                // we've defined this
                case T_DOC_COMMENT:
                    // and this
                    // no action on comments
                    $output .= " ";
                    break;
                default:
                    // anything else -> output "as is"
                    $output .= $text;
                    break;
            }
        }
    }
    // Do compress spaces
    $replace_pairs = ["( " => "(", " )" => ")", "{ " => "{", " }" => "}", ") " => ")", "} " => "}", "; " => ";", "if (" => "if(", "for (" => "for(", "while (" => "while(", ", " => ",", " =" => "=", "= " => "=", " ? " => "?", "=> " => "=>", " =>" => "=>", " !=" => "!=", " ||" => "||", "|| " => "||", " &&" => "&&", "&& " => "&&", " >" => ">", "> " => ">", " <" => "<", "< " => "<"];
    $output = str_replace(["\r", "\n"], "", $output);
    $output = str_replace("\t", " ", $output);
    $output = preg_replace("/[\\s\t]{2,}/ims", " ", $output);
    $output = str_replace(array_keys($replace_pairs), array_values($replace_pairs), $output);
    // Write the file
    $fh = @fopen($file_to_save, "w");
    fwrite($fh, $output);
    @fclose($fh);
    // Display compress ratio
    $body .= "compressed file \"" . $file_to_open . "\" saved into \"" . $file_to_save . "\"<br />\r\n";
    $body .= "<b>compress ratio: " . round(@filesize($file_to_open) / @filesize($file_to_save), 2) * 100 . "% (" . @filesize($file_to_open) . " / " . @filesize($file_to_save) . " bytes)</b><br />\r\n";
    return $body;
}
// Do execute compression engine
$result = _do_compress_php_file($_file_to_open, $_file_to_save);
echo $result;