Beispiel #1
0
 /**
  * 加载配置
  */
 protected final function initConfig()
 {
     // 加载配置文件
     C($this->options['config']);
     // 初始化静态文件访问前缀
     // 用于引用路径和实际路径的映射
     if (isset($this->options['static_case'])) {
         $staticInSrc = $this->options['static_case']['static_in_src'];
         $staticInFile = $this->options['static_case']['static_in_file'];
         $staticInBuild = $this->options['static_case']['static_in_build'];
         if ($staticInSrc && $staticInFile) {
             str_diff($staticInSrc, $staticInFile, $pos);
             $pos = $pos ? -$pos : null;
             C('STATIC_ACTUAL_PREFIX', str_slice($staticInSrc, 0, $pos));
             C('STATIC_VIRTUAL_PREFIX', str_slice($staticInFile, 0, $pos));
         }
         if ($staticInSrc && $staticInBuild) {
             str_diff($staticInSrc, $staticInBuild, $pos);
             $pos = $pos ? -$pos : null;
             C('STATIC_BUILD_PREFIX', str_slice($staticInFile, 0, $pos));
         }
     }
     // 加载自定义插件
     $pluginPath = C('PLUGIN_PATH');
     if ($pluginPath && file_exists($pluginPath)) {
         Plugin::start($pluginPath);
     }
 }
Beispiel #2
0
/**
 * 比较两个字符串,找到不同的部分
 * 从字符串后面开始查找,直到遇见不同的字符
 * 该函数没有返回,传入$pos引用,接受位置
 *  'abcd' & 'aacd' => $pos = -2
 * @param $str1
 * @param $str2
 * @param int $pos
 */
function str_diff($str1, $str2, &$pos = 0)
{
    $len1 = strlen($str1);
    $len2 = strlen($str2);
    $minLen = min($len1, $len2);
    if ($minLen > 0) {
        $minLen = ceil($minLen / 2);
        $temp1 = array('start' => str_slice($str1, 0, -$minLen), 'end' => str_slice($str1, -$minLen));
        $temp2 = array('start' => str_slice($str2, 0, -$minLen), 'end' => str_slice($str2, -$minLen));
        if ($temp1['end'] === $temp2['end']) {
            $pos = $pos + $minLen;
            str_diff($temp1['start'], $temp2['start'], $pos);
        } elseif ($temp1['start'] && $temp2['start']) {
            str_diff($temp1['end'], $temp2['end'], $pos);
        }
    }
}