Example #1
0
 /**
  * Factory method for creating an email log writer based on the configuration array
  * @param array $config
  * @return \Zend\Log\Writer\Mail
  */
 public function create($config)
 {
     $to = $config['to'];
     $from = $config['from'];
     $subject = $config['subject'];
     //create the message object that should be sent
     $message = new \Zend\Mail\Message();
     //populate it with data based on the config
     $message->setFrom($from);
     $message->setSubject($subject);
     if (is_string($to)) {
         $to = array($to);
     }
     foreach ($to as $email) {
         $message->addTo($email);
     }
     //create the log writer
     $writer = new Mail($message);
     //set up a formatter if present
     if (isset($config['formatter'])) {
         $formatter = new $config['formatter']();
         $writer->setFormatter($formatter);
     }
     return $writer;
 }
Example #2
0
 public function testSetSubjectPrependText()
 {
     $this->writer->setSubjectPrependText('test');
     $this->log->info('an info message');
     $this->log->info('a second info message');
     unset($this->log);
     $contents = file_get_contents(__DIR__ . '/' . self::FILENAME);
     $this->assertContains('an info message', $contents);
     $this->assertContains('Subject: test', $contents);
 }
Example #3
0
 /**
  * Write a message to the log.
  *
  * @param array $event event data
  *
  * @return void
  * @throws \Zend\Log\Exception\RuntimeException
  */
 protected function doWrite(array $event)
 {
     // Apply verbosity filter:
     if (is_array($event['message'])) {
         $event['message'] = $event['message'][$this->verbosity];
     }
     // Call parent method:
     return parent::doWrite($event);
 }
Example #4
0
 /**
  * @return Mail
  */
 protected function _getMailWriter()
 {
     $oMailMessage = new MailMessage();
     if (isset($this->_aConfig['writer']['mail']['sender_mail']) && isset($this->_aConfig['writer']['mail']['sender_name'])) {
         $oMailMessage->setFrom($this->_aConfig['writer']['mail']['sender_mail'], $this->_aConfig['writer']['mail']['sender_name']);
     }
     foreach ((array) $this->_aConfig['writer']['mail']['receivers'] as $sRec) {
         $oMailMessage->addTo($sRec);
     }
     $oWriter = new Mail($oMailMessage, $this->_oTransportService->getTransport());
     $oWriter->setFormatter($this->_getDefaultFormatter());
     if (isset($this->_aConfig['writer']['mail']['subject_prepend_text'])) {
         $oWriter->setSubjectPrependText($this->_aConfig['writer']['mail']['subject_prepend_text']);
     }
     $oFilter = new FilterPriority(Logger::ERR);
     $oWriter->addFilter($oFilter);
     return $oWriter;
 }
Example #5
0
    /**
     * @group ZF-9990
     */
    public function testFactoryWithCustomLayoutClass()
    {
        $this->getMock('Zend\Layout\Layout', null, array(), 'StubLayoutCustom');
    	$config = array(
    	    'layout' => 'StubLayoutCustom'
    	);

    	$writer = MailWriter::factory($config);
    	$this->assertInstanceOf('Zend\Log\Writer\Mail', $writer);
    }
Example #6
0
 /**
  * Write a message to the log.
  *
  * @param array $event event data
  *
  * @return void
  * @throws \Zend\Log\Exception\RuntimeException
  */
 protected function doWrite(array $event)
 {
     // Apply verbosity, Call parent method:
     return parent::doWrite($this->applyVerbosity($event));
 }