本文整理汇总了PHP中resource::valid方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::valid方法的具体用法?PHP resource::valid怎么用?PHP resource::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _get_result
/**
* Method used to get a row from the executed query
*
* @return array An array containing the row data of the result
* @access private
*/
private function _get_result()
{
if ($this->_result->valid()) {
$row = $this->_result->current();
if ($this->config_item('mongo_expand_dbrefs')) {
$this->_deref($row);
}
return $row;
} else {
return array();
}
}
示例2: next
/**
* Advanced to the next context.
*
* This method parses a little bit more of the XML file to be able to
* return the next context. If no more contexts are available it sets the
* $currentContext member variable to null, so that the valid() method can
* pick this up. If there are more contexts available it reads the context
* from the file and stores it into the $currentContext member variable.
* This method is used for iteration as part of the Iterator interface.
*
* @throws ezcTranslationReaderNotInitializedException when the reader is
* not initialized with initReader().
* @return void
*/
public function next()
{
if (is_null($this->xmlParser)) {
throw new ezcTranslationReaderNotInitializedException();
}
$valid = $this->xmlParser->valid();
if ($valid) {
$newContext = array(trim($this->xmlParser->getChildren()->name), array());
foreach ($this->xmlParser->getChildren()->message as $data) {
$translationItem = $this->parseSimpleXMLMessage($data);
if (!is_null($translationItem)) {
$newContext[1][] = $translationItem;
}
}
$this->currentContext = $newContext;
$this->xmlParser->next();
} else {
$this->currentContext = null;
}
}
示例3: write
/**
* Writes input to stdin.
*
* @throws InvalidArgumentException When an input iterator yields a non supported value
*/
protected function write()
{
if (!isset($this->pipes[0])) {
return;
}
$input = $this->input;
if ($input instanceof \Iterator) {
if (!$input->valid()) {
$input = null;
} elseif (is_resource($input = $input->current())) {
stream_set_blocking($input, 0);
} elseif (!isset($this->inputBuffer[0])) {
if (!is_string($input)) {
if (!is_scalar($input)) {
throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input)));
}
$input = (string) $input;
}
$this->inputBuffer = $input;
$this->input->next();
$input = null;
} else {
$input = null;
}
}
$r = $e = array();
$w = array($this->pipes[0]);
// let's have a look if something changed in streams
if (false === ($n = @stream_select($r, $w, $e, 0, 0))) {
return;
}
foreach ($w as $stdin) {
if (isset($this->inputBuffer[0])) {
$written = fwrite($stdin, $this->inputBuffer);
$this->inputBuffer = substr($this->inputBuffer, $written);
if (isset($this->inputBuffer[0])) {
return array($this->pipes[0]);
}
}
if ($input) {
for (;;) {
$data = fread($input, self::CHUNK_SIZE);
if (!isset($data[0])) {
break;
}
$written = fwrite($stdin, $data);
$data = substr($data, $written);
if (isset($data[0])) {
$this->inputBuffer = $data;
return array($this->pipes[0]);
}
}
if (feof($input)) {
if ($this->input instanceof \Iterator) {
$this->input->next();
} else {
$this->input = null;
}
}
}
}
// no input to read on resource, buffer is empty
if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
$this->input = null;
fclose($this->pipes[0]);
unset($this->pipes[0]);
} elseif (!$w) {
return array($this->pipes[0]);
}
}
示例4: getSourceFields
/**
* {@inheritdoc}
*/
public function getSourceFields($url)
{
if (!$this->getSourceData($url)) {
return array();
}
// Recurse through the result array. When there is an array of items at the
// expected depth that has the expected identifier as one of the keys, pull that
// array out as a distinct item.
$identifier = $this->getIdentifier();
$identifierDepth = $this->getIdentifierDepth();
$items = array();
while ($this->iterator->valid()) {
$this->iterator->next();
$item = $this->iterator->current();
if (is_array($item) && array_key_exists($identifier, $item) && $this->iterator->getDepth() == $identifierDepth) {
$items[] = $item;
}
}
return $items;
}
示例5: write
/**
* Writes input to stdin.
*/
protected function write()
{
if (!isset($this->pipes[0])) {
return;
}
$input = $this->input;
if ($input instanceof \Iterator) {
if (!$input->valid()) {
$input = null;
} elseif (is_resource($input = $input->current())) {
stream_set_blocking($input, 0);
} else {
$this->inputBuffer .= $input;
$this->input->next();
$input = null;
}
}
$r = $e = array();
$w = array($this->pipes[0]);
// let's have a look if something changed in streams
if (false === ($n = @stream_select($r, $w, $e, 0, 0))) {
return;
}
foreach ($w as $stdin) {
if (isset($this->inputBuffer[0])) {
$written = fwrite($stdin, $this->inputBuffer);
$this->inputBuffer = substr($this->inputBuffer, $written);
if (isset($this->inputBuffer[0])) {
return array($this->pipes[0]);
}
}
if ($input) {
for (;;) {
$data = fread($input, self::CHUNK_SIZE);
if (!isset($data[0])) {
break;
}
$written = fwrite($stdin, $data);
$data = substr($data, $written);
if (isset($data[0])) {
$this->inputBuffer = $data;
return array($this->pipes[0]);
}
}
if (feof($input)) {
if ($this->input instanceof \Iterator) {
$this->input->next();
} else {
$this->input = null;
}
}
}
}
// no input to read on resource, buffer is empty
if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
$this->input = null;
fclose($this->pipes[0]);
unset($this->pipes[0]);
}
if (!$w) {
return array($this->pipes[0]);
}
}