Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns a array of all configuration settings of the local server.
  * The list returned is an array of name/value pair arrays.
  *
  * @return array local server's configuration settings, false if can't get settings
  */
 public function execute()
 {
     $_settings = new M3_Util_PhpSettings();
     $_results = array();
     if ($_settings->readPhpFile($_results, true)) {
         $_nameValues = array();
         foreach ($_results as $_name => $_value) {
             $_nameValues[] = array('name' => $_name, 'value' => $_value);
         }
         return array('local_setting' => $_nameValues);
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 public function testWriteWithRuntimeValues()
 {
     $_php = new M3_Util_PhpSettings('PhpSettingsTestCase4.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 . '2' => "?>\n");
     $GLOBALS['g1'] = '"GONE REPLACEMENT"';
     $GLOBALS['str1'] = '"STR1 REPLACEMENT"';
     $_php->writePhpFileWithRuntimeValues($_data);
     $_contents = file_get_contents($_php->getConfigurationPathName());
     $this->assertEquals(1, preg_match('/\\n\\$GLOBALS\\[\'g1\'\\]="GONE REPLACEMENT";\\n/', $_contents), "bad 1");
     $this->assertEquals(1, preg_match('/\\n\\$GLOBALS\\[\'g2\'\\]=;\\n/', $_contents), "bad 2");
     $this->assertEquals(1, preg_match('/\\n\\$GLOBALS\\[\'str1\'\\]="STR1 REPLACEMENT";\\n/', $_contents), "bad 3");
     $this->assertEquals(1, preg_match('/\\n\\$GLOBALS\\[\'str2\'\\]=;\\n/', $_contents), "bad 4");
     $_php->readPhpFile($_readData);
     $this->assertArrayHasKey('GLOBALS[\'g1\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'g2\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'str1\']', $_readData);
     $this->assertArrayHasKey('GLOBALS[\'str2\']', $_readData);
     // remove test file
     unlink($_php->getConfigurationPathName());
 }