Ejemplo n.º 1
0
 /**
  * @inherit
  */
 function contentToData($content)
 {
     $arrayData = json_decode($content, true);
     $dataInstance = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_ROOT);
     $this->data = $dataInstance->buildFromArray($arrayData);
     return $this->data;
 }
Ejemplo n.º 2
0
 /**
  * 
  */
 function compare(Alternc_Diagnostic_Data $source, Alternc_Diagnostic_Data $target)
 {
     $sourceIndex = $source->getIndex();
     $targetIndex = $target->getIndex();
     // Check diagnostics are same level
     $source_type = $source->getType();
     $target_type = $target->getType();
     if ($source_type != $target_type) {
         throw new \Exception("Invalid type comparison requested: {$source_type} vs {$target_type}");
     }
     $diffInstance = new Alternc_Diagnostic_Data($source_type);
     #echo "type $source_type\n";
     // Compare general data
     if ($source->getMetadata() != $target->getMetadata()) {
         $diffInstance->setMetadata(array_diff($source->getMetadata(), $target->getMetadata()));
     }
     if ($source->getIndex() != $target->getIndex()) {
         $diffInstance->setIndex(array_diff($source->getIndex(), $target->getIndex()));
     }
     // If section content ie. no subsections
     if ($source_type == Alternc_Diagnostic_Data::TYPE_SECTION) {
         #echo "Real section\n";
         if (is_array($source->getData()) && is_array($target->getData())) {
             $diff = array_diff($source->getData(), $target->getData());
             if ($diff) {
                 $diffInstance->setData(array_diff($source->getData(), $target->getData()));
             }
         } else {
             if ($source->getData() != $target->getData()) {
                 $diffInstance->setData(array("source" => $source->getData(), "target" => $target->getData()));
             }
         }
     } else {
         $sourceData = $source->getData();
         $targetData = $target->getData();
         $seenSections = array();
         foreach ($sourceData as $section_name => $sectionData) {
             #echo "section_name $section_name\n";
             $section_data_type = $sectionData->getType();
             if (!isset($targetData[$section_name])) {
                 #echo "section_name not in target\n";
                 $tempDataInstance = new Alternc_Diagnostic_Data($section_data_type);
                 $tempDataInstance->setMetadata(array("Not in target"));
             } else {
                 #echo "section_name for diff\n";
                 $tempDataInstance = $this->compare($sectionData, $targetData[$section_name]);
             }
             if (!is_null($tempDataInstance)) {
                 $diffInstance->addData($section_name, $tempDataInstance);
             }
         }
     }
     if (count($diffInstance->getData()) || count($diffInstance->getIndex()) || count($diffInstance->getMetadata())) {
         return $diffInstance;
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * Controls the diagnostics creation
  * 
  * @param Console_CommandLine_Result $options
  * @throws \Exception
  */
 function c_create(Console_CommandLine_Result $options)
 {
     $args = $options->args;
     $options = $options->options;
     $diagnosticdata = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_ROOT);
     $servicelist = explode(',', $options["services"]);
     foreach ($servicelist as $service) {
         $class_name = "Alternc_Diagnostic_Service_" . trim(ucfirst($service));
         if (!class_exists($class_name)) {
             throw new \exception("invalid service {$service}");
         }
         /** @var alternc_diagnostic_service_interface */
         $serviceagent = new $class_name(array("service" => $this));
         // runs the service agent and store the results
         $diagnosticdata->addData($serviceagent->name, $serviceagent->run());
     }
     $this->formatInstance->setData($diagnosticdata)->write();
 }
Ejemplo n.º 4
0
 function buildFromArray($content)
 {
     if (!$this->isValidArrayData($content)) {
         return $content;
     }
     $type = $content["type"];
     $newInstance = new Alternc_Diagnostic_Data($type);
     $newInstance->index = $content["index"];
     $newInstance->metadata = $content["metadata"];
     $data = $content["data"];
     // The content is raw
     if ($type === self::TYPE_SECTION) {
         $newInstance->data = $data;
     } else {
         foreach ($content["data"] as $section_name => $sectionData) {
             $sectionContent = $this->buildFromArray($sectionData);
             $newInstance->addData($section_name, $sectionContent);
         }
     }
     return $newInstance;
 }
Ejemplo n.º 5
0
 /**
  * Utility for filling the service agent data holder
  * 
  * @param string $name
  * @param mixed $content
  * @return boolean
  */
 function writeSectionData($name, $content)
 {
     $section = new Alternc_Diagnostic_Data(Alternc_Diagnostic_Data::TYPE_SECTION, $content);
     $this->data->addData($name, $section);
     return true;
 }