本文整理汇总了PHP中Swift_OutputByteStream::setReadPointer方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_OutputByteStream::setReadPointer方法的具体用法?PHP Swift_OutputByteStream::setReadPointer怎么用?PHP Swift_OutputByteStream::setReadPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_OutputByteStream
的用法示例。
在下文中一共展示了Swift_OutputByteStream::setReadPointer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: streamToMime
/**
* Merges an OutputByteStream to Swift_Message.
*
* @param Swift_OutputByteStream $fromStream
* @param Swift_Message $message
*/
protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message)
{
$bufferLength = 78;
$headerData = '';
$fromStream->setReadPointer(0);
while (($buffer = $fromStream->read($bufferLength)) !== false) {
$headerData .= $buffer;
if (false !== strpos($buffer, "\r\n\r\n")) {
break;
}
}
$headersPosEnd = strpos($headerData, "\r\n\r\n");
$headerData = trim($headerData);
$headerData = substr($headerData, 0, $headersPosEnd);
$headerLines = explode("\r\n", $headerData);
unset($headerData);
$headers = array();
$currentHeaderName = '';
foreach ($headerLines as $headerLine) {
// Line separated
if (ctype_space($headerLines[0]) || false === strpos($headerLine, ':')) {
$headers[$currentHeaderName] .= ' ' . trim($headerLine);
continue;
}
$header = explode(':', $headerLine, 2);
$currentHeaderName = strtolower($header[0]);
$headers[$currentHeaderName] = trim($header[1]);
}
$messageStream = new Swift_ByteStream_TemporaryFileByteStream();
$messageStream->addFilter($this->replacementFactory->createFilter("\r\n", "\n"), 'CRLF to LF');
$messageStream->addFilter($this->replacementFactory->createFilter("\n", "\r\n"), 'LF to CRLF');
$messageHeaders = $message->getHeaders();
// No need to check for 'application/pkcs7-mime', as this is always base64
if ('multipart/signed;' === substr($headers['content-type'], 0, 17)) {
if (!preg_match('/boundary=("[^"]+"|(?:[^\\s]+|$))/is', $headers['content-type'], $contentTypeData)) {
throw new Swift_SwiftException('Failed to find Boundary parameter');
}
$boundary = trim($contentTypeData['1'], '"');
$boundaryLen = strlen($boundary);
// Skip the header and CRLF CRLF
$fromStream->setReadPointer($headersPosEnd + 4);
while (false !== ($buffer = $fromStream->read($bufferLength))) {
$messageStream->write($buffer);
}
$messageStream->commit();
$messageHeaders->remove('Content-Transfer-Encoding');
$message->setContentType($headers['content-type']);
$message->setBoundary($boundary);
$message->setBody($messageStream);
} else {
$fromStream->setReadPointer($headersPosEnd + 4);
if (null === $this->headerFactory) {
$this->headerFactory = Swift_DependencyContainer::getInstance()->lookup('mime.headerfactory');
}
$message->setContentType($headers['content-type']);
$messageHeaders->set($this->headerFactory->createTextHeader('Content-Transfer-Encoding', $headers['content-transfer-encoding']));
$messageHeaders->set($this->headerFactory->createTextHeader('Content-Disposition', $headers['content-disposition']));
while (false !== ($buffer = $fromStream->read($bufferLength))) {
$messageStream->write($buffer);
}
$messageStream->commit();
$message->setBody($messageStream);
}
}
示例2: importByteStream
/**
* @see Swift_CharacterStream::importByteStream()
*
* @param Swift_OutputByteStream $os
*/
public function importByteStream(Swift_OutputByteStream $os)
{
$this->flushContents();
$blocks = 512;
$os->setReadPointer(0);
while (false !== ($read = $os->read($blocks))) {
$this->write($read);
}
}
示例3: _readStream
private function _readStream(Swift_OutputByteStream $os)
{
$string = '';
while (false !== ($bytes = $os->read(8192))) {
$string .= $bytes;
}
$os->setReadPointer(0);
return $string;
}