mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 20:48:46 +02:00
N°4307 Replace SwiftMailer with Laminas-mail
This commit is contained in:
64
lib/laminas/laminas-mail/src/MessageFactory.php
Normal file
64
lib/laminas/laminas-mail/src/MessageFactory.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mail for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mail/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mail/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mail;
|
||||
|
||||
use Traversable;
|
||||
|
||||
class MessageFactory
|
||||
{
|
||||
/**
|
||||
* @param array|Traversable $options
|
||||
* @return Message
|
||||
*/
|
||||
public static function getInstance($options = [])
|
||||
{
|
||||
if (! is_array($options) && ! $options instanceof Traversable) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'"%s" expects an array or Traversable; received "%s"',
|
||||
__METHOD__,
|
||||
(is_object($options) ? get_class($options) : gettype($options))
|
||||
));
|
||||
}
|
||||
|
||||
$message = new Message();
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
$setter = self::getSetterMethod($key);
|
||||
if (method_exists($message, $setter)) {
|
||||
$message->{$setter}($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a setter method name based on a provided key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
private static function getSetterMethod($key)
|
||||
{
|
||||
return 'set'
|
||||
. str_replace(
|
||||
' ',
|
||||
'',
|
||||
ucwords(
|
||||
strtr(
|
||||
$key,
|
||||
[
|
||||
'-' => ' ',
|
||||
'_' => ' ',
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user