当前位置: 首页>>代码示例>>PHP>>正文


PHP Swift_Message::getChildren方法代码示例

本文整理汇总了PHP中Swift_Message::getChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::getChildren方法的具体用法?PHP Swift_Message::getChildren怎么用?PHP Swift_Message::getChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Swift_Message的用法示例。


在下文中一共展示了Swift_Message::getChildren方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getHtmlBody

 /**
  * @return string|null
  */
 public function getHtmlBody()
 {
     foreach ($this->message->getChildren() as $child) {
         if ($child->getContentType() == 'text/html') {
             return $child->getBody();
         }
     }
 }
开发者ID:cawaphp,项目名称:email,代码行数:11,代码来源:Message.php

示例2: getEmailAttachments

 /**
  * @return array
  */
 protected function getEmailAttachments()
 {
     if (null === $this->message) {
         throw new \RuntimeException('Select an email which has to have been sent first. ' . 'You can use the step: "an email with subject :subject should have been sent (to :email)"');
     }
     $files = [];
     /** @var \Swift_Mime_MimeEntity $child */
     foreach ($this->message->getChildren() as $child) {
         if (null !== ($disposition = $child->getHeaders()->get('content-disposition'))) {
             /** @var \Swift_Mime_Headers_ParameterizedHeader $disposition */
             $files[] = $disposition->getParameter('filename');
         }
     }
     return $files;
 }
开发者ID:treehouselabs,项目名称:behat-common,代码行数:18,代码来源:SwiftmailerContext.php

示例3: messageToArray

 /**
  * Converts \Swift_Message into associative array
  *
  * @param array          $search   If the mailer requires tokens in another format than Mautic's, pass array of Mautic tokens to replace
  * @param array          $replace  If the mailer requires tokens in another format than Mautic's, pass array of replacement tokens
  *
  * @return array|\Swift_Message
  */
 protected function messageToArray($search = array(), $replace = array())
 {
     if (!empty($search)) {
         MailHelper::searchReplaceTokens($search, $replace, $this->message);
     }
     $from = $this->message->getFrom();
     $fromEmail = current(array_keys($from));
     $fromName = $from[$fromEmail];
     $message = array('html' => $this->message->getBody(), 'text' => MailHelper::getPlainTextFromMessage($this->message), 'subject' => $this->message->getSubject(), 'from' => array('name' => $fromName, 'email' => $fromEmail));
     // Generate the recipients
     $message['recipients'] = array('to' => array(), 'cc' => array(), 'bcc' => array());
     $to = $this->message->getTo();
     foreach ($to as $email => $name) {
         $message['recipients']['to'][$email] = array('email' => $email, 'name' => $name);
     }
     $cc = $this->message->getCc();
     if (!empty($cc)) {
         foreach ($cc as $email => $name) {
             $message['recipients']['cc'][$email] = array('email' => $email, 'name' => $name);
         }
     }
     $bcc = $this->message->getBcc();
     if (!empty($bcc)) {
         foreach ($bcc as $email => $name) {
             $message['recipients']['bcc'][$email] = array('email' => $email, 'name' => $name);
         }
     }
     $replyTo = $this->message->getReplyTo();
     if (!empty($replyTo)) {
         foreach ($replyTo as $email => $name) {
             $message['replyTo'] = array('email' => $email, 'name' => $name);
         }
     }
     $returnPath = $this->message->getReturnPath();
     if (!empty($returnPath)) {
         $message['returnPath'] = $returnPath;
     }
     // Attachments
     $children = $this->message->getChildren();
     $attachments = array();
     foreach ($children as $child) {
         if ($child instanceof \Swift_Attachment) {
             $attachments[] = array('type' => $child->getContentType(), 'name' => $child->getFilename(), 'content' => $child->getEncoder()->encodeString($child->getBody()));
         }
     }
     $message['attachments'] = $attachments;
     return $message;
 }
开发者ID:Jornve,项目名称:mautic,代码行数:56,代码来源:AbstractTokenArrayTransport.php

示例4: getPlainTextFromMessage

 /**
  * Extract plain text from message
  *
  * @param \Swift_Message $message
  *
  * @return string
  */
 public static function getPlainTextFromMessage(\Swift_Message $message)
 {
     $children = (array) $message->getChildren();
     /** @var \Swift_Mime_MimeEntity $child */
     foreach ($children as $child) {
         $childType = $child->getContentType();
         if ($childType == 'text/plain' && $child instanceof \Swift_MimePart) {
             return $child->getBody();
         }
     }
     return '';
 }
开发者ID:emtudo,项目名称:mautic,代码行数:19,代码来源:MailHelper.php

示例5: createMessage

 /**
  * @param Swift_Message $message
  *
  * @return Swift_Message
  */
 protected function createMessage(Swift_Message $message)
 {
     $mimeEntity = new Swift_Message('', $message->getBody(), $message->getContentType(), $message->getCharset());
     $mimeEntity->setChildren($message->getChildren());
     $messageHeaders = $mimeEntity->getHeaders();
     $messageHeaders->remove('Message-ID');
     $messageHeaders->remove('Date');
     $messageHeaders->remove('Subject');
     $messageHeaders->remove('MIME-Version');
     $messageHeaders->remove('To');
     $messageHeaders->remove('From');
     return $mimeEntity;
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:18,代码来源:SMimeSigner.php

示例6: messageToArray

 /**
  * Converts \Swift_Message into associative array.
  *
  * @param array      $search            If the mailer requires tokens in another format than Mautic's, pass array of Mautic tokens to replace
  * @param array      $replace           If the mailer requires tokens in another format than Mautic's, pass array of replacement tokens
  * @param bool|false $binaryAttachments True to convert file attachments to binary
  *
  * @return array|\Swift_Message
  */
 protected function messageToArray($search = [], $replace = [], $binaryAttachments = false)
 {
     if (!empty($search)) {
         MailHelper::searchReplaceTokens($search, $replace, $this->message);
     }
     $from = $this->message->getFrom();
     $fromEmail = current(array_keys($from));
     $fromName = $from[$fromEmail];
     $message = ['html' => $this->message->getBody(), 'text' => MailHelper::getPlainTextFromMessage($this->message), 'subject' => $this->message->getSubject(), 'from' => ['name' => $fromName, 'email' => $fromEmail]];
     // Generate the recipients
     $message['recipients'] = ['to' => [], 'cc' => [], 'bcc' => []];
     $to = $this->message->getTo();
     foreach ($to as $email => $name) {
         $message['recipients']['to'][$email] = ['email' => $email, 'name' => $name];
     }
     $cc = $this->message->getCc();
     if (!empty($cc)) {
         foreach ($cc as $email => $name) {
             $message['recipients']['cc'][$email] = ['email' => $email, 'name' => $name];
         }
     }
     $bcc = $this->message->getBcc();
     if (!empty($bcc)) {
         foreach ($bcc as $email => $name) {
             $message['recipients']['bcc'][$email] = ['email' => $email, 'name' => $name];
         }
     }
     $replyTo = $this->message->getReplyTo();
     if (!empty($replyTo)) {
         foreach ($replyTo as $email => $name) {
             $message['replyTo'] = ['email' => $email, 'name' => $name];
         }
     }
     $returnPath = $this->message->getReturnPath();
     if (!empty($returnPath)) {
         $message['returnPath'] = $returnPath;
     }
     // Attachments
     $children = $this->message->getChildren();
     $attachments = [];
     foreach ($children as $child) {
         if ($child instanceof \Swift_Attachment) {
             $attachments[] = ['type' => $child->getContentType(), 'name' => $child->getFilename(), 'content' => $child->getEncoder()->encodeString($child->getBody())];
         }
     }
     if ($binaryAttachments) {
         // Convert attachments to binary if applicable
         $message['attachments'] = $attachments;
         $fileAttachments = $this->getAttachments();
         if (!empty($fileAttachments)) {
             foreach ($fileAttachments as $attachment) {
                 if (file_exists($attachment['filePath']) && is_readable($attachment['filePath'])) {
                     try {
                         $swiftAttachment = \Swift_Attachment::fromPath($attachment['filePath']);
                         if (!empty($attachment['fileName'])) {
                             $swiftAttachment->setFilename($attachment['fileName']);
                         }
                         if (!empty($attachment['contentType'])) {
                             $swiftAttachment->setContentType($attachment['contentType']);
                         }
                         if (!empty($attachment['inline'])) {
                             $swiftAttachment->setDisposition('inline');
                         }
                         $message['attachments'][] = ['type' => $swiftAttachment->getContentType(), 'name' => $swiftAttachment->getFilename(), 'content' => $swiftAttachment->getEncoder()->encodeString($swiftAttachment->getBody())];
                     } catch (\Exception $e) {
                         error_log($e);
                     }
                 }
             }
         }
     } else {
         $message['binary_attachments'] = $attachments;
         $message['file_attachments'] = $this->getAttachments();
     }
     $message['headers'] = [];
     $headers = $this->message->getHeaders()->getAll();
     /** @var \Swift_Mime_Header $header */
     foreach ($headers as $header) {
         if ($header->getFieldType() == \Swift_Mime_Header::TYPE_TEXT) {
             $message['headers'][$header->getFieldName()] = $header->getFieldBodyModel();
         }
     }
     return $message;
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:93,代码来源:AbstractTokenArrayTransport.php

示例7: getChildren

 public function getChildren()
 {
     return $this->message->getChildren();
 }
开发者ID:Webiny,项目名称:Framework,代码行数:4,代码来源:Message.php


注:本文中的Swift_Message::getChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。