[Beeframework-svn] SF.net SVN: beeframework:[100] trunk
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2013-10-15 17:17:25
|
Revision: 100
http://sourceforge.net/p/beeframework/code/100
Author: m_plomer
Date: 2013-10-15 17:17:20 +0000 (Tue, 15 Oct 2013)
Log Message:
-----------
- extracted PhpMailerWrapper base class out of SmartyMailer as a base class for PHPMailer based classes
- added smarty and phpmailer as require-dev dependencies
Modified Paths:
--------------
trunk/composer.json
trunk/framework/Bee/Utils/SmartyMailer.php
Added Paths:
-----------
trunk/framework/Bee/Utils/PhpMailerWrapper.php
Modified: trunk/composer.json
===================================================================
--- trunk/composer.json 2013-09-30 20:49:26 UTC (rev 99)
+++ trunk/composer.json 2013-10-15 17:17:20 UTC (rev 100)
@@ -21,6 +21,10 @@
"niktux/addendum": "0.4.1",
"apache/log4php": "~2.3@stable"
},
+ "require-dev": {
+ "smarty/smarty": "~3.1@stable",
+ "phpmailer/phpmailer": "~5@stable"
+ },
"minimum-stability": "RC",
"autoload": {
"psr-0": {
Added: trunk/framework/Bee/Utils/PhpMailerWrapper.php
===================================================================
--- trunk/framework/Bee/Utils/PhpMailerWrapper.php (rev 0)
+++ trunk/framework/Bee/Utils/PhpMailerWrapper.php 2013-10-15 17:17:20 UTC (rev 100)
@@ -0,0 +1,350 @@
+<?php
+
+namespace Bee\Utils;
+
+use Bee_Utils_Strings;
+use Exception;
+use PHPMailer;
+
+
+/**
+ * Class PhpMailerWrapper
+ * @package Bee\Utils
+ */
+class PhpMailerWrapper {
+
+ /**
+ * Enter description here...
+ *
+ * @var string
+ */
+ private $smtpHost;
+
+ /**
+ * Enter description here...
+ *
+ * @var int
+ */
+ private $smtpPort = 25;
+
+ /**
+ * Enter description here...
+ *
+ * @var string
+ */
+ private $smtpUsername;
+
+ /**
+ * Enter description here...
+ *
+ * @var string
+ */
+ private $smtpPassword;
+
+ /**
+ * @var string
+ */
+ private $smtpSecurity;
+
+ /**
+ * Enter description here...
+ *
+ * @var string
+ */
+ private $defaultSenderAddress;
+
+ /**
+ * Enter description here...
+ *
+ * @var string
+ */
+ private $defaultSenderName;
+
+ /**
+ * @var string
+ */
+ private $defaultRecipientAddress;
+
+ /**
+ * @var string
+ */
+ private $defaultRecipientName;
+
+ /**
+ * @var string
+ */
+ private $mailType = 'mail';
+
+ /**
+ * Enter description here...
+ *
+ * @return string
+ */
+ public final function getSmtpHost() {
+ return $this->smtpHost;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $smtpHost
+ * @return void
+ */
+ public final function setSmtpHost($smtpHost) {
+ $this->smtpHost = $smtpHost;
+ }
+
+ /**
+ * Gets the SmtpPort
+ *
+ * @return int $smtpPort
+ */
+ public function getSmtpPort() {
+ return $this->smtpPort;
+ }
+
+ /**
+ * Sets the SmtpPort
+ *
+ * @param int $smtpPort
+ * @return void
+ */
+ public function setSmtpPort($smtpPort) {
+ $this->smtpPort = $smtpPort;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @return string
+ */
+ public final function getSmtpUsername() {
+ return $this->smtpUsername;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $smtpUsername
+ * @return void
+ */
+ public final function setSmtpUsername($smtpUsername) {
+ $this->smtpUsername = $smtpUsername;
+ }
+
+ /**
+ * Gets the SmtpPassword
+ *
+ * @return string $smtpPassword
+ */
+ public function getSmtpPassword() {
+ return $this->smtpPassword;
+ }
+
+ /**
+ * Sets the SmtpPassword
+ *
+ * @param string $smtpPassword
+ * @return void
+ */
+ public function setSmtpPassword($smtpPassword) {
+ $this->smtpPassword = $smtpPassword;
+ }
+
+ /**
+ * Gets the SmtpSecurity
+ *
+ * @return string $smtpSecurity
+ */
+ public function getSmtpSecurity() {
+ return $this->smtpSecurity;
+ }
+
+ /**
+ * Sets the SmtpSecurity
+ *
+ * @param string $smtpSecurity
+ * @return void
+ */
+ public function setSmtpSecurity($smtpSecurity) {
+ $this->smtpSecurity = $smtpSecurity;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @return string
+ */
+ public final function getDefaultSenderAddress() {
+ return $this->defaultSenderAddress;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $defaultSenderAddress
+ */
+ public final function setDefaultSenderAddress($defaultSenderAddress) {
+ $this->defaultSenderAddress = $defaultSenderAddress;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @return string
+ */
+ public final function getDefaultSenderName() {
+ return $this->defaultSenderName;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $defaultSenderName
+ * @return void
+ */
+ public final function setDefaultSenderName($defaultSenderName) {
+ $this->defaultSenderName = $defaultSenderName;
+ }
+
+ /**
+ * Gets the DefaultRecipientAddress
+ *
+ * @return string $defaultRecipientAddress
+ */
+ public function getDefaultRecipientAddress() {
+ return $this->defaultRecipientAddress;
+ }
+
+ /**
+ * Sets the DefaultRecipientAddress
+ *
+ * @param string $defaultRecipientAddress
+ * @return void
+ */
+ public function setDefaultRecipientAddress($defaultRecipientAddress) {
+ $this->defaultRecipientAddress = $defaultRecipientAddress;
+ }
+
+ /**
+ * Gets the DefaultRecipientName
+ *
+ * @return string $defaultRecipientName
+ */
+ public function getDefaultRecipientName() {
+ return $this->defaultRecipientName;
+ }
+
+ /**
+ * Sets the DefaultRecipientName
+ *
+ * @param string $defaultRecipientName
+ * @return void
+ */
+ public function setDefaultRecipientName($defaultRecipientName) {
+ $this->defaultRecipientName = $defaultRecipientName;
+ }
+
+ /**
+ * Gets the MailType
+ *
+ * @return string $mailType
+ */
+ public function getMailType() {
+ return $this->mailType;
+ }
+
+ /**
+ * Sets the MailType
+ *
+ * @param string $mailType
+ * @return void
+ */
+ public function setMailType($mailType) {
+ $this->mailType = $mailType;
+ }
+
+ protected function createMailer($sender, $recipient, $charSet = 'UTF-8', $html = true) {
+ $phpMailer = new PHPMailer(true);
+ $phpMailer->CharSet = $charSet;
+ $phpMailer->IsHTML($html);
+
+ // SET CONNECTION
+ switch ($this->getMailType()) {
+ case 'smtp' :
+ $phpMailer->IsSMTP();
+ $phpMailer->Host = $this->getSmtpHost();
+ $phpMailer->Port = intval($this->getSmtpPort());
+
+ if (Bee_Utils_Strings::hasText($this->getSmtpUsername())) {
+ $phpMailer->SMTPAuth = true;
+ $phpMailer->Username = $this->getSmtpUsername();
+ $phpMailer->Password = $this->getSmtpPassword();
+
+ if (Bee_Utils_Strings::hasText($this->getSmtpSecurity())) {
+ $phpMailer->SMTPSecure = $this->getSmtpSecurity();
+ }
+ } else {
+ }
+ break;
+
+ case 'mail' :
+ $phpMailer->IsMail();
+ break;
+ }
+
+
+ // SET RECIPIENT
+ if (is_null($recipient)) {
+ $recipient = array();
+ $recipient['address'] = $this->getDefaultRecipientAddress();
+ $recipient['name'] = $this->getDefaultRecipientName();
+ }
+
+ if (is_string($recipient)) {
+ $phpMailer->AddAddress($recipient);
+
+ } else if (is_array($recipient)) {
+ if (!array_key_exists('address', $recipient)) {
+ throw new Exception('SmartyMailer failed: mailformed recipient. Field not found: "address"');
+ }
+
+ if (array_key_exists('name', $recipient)) {
+ $phpMailer->AddAddress($recipient['address'], $recipient['name']);
+ } else {
+ $phpMailer->AddAddress($recipient['address'], $recipient['name']);
+ }
+
+ } else {
+ throw new Exception('SmartyMailer failed: mailformed recipient. Type-mismatch. Recipient must be either string or array, but is: "' . gettype($recipient) . '" instead.');
+ }
+
+
+ // SET SENDER
+ if (is_null($sender)) {
+ $sender = array();
+ $sender['address'] = $this->getDefaultSenderAddress();
+ $sender['name'] = $this->getDefaultSenderName();
+ }
+
+ if (is_string($sender)) {
+ $phpMailer->SetFrom($sender);
+
+ } else if (is_array($sender)) {
+ if (!array_key_exists('address', $sender)) {
+ throw new Exception('SmartyMailer failed: mailformed sender. Field not found: "address"');
+ }
+
+ if (array_key_exists('name', $sender)) {
+ $phpMailer->SetFrom($sender['address'], $sender['name']);
+ } else {
+ $phpMailer->SetFrom($sender['address'], $sender['name']);
+ }
+
+ } else {
+ throw new Exception('SmartyMailer failed: mailformed sender. Type-mismatch. Sender must be either string or array, but is: "' . gettype($sender) . '" instead.');
+ }
+
+ return $phpMailer;
+ }
+}
\ No newline at end of file
Modified: trunk/framework/Bee/Utils/SmartyMailer.php
===================================================================
--- trunk/framework/Bee/Utils/SmartyMailer.php 2013-09-30 20:49:26 UTC (rev 99)
+++ trunk/framework/Bee/Utils/SmartyMailer.php 2013-10-15 17:17:20 UTC (rev 100)
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+use Bee\Utils\PhpMailerWrapper;
/**
* @throws Exception
*
*/
-class Bee_Utils_SmartyMailer {
+class Bee_Utils_SmartyMailer extends PhpMailerWrapper {
private $pluginDir;
@@ -29,68 +30,7 @@
*/
private $smarty;
- /**
- * Enter description here...
- *
- * @var String
- */
- private $smtpHost;
-
- /**
- * Enter description here...
- *
- * @var String
- */
- private $smtpPort = 25;
-
- /**
- * Enter description here...
- *
- * @var String
- */
- private $smtpUsername;
-
- /**
- * Enter description here...
- *
- * @var String
- */
- private $smtpPassword;
-
/**
- * @var string
- */
- private $smtpSecurity;
-
- /**
- * Enter description here...
- *
- * @var String
- */
- private $defaultSenderAddress;
-
- /**
- * Enter description here...
- *
- * @var String
- */
- private $defaultSenderName;
-
- /**
- * @var string
- */
- private $defaultRecipientAddress;
-
- /**
- * @var string
- */
- private $defaultRecipientName;
-
-
- private $mailType = 'mail';
-
-
- /**
* @param $subjectTemplate
* @param $bodyTemplate
* @param array $model
@@ -136,99 +76,19 @@
}
- /**
- * @param $subjectTemplate
- * @param $bodyTemplate
- * @param array $model
- * @param mixed $recipient Either string ex...@ma... or array with keys "address" and optional "name"
- * @param mixed $sender Either string ex...@ma... or array with keys "address" and optional "name"
- *
- * @return PHPMailer
- */
+ /**
+ * @param $subjectTemplate
+ * @param $bodyTemplate
+ * @param array $model
+ * @param mixed $recipient Either string ex...@ma... or array with keys "address" and optional "name"
+ * @param mixed $sender Either string ex...@ma... or array with keys "address" and optional "name"
+ *
+ * @throws Exception
+ * @return \PHPMailer
+ */
public function instantiatePhpMailer($subjectTemplate, $bodyTemplate, array $model, $recipient=null, $sender=null) {
- $phpMailer = new PHPMailer(true);
- $phpMailer->PluginDir = $this->getPluginDir();
- $phpMailer->CharSet = 'UTF-8';
- $phpMailer->IsHTML(true);
+ $phpMailer = $this->createMailer($sender, $recipient);
-
- // SET CONNECTION
- switch ($this->getMailType()) {
- case 'smtp' :
- $phpMailer->IsSMTP();
- $phpMailer->Host = $this->getSmtpHost();
- $phpMailer->Port = intval($this->getSmtpPort());
-
- if (Bee_Utils_Strings::hasText($this->getSmtpUsername())) {
- $phpMailer->SMTPAuth = true;
- $phpMailer->Username = $this->getSmtpUsername();
- $phpMailer->Password = $this->getSmtpPassword();
-
- if (Bee_Utils_Strings::hasText($this->getSmtpSecurity())) {
- $phpMailer->SMTPSecure = $this->getSmtpSecurity();
- }
- } else {
- }
- break;
-
- case 'mail' :
- $phpMailer->IsMail();
- break;
- }
-
-
- // SET RECIPIENT
- if (is_null($recipient)) {
- $recipient = array();
- $recipient['address'] = $this->getDefaultRecipientAddress();
- $recipient['name'] = $this->getDefaultRecipientName();
- }
-
- if (is_string($recipient)) {
- $phpMailer->AddAddress($recipient);
-
- } else if (is_array($recipient)) {
- if (!array_key_exists('address', $recipient)) {
- throw new Exception('SmartyMailer failed: mailformed recipient. Field not found: "address"');
- }
-
- if (array_key_exists('name', $recipient)) {
- $phpMailer->AddAddress($recipient['address'], $recipient['name']);
- } else {
- $phpMailer->AddAddress($recipient['address'], $recipient['name']);
- }
-
- } else {
- throw new Exception('SmartyMailer failed: mailformed recipient. Type-mismatch. Recipient must be either string or array, but is: "'.gettype($recipient).'" instead.');
- }
-
-
- // SET SENDER
- if (is_null($sender)) {
- $sender = array();
- $sender['address'] = $this->getDefaultSenderAddress();
- $sender['name'] = $this->getDefaultSenderName();
- }
-
- if (is_string($sender)) {
- $phpMailer->SetFrom($sender);
-
- } else if (is_array($sender)) {
- if (!array_key_exists('address', $sender)) {
- throw new Exception('SmartyMailer failed: mailformed sender. Field not found: "address"');
- }
-
- if (array_key_exists('name', $sender)) {
- $phpMailer->SetFrom($sender['address'], $sender['name']);
- } else {
- $phpMailer->SetFrom($sender['address'], $sender['name']);
- }
-
- } else {
- throw new Exception('SmartyMailer failed: mailformed sender. Type-mismatch. Sender must be either string or array, but is: "'.gettype($sender).'" instead.');
- }
-
-
// SET CONTENT
$this->smarty->clearAllAssign();
foreach($model as $key => $value) {
@@ -240,8 +100,6 @@
return $phpMailer;
}
-
-
//=== GETTERS & SETTERS ============================================================================================
/**
* Gets the PluginDir
@@ -278,194 +136,4 @@
public final function setSmarty(Smarty $smarty) {
$this->smarty = $smarty;
}
-
- /**
- * Enter description here...
- *
- * @return String
- */
- public final function getSmtpHost() {
- return $this->smtpHost;
- }
-
- /**
- * Enter description here...
- *
- * @param String $smtpHost
- * @return void
- */
- public final function setSmtpHost($smtpHost) {
- $this->smtpHost = $smtpHost;
- }
-
- /**
- * Gets the SmtpPort
- *
- * @return $smtpPort
- */
- public function getSmtpPort() {
- return $this->smtpPort;
- }
-
- /**
- * Sets the SmtpPort
- *
- * @param $smtpPort
- * @return void
- */
- public function setSmtpPort($smtpPort) {
- $this->smtpPort = $smtpPort;
- }
-
- /**
- * Enter description here...
- *
- * @return String
- */
- public final function getDefaultSenderAddress() {
- return $this->defaultSenderAddress;
- }
-
- /**
- * Enter description here...
- *
- * @param String $defaultSenderAddress
- */
- public final function setDefaultSenderAddress($defaultSenderAddress) {
- $this->defaultSenderAddress = $defaultSenderAddress;
- }
-
- /**
- * Enter description here...
- *
- * @return String
- */
- public final function getDefaultSenderName() {
- return $this->defaultSenderName;
- }
-
- /**
- * Enter description here...
- *
- * @param String $defaultSenderName
- * @return void
- */
- public final function setDefaultSenderName($defaultSenderName) {
- $this->defaultSenderName = $defaultSenderName;
- }
-
- /**
- * Enter description here...
- *
- * @return String
- */
- public final function getSmtpUsername() {
- return $this->smtpUsername;
- }
-
- /**
- * Enter description here...
- *
- * @param String $smtpUsername
- * @return void
- */
- public final function setSmtpUsername($smtpUsername) {
- $this->smtpUsername = $smtpUsername;
- }
-
- /**
- * Gets the SmtpPassword
- *
- * @return $smtpPassword
- */
- public function getSmtpPassword() {
- return $this->smtpPassword;
- }
-
- /**
- * Sets the SmtpPassword
- *
- * @param $smtpPassword
- * @return void
- */
- public function setSmtpPassword($smtpPassword) {
- $this->smtpPassword = $smtpPassword;
- }
-
- /**
- * Gets the SmtpSecurity
- *
- * @return $smtpSecurity
- */
- public function getSmtpSecurity() {
- return $this->smtpSecurity;
- }
-
- /**
- * Sets the SmtpSecurity
- *
- * @param $smtpSecurity
- * @return void
- */
- public function setSmtpSecurity($smtpSecurity) {
- $this->smtpSecurity = $smtpSecurity;
- }
-
- /**
- * Gets the MailType
- *
- * @return String $mailType
- */
- public function getMailType() {
- return $this->mailType;
- }
-
- /**
- * Sets the MailType
- *
- * @param $mailType
- * @return void
- */
- public function setMailType($mailType) {
- $this->mailType = $mailType;
- }
-
- /**
- * Gets the DefaultRecipientAddress
- *
- * @return $defaultRecipientAddress
- */
- public function getDefaultRecipientAddress() {
- return $this->defaultRecipientAddress;
- }
-
- /**
- * Sets the DefaultRecipientAddress
- *
- * @param $defaultRecipientAddress
- * @return void
- */
- public function setDefaultRecipientAddress($defaultRecipientAddress) {
- $this->defaultRecipientAddress = $defaultRecipientAddress;
- }
-
- /**
- * Gets the DefaultRecipientName
- *
- * @return $defaultRecipientName
- */
- public function getDefaultRecipientName() {
- return $this->defaultRecipientName;
- }
-
- /**
- * Sets the DefaultRecipientName
- *
- * @param $defaultRecipientName
- * @return void
- */
- public function setDefaultRecipientName($defaultRecipientName) {
- $this->defaultRecipientName = $defaultRecipientName;
- }
-
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|