public static function buildComponent(tao_install_services_Data $data)
 {
     $content = json_decode($data->getContent(), true);
     $extensionName = $content['value']['name'];
     if (isset($content['value']['optional'])) {
         $optional = $content['value']['optional'];
     } else {
         $optional = false;
     }
     $ext = common_configuration_ComponentFactory::buildPHPExtension($extensionName, null, null, $optional);
     return $ext;
 }
 /**
  * Executes the main logic of the service.
  * @return tao_install_services_Data The result of the service execution.
  */
 public function execute()
 {
     $ext = common_configuration_ComponentFactory::buildPHPExtension('json');
     $report = $ext->check();
     // We fake JSON encoding for a gracefull response in any case.
     $json = $report->getStatus() == common_configuration_Report::VALID;
     if (!$json) {
         $data = '{"type": "SyncReport", "value": { "json": ' . ($json ? 'true' : 'false') . '}}';
     } else {
         $localesDir = dirname(__FILE__) . '/../../locales';
         $data = json_encode(array('type' => 'SyncReport', 'value' => array('json' => true, 'rootURL' => self::getRootUrl(), 'availableDrivers' => self::getAvailableDrivers(), 'availableLanguages' => self::getAvailableLanguages($localesDir), 'availableTimezones' => self::getAvailableTimezones())));
     }
     $this->setResult(new tao_install_services_Data($data));
 }
Beispiel #3
0
 public function testComponentFactory()
 {
     $component = common_configuration_ComponentFactory::buildPHPRuntime('5.0', '7.0.x', true);
     $this->assertIsA($component, 'common_configuration_PHPRuntime');
     $this->assertEquals($component->getMin(), '5.0');
     // 5.5.x will be replaced internally
     //$this->assertEquals($component->getMax(), '5.5.x');
     $this->assertTrue($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $component = common_configuration_ComponentFactory::buildPHPExtension('spl');
     $this->assertIsA($component, 'common_configuration_PHPExtension');
     $this->assertNull($component->getMin());
     $this->assertNull($component->getMax());
     $this->assertEquals($component->getName(), 'spl');
     $this->assertFalse($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $component = common_configuration_ComponentFactory::buildPHPExtension('spl', null, null, true);
     $this->assertIsA($component, 'common_configuration_PHPExtension');
     $this->assertEquals($component->getName(), 'spl');
     $this->assertTrue($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $component = common_configuration_ComponentFactory::buildPHPINIValue('magic_quotes_gpc', '0');
     $this->assertIsA($component, 'common_configuration_PHPINIValue');
     $this->assertEquals($component->getName(), 'magic_quotes_gpc');
     $this->assertFalse($component->isOptional());
     $component = common_configuration_ComponentFactory::buildPHPDatabaseDriver('pdo_mysql', true);
     $this->assertIsA($component, 'common_configuration_PHPDatabaseDriver');
     $this->assertEquals($component->getName(), 'pdo_mysql');
     $this->assertTrue($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $location = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ConfigurationTest.php';
     $component = common_configuration_ComponentFactory::buildFileSystemComponent($location, 'r');
     $this->assertIsA($component, 'common_configuration_FileSystemComponent');
     $this->assertFalse($component->isOptional());
     $this->assertEquals($component->getLocation(), $location);
     $this->assertEquals($component->getExpectedRights(), 'r');
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     // TAO Dependency
     /*$component = common_configuration_ComponentFactory::buildCustom('database_drivers', 'tao', false);
      	$this->assertIsA($component, 'common_configuration_Component');
      	$this->assertEquals($component->getName(), 'custom_tao_DatabaseDrivers');
      	$this->assertFalse($component->isOptional());*/
     $array = array('type' => 'PHPRuntime', 'value' => array('min' => '5.0', 'max' => '7.0.x', 'optional' => true));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_PHPRuntime');
     $this->assertEquals($component->getMin(), '5.0');
     // 5.5.x will be replaced internally
     // $this->assertEquals($component->getMax(), '5.5');
     $this->assertTrue($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $array = array('type' => 'PHPExtension', 'value' => array('name' => 'spl'));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_PHPExtension');
     $this->assertEquals($component->getName(), 'spl');
     $this->assertFalse($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     // 'Check' before the Component type is accepted.
     $array = array('type' => 'CheckPHPINIValue', 'value' => array('name' => 'magic_quotes_gpc', 'value' => '0'));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_PHPINIValue');
     $this->assertEquals($component->getName(), 'magic_quotes_gpc');
     $this->assertFalse($component->isOptional());
     $array = array('type' => 'PHPDatabaseDriver', 'value' => array('name' => 'pdo_mysql', 'optional' => true));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_PHPDatabaseDriver');
     $this->assertEquals($component->getName(), 'pdo_mysql');
     $this->assertTrue($component->isOptional());
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     $array = array('type' => 'FileSystemComponent', 'value' => array('location' => $location, 'rights' => 'r'));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_FileSystemComponent');
     $this->assertFalse($component->isOptional());
     $this->assertEquals($component->getLocation(), $location);
     $this->assertEquals($component->getExpectedRights(), 'r');
     $report = $component->check();
     $this->assertIsA($report, 'common_configuration_Report');
     $this->assertEquals($report->getStatus(), common_configuration_Report::VALID);
     // TAO Dependency
     /*
     $array = array('type' => 'Custom', 'value' => array('name' => 'database_drivers', 'extension' => 'tao', 'optional' => false));
     $component = common_configuration_ComponentFactory::buildFromArray($array);
     $this->assertIsA($component, 'common_configuration_Component');
     $this->assertEquals($component->getName(), 'custom_tao_DatabaseDrivers');
     $this->assertFalse($component->isOptional());
     
     try{
     	$array = array('type' => 'Custom', 'value' => array('name' => 'mod_rewrite'));
     	$component = common_configuration_ComponentFactory::buildFromArray($array);
     	$this->assertTrue(false, 'An exception should be raised because mod_rewrite check does not exist for default extension generis.');
     }
     catch (common_configuration_ComponentFactoryException $e){
     	$this->assertTrue(true);
     }
     */
     try {
         $array = array('type' => 'PHPINIValue', 'value' => array());
         $component = common_configuration_ComponentFactory::buildFromArray($array);
         $this->assertTrue(false, 'An exception should be raised because of missing attributes.');
     } catch (common_configuration_ComponentFactoryException $e) {
         $this->assertTrue(true);
     }
 }