Beispiel #1
0
 /**
  * Among the stored selectors search those, which are matched with the 
  * current widget's state.
  *
  * For matched selectors {@link WidgetResultSet} will be filled with the 
  * data, passed from the user's models.
  *
  * In order to reduce the lookups of result of matching given widget with
  * the particular selector, intermediate caching in $GLBALS is used.
  *
  * @param WComponent widget to be analyzed
  * @return WidgetResultSet with the data that should be passed to this widget
  */
 function findMatched(WComponent $widget)
 {
     $wrs = new WidgetResultSet();
     foreach ($this->fors as $selectors => $v) {
         foreach (explode(",", $selectors) as $selector) {
             // hit the cache, ie SelectorMatcher::matched for this widget and selector
             // was called
             if (array_key_exists($md5 = md5($selector . $widget->getId()), $GLOBALS['__m_cache'])) {
                 if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) {
                     continue;
                 } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) {
                     @$wrs->merge($this->for_values[$selectors]);
                     @$wrs->setDef($this->default_values[$selectors]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors[$selectors]);
                         unset($this->for_values[$selectors]);
                     }
                 } elseif (SelectorMatcher::matched($widget, $selector, null, null)) {
                     @$wrs->merge($this->for_values[$selectors]);
                     @$wrs->setDef($this->default_values[$selectors]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors[$selectors]);
                         unset($this->for_values[$selectors]);
                     }
                 }
             } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, null, null)) {
                 @$wrs->merge($this->for_values[$selectors]);
                 @$wrs->setDef($this->default_values[$selectors]);
                 if (isset($this->f1s[$selectors])) {
                     unset($this->fors[$selectors]);
                     unset($this->for_values[$selectors]);
                 }
             }
         }
     }
     //once again but now for selector with indexes
     foreach ($this->fors_array as $selectors => $arr) {
         foreach (explode(",", $selectors) as $selector) {
             $md5 = md5($selector . $widget->getId());
             if (array_key_exists($md5, $GLOBALS['__m_cache'])) {
                 if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) {
                     continue;
                 } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) {
                     @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                     @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors_array[$selectors]['index'][$matched]);
                         unset($this->fors_array[$selectors]['scope'][$matched]);
                         unset($this->for_values_array[$selectors][$matched]);
                     }
                 } elseif (SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) {
                     @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                     @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors_array[$selectors]['index'][$matched]);
                         unset($this->fors_array[$selectors]['scope'][$matched]);
                         unset($this->for_values_array[$selectors][$matched]);
                     }
                 }
             } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) {
                 @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                 @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                 if (isset($this->f1s[$selectors])) {
                     unset($this->fors_array[$selectors]['index'][$matched]);
                     unset($this->fors_array[$selectors]['scope'][$matched]);
                     unset($this->for_values_array[$selectors][$matched]);
                 }
             }
         }
     }
     return $wrs;
 }