From 8e0ebc88d9f735ceb97d4ee81d5441cdf0c77d80 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 5 Feb 2018 16:33:49 -0500
Subject: [PATCH] Modernize SMS service. - Use interface name as service name.

---
 module/VuFind/config/module.config.php        |  3 ++-
 .../src/VuFind/Controller/AbstractRecord.php  |  2 +-
 module/VuFind/src/VuFind/SMS/Factory.php      | 19 ++++++++++---------
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php
index d01cc263cac..ec4c611fba4 100644
--- a/module/VuFind/config/module.config.php
+++ b/module/VuFind/config/module.config.php
@@ -342,7 +342,7 @@ $config = [
             'VuFind\Service\ReCaptcha' => 'VuFind\Service\ReCaptchaFactory',
             'VuFind\Session\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
             'VuFind\Session\Settings' => 'Zend\ServiceManager\Factory\InvokableFactory',
-            'VuFind\SMS' => 'VuFind\SMS\Factory',
+            'VuFind\SMS\SMSInterface' => 'VuFind\SMS\Factory',
             'VuFind\Solr\Writer' => 'VuFind\Solr\WriterFactory',
             'VuFind\Tags' => 'VuFind\Service\Factory::getTags',
             'VuFind\Translator' => 'VuFind\Service\Factory::getTranslator',
@@ -413,6 +413,7 @@ $config = [
             'VuFind\SearchTabsHelper' => 'VuFind\Search\SearchTabsHelper',
             'VuFind\SessionManager' => 'Zend\Session\SessionManager',
             'VuFind\SessionPluginManager' => 'VuFind\Session\PluginManager',
+            'VuFind\SMS' => 'VuFind\SMS\SMSInterface',
             'VuFind\YamlReader' => 'VuFind\Config\YamlReader',
         ],
     ],
diff --git a/module/VuFind/src/VuFind/Controller/AbstractRecord.php b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
index 57be64272ac..ed085cc8e7d 100644
--- a/module/VuFind/src/VuFind/Controller/AbstractRecord.php
+++ b/module/VuFind/src/VuFind/Controller/AbstractRecord.php
@@ -472,7 +472,7 @@ class AbstractRecord extends AbstractBase
         $driver = $this->loadRecord();
 
         // Load the SMS carrier list:
-        $sms = $this->serviceLocator->get('VuFind\SMS');
+        $sms = $this->serviceLocator->get('VuFind\SMS\SMSInterface');
         $view = $this->createViewModel();
         $view->carriers = $sms->getCarriers();
         $view->validation = $sms->getValidationType();
diff --git a/module/VuFind/src/VuFind/SMS/Factory.php b/module/VuFind/src/VuFind/SMS/Factory.php
index 91e8bc29057..8892f42a3fe 100644
--- a/module/VuFind/src/VuFind/SMS/Factory.php
+++ b/module/VuFind/src/VuFind/SMS/Factory.php
@@ -46,19 +46,20 @@ class Factory implements FactoryInterface
     /**
      * Create service
      *
-     * @param ContainerInterface $sm      Service manager
-     * @param string             $name    Requested service name (unused)
-     * @param array              $options Extra options (unused)
+     * @param ContainerInterface $container Service manager
+     * @param string             $name      Requested service name (unused)
+     * @param array              $options   Extra options (unused)
      *
      * @return SMSInterface
      *
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
      */
-    public function __invoke(ContainerInterface $sm, $name, array $options = null)
-    {
+    public function __invoke(ContainerInterface $container, $name,
+        array $options = null
+    ) {
         // Load configurations:
-        $mainConfig = $sm->get('VuFind\Config\PluginManager')->get('config');
-        $smsConfig = $sm->get('VuFind\Config\PluginManager')->get('sms');
+        $mainConfig = $container->get('VuFind\Config\PluginManager')->get('config');
+        $smsConfig = $container->get('VuFind\Config\PluginManager')->get('sms');
 
         // Determine SMS type:
         $type = isset($smsConfig->General->smsType)
@@ -67,10 +68,10 @@ class Factory implements FactoryInterface
         // Initialize object based on requested type:
         switch (strtolower($type)) {
         case 'clickatell':
-            $client = $sm->get('VuFindHttp\HttpService')->createClient();
+            $client = $container->get('VuFindHttp\HttpService')->createClient();
             return new Clickatell($smsConfig, ['client' => $client]);
         case 'mailer':
-            $options = ['mailer' => $sm->get('VuFind\Mailer\Mailer')];
+            $options = ['mailer' => $container->get('VuFind\Mailer\Mailer')];
             if (isset($mainConfig->Site->email)) {
                 $options['defaultFrom'] = $mainConfig->Site->email;
             }
-- 
GitLab