コード例 #1
0
 /**
  * Puts the new settings in the local server's configuration.
  * Returns true on success; an exception is thrown on error.
  */
 public function execute()
 {
     $_settings = new M3_Util_PhpSettings();
     $_results = array();
     if ($_settings->readPhpFile($_results, false)) {
         // overlay new settings that exist in the current configuration
         foreach (array_intersect_key($_results, $this->newSettings) as $_existingKey => $_existingValue) {
             $_results[$_existingKey] = $this->newSettings[$_existingKey];
         }
         // add new settings that don't yet exist in the current config (the existing variable might have been commented out)
         foreach (array_diff_key($this->newSettings, $_results) as $_newKey => $_newValue) {
             $_results[$_newKey] = $_newValue;
         }
         // remove existing settings that are no longer being set (we unset them by setting them to null)
         foreach (array_diff_key($_results, $this->newSettings) as $_oldKey => $_oldValue) {
             if (!($this->beginsWith($_oldKey, M3_Util_PhpSettings::UNPARSED) || $this->beginsWith($_oldKey, M3_Util_PhpSettings::NEWLINE))) {
                 $_results[$_oldKey] = "null";
             }
         }
         $_writeResults = $_settings->writePhpFile($_results);
         if ($_writeResults) {
             return true;
         } else {
             throw new OpenFBAPIException("Failed to write the new settings", -2);
         }
     } else {
         throw new OpenFBAPIException("Failed to read the settings file", -1);
     }
 }
コード例 #2
0
 public function testReadSetRuntimeValues()
 {
     $_php = new M3_Util_PhpSettings('PhpSettingsTestCase3.php');
     $_data = array(M3_Util_PhpSettings::UNPARSED . '0' => "<?php\n", 'GLOBALS[\'g1\']' => 'gone', 'GLOBALS[\'g2\']' => 'gtwo', 'GLOBALS[\'str1\']' => '"string here"', 'GLOBALS[\'str2\']' => '\'another string\'', M3_Util_PhpSettings::UNPARSED . '1' => "?>\n");
     $_php->writePhpFile($_data);
     $_php->readPhpFileSetRuntimeValues($_readData, true);
     $this->assertEquals(4, count($_readData));
     // does not include the two UNPARSED lines
     $this->assertArrayHasKey('GLOBALS[\'g1\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'g2\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'str1\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'str1\']', $_readData);
     $this->assertArrayNotHasKey(M3_Util_PhpSettings::UNPARSED . '0', $_readData);
     $this->assertArrayNotHasKey(M3_Util_PhpSettings::UNPARSED . '1', $_readData);
     $this->assertEquals($GLOBALS['g1'], "gone");
     $this->assertEquals($GLOBALS['g2'], "gtwo");
     $this->assertEquals($GLOBALS['str1'], "string here");
     $this->assertEquals($GLOBALS['str2'], "another string");
     unlink($_php->getConfigurationPathName());
 }