common\ModulesSettings::set PHP Метод

set() публичный Метод

Store a module setting
public set ( string $module, string $key, mixed $value )
$module string The module wherefore a setting has to be stored.
$key string The name of the setting.
$value mixed The value to save
    public function set($module, $key, $value)
    {
        $valueToStore = serialize($value);
        $this->database->execute('INSERT INTO modules_settings(module, name, value)
             VALUES(?, ?, ?)
             ON DUPLICATE KEY UPDATE value = ?', array($module, $key, $valueToStore, $valueToStore));
        /*
         * Instead of invalidating the cache, we could also fetch existing
         * settings, update them & re-store them to cache. That would save
         * us the next query to repopulate the cache.
         * However, there could be race conditions where 2 concurrent
         * requests write at the same time and one ends up overwriting the
         * other (unless we do a CAS, but PSR-6 doesn't support that)
         * Clearing cache will be safe: in the case of concurrent requests
         * & cache being regenerated while the other is being saved, it will
         * be cleared again after saving the new setting!
         */
        $this->cache->deleteItems(array('settings'));
    }

Usage Example

 /**
  * @return bool
  */
 public function handle()
 {
     $this->form->cleanupFields();
     if (!$this->form->isSubmitted() || !$this->isValid()) {
         return false;
     }
     $this->settings->set('Analytics', 'web_property_id', $this->form->getField('web_property_id')->getValue());
     return true;
 }
All Usage Examples Of common\ModulesSettings::set