예제 #1
0
 /**
  * run
  * @see Fl_Base::run()
  */
 public function run($options = array())
 {
     $this->options = array_merge($this->options, $options);
     $this->tokenInstance = $this->getInstance("Fl_Css_Token");
     $selectorPos = 0;
     $sortSelector = $this->options['sort_selector'];
     $mergeSelector = $this->options['merge_selector'];
     //是否已经含有charset
     $hasCharset = false;
     while ($token = $this->tokenInstance->getNextToken()) {
         switch ($token['type']) {
             case FL_TOKEN_CSS_SELECTOR:
                 $this->collectionSelector($token, $selectorPos++);
                 break;
             case FL_TOKEN_CSS_BRACES_TWO_END:
                 $this->compressSelector();
                 $this->options['sort_selector'] = $sortSelector;
                 $this->options['merge_selector'] = $mergeSelector;
                 $this->output[] = trim($token['value']);
                 $this->inKeyframes = false;
                 break;
             case FL_TOKEN_CSS_AT_KEYFRAMES:
                 $this->options['sort_selector'] = false;
                 $this->options['merge_selector'] = false;
                 $this->inKeyframes = true;
             default:
                 if (Fl_Css_Static::isAtType($token['type'])) {
                     $this->compressSelector(false, false);
                 }
                 //只允许含有一个charset
                 if ($token['type'] === FL_TOKEN_CSS_AT_CHARSET) {
                     if (!$hasCharset) {
                         $this->output[] = trim($token['value']);
                         $hasCharset = true;
                     }
                 } else {
                     $this->output[] = trim($token['value']);
                 }
         }
     }
     $this->compressSelector();
     $result = join('', $this->output);
     return Fl_Css_Static::compressCommon($result);
 }