/** * Executes the main logic of the service. * @return tao_install_services_Data The result of the service execution. */ public function execute() { // contains an array of 'component', associated input 'data' // and service 'class'. $componentToData = array(); $content = json_decode($this->getData()->getContent(), true); if (self::getRequestMethod() == 'get') { // We extract the checks to perform from the manifests // depending on the distribution. $content['value'] = tao_install_utils_ChecksHelper::getRawChecks($content['extensions']); } // Deal with checks to be done. $collection = new common_configuration_ComponentCollection(); foreach ($content['value'] as $config) { $class = new ReflectionClass('tao_install_services_' . $config['type'] . 'Service'); $buildMethod = $class->getMethod('buildComponent'); $args = new tao_install_services_Data(json_encode($config)); $component = $buildMethod->invoke(null, $args); $collection->addComponent($component); if (!empty($config['value']['silent']) && is_bool($config['value']['silent'])) { $collection->silent($component); } $componentToData[] = array('component' => $component, 'id' => $config['value']['id'], 'data' => $args, 'class' => $class); } // Deal with the dependencies. foreach ($content['value'] as $config) { if (!empty($config['value']['dependsOn']) && is_array($config['value']['dependsOn'])) { foreach ($config['value']['dependsOn'] as $d) { // Find the component it depends on and tell the ComponentCollection. $dependent = self::getComponentById($componentToData, $config['value']['id']); $dependency = self::getComponentById($componentToData, $d); if (!empty($dependent) && !empty($dependency)) { $collection->addDependency($dependent, $dependency); } } } } // Deal with results to be sent to the client. $resultValue = array(); $reports = $collection->check(); foreach ($reports as $r) { $component = $r->getComponent(); // For the retrieved component, what was the associated data and class ? $associatedData = null; $class = null; foreach ($componentToData as $ctd) { if ($component == $ctd['component']) { $associatedData = $ctd['data']; $class = $ctd['class']; } } $buildMethod = $class->getMethod('buildResult'); $serviceResult = $buildMethod->invoke(null, $associatedData, $r, $component); $resultValue[] = $serviceResult->getContent(); } // Sort by 'optional'. usort($resultValue, array('tao_install_services_CheckPHPConfigService', 'sortReports')); $resultData = json_encode(array('type' => 'ReportCollection', 'value' => '{RETURN_VALUE}')); $resultData = str_replace('"{RETURN_VALUE}"', '[' . implode(',', $resultValue) . ']', $resultData); $this->setResult(new tao_install_services_Data($resultData)); }