Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrevin committed Nov 21, 2013
1 parent 97a492c commit c6a15ac
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 66 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ configuration
`/protected/config/main.php`
```php
<?
return array(
return [
// ...
'components' => array(
'components' => [
// ...
'postman' => array(
'postman' => [
'class' => 'yii\postman\Postman',
'driver' => 'smtp',
'default_from' => array('track@rmrevin.ru', 'Mailer'),
'table' => 'tbl_letters',
'view_path' => '/email',
'smtp_config' => array(
'smtp_config' => [
'host' => 'smtp.domain.cpom',
'port' => 25,
'auth' => true,
'user' => 'email@domain.cpom',
'password' => 'password',
'secure' => false,
'debug' => false,
)
),
),
]
],
],
// ...
);
];
```

Usage
Expand Down Expand Up @@ -70,5 +70,5 @@ if(!$Letter->send()){

In cron script:
```php
LetterMode::cron($num_letters_per_step = 10)
LetterModel::cron($num_letters_per_step = 10)
```
1 change: 0 additions & 1 deletion tests/unit/postman/LetterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace postmantest\postman;

use postmantest\TestCase;
use yii\postman\Postman;
use yii\postman\RawLetter;

class LetterTest extends TestCase
Expand Down
32 changes: 20 additions & 12 deletions yii/postman/Letter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace yii\postman;

use Yii;
use PHPMailer;
use yii\base\Component;
use yii\base\Event;
use yii\db\Expression;
use yii\helpers\Json;
use Yii;
use yii\postman\models\LetterModel;

/**
Expand All @@ -37,7 +37,7 @@ abstract class Letter extends Component
protected $body;

/** @var array recipients */
protected $recipients = array();
protected $recipients = [];

/** @var array attachments */
protected $attachments;
Expand Down Expand Up @@ -84,12 +84,13 @@ public function set_postman(Postman $Postman)
public function set_subject($subject)
{
$this->subject = $subject;

return $this;
}

/**
* the method sets the value of the "From" field
* @param array $from = array('user@somehost.com') || array('user@somehost.com', 'John Smith')
* @param array $from = ['user@somehost.com'] || ['user@somehost.com', 'John Smith']
*
* @return $this
*/
Expand All @@ -114,6 +115,7 @@ public function get_count_recipients()
}
$count += count($recipients);
}

return $count;
}

Expand All @@ -128,7 +130,7 @@ public function get_count_recipients()
*
* @return $this
*/
public function add_address_list($to = array(), $cc = array(), $bcc = array(), $reply_to = array())
public function add_address_list($to = [], $cc = [], $bcc = [], $reply_to = [])
{
foreach ($to as $address) {
$this->add_address($address);
Expand All @@ -148,7 +150,7 @@ public function add_address_list($to = array(), $cc = array(), $bcc = array(), $

/**
* the method adds a recipient
* @param array $address = array('user@somehost.com') || array('user@somehost.com', 'John Smith')
* @param array $address = ['user@somehost.com'] || ['user@somehost.com', 'John Smith']
*
* @return $this
*/
Expand All @@ -158,12 +160,13 @@ public function add_address($address)
foreach ($args as $address) {
$this->_add_addr('to', $address);
}

return $this;
}

/**
* the method adds a recipient to Cc
* @param array $address = array('user@somehost.com') || array('user@somehost.com', 'John Smith')
* @param array $address = ['user@somehost.com'] || ['user@somehost.com', 'John Smith']
*
* @return $this
*/
Expand All @@ -173,12 +176,13 @@ public function add_cc_address($address)
foreach ($args as $address) {
$this->_add_addr('cc', $address);
}

return $this;
}

/**
* the method adds a recipient to Bcc
* @param array $address = array('user@somehost.com') || array('user@somehost.com', 'John Smith')
* @param array $address = ['user@somehost.com'] || ['user@somehost.com', 'John Smith']
*
* @return $this
*/
Expand All @@ -188,12 +192,13 @@ public function add_bcc_address($address)
foreach ($args as $address) {
$this->_add_addr('bcc', $address);
}

return $this;
}

/**
* the method adds a "Reply-to" address
* @param array $address = array('user@somehost.com') || array('user@somehost.com', 'John Smith')
* @param array $address = ['user@somehost.com'] || ['user@somehost.com', 'John Smith']
*
* @return $this
*/
Expand All @@ -203,6 +208,7 @@ public function add_reply_to($address)
foreach ($args as $address) {
$this->_add_addr('reply', $address);
}

return $this;
}

Expand All @@ -215,11 +221,12 @@ public function add_reply_to($address)
*/
private function _add_addr($type, $address)
{
$address = !is_array($address) ? array($address) : $address;
$address = !is_array($address) ? [$address] : $address;
if (!isset($this->recipients[$type])) {
$this->recipients[$type] = array();
$this->recipients[$type] = [];
}
$this->recipients[$type][] = $address;

return $this;
}

Expand All @@ -234,12 +241,13 @@ private function _add_addr($type, $address)
*/
public function add_attachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream')
{
$this->attachments[] = array(
$this->attachments[] = [
'path' => $path,
'name' => $name,
'encoding' => $encoding,
'type' => $type
);
];

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion yii/postman/Postman.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace yii\postman;

use Yii;
use PHPMailer;
use Yii;
use yii\base\Component;

/**
Expand Down
8 changes: 4 additions & 4 deletions yii/postman/RawLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class RawLetter extends Letter
{

/**
* @param string $subject a subject of a message
* @param string $body a text of a message
* @param string $subject a subject of a message
* @param string $body a text of a message
*/
public function __construct($subject, $body)
{
Expand All @@ -26,8 +26,8 @@ public function __construct($subject, $body)
}

/**
* @param string $subject a subject of a message
* @param string $body a text of a message
* @param string $subject a subject of a message
* @param string $body a text of a message
*/
public function set_data($subject, $body)
{
Expand Down
10 changes: 6 additions & 4 deletions yii/postman/ViewLetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ViewLetter extends Letter

/**
* @param string $subject a subject of a message
* @param string $view a name of a view file
* @param array $params params for a view
* @param string $view a name of a view file
* @param array $params params for a view
*/
public function __construct($subject, $view, $params = array())
{
Expand All @@ -36,7 +36,7 @@ public function __construct($subject, $view, $params = array())

$this->set_view($view)->set_params($params);

$this->on(self::EVENT_BEFORE_SEND, array($this, 'before_send'));
$this->on(self::EVENT_BEFORE_SEND, [$this, 'before_send']);
}

/**
Expand All @@ -48,6 +48,7 @@ public function __construct($subject, $view, $params = array())
public function set_view($view)
{
$this->_view = $view;

return $this;
}

Expand All @@ -60,6 +61,7 @@ public function set_view($view)
public function set_params($params)
{
$this->_params = $params;

return $this;
}

Expand All @@ -73,7 +75,7 @@ public function before_send(Event $Event)
{
$path = Yii::$app->getViewPath() . $this->_postman->view_path . DIRECTORY_SEPARATOR . $this->_view . '.php';
if (!file_exists($path)) {
throw new LetterException(Yii::t('app', 'View file «{path}» not found.', array('{path}' => $path)));
throw new LetterException(Yii::t('app', 'View file «{path}» not found.', ['{path}' => $path]));
} else {
$this->body = Yii::$app->getView()->renderFile($path, $this->_params);
}
Expand Down
28 changes: 7 additions & 21 deletions yii/postman/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@
namespace yii\postman;

$Letter = new RawLetter('Subject', 'Message body', 'Alternative message body', true);
$Letter->add_address_list(
// main
array(
array('user@somehost.com', 'John Smith'),
array('user2@somehost.com', 'Mary Jane'),
),
// cc
array(),
// bcc
array(
array('tech@somehost.com')
),
// reply_to
array(
array('abuse@somehost.com')
)
)->send();

$Letter
->add_address('user@somehost.com')
->add_bcc_address(['tech@somehost.com'])
->send();

$Letter = new ViewLetter('Subject', 'letter-view', array(
$Letter = new ViewLetter('Subject', 'letter-view', [
'name' => 'Rosy',
'date' => date('Y-m-d')
), false);
], false);
$Letter
->add_address(array('user@somehost.com', 'John Smith'))
->add_address(['user@somehost.com', 'John Smith'])
->add_attachment('/path/to/file.tar.gz')
->send();

0 comments on commit c6a15ac

Please sign in to comment.