Esempio n. 1
0
 /**
  * 設定を読み込む
  *
  * @param string $mailType
  * @param string $to
  * @param string $subject
  * @return array
  * @throws \LibraryBundle\Exception\DataNotFoundException
  */
 private function _loadSetting($mailType, $to, $subject)
 {
     $setting = array('from' => null, 'fromLabel' => null, 'to' => $to, 'subject' => $subject, 'template' => null);
     // メッセージ設定取得
     $config = $this->container->get('lib.config_mail')->getData($mailType);
     // メーラー設定取得
     if (!$this->container->hasParameter('mailer')) {
         throw new \LibraryBundle\Exception\DataNotFoundException('parameters.mailを設定してください');
     }
     $mailer = $this->container->getParameter('mailer');
     // 送信元アカウント情報
     if (!isset($mailer[$config['account']])) {
         throw new \LibraryBundle\Exception\DataNotFoundException($config['account'] . 'を設定してください');
     }
     $account = $mailer[$config['account']];
     // 送信者
     $setting['from'] = $account['address'];
     // 返信先
     if (isset($account['reply'])) {
         $setting['reply'] = $account['reply'];
     }
     $setting['fromLabel'] = s_empty($account, 'label') ? $account['label'] : null;
     // 宛先
     // force_sendがtrueで設定されていない
     // 開発環境 or 開発サーバーだったら誤送信防止のためのメールアドレスへ飛ばす
     if ((!isset($config['force_send']) || $config['force_send'] === false) && (parent::isDevelopment() || parent::isDevelopmentServer())) {
         if (!isset($mailer['development_to'])) {
             throw new \LibraryBundle\Exception\DataNotFoundException('parameters.mailer.development_toを設定してください');
         }
         $setting['to'] = $mailer['development_to'];
     }
     // 件名
     // 件名がどこにもない場合Exception
     if (is_null($subject) && !s_empty($config, 'subject')) {
         throw new \LibraryBundle\Exception\DataNotFoundException('subjectを設定してください');
     } elseif (is_null($subject) && s_empty($config, 'subject')) {
         $setting['subject'] = $config['subject'];
     }
     // 本文テンプレート
     $setting['template'] = $config['template'];
     return $setting;
 }
Esempio n. 2
0
 /**
  * 開発環境のサーバーであるか判定します。
  * PRODでもメール送信等で開発環境用の判定を行いたい場合に使用してください。
  *
  * サーバーの区別にはIPを使用し、app/config.ymlのenvironment.server.prodによって判定を行います。
  * また一度判定を行ったら、$this->_isDevelopmentServerに結果をキャッシュし、以降はこれを使います。
  *
  * @return bool
  */
 protected final function isDevelopmentServer()
 {
     // パラメーターが設定されているかチェック
     if (!$this->container->hasParameter('environment')) {
         throw new \LibraryBundle\Exception\DataNotFoundException('parameters.environmentが設定されていません');
     }
     if (!is_null($this->_isDevelopmentServer)) {
         return $this->_isDevelopmentServer;
     }
     $environment = $this->container->getParameter('environment');
     if (isset($environment['prod'])) {
         $prod = $environment['prod'];
         // Web経由のアクセスでないとIPが取れないので、その場合だけチェック
         try {
             $ip = $this->container->get('request')->server->get('SERVER_ADDR');
             // IPでの判定
             if (s_empty($prod, 'ip')) {
                 if (!is_array($prod['ip'])) {
                     $prod['ip'] = array($prod['ip']);
                 }
                 // サーバーのIPが含まれいたら本番
                 if (in_array($ip, $prod['ip'])) {
                     return $this->_isDevelopmentServer = false;
                 }
             }
         } catch (\Symfony\Component\DependencyInjection\Exception\InactiveScopeException $e) {
             // CLIアクセスで取得できなかった場合スルー
         }
         // hostnameでの判定
         if (s_empty($prod, 'hostname')) {
             if (!is_array($prod['hostname'])) {
                 $prod['hostname'] = array($prod['hostname']);
             }
             // サーバーのホスト名が含まれていたら本番
             if (in_array(gethostname(), $prod['hostname'])) {
                 return $this->_isDevelopmentServer = false;
             }
         }
     }
     return $this->_isDevelopmentServer = true;
 }