diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 88fbecf913598000f5a8ae91c1e42f06e8167406..91554c95d8c246315143322c3743faaa53feed5a 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -2,6 +2,11 @@ namespace finc\Module\Configuration; $config = [ + 'service_manager' => [ + 'factories' => [ + 'VuFind\Mailer' => 'finc\Mailer\Factory' + ] + ], 'controllers' => [ 'invokables' => [ 'my-research' => 'finc\Controller\MyResearchController', @@ -9,6 +14,11 @@ $config = [ ], 'vufind' => [ 'plugin_managers' => [ + 'auth' => [ + 'invokables' => [ + 'shibboleth' => 'finc\Auth\Shibboleth', + ], + ], 'ils_driver' => [ 'factories' => [ 'fincils' => 'finc\ILS\Driver\Factory::getFincILS', diff --git a/module/finc/src/finc/Mailer/Factory.php b/module/finc/src/finc/Mailer/Factory.php new file mode 100644 index 0000000000000000000000000000000000000000..d2707db21a48a3c217dc4b4c5c13a3a022ddc0b6 --- /dev/null +++ b/module/finc/src/finc/Mailer/Factory.php @@ -0,0 +1,85 @@ +<?php +/** + * Factory for instantiating Mailer objects + * + * PHP version 5 + * + * Copyright (C) Villanova University 2009. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Mailer + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + */ +namespace finc\Mailer; +use Zend\Mail\Transport\Smtp, Zend\Mail\Transport\SmtpOptions; +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Factory for instantiating Mailer objects + * + * @category VuFind2 + * @package Mailer + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:developer_manual Wiki + * + * @codeCoverageIgnore + */ +class Factory implements \Zend\ServiceManager\FactoryInterface +{ + /** + * Create service + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return mixed + */ + public function createService(ServiceLocatorInterface $sm) + { + // Load configurations: + $config = $sm->get('VuFind\Config')->get('config'); + + // Create mail transport: + $settings = [ + 'host' => $config->Mail->host, 'port' => $config->Mail->port + ]; + if (isset($config->Mail->username) && isset($config->Mail->password)) { + $settings['connection_class'] = 'login'; + $settings['connection_config'] = [ + 'username' => $config->Mail->username, + 'password' => $config->Mail->password + ]; + if (isset($config->Mail->secure)) { + // always set user defined secure connection + $settings['connection_config']['ssl'] = $config->Mail->secure; + } else { + // set default secure connection based on configured port + if ($settings['port'] == '587') { + $settings['connection_config']['ssl'] = 'tls'; + } elseif ($settings['port'] == '487') { + $settings['connection_config']['ssl'] = 'ssl'; + } + } + } + $transport = new Smtp(); + $transport->setOptions(new SmtpOptions($settings)); + + // Create service: + return new \VuFind\Mailer\Mailer($transport); + } +}