/** * Parses the Property element. * * The Property element can be a child of either the root XRD * element or the Link element * * @param array &$el the parent JRD element */ private function parseProperty(&$el) { $type = $this->reader->getAttribute('type'); if ($this->reader->getAttributeNs('nil', self::XSI_NS)) { $value = null; } else { $value = $this->reader->readString(); } $el[$this->reader->getAttribute('type')] = $value; $this->reader->next(); }
/** * Method used to get a row resulting from the executed query * * @param int The index of the row to be returned * @return array An array containing the result of the query * @access private */ private function _row($row) { if (!$row) { return $this->_get_result(); } // Move the cursor to the required position for ($i = 1; $i < $row; $i++) { $this->_result->next(); } return $this->_get_result(); }
/** * 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; }
/** * 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; } }
/** * {@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. * * @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]); } }
/** * 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]); } }