setReadOnly() public method

Prevent any more modifications being made to this instance. Useful after merge() has been used to merge multiple Zend_Config objects into one object which should then not be modified again.
public setReadOnly ( )
Example #1
0
 /**
  * Combine the static info found in application.ini with the
  * dynamic info found in the Info table.
  *
  * @return void
  */
 protected function _initConfig()
 {
     $this->bootstrap('db');
     $this->bootstrap('locale');
     if (!class_exists('Model_Info')) {
         return;
     }
     try {
         $staticConfig = Zend_Registry::get('config');
         $infoModel = $this->_getInfoModel();
         $dynamicConfig = $infoModel->fetchAsConfig(null, APPLICATION_ENV);
         // Very sneakily bypass 'readOnly'
         if ($staticConfig->readOnly()) {
             $staticConfig = new Zend_Config($staticConfig->toArray(), APPLICATION_ENV, true);
         }
         $staticConfig->merge($dynamicConfig);
         $staticConfig->setReadOnly();
         Zend_Registry::set('config', $staticConfig);
     } catch (Exception $e) {
         $msg = $e->getMessage();
         if (strpos($msg, 'Unknown database') === false && strpos($msg, "doesn't exist") === false) {
             throw $e;
         }
     }
 }
 /**
  * @param boolean $enableDev
  */
 protected function setQuotaModuleEnableDev($enableDev)
 {
     $config = Registry::getConfig();
     $newConfig = new \Zend_Config($config->toArray(), true);
     $newConfig->quota->module->enableDev = $enableDev;
     $newConfig->setReadOnly();
     Registry::setConfig($newConfig);
 }
 public function _initConfig()
 {
     $config = new Zend_Config($this->getOptions(), true);
     $inifiles = array('app', 'cache', 'private');
     //TODO: only load cache.ini for models
     foreach ($inifiles as $file) {
         $inifile = APPLICATION_PATH . "/configs/{$file}.ini";
         if (is_readable($inifile)) {
             $config->merge(new Zend_Config_Ini($inifile));
         }
     }
     $config->setReadOnly();
     $this->setOptions($config->toArray());
     Zend_Registry::set('config', $config);
     define('DATE_DB', 'Y-m-d H:i:s');
 }
Example #4
0
 /**
  * Load both config files.
  *
  * @return Zend_Config
  */
 public function init()
 {
     $mainConfig = $this->_coreResource->init();
     $testConfigPath = APP_DIR . '/tests/config.ini';
     $config = new Zend_Config_Ini($testConfigPath);
     if (!Zend_Registry::isRegistered('test_config')) {
         Zend_Registry::set('test_config', $config->testing);
     }
     // Merging the configs allows us to override settings only for tests.
     if ($config->site instanceof Zend_Config) {
         $mainCopy = new Zend_Config($mainConfig->toArray(), true);
         $mainCopy->merge($config->site);
         $mainCopy->setReadOnly(true);
         $mainConfig = $mainCopy;
     }
     return $mainConfig;
 }
Example #5
0
 /**
  * ensure that modification is not allowed after calling setReadOnly()
  *
  */
 public function testSetReadOnly()
 {
     $configData = array('a' => 'a');
     $config = new Zend_Config($configData, true);
     $config->b = 'b';
     $config->setReadOnly();
     try {
         $config->c = 'c';
     } catch (Zend_Config_Exception $expected) {
         $this->assertContains('is read only', $expected->getMessage());
         return;
     }
     $this->fail('Expected read only exception has not been raised.');
 }
 /**
  * @group ZF-4728
  *
  */
 public function testSetReadOnlyAppliesToChildren()
 {
     $config = new Zend_Config($this->_all, true);
     $config->setReadOnly();
     $this->assertTrue($config->readOnly());
     $this->assertTrue($config->one->readOnly(), 'First level children are writable');
     $this->assertTrue($config->one->two->readOnly(), 'Second level children are writable');
 }
Example #7
0
    if (isset($arr['zend']['zend_path'])) {
        $zenddir = $arr['zend']['zend_path'];
    }
}
// Setup include path
//add zend directory to include path
set_include_path(get_include_path() . PATH_SEPARATOR . $zenddir);
// Initialize Zend Framework loader
require_once 'Zend/Loader/Autoloader.php';
// require_once 'services/Pdoconfig.php';
// require_once 'services/UserModel.php';
Zend_Loader_Autoloader::getInstance();
// Load configuration
$default_config = new Zend_Config(array("production" => false), true);
$default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
$default_config->setReadOnly();
$amf = $default_config->amf;
// Store configuration in the registry
Zend_Registry::set("amf-config", $amf);
// Initialize AMF Server
$server = new Zend_Amf_Server();
$server->setProduction($amf->production);
if (isset($amf->directories)) {
    $dirs = $amf->directories->toArray();
    foreach ($dirs as $dir) {
        // get the first character of the path.
        // If it does not start with slash then it implies that the path is relative to webroot. Else it will be treated as absolute path
        $length = strlen($dir);
        $firstChar = $dir;
        if ($length >= 1) {
            $firstChar = $dir[0];
Example #8
0
 /**
  * @param array $pathToValue
  */
 public static function removeValue(array $pathToValue)
 {
     $config = Registry::getConfig()->toArray();
     if (count($pathToValue) <= 0) {
         $config = array();
     } else {
         $configPart =& $config;
         foreach (array_slice($pathToValue, 0, -1) as $key) {
             if (!array_key_exists($key, $configPart)) {
                 return;
             }
             $configPart =& $configPart[$key];
         }
         unset($configPart[end($pathToValue)]);
     }
     $newConfig = new \Zend_Config($config, true);
     $newConfig->setReadOnly();
     Registry::setConfig($newConfig);
 }