/** * 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(); } }
/** * 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; } }
/** * 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]); } }
/** * {@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; }
/** * 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]); } }