Install.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * 应用安装
  4. */
  5. namespace app\system\event;
  6. class Install{
  7. /**
  8. * @param $dir 路径
  9. * @param $except 排除项
  10. * @return array
  11. * 搜索给定地址下目录列表
  12. */
  13. public static function getDir($dir,$except){
  14. $dirArray[]=NULL;
  15. if(false != ($handle = opendir($dir))){
  16. $i=0;
  17. while(false !== ($file = readdir($handle))) {
  18. //去掉"“.”、“..”以及带“.xxx”后缀的文件
  19. if (array_search($file,$except) === false && $file != ".htaccess" && $file != "." && $file != ".."&&!strpos($file,".")){
  20. $dirArray[$i]=$file;
  21. $i++;
  22. }
  23. }
  24. //关闭句柄
  25. closedir($handle);
  26. }
  27. return $dirArray;
  28. }
  29. /**
  30.  * 读取sql文件为数组
  31.  * @param $sqlFile sql 文件路径
  32.  * @param string $prefix 添加表前缀
  33.  * @return array|bool
  34.  */
  35. public static function get_sql_array($sqlFile,$prefix = ''){
  36. $sql = file_get_contents($sqlFile);
  37. $str = preg_replace('/(--.*)|(\/\*(.|\s)*?\*\/)|(\n)/', '',$sql);
  38. if(!empty($prefix)){
  39. $str = str_replace('ai_',$prefix,$str);
  40. }
  41. $list = explode(';',trim($str));
  42. foreach ($list as $key => $val) {
  43. if (empty($val)) {
  44. unset($list[$key]);
  45. } else {
  46. $list[$key] .= ';';
  47. }
  48. }
  49. return array_values($list);
  50. }
  51. }