Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
Factory
n/a
0 / 0
n/a
0 / 0
5
n/a
0 / 0
 __invoke
n/a
0 / 0
n/a
0 / 0
5
1<?php
2
3/**
4 * Factory for instantiating SMS objects
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2009.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  SMS
25 * @author   Ronan McHugh <vufind-tech@lists.sourceforge.net>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development Wiki
28 */
29
30namespace VuFind\SMS;
31
32use Laminas\ServiceManager\Factory\FactoryInterface;
33use Psr\Container\ContainerInterface;
34
35/**
36 * Factory for instantiating SMS objects
37 *
38 * @category VuFind
39 * @package  SMS
40 * @author   Ronan McHugh <vufind-tech@lists.sourceforge.net>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development Wiki
43 *
44 * @codeCoverageIgnore
45 */
46class Factory implements FactoryInterface
47{
48    /**
49     * Create service
50     *
51     * @param ContainerInterface $container Service manager
52     * @param string             $name      Requested service name (unused)
53     * @param array              $options   Extra options (unused)
54     *
55     * @return SMSInterface
56     *
57     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
58     */
59    public function __invoke(
60        ContainerInterface $container,
61        $name,
62        array $options = null
63    ) {
64        // Load configurations:
65        $configManager = $container->get(\VuFind\Config\PluginManager::class);
66        $mainConfig = $configManager->get('config');
67        $smsConfig = $configManager->get('sms');
68
69        // Determine SMS type:
70        $type = $smsConfig->General->smsType ?? 'Mailer';
71
72        // Initialize object based on requested type:
73        switch (strtolower($type)) {
74            case 'clickatell':
75                $client = $container->get(\VuFindHttp\HttpService::class)
76                    ->createClient();
77                return new Clickatell($smsConfig, ['client' => $client]);
78            case 'mailer':
79                $options = [
80                    'mailer' => $container->get(\VuFind\Mailer\Mailer::class),
81                ];
82                if (isset($mainConfig->Site->email)) {
83                    $options['defaultFrom'] = $mainConfig->Site->email;
84                }
85                return new Mailer($smsConfig, $options);
86            default:
87                throw new \Exception('Unrecognized SMS type: ' . $type);
88        }
89    }
90}