Revert "1. add edit event fails when save edited single provider recurring events...
[openemr.git] / vendor / zendframework / zend-mail / src / MessageFactory.php
blob9facf9db4c94c1bc1756ee44f3ed7bd6f82fc439
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mail;
12 use Traversable;
14 class MessageFactory
16 /**
17 * @param array|Traversable $options
18 * @return Message
20 public static function getInstance($options = [])
22 if (! is_array($options) && ! $options instanceof Traversable) {
23 throw new Exception\InvalidArgumentException(sprintf(
24 '"%s" expects an array or Traversable; received "%s"',
25 __METHOD__,
26 (is_object($options) ? get_class($options) : gettype($options))
27 ));
30 $message = new Message();
32 foreach ($options as $key => $value) {
33 $setter = self::getSetterMethod($key);
34 if (method_exists($message, $setter)) {
35 $message->{$setter}($value);
39 return $message;
42 /**
43 * Generate a setter method name based on a provided key.
45 * @param string $key
46 * @return string
48 private static function getSetterMethod($key)
50 return 'set'
51 . str_replace(
52 ' ',
53 '',
54 ucwords(
55 strtr(
56 $key,
58 '-' => ' ',
59 '_' => ' ',