compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (28)

View Page History
{zone-data:skeletons}
{code}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Log
* @subpackage Writer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/

/** Zend_Log_Writer_Abstract */
require_once 'Zend/Log/Writer/Abstract.php';

/** Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';

/**
* @category Zend
* @package Zend_Log
* @subpackage Writer
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
{
/**
* Array of formatted lines events to use as include in message body.
*
* @var array
*/
private $_linesToMail; $_eventsToMail;

/**
* Zend_Mail instance to use
*
* @var Zend_Mail
*/

/**
* Zend_Layout instance to use
*
* @var Zend_Layout
*/
private $_layout;

/**
* Class constructor
*
* @param Zend_Mail $mail Mail instance
* @param Zend_Layout $layout Layout instance; optional
*/
public function __construct(Zend_Mail $mail)
public function __construct(Zend_Mail $mail, Zend_Layout $layout = null)
{
$this->_mail = $mail;
$this->_layout = $layout;
$this->_formatter = new Zend_Log_Formatter_Simple();
$this->_linesToMail $this->_eventsToMail = array();
}

* Places event line into array of lines to be used as message body.
*
* @param array $event eEvent data
* @return void
*/
protected function _write($event)
{
$this->_linesToMail[] $this->_eventsToMail[] = $this->_formatter->format($event);
}

public function shutdown()
{
// If there are lines events to mail, use them as message body. Otherwise,
// there is no mail to be sent.
if (!empty($this->_linesToMail)) (!empty($this->_eventsToMail)) {
// Always provide events to mail as plaintext.
// Set body text to all lines meant to be mailed, $this->_mail->setBodyText(implode("", $this->_eventsToMail));
// then send message.
$this->_mail->setBodyText(implode('', $this->_linesToMail));

// If a Zend_Layout instance exists, assume that it's for the HTML
// portion of the message.
$this->_mail->send(); if ($this->_layout) {
}
// Separate each line with a linebreak.
$bodyHtml = implode('<br/>', $this->_eventsToMail);

// Set the required "messages" value for the layout and the
// message's HTML body.
// Note that we don't destroy $this->_mail as the user may $this->_layout->messages = $bodyHtml;
// want to use that object after mail sending. $this->_mail->setBodyHtml($this->_layout->render());
}

// Finally, send the mail, but re-throw any exceptions at the
// proper level of abstraction.
try {
$this->_mail->send();
} catch (Exception $e) {
throw new Zend_Log_Exception(
$e->getMessage(),
$e->getCode());
}
}
}
}

{code}
{zone-data}