Skip to content

Commit

Permalink
update lib for swift v6 (#7)
Browse files Browse the repository at this point in the history
update lib for swift v6
  • Loading branch information
kaioken authored May 10, 2019
2 parents 1a84e27 + 970522c commit d1bff4c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 53 deletions.
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PRODUCTION=0

# Email
EMAIL_HOST=smtp.mailgun.org
EMAIL_PORT=587
EMAIL_USER=
EMAIL_PASS=
EMAIL_FROM_PRODUCTION=info@baka.io
EMAIL_FROM_NAME_PRODUCTION="Baka Canvas"
EMAIL_FROM_DEBUG=info@baka.io
EMAIL_FROM_NAME_DEBUG="Baka Canvas"

# Redis
REDIS_HOST=redis
REDIS_PORT=6379

# Beanstalk
BEANSTALK_HOST=beanstalkd
BEANSTALK_PORT=11300
BEANSTALK_PREFIX=canvas_
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"email": "max@mctekk.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.0",
"ext-phalcon": ">=3.0.0",
Expand All @@ -19,6 +18,7 @@
"require-dev": {
"codeception/verify": "*",
"vlucas/phpdotenv": "^2.0",
"codeception/codeception": "2.4"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Phalcon\Mvc\View\Engine\Volt;

/**
* Class Manager
* Class Manager.
*
* @package Phalcon\Manager
*/
Expand All @@ -14,7 +14,7 @@ class Manager extends \Phalcon\Mailer\Manager
protected $queue;

/**
* Overwrite this funciton to use ower mail message
* Overwrite this funciton to use ower mail message.
*
* Create a new Message instance.
*
Expand Down Expand Up @@ -44,7 +44,7 @@ public function createMessage()
}

/**
* Configure MailerManager class
* Configure MailerManager class.
*
* @param array $config
*
Expand All @@ -61,7 +61,7 @@ protected function configure(array $config)
}

/**
* Register the queue service
* Register the queue service.
*
* @return BeanstalkExtended
*/
Expand All @@ -71,7 +71,7 @@ public function registerQueue()
}

/**
* Get the queue service
* Get the queue service.
*
* @return BeanstalkExtended
*/
Expand All @@ -81,7 +81,7 @@ public function getQueue()
}

/**
* Renders a view
* Renders a view.
*
* @param $viewPath
* @param $params
Expand Down
27 changes: 14 additions & 13 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Baka\Mail;

use Exception;
use Swift_SmtpTransport;
use Swift_Mailer;

/**
* Class Message
* Class Message.
*
* @package Phalcon\Mailer
*/
Expand Down Expand Up @@ -96,7 +98,7 @@ public function send()
}

/**
* Send message instantly, without a queue
* Send message instantly, without a queue.
*
* @return void
*/
Expand All @@ -110,20 +112,19 @@ public function sendNow()
$host = $config->email->host;
$port = $config->email->port;

$transport = \Swift_SmtpTransport::newInstance($host, $port);
$transport = (new Swift_SmtpTransport($host, $port))
->setUsername($username)
->setPassword($password);

$transport->setUsername($username);
$transport->setPassword($password);

$swift = \Swift_Mailer::newInstance($transport);
$swift = new Swift_Mailer($transport);

$failures = [];

$swift->send($message, $failures);
}

/**
* Overwrite the baka SMTP connection for this current email
* Overwrite the baka SMTP connection for this current email.
*
* @param array $smtp
* @return this
Expand All @@ -146,7 +147,7 @@ public function smtp(array $params)
}

/**
* Set the queue name if the user wants to shange it
* Set the queue name if the user wants to shange it.
*
* @param string $queuName
*
Expand All @@ -159,7 +160,7 @@ public function queue($queue)
}

/**
* Set variables to views
* Set variables to views.
*
* @param string $params
*
Expand All @@ -172,7 +173,7 @@ public function params($params)
}

/**
* The local path to the folder viewsDir only this message. (OPTIONAL)
* The local path to the folder viewsDir only this message. (OPTIONAL).
*
* @param string $dir
*
Expand All @@ -185,7 +186,7 @@ public function viewDir($dir)
}

/**
* view relative to the folder viewsDir (REQUIRED)
* view relative to the folder viewsDir (REQUIRED).
*
* @param string $template
*
Expand All @@ -206,7 +207,7 @@ public function template($template = 'email.volt')
}

/**
* Set content dynamically by params
* Set content dynamically by params.
* @param $params
* @param $content
* @return string
Expand Down
6 changes: 5 additions & 1 deletion tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// This is global bootstrap for autoloading

/**
* Setup autoloading
* Setup autoloading.
*/
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/unit/PhalconUnitTestCase.php';

if (!defined('APP_PATH')) {
define('APP_PATH', dirname(__DIR__) . '/tests/unit/view');
}

$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
$dotenv->load();
28 changes: 14 additions & 14 deletions tests/unit/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

class AuthTest extends PhalconUnitTestCase
{

/**
* Test normal email
* Test normal email.
*
* @return boolean
*/
Expand All @@ -19,7 +18,7 @@ public function testSimpleEmail()
}

/**
* Test html email
* Test html email.
*
* @return boolean
*/
Expand All @@ -35,7 +34,7 @@ public function testTemplateMail()
}

/**
* test the smtp configuration
* test the smtp configuration.
*
* @return boolean
*/
Expand All @@ -52,16 +51,17 @@ public function testEmailSmtpConfig()
}

/**
* this runs before everyone
*/
protected function setUp()
{
$this->_getDI();

}

protected function tearDown()
* Test normal email.
*
* @return boolean
*/
public function testSimpleEmailNow()
{
//send email
$this->_getDI()->get('mail')
->to('max@mctekk.com')
->subject('Test Normal Email queue')
->content('normal email send via queue')
->sendNow();
}

}
Loading

0 comments on commit d1bff4c

Please sign in to comment.