class DomXMLFIReader in Feed Import 8
DomDocument XML reader
Hierarchy
- class \Drupal\feed_import_base\FeedImportConfigurable
- class \Drupal\feed_import_base\FeedImportReader
- class \Drupal\feed_import_base\FeedImportDomXPathReader
- class \Drupal\feed_import_base\DomXMLFIReader
- class \Drupal\feed_import_base\FeedImportDomXPathReader
- class \Drupal\feed_import_base\FeedImportReader
Expanded class hierarchy of DomXMLFIReader
File
- feed_import_base/
src/ DomXMLFIReader.php, line 7
Namespace
Drupal\feed_import_baseView source
class DomXMLFIReader extends FeedImportDomXPathReader {
// Number of items returned by parent xpath
protected $totalItems = 0;
// Current item.
protected $currentItem = 0;
/**
* {@inheritdoc}
*/
public function init() {
if (empty($this->options['parent']) || empty($this->options['format'])) {
return FALSE;
}
$this->options += array(
'url' => NULL,
'raw' => NULL,
'options' => array(
LIBXML_NOCDATA,
),
'php_func' => NULL,
'recover' => FALSE,
'normalizeDocument' => FALSE,
'strictErrorChecking' => FALSE,
'preserveWhiteSpace' => FALSE,
'resolveExternals' => FALSE,
'stream' => NULL,
'silence_load_errors' => FALSE,
);
$opts = 0;
foreach ($this->options['options'] as $opt) {
$opts |= $opt;
}
list($majorv, $minorv) = explode('.', phpversion());
$htmlok = $majorv >= 5 && $minorv >= 4;
$doc = new DOMDocument();
$doc->strictErrorChecking = $this->options['strictErrorChecking'];
$doc->preserveWhiteSpace = $this->options['preserveWhiteSpace'];
$doc->resolveExternals = $this->options['resolveExternals'];
$silence_load = $this->options['silence_load_errors'];
$loaded = FALSE;
if ($this->options['url']) {
if ($ctx = $this
->getStreamContext($this->options['stream'])) {
libxml_set_streams_context($ctx);
}
if ($this->options['format'] == 'html') {
if ($htmlok) {
$loaded = $silence_load ? @$doc
->loadHTMLFile($this->options['url'], $opts) : $doc
->loadHTMLFile($this->options['url'], $opts);
}
else {
$loaded = $silence_load ? @$doc
->loadHTMLFile($this->options['url']) : $doc
->loadHTMLFile($this->options['url']);
}
}
else {
$loaded = $silence_load ? @$doc
->load($this->options['url'], $opts) : $doc
->load($this->options['url'], $opts);
}
}
elseif ($this->options['raw']) {
if ($this->options['format'] == 'html') {
if ($htmlok) {
$loaded = $silence_load ? @$doc
->loadHTML($this->options['raw'], $opts) : $doc
->loadHTML($this->options['raw'], $opts);
}
else {
$loaded = $silence_load ? @$doc
->loadHTML($this->options['raw']) : $doc
->loadHTML($this->options['raw']);
}
}
else {
$loaded = $silence_load ? @$doc
->loadXML($this->options['raw'], $opts) : $doc
->loadXML($this->options['raw'], $opts);
}
}
if (!$loaded) {
return FALSE;
}
// Add X inclusions
if ($opts & LIBXML_XINCLUDE) {
$doc
->xinclude();
}
unset($this->options['raw'], $opts, $opt, $htmlok, $loaded, $e);
$doc->recover = $this->options['recover'];
if ($this->options['normalizeDocument']) {
$doc
->normalizeDocument();
}
// Create xpath object.
$this->xpath = new DOMXPath($doc);
if ($this->options['php_func']) {
if (!is_array($this->options['php_func'])) {
$this->options['php_func'] = static::cleanLines($this->options['php_func']);
}
$this->xpath
->registerNamespace('php', 'http://php.net/xpath');
$this->xpath
->registerPhpFunctions($this->options['php_func']);
}
// Check for namespace settings.
if (!empty($this->options['namespaces'])) {
if (!is_array($this->options['namespaces'])) {
$this->options['namespaces'] = static::cleanLines($this->options['namespaces']);
}
foreach ($this->options['namespaces'] as $key => &$ns) {
$ns = explode('=', $ns, 2);
if (count($ns) == 2 && !empty($ns[0]) && !empty($ns[1])) {
$this->xpath
->registerNamespace($ns[0], $ns[1]);
}
}
// Not needed anymore.
unset($this->options['namespaces'], $ns);
}
$this->items = $this->xpath
->query($this->options['parent']);
if ($this->items === FALSE) {
return FALSE;
}
$this->totalItems = $this->items->length;
return TRUE;
}
/**
* {@inheritdoc}
*/
public function get() {
if ($this->currentItem < $this->totalItems) {
return $this->items
->item($this->currentItem++);
}
unset($this->items);
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DomXMLFIReader:: |
protected | property | ||
DomXMLFIReader:: |
protected | property | ||
DomXMLFIReader:: |
public | function |
This method returns the next available item or NULL if there are no items
left. Overrides FeedImportReader:: |
|
DomXMLFIReader:: |
public | function |
Here you'll init your reader. Overrides FeedImportReader:: |
|
FeedImportConfigurable:: |
protected | property | ||
FeedImportConfigurable:: |
public static | function | Helper function to get lines of a string | |
FeedImportConfigurable:: |
public | function | Sets options for this instance | 4 |
FeedImportDomXPathReader:: |
protected | property | ||
FeedImportDomXPathReader:: |
protected | property | ||
FeedImportDomXPathReader:: |
public | function |
Returns a value mapped from obj by path. Overrides FeedImportReader:: |
|
FeedImportReader:: |
protected | property | ||
FeedImportReader:: |
public | function | Override this to preprocess your paths before they are used in map(). | 2 |
FeedImportReader:: |
public | function | Returns a stream context | |
FeedImportReader:: |
final public | function | Constructor of reader. Constructor is final but you'll have to implement init() to init your reader. | |
FeedImportReader:: |
public | function | Destructor. | 2 |