Пример #1
0
 /**
  * generate validation data (list of known configd actions)
  */
 public function eventPostLoading()
 {
     if (!array_key_exists($this->internalCacheKey, self::$internalOptionList)) {
         self::$internalOptionList[$this->internalCacheKey] = array();
         $backend = new Backend();
         $service_tempfile = "/tmp/configdmodelfield.data";
         // check configd daemon for list of available actions, cache results as long as configd is not restarted
         if (!file_exists($service_tempfile) || filemtime($service_tempfile) < $backend->getLastRestart()) {
             $response = $backend->configdRun("configd actions json", false, 20);
             $actions = json_decode($response, true);
             if (is_array($actions)) {
                 file_put_contents($service_tempfile, $response);
             }
         } else {
             $actions = json_decode(file_get_contents($service_tempfile), true);
             if (!is_array($actions)) {
                 $actions = array();
             }
         }
         foreach ($actions as $key => $value) {
             // use filters to determine relevance
             $isMatched = true;
             foreach ($this->internalFilters as $filterKey => $filterData) {
                 if (array_key_exists($filterKey, $value)) {
                     $fieldData = $value[$filterKey];
                     if (!preg_match($filterData, $fieldData)) {
                         $isMatched = false;
                     }
                 }
             }
             if ($isMatched) {
                 if (!isset($value['description']) || $value['description'] == '') {
                     self::$internalOptionList[$this->internalCacheKey][$key] = $key;
                 } else {
                     self::$internalOptionList[$this->internalCacheKey][$key] = $value['description'];
                 }
             }
         }
     }
 }