Esempio n. 1
0
 /**
  * 
  * selectors intersect
  * @param array $selectors
  */
 public function selectorsIntersect($selectors = array())
 {
     while (true) {
         $length = count($selectors);
         if ($length < 2) {
             break;
         }
         $result = array();
         $flag = false;
         $pos = 0;
         for ($i = 0; $i < $length - 1; $i++) {
             $strs = array($selectors[$i]['selector'], $selectors[$i + 1]['selector']);
             if ($this->checkSelector($strs)) {
                 $assoc = Fl_Css_Static::getPropertiesIntersect($selectors[$i], $selectors[$i + 1]);
             } else {
                 $assoc = null;
             }
             if (!empty($assoc)) {
                 foreach ($assoc as $name => $item) {
                     unset($selectors[$i]['attrs'][$name]);
                     unset($selectors[$i + 1]['attrs'][$name]);
                 }
                 $equal = array_merge(array($selectors[$i + 1]['selector']), $selectors[$i]['equal'], $selectors[$i + 1]['equal']);
                 $selectors[$i]['pos'] = $pos++;
                 $result[] = $selectors[$i];
                 $result[] = array("attrs" => $assoc, "selector" => $selectors[$i]['selector'], "score" => $selectors[$i]['score'], "same_score" => $selectors[$i]['score'] == $selectors[$i + 1]['score'] ? true : false, 'equal' => $equal, 'pos' => $pos++);
                 $flag = true;
             } elseif (!empty($selectors[$i]['attrs'])) {
                 $result[] = array_merge($selectors[$i], array('pos' => $pos++));
             }
         }
         if (!empty($selectors[$length - 1])) {
             $result[] = array_merge($selectors[$length - 1], array('pos' => $pos++));
         }
         $selectors = $result;
         if (!$flag) {
             break;
         }
     }
     return $selectors;
 }