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


PHP Headers::fromString方法代码示例

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


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

示例1: testHeadersFromStringFactoryCreatesMultipleObjects

 public function testHeadersFromStringFactoryCreatesMultipleObjects()
 {
     $headers = Headers::fromString("Fake: foo-bar\r\nAnother-Fake: boo-baz");
     $this->assertEquals(2, $headers->count());
     $header = $headers->get('fake');
     $this->assertInstanceOf('Zend\\Mail\\Header\\GenericHeader', $header);
     $this->assertEquals('Fake', $header->getFieldName());
     $this->assertEquals('foo-bar', $header->getFieldValue());
     $header = $headers->get('anotherfake');
     $this->assertInstanceOf('Zend\\Mail\\Header\\GenericHeader', $header);
     $this->assertEquals('Another-Fake', $header->getFieldName());
     $this->assertEquals('boo-baz', $header->getFieldValue());
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:13,代码来源:HeadersTest.php

示例2: splitMessage

 /**
  * split a message in header and body part, if no header or an
  * invalid header is found $headers is empty
  *
  * The charset of the returned headers depend on your iconv settings.
  *
  * @param  string|Headers  $message raw message with header and optional content
  * @param  Headers         $headers output param, headers container
  * @param  string          $body    output param, content of message
  * @param  string          $EOL EOL string; defaults to {@link Zend\Mime\Mime::LINEEND}
  * @param  bool         $strict  enable strict mode for parsing message
  * @return null
  */
 public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND, $strict = false)
 {
     if ($message instanceof Headers) {
         $message = $message->toString();
     }
     // check for valid header at first line
     $firstlinePos = strpos($message, "\n");
     $firstline = $firstlinePos === false ? $message : substr($message, 0, $firstlinePos);
     if (!preg_match('%^[^\\s]+[^:]*:%', $firstline)) {
         $headers = [];
         // TODO: we're ignoring \r for now - is this function fast enough and is it safe to assume noone needs \r?
         $body = str_replace(["\r", "\n"], ['', $EOL], $message);
         return;
     }
     // see @ZF2-372, pops the first line off a message if it doesn't contain a header
     if (!$strict) {
         $parts = explode(':', $firstline, 2);
         if (count($parts) != 2) {
             $message = substr($message, strpos($message, $EOL) + 1);
         }
     }
     // find an empty line between headers and body
     // default is set new line
     if (strpos($message, $EOL . $EOL)) {
         list($headers, $body) = explode($EOL . $EOL, $message, 2);
         // next is the standard new line
     } elseif ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
         list($headers, $body) = explode("\r\n\r\n", $message, 2);
         // next is the other "standard" new line
     } elseif ($EOL != "\n" && strpos($message, "\n\n")) {
         list($headers, $body) = explode("\n\n", $message, 2);
         // at last resort find anything that looks like a new line
     } else {
         ErrorHandler::start(E_NOTICE | E_WARNING);
         list($headers, $body) = preg_split("%([\r\n]+)\\1%U", $message, 2);
         ErrorHandler::stop();
     }
     $headers = Headers::fromString($headers, $EOL);
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:52,代码来源:Decode.php

示例3: getHeaders

 /**
  * Access headers collection
  *
  * Lazy-loads if not already attached.
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if (null === $this->headers) {
         if ($this->mail) {
             $part = $this->mail->getRawHeader($this->messageNum);
             $this->headers = Headers::fromString($part);
         } else {
             $this->headers = new Headers();
         }
     }
     return $this->headers;
 }
开发者ID:karnurik,项目名称:zf2-turtorial,代码行数:19,代码来源:Part.php

示例4: __construct

 /**
  * Public constructor
  *
  * This handler supports the following params:
  * - file     filename or open file handler with message content (required)
  * - startPos start position of message or part in file (default: current position)
  * - endPos   end position of message or part in file (default: end of file)
  *
  * @param   array $params  full message with or without headers
  * @throws Exception\RuntimeException
  * @throws Exception\InvalidArgumentException
  */
 public function __construct(array $params)
 {
     if (empty($params['file'])) {
         throw new Exception\InvalidArgumentException('no file given in params');
     }
     if (!is_resource($params['file'])) {
         $this->_fh = fopen($params['file'], 'r');
     } else {
         $this->_fh = $params['file'];
     }
     if (!$this->_fh) {
         throw new Exception\RuntimeException('could not open file');
     }
     if (isset($params['startPos'])) {
         fseek($this->_fh, $params['startPos']);
     }
     $header = '';
     $endPos = isset($params['endPos']) ? $params['endPos'] : null;
     while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) {
         $header .= $line;
     }
     $this->_headers = Headers::fromString($header);
     $this->_contentPos[0] = ftell($this->_fh);
     if ($endPos !== null) {
         $this->_contentPos[1] = $endPos;
     } else {
         fseek($this->_fh, 0, SEEK_END);
         $this->_contentPos[1] = ftell($this->_fh);
     }
     if (!$this->isMultipart()) {
         return;
     }
     $boundary = $this->getHeaderField('content-type', 'boundary');
     if (!$boundary) {
         throw new Exception\RuntimeException('no boundary found in content type to split message');
     }
     $part = array();
     $pos = $this->_contentPos[0];
     fseek($this->_fh, $pos);
     while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) {
         $line = fgets($this->_fh);
         if ($line === false) {
             if (feof($this->_fh)) {
                 break;
             }
             throw new Exception\RuntimeException('error reading file');
         }
         $lastPos = $pos;
         $pos = ftell($this->_fh);
         $line = trim($line);
         if ($line == '--' . $boundary) {
             if ($part) {
                 // not first part
                 $part[1] = $lastPos;
                 $this->_partPos[] = $part;
             }
             $part = array($pos);
         } else {
             if ($line == '--' . $boundary . '--') {
                 $part[1] = $lastPos;
                 $this->_partPos[] = $part;
                 break;
             }
         }
     }
     $this->_countParts = count($this->_partPos);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:79,代码来源:File.php

示例5: splitMessage

 /**
  * split a message in header and body part, if no header or an
  * invalid header is found $headers is empty
  *
  * The charset of the returned headers depend on your iconv settings.
  *
  * @param  string|Headers  $message raw message with header and optional content
  * @param  Headers         $headers output param, headers container
  * @param  string          $body    output param, content of message
  * @param  string          $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
  * @return null
  */
 public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND)
 {
     if ($message instanceof Headers) {
         $message = $message->toString();
     }
     // check for valid header at first line
     $firstline = strtok($message, "\n");
     if (!preg_match('%^[^\\s]+[^:]*:%', $firstline)) {
         $headers = array();
         // TODO: we're ignoring \r for now - is this function fast enough and is it safe to asume noone needs \r?
         $body = str_replace(array("\r", "\n"), array('', $EOL), $message);
         return;
     }
     // find an empty line between headers and body
     // default is set new line
     if (strpos($message, $EOL . $EOL)) {
         list($headers, $body) = explode($EOL . $EOL, $message, 2);
         // next is the standard new line
     } else {
         if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
             list($headers, $body) = explode("\r\n\r\n", $message, 2);
             // next is the other "standard" new line
         } else {
             if ($EOL != "\n" && strpos($message, "\n\n")) {
                 list($headers, $body) = explode("\n\n", $message, 2);
                 // at last resort find anything that looks like a new line
             } else {
                 @(list($headers, $body) = @preg_split("%([\r\n]+)\\1%U", $message, 2));
             }
         }
     }
     $headers = Headers::fromString($headers, $EOL);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:45,代码来源:Decode.php

示例6: testGetEmbeddedContentId

 /**
  * @dataProvider getEmbeddedContentIdProvider
  * @param $rawHeaders
  * @param $expected
  */
 public function testGetEmbeddedContentId($rawHeaders, $expected)
 {
     $headers = Headers::fromString(implode(PHP_EOL, $rawHeaders), PHP_EOL);
     $contentIdHeader = null;
     $contentDispositionHeader = null;
     if (isset($rawHeaders['Content-ID'])) {
         $contentIdHeader = GenericHeader::fromString($rawHeaders['Content-ID']);
     }
     if (isset($rawHeaders['Content-Disposition'])) {
         $contentDispositionHeader = GenericHeader::fromString($rawHeaders['Content-Disposition']);
     }
     $this->part->expects($this->any())->method('getHeader')->willReturnMap([['Content-ID', null, $contentIdHeader], ['Content-Disposition', null, $contentDispositionHeader]]);
     $this->part->expects($this->any())->method('getHeaders')->willReturn($headers);
     $this->assertEquals($expected, $this->attachment->getEmbeddedContentId());
 }
开发者ID:ramunasd,项目名称:platform,代码行数:20,代码来源:AttachmentTest.php


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