本文整理汇总了PHP中resource::rewind方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::rewind方法的具体用法?PHP resource::rewind怎么用?PHP resource::rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::rewind方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculateRequestLength
/**
* Calculates length of the request body, adds proper headers
*
* @param array &$headers associative array of request headers, this method
* will add proper 'Content-Length' and 'Content-Type'
* headers to this array (or remove them if not needed)
*/
protected function calculateRequestLength(&$headers)
{
$this->requestBody = $this->request->getBody();
if (is_string($this->requestBody)) {
$this->contentLength = strlen($this->requestBody);
} elseif (is_resource($this->requestBody)) {
$stat = fstat($this->requestBody);
$this->contentLength = $stat['size'];
rewind($this->requestBody);
} else {
$this->contentLength = $this->requestBody->getLength();
$headers['content-type'] = 'multipart/form-data; boundary=' . $this->requestBody->getBoundary();
$this->requestBody->rewind();
}
if (in_array($this->request->getMethod(), self::$bodyDisallowed) || 0 == $this->contentLength) {
// No body: send a Content-Length header nonetheless (request #12900),
// but do that only for methods that require a body (bug #14740)
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
$headers['content-length'] = 0;
} else {
unset($headers['content-length']);
// if the method doesn't require a body and doesn't have a
// body, don't send a Content-Type header. (request #16799)
unset($headers['content-type']);
}
} else {
if (empty($headers['content-type'])) {
$headers['content-type'] = 'application/x-www-form-urlencoded';
}
// Content-Length should not be sent for chunked Transfer-Encoding (bug #20125)
if (!isset($headers['transfer-encoding'])) {
$headers['content-length'] = $this->contentLength;
}
}
}
示例2: previous_row
/**
* Method used to retrieve the previous row from a query result
*
* @param string Whether or not the result should be returned as an array
* @return mixed An array or an object with the result of the previous query result
* @access public
*/
public function previous_row($array = '')
{
$info = $this->_result->info();
$this->_result->rewind();
// Check that the cursor has started iterating
if (isset($info['at'])) {
// Move the cursor to the required position
for ($i = 1; $i < $info['at'] - 1; $i++) {
$this->_result->next();
}
}
$result = $this->_get_result();
return $this->_cast_result($array, $result);
}
示例3: doCreateStream
/**
* Creates a stream.
*
* @param null|resource|string|\Psr\Http\Message\StreamInterface|null $body The body
*
* @return \Psr\Http\Message\StreamInterface The stream
*/
private function doCreateStream($body)
{
if ($body instanceof StreamInterface) {
$body->rewind();
return $body;
}
if (is_resource($body)) {
return $this->doCreateStream(new Stream($body));
}
$stream = new Stream('php://memory', 'rw');
if ($body === null) {
return $stream;
}
$stream->write((string) $body);
return $this->doCreateStream($stream);
}
示例4: remove
/**
* remove host from hosts file.
*
* @param string The $host to be removed to the hosts file
*
* @throws RuntimeException if host does not exists or cant write to file
*
* @return bool
**/
public function remove($host)
{
$this->validHost($host);
if (!$this->check($host)) {
throw new \RuntimeException('Host does not exists in the file');
}
$this->backup();
$tmpFilePath = $this->filepath . '.tmp';
$tmpFile = new \SplFileObject($tmpFilePath, 'w+');
$this->file->rewind();
while (!$this->file->eof()) {
$pattern = '/\\b' . $host . '\\b/i';
if (!preg_match($pattern, $this->file->current())) {
$tmpFile->fwrite($this->file->current());
}
$this->file->next();
}
copy($tmpFilePath, $this->filepath);
unlink($tmpFilePath);
return true;
}
示例5: calculateRequestLength
/**
* Calculates length of the request body, adds proper headers
*
* @param array associative array of request headers, this method will
* add proper 'Content-Length' and 'Content-Type' headers
* to this array (or remove them if not needed)
*/
protected function calculateRequestLength(&$headers)
{
$this->requestBody = $this->request->getBody();
if (is_string($this->requestBody)) {
$this->contentLength = strlen($this->requestBody);
} elseif (is_resource($this->requestBody)) {
$stat = fstat($this->requestBody);
$this->contentLength = $stat['size'];
rewind($this->requestBody);
} else {
$this->contentLength = $this->requestBody->getLength();
$headers['content-type'] = 'multipart/form-data; boundary=' . $this->requestBody->getBoundary();
$this->requestBody->rewind();
}
if (in_array($this->request->getMethod(), self::$bodyDisallowed) || 0 == $this->contentLength) {
unset($headers['content-type']);
// No body: send a Content-Length header nonetheless (request #12900),
// but do that only for methods that require a body (bug #14740)
if (in_array($this->request->getMethod(), self::$bodyRequired)) {
$headers['content-length'] = 0;
} else {
unset($headers['content-length']);
}
} else {
if (empty($headers['content-type'])) {
$headers['content-type'] = 'application/x-www-form-urlencoded';
}
$headers['content-length'] = $this->contentLength;
}
}
示例6: initReader
/**
* Initializes the reader to read from locale $locale.
*
* Opens the translation file.
*
* @throws ezcTranslationNotConfiguredException if the option <i>format</i>
* is not set before this method is called.
*
* @param string $locale
* @return void
*/
public function initReader($locale)
{
$this->xmlParser = $this->openTranslationFile($locale, 'SimpleXMLIterator');
$this->xmlParser->rewind();
}