From f270c7700fe81869169912606abd34751e808929 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 14 Sep 2012 11:08:08 -0400
Subject: [PATCH] Mailer and SMS objects are now loaded through the service
 manager.

---
 module/VuFind/config/module.config.php              |  2 ++
 .../VuFind/src/VuFind/Controller/AbstractRecord.php | 13 ++++++-------
 .../VuFind/src/VuFind/Controller/AjaxController.php | 13 +++++--------
 .../VuFind/src/VuFind/Controller/CartController.php |  5 ++---
 .../src/VuFind/Controller/SearchController.php      |  5 ++---
 module/VuFind/src/VuFind/Log/Logger.php             |  5 ++---
 module/VuFind/src/VuFind/Mailer/SMS.php             |  5 ++---
 7 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index 4fd2782a9b7..812fdb630f9 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -288,9 +288,11 @@ $config = array(
             'authmanager' => 'VuFind\Auth\Manager',
             'cart' => 'VuFind\Cart',
             'cachemanager' => 'VuFind\Cache\Manager',
+            'mailer' => 'VuFind\Mailer',
             'recordloader' => 'VuFind\Record\Loader',
             'searchspecsreader' => 'VuFind\Config\SearchSpecsReader',
             'sessionmanager' => 'Zend\Session\SessionManager',
+            'sms' => 'VuFind\Mailer\SMS',
         )
     ),
     'session_plugin_manager' => array(
diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
index 316cc15ba92..53f56576088 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
@@ -26,8 +26,8 @@
  * @link     http://vufind.org/wiki/building_a_recommendations_module Wiki
  */
 namespace VuFind\Controller;
-use VuFind\Exception\Mail as MailException, VuFind\Export, VuFind\Mailer,
-    VuFind\Mailer\SMS, VuFind\Record\Router as RecordRouter,
+use VuFind\Exception\Mail as MailException, VuFind\Export,
+    VuFind\Record\Router as RecordRouter,
     Zend\Session\Container as SessionContainer;
 
 /**
@@ -307,8 +307,7 @@ class AbstractRecord extends AbstractBase
 
             // Attempt to send the email and show an appropriate flash message:
             try {
-                $mailer = new Mailer();
-                $mailer->sendRecord(
+                $this->getServiceLocator()->get('Mailer')->sendRecord(
                     $view->to, $view->from, $view->message, $driver,
                     $this->getViewRenderer()
                 );
@@ -337,9 +336,9 @@ class AbstractRecord extends AbstractBase
         $driver = $this->loadRecord();
 
         // Load the SMS carrier list:
-        $mailer = new SMS();
+        $sms = $this->getServiceLocator()->get('SMS');
         $view = $this->createViewModel();
-        $view->carriers = $mailer->getCarriers();
+        $view->carriers = $sms->getCarriers();
 
         // Process form submission:
         if ($this->params()->fromPost('submit')) {
@@ -349,7 +348,7 @@ class AbstractRecord extends AbstractBase
 
             // Attempt to send the email and show an appropriate flash message:
             try {
-                $mailer->textRecord(
+                $sms->textRecord(
                     $view->provider, $view->to, $driver, $this->getViewRenderer()
                 );
                 $this->flashMessenger()->setNamespace('info')
diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php
index d2a75c23f29..d5080ead799 100644
--- a/module/VuFind/src/VuFind/Controller/AjaxController.php
+++ b/module/VuFind/src/VuFind/Controller/AjaxController.php
@@ -28,8 +28,8 @@
 namespace VuFind\Controller;
 use VuFind\Config\Reader as ConfigReader,
     VuFind\Connection\Manager as ConnectionManager,
-    VuFind\Exception\Auth as AuthException, VuFind\Export, VuFind\Mailer,
-    VuFind\Mailer\SMS, VuFind\Translator\Translator;
+    VuFind\Exception\Auth as AuthException, VuFind\Export,
+    VuFind\Translator\Translator;
 
 /**
  * This controller handles global AJAX functionality
@@ -940,8 +940,7 @@ class AjaxController extends AbstractBase
                 $this->params()->fromPost('id'),
                 $this->params()->fromPost('source', 'VuFind')
             );
-            $mailer = new SMS();
-            $mailer->textRecord(
+            $this->getServiceLocator()->get('SMS')->textRecord(
                 $this->params()->fromPost('provider'),
                 $this->params()->fromPost('to'), $record, $this->getViewRenderer()
             );
@@ -969,8 +968,7 @@ class AjaxController extends AbstractBase
                 $this->params()->fromPost('id'),
                 $this->params()->fromPost('source', 'VuFind')
             );
-            $mailer = new Mailer();
-            $mailer->sendRecord(
+            $this->getServiceLocator()->get('Mailer')->sendRecord(
                 $this->params()->fromPost('to'), $this->params()->fromPost('from'),
                 $this->params()->fromPost('message'), $record,
                 $this->getViewRenderer()
@@ -1002,8 +1000,7 @@ class AjaxController extends AbstractBase
 
         // Attempt to send the email:
         try {
-            $mailer = new Mailer();
-            $mailer->sendLink(
+            $this->getServiceLocator()->get('Mailer')->sendLink(
                 $this->params()->fromPost('to'), $this->params()->fromPost('from'),
                 $this->params()->fromPost('message'),
                 $url, $this->getViewRenderer(), $this->params()->fromPost('subject')
diff --git a/module/VuFind/src/VuFind/Controller/CartController.php b/module/VuFind/src/VuFind/Controller/CartController.php
index 3ac4864703c..5caf4cc3a0f 100644
--- a/module/VuFind/src/VuFind/Controller/CartController.php
+++ b/module/VuFind/src/VuFind/Controller/CartController.php
@@ -26,7 +26,7 @@
  * @link     http://vufind.org   Main Site
  */
 namespace VuFind\Controller;
-use VuFind\Exception\Mail as MailException, VuFind\Export, VuFind\Mailer,
+use VuFind\Exception\Mail as MailException, VuFind\Export,
     VuFind\Translator\Translator, Zend\Session\Container as SessionContainer;
 
 /**
@@ -192,8 +192,7 @@ class CartController extends AbstractBase
             // Attempt to send the email and show an appropriate flash message:
             try {
                 // If we got this far, we're ready to send the email:
-                $mailer = new Mailer();
-                $mailer->sendLink(
+                $this->getServiceLocator()->get('Mailer')->sendLink(
                     $view->to, $view->from, $view->message,
                     $url, $this->getViewRenderer(), 'bulk_email_title'
                 );
diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php
index d38b92aabfd..2245f04c87e 100644
--- a/module/VuFind/src/VuFind/Controller/SearchController.php
+++ b/module/VuFind/src/VuFind/Controller/SearchController.php
@@ -29,7 +29,7 @@ namespace VuFind\Controller;
 
 use VuFind\Config\Reader as ConfigReader,
     VuFind\Connection\Manager as ConnectionManager,
-    VuFind\Exception\Mail as MailException, VuFind\Mailer, VuFind\Search\Memory,
+    VuFind\Exception\Mail as MailException, VuFind\Search\Memory,
     VuFind\Solr\Utils as SolrUtils;
 
 /**
@@ -100,8 +100,7 @@ class SearchController extends AbstractSearch
             // Attempt to send the email and show an appropriate flash message:
             try {
                 // If we got this far, we're ready to send the email:
-                $mailer = new Mailer();
-                $mailer->sendLink(
+                $this->getServiceLocator()->get('Mailer')->sendLink(
                     $view->to, $view->from, $view->message,
                     $view->url, $this->getViewRenderer()
                 );
diff --git a/module/VuFind/src/VuFind/Log/Logger.php b/module/VuFind/src/VuFind/Log/Logger.php
index c78d3c56e28..c3b3f220fca 100644
--- a/module/VuFind/src/VuFind/Log/Logger.php
+++ b/module/VuFind/src/VuFind/Log/Logger.php
@@ -26,8 +26,7 @@
  * @link     http://vufind.org   Main Site
  */
 namespace VuFind\Log;
-use VuFind\Mailer,
-    Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter,
+use Zend\Db\TableGateway\Feature\GlobalAdapterFeature as DbGlobalAdapter,
     Zend\Log\Logger as BaseLogger,
     Zend\ServiceManager\ServiceLocatorAwareInterface,
     Zend\ServiceManager\ServiceLocatorInterface;
@@ -123,7 +122,7 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface
             $error_types = isset($parts[1]) ? $parts[1] : '';
 
             // use smtp
-            $mailer = new Mailer(null, $config);
+            $mailer = $this->getServiceLocator()->get('Mailer');
             $msg = $mailer->getNewMessage()
                 ->addFrom($config->Site->email)
                 ->addTo($email)
diff --git a/module/VuFind/src/VuFind/Mailer/SMS.php b/module/VuFind/src/VuFind/Mailer/SMS.php
index a6325bb4d28..1428012a765 100644
--- a/module/VuFind/src/VuFind/Mailer/SMS.php
+++ b/module/VuFind/src/VuFind/Mailer/SMS.php
@@ -26,8 +26,7 @@
  * @link     http://vufind.org/wiki/system_classes Wiki
  */
 namespace VuFind\Mailer;
-use VuFind\Config\Reader as ConfigReader, VuFind\Exception\Mail as MailException,
-    VuFind\Mailer;
+use VuFind\Config\Reader as ConfigReader, VuFind\Exception\Mail as MailException;
 
 /**
  * VuFind Mailer Class for SMS messages
@@ -38,7 +37,7 @@ use VuFind\Config\Reader as ConfigReader, VuFind\Exception\Mail as MailException
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://vufind.org/wiki/system_classes Wiki
  */
-class SMS extends Mailer
+class SMS extends \VuFind\Mailer
 {
     // Defaults, usually overridden by contents of sms.ini:
     protected $carriers = array(
-- 
GitLab