AbstractTransport.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ Y7oXnezjmjKedSNg5/C200cARbcE7w2Bq94ZIHf6EAA=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.2
  11. */
  12. /**
  13. * mailer transport abstract class
  14. */
  15. namespace Cube\Mail\Transport;
  16. use Cube\Mail;
  17. abstract class AbstractTransport
  18. {
  19. /**
  20. *
  21. * mail object
  22. *
  23. * @var \Cube\Mail
  24. */
  25. protected $_mail;
  26. /**
  27. *
  28. * options array
  29. *
  30. * @var array
  31. */
  32. protected $_options;
  33. /**
  34. *
  35. * class constructor
  36. *
  37. * @param array $options
  38. */
  39. public function __construct(array $options = null)
  40. {
  41. $this->setOptions($options);
  42. }
  43. /**
  44. *
  45. * get options array
  46. *
  47. * @return array
  48. */
  49. public function getOptions()
  50. {
  51. return $this->_options;
  52. }
  53. /**
  54. *
  55. * set options array
  56. * override to accommodate smtp settings
  57. *
  58. * @param array $options
  59. *
  60. * @return $this
  61. */
  62. public function setOptions($options)
  63. {
  64. $this->_options = (array)$options;
  65. foreach ($this->_options as $key => $value) {
  66. $methodName = 'set' . ucfirst($key);
  67. if (method_exists($this, $methodName)) {
  68. $this->$methodName($value);
  69. }
  70. }
  71. return $this;
  72. }
  73. /**
  74. *
  75. * get mail object
  76. *
  77. * @throws \RuntimeException
  78. * @return \Cube\Mail
  79. */
  80. public function getMail()
  81. {
  82. if (!$this->_mail instanceof Mail) {
  83. throw new \RuntimeException("An object of type \Cube\Mail
  84. is required by the mail transport class.");
  85. }
  86. return $this->_mail;
  87. }
  88. /**
  89. *
  90. * set mail object
  91. *
  92. * @param \Cube\Mail $mail
  93. *
  94. * @return \Cube\Mail\Transport\AbstractTransport
  95. */
  96. public function setMail(Mail $mail)
  97. {
  98. $this->_mail = $mail;
  99. return $this;
  100. }
  101. abstract public function send();
  102. }