private function handle($matches)
 {
     $path = Tool::getActualPath($matches[1]);
     $processor = new JsPreprocess($this->processor->getMap());
     $processor->setFile(C('SRC.SRC_PATH') . $path);
     $processor->process();
     trigger('js_import', $this->processor, $processor);
     return $processor->getContents();
 }
 private function replaceMediaPath($matches)
 {
     $path = $matches[0];
     $aPath = Tool::getActualPath($path);
     if (isset($this->map['media'][$aPath])) {
         trigger('js_replace', $this, $aPath);
         return Tool::addCdn($this->map['media'][$aPath]);
     }
     return $path;
 }
 /**
  * 设置mergeConfig,并检查合法性
  * @param $mergeValue
  * @param $url
  * @param $config
  * @throws MergeConfigException
  */
 private function setConfig($mergeValue, $url, $config)
 {
     $url = Tool::getActualPath($url);
     if (!isset($this->mergeConfig[$mergeValue][$url])) {
         $this->mergeConfig[$mergeValue][$url] = $config;
     } else {
         // 如果这个图片地址,之前处理过
         // 取最大的padding
         $paddings = array('padding-left', 'padding-right', 'padding-top', 'padding-bottom');
         $oldConfig =& $this->mergeConfig[$mergeValue][$url];
         foreach ($paddings as $padding) {
             $oldConfig[$padding] = max($oldConfig[$padding], $config[$padding]);
         }
         // 之前float = none,而现在float != none
         if ($oldConfig['float'] === 'none') {
             if ($config['float'] !== 'none') {
                 $oldConfig['float'] = $config['float'];
             }
         } else {
             if ($config['float'] !== 'none' && $oldConfig['float'] !== $config['float']) {
                 //                    throw new MergeConfigException('图片:'.$url.',被多次引用,但存在冲突,请检查background-position!', self::MERGE_FLOAT_ERROR);
             }
         }
         // 之前 repeat none, 现在 repeat !none
         if ($oldConfig['repeat'] === 'none') {
             if ($config['repeat'] !== 'none') {
                 $oldConfig['repeat'] = $config['repeat'];
             }
         } else {
             if ($config['repeat'] !== 'none' && $oldConfig['repeat'] !== $config['repeat']) {
                 throw new MergeConfigException('图片:' . $url . ',被多次引用,但存在冲突,请检查background-repeat!', self::MERGE_REPEAT_ERROR);
             }
         }
     }
 }
 private function getBackgroundUrlData($url, $merge = null)
 {
     $ret = array('url' => $url, 'config' => null);
     $newUrl = $url;
     if (!$url || strpos($url, 'data:') !== false || strpos($url, 'about:') !== false || strpos($url, '://') !== false) {
         return $ret;
     }
     $url = Tool::getActualPath($url);
     $mask = 0;
     $mask += !is_null($merge);
     $mask += $mask > 0 && isset($this->spriteConfig[$merge]);
     $mask += $mask > 1 && isset($this->spriteConfig[$merge]['config'][$url]);
     $mask <<= 1;
     $mask += isset($this->map['media'][$url]);
     if (($mask & 6) === 6) {
         $sprite = $this->spriteConfig[$merge]['attr']['filename'];
         if (isset($this->map['media'][$sprite])) {
             $newUrl = $this->map['media'][$sprite];
         } else {
             mark('找不到合图文件' . $sprite . '的去向,请确定该合图已编译', 'error');
             return $ret;
         }
         $ret['config'] = $this->spriteConfig[$merge]['config'][$url];
         trigger('css_background_change', $this, $sprite);
     } else {
         if (($mask & 1) === 1) {
             $newUrl = $this->map['media'][$url];
         }
         trigger('css_background_change', $this, $url);
         // 依然将合图加入依赖关系表中,万一某天心血来潮又合图了,依然可以进行增量编译
         if ($mask > 1) {
             trigger('css_background_change', $this, $merge . C('SPRITE_SUFFIX') . '.png');
         }
         // 5中异常情况
         switch ($mask) {
             case 0:
                 mark('文件“' . $this->path . '”中引用了“' . $url . '”,但该图片不存在!', 'warn');
                 return $ret;
             case 1:
                 // 正常情况
                 break;
             case 2:
                 mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,并且图片“' . $url . '”也不存在', 'warn');
                 return $ret;
             case 3:
                 mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,将用小图地址代替', 'warn');
                 break;
             case 4:
                 mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,并且该图片也不存在', 'warn');
                 return $ret;
             case 5:
                 mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,将用小图地址代替', 'warn');
                 break;
             default:
                 mark('文件“' . $this->path . '”中引用了“' . $url . '”,未知错误码:' . $mask, 'error');
                 return $ret;
         }
     }
     $ret['url'] = Tool::addCdn($newUrl);
     return $ret;
 }
 /**
  * 进行地址替换
  * @param $type
  * @param $key
  * @param $orgValue
  */
 private function replacePath($type, &$key, $prop)
 {
     $value = $key->{$prop};
     // 去掉queryString
     $pos = strpos($value, '?');
     if ($pos !== false) {
         $value = substr($value, 0, $pos);
     }
     $value = Tool::getActualPath($value);
     if (isset($this->map[$type][$value])) {
         $key->{$prop} = Tool::addCdn($this->map[$type][$value]);
         trigger('html_href_change', $this, $value);
     }
 }