# 多项目 函数库、类库 统一为一个版本的方法 – one.php one.php 源代码：http://www.miaoqiyuan.cn/products/onephp.rar

```<?php
/**
* 类名：One
* 作者：mqycn
* 博客：http://www.miaoqiyuan.cn
* 源码：http://www.miaoqiyuan.cn/p/one-php
* 说明：多项目 函数库、类库 统一为一个版本的方法
*/

class OneFile {

//已经合并的文件
public static \$includes;

//处理一个文件
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); \$i++) {
\$code = str_replace(\$match[\$i], self::parse(\$match[\$i]), \$code);
}

}
return \$code;
} else {
self::log('Ignore', \$file);
return '';
}
}

//代码修复
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');
```

## 1 thought on “多项目 函数库、类库 统一为一个版本的方法 – one.php”

1. Pingback引用通告： 多项目 函数库、类库 统一为一个版本的方法 – one.asp | 启源的部落格
{"ft_lang_label":"__label__zh","ft_lang_prob":0.7236019,"math_prob":0.8225731,"size":2278,"snap":"2019-35-2019-39","text_gpt3_token_len":1062,"char_repetition_ratio":0.12005277,"word_repetition_ratio":0.01793722,"special_character_ratio":0.3503073,"punctuation_ratio":0.26340327,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.968361,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-16T06:03:34Z\",\"WARC-Record-ID\":\"<urn:uuid:3c3e7e7d-4803-4e60-b5a4-853b3fc6587b>\",\"Content-Length\":\"44449\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:16a6e161-2d08-403f-8754-f9b173d415b2>\",\"WARC-Concurrent-To\":\"<urn:uuid:93fcc752-8348-46d8-ad9c-924bf8ef45c5>\",\"WARC-IP-Address\":\"122.114.159.220\",\"WARC-Target-URI\":\"http://www.miaoqiyuan.cn/p/one-php\",\"WARC-Payload-Digest\":\"sha1:K77UPCM3QLWN4Z4NLICRQQAWSGJCDKVI\",\"WARC-Block-Digest\":\"sha1:PBHUJ5TVIGR4L4MF43DDB7ATOQOGTOT5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514572491.38_warc_CC-MAIN-20190916060046-20190916082046-00409.warc.gz\"}"}