one.php 多項(xiàng)目、函數(shù)庫(kù)、類庫(kù) 統(tǒng)一為一個(gè)版本的方法
現(xiàn)在 手里 有好幾個(gè) 項(xiàng)目在進(jìn)行,每個(gè)項(xiàng)目都有部分通用的代碼,只想維護(hù)一個(gè) 函數(shù)庫(kù)、類庫(kù),并且每個(gè)項(xiàng)目都不想有冗余代碼,函數(shù)功能更新后,其他項(xiàng)目的函數(shù)也需要更新。晚上抽空寫了個(gè) 簡(jiǎn)單的打包小腳本:one.php,以后 更新函數(shù)或類時(shí),只需要在唯一的 函數(shù)庫(kù)、類庫(kù) 中更新,其他項(xiàng)目使用 打包后的 php 腳本即可(理論上也能提高PHP的運(yùn)行速度,只需要加載、分析一個(gè)文件)。
因?yàn)槲业?nbsp;函數(shù)庫(kù)、類庫(kù)都在一個(gè)目錄下,所以沒有針對(duì)相對(duì)路徑 做處理(懶),cmd 進(jìn)入 core 目錄,執(zhí)行 php one.php 即可按規(guī)則打包成一個(gè)獨(dú)立的文件,運(yùn)行效果如下。
打包流程,以 public.php 為例。
現(xiàn)在功能有限,僅支持 同一個(gè)目錄(因?yàn)槲抑挥玫搅藛文夸洠?,如果有哪位大?在此基礎(chǔ)上修改了多目錄版本,請(qǐng)一定要分享一分給我。
至于用處,除了 方便維護(hù)多個(gè)項(xiàng)目(A項(xiàng)目、B項(xiàng)目)或同一個(gè)項(xiàng)目的多個(gè)版本(比如:VIP版、普通版),最大的用處,可以用于商業(yè)版程序混淆加密。比如商業(yè)軟件:index.php,product.php 每個(gè)文件都打包混淆加密,每個(gè)文件都包含了所有的代碼(幾萬行)。破解者解密后,看到幾萬行代碼,上百個(gè)函數(shù)(可能都還有用),同一個(gè)功能,各個(gè)文件內(nèi)的函數(shù)名都不一致,會(huì)哭死的。。。。
測(cè)試包下載地址:
one.php 源代碼:onephp.rar
核心代碼
<?php /** * 類名:One * 作者:mqycn * 博客:http://www.miaoqiyuan.cn * 源碼:http://www.miaoqiyuan.cn/p/one-php * 說明:多項(xiàng)目 函數(shù)庫(kù)、類庫(kù) 統(tǒng)一為一個(gè)版本的方法 */ class OneFile { //已經(jīng)合并的文件 public static $includes; //處理一個(gè)文件 public static function run($index_file, $output_file) { self::$includes = array(); self::log('Input', $index_file); $output = self::parse($index_file); file_put_contents($output_file, self::repair($output)); self::log('Output', $output_file); } //分析PHP文件 public static function parse($file) { if (empty(self::$includes[$file])) { self::log('Append', $file); self::$includes[$file] = true; $code = file_get_contents($file); if (preg_match_all("/(require_once|require|include_once|include)\s+'([^']*)';/", $code, $match)) { for ($i = 0; $i < count($match[0]); $i++) { $code = str_replace($match[0][$i], self::parse($match[2][$i]), $code); } } return $code; } else { self::log('Ignore', $file); return ''; } } //代碼修復(fù) public static function repair($code) { $php_prefix = "<?php\r\n"; $php_suffix = "\r\n?>"; $code = str_replace("\n", "\r\n", $code); $code = str_replace("\r\r\n", "\r\n", $code); $code = str_replace($php_prefix, '', $code); $code = str_replace($php_suffix, '', $code); for ($i = 0; $i < 5; $i++) { $code = str_replace("\r\n\r\n", "\r\n", $code); } return $php_prefix . $code . $php_suffix; } //輸出日志 public static function log($type, $text, $status = '') { if (in_array($type, array('Append', 'Ignore'))) { $status = "- ${type}"; $type = " |-- "; } else { $type = "${type}:"; } echo "${type} ${text} {$status}\r\n"; } } OneFile::run('vip.php', '../vip.php'); OneFile::run('public.php', '../public.php');
到此這篇關(guān)于one.php 多項(xiàng)目、函數(shù)庫(kù)、類庫(kù) 統(tǒng)一為一個(gè)版本的方法的文章就介紹到這了,更多相關(guān)多項(xiàng)目、函數(shù)庫(kù)、類庫(kù)統(tǒng)一為一個(gè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
php checkdate、getdate等日期時(shí)間函數(shù)操作詳解
PHP的日期時(shí)間函數(shù)date()中介紹了PHP日期時(shí)間函數(shù)的簡(jiǎn)單用法,這類將介紹更多的函數(shù)來豐富我們的應(yīng)用。2010-03-03PHP+Ajax實(shí)現(xiàn)的博客文章添加類別功能示例
這篇文章主要介紹了PHP+Ajax實(shí)現(xiàn)的博客文章添加類別功能,結(jié)合實(shí)例形式分析了php+ajax實(shí)現(xiàn)的數(shù)據(jù)交互、數(shù)據(jù)庫(kù)連接、查詢等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03php setcookie函數(shù)的參數(shù)說明及其用法
這篇文章主要介紹了php setcookie函數(shù)的參數(shù)說明及其用法,需要的朋友可以參考下2014-04-04PHP通過正則表達(dá)式下載圖片到本地的實(shí)現(xiàn)代碼
PHP通過正則表達(dá)式下載圖片到本地的實(shí)現(xiàn)代碼,主要是通過正則表達(dá)式匹配網(wǎng)頁(yè)內(nèi)容中的圖片地址并下載。2011-09-09