Esempio n. 1
0
 /**
  * @inheritdoc
  */
 protected function createTransport(array $config)
 {
     try {
         $this->_settings = Instance::ensure(Yii::$app->settings, Settings::className());
     } catch (InvalidConfigException $ex) {
         Yii::error("Couldn't load settings component! Fallback to standard mailer");
         $config['class'] = 'Swift_MailTransport';
         return parent::createTransport($config);
     }
     if ($this->_settings->get('email', 'is_smtp', false)) {
         $config['class'] = 'Swift_SmtpTransport';
         $config['host'] = $this->_settings->get('email', 'host', $config['host']);
         $config['port'] = $this->_settings->get('email', 'port', $config['port']);
         $config['username'] = $this->_settings->get('email', 'username', $config['username']);
         $config['password'] = $this->_settings->get('email', 'password', $config['password']);
         $config['encryption'] = $this->_settings->get('email', 'encryption', $config['encryption']);
     } else {
         $config['class'] = 'Swift_MailTransport';
     }
     return parent::createTransport($config);
 }
Esempio n. 2
0
 /**
  * Удаление настроек из кэша и опционально из БД.
  *
  * @param string $category название категории
  * @param string $key название ключа
  * @param bool|true $fromDatabase если установлено true, то удаляет и из БД. По умолчанию установлено true.
  * @return bool
  * @throws \yii\db\Exception
  */
 public function delete($category, $key, $fromDatabase = true)
 {
     if (empty($category) || empty($key)) {
         return false;
     }
     if ($fromDatabase) {
         $cmd = $this->db->createCommand();
         $cmd->delete($this->tableName, ['category' => $category, 'key' => $key]);
         $cmd->execute();
     }
     return Yii::$app->cache->delete(Settings::generateHash($category, $key));
 }