JSONFIReader.php in Feed Import 8
File
feed_import_base/src/JSONFIReader.php
View source
<?php
namespace Drupal\feed_import_base;
class JSONFIReader extends FeedImportVectorReader {
public function init() {
$this->options += array(
'stream' => NULL,
'parent' => NULL,
'raw' => NULL,
'url' => NULL,
);
if ($this->options['url']) {
if ($ctx = $this
->getStreamContext($this->options['stream'])) {
$this->items = json_decode(file_get_contents($this->options['url'], FALSE, $ctx));
}
else {
$this->items = json_decode(file_get_contents($this->options['url']));
}
}
elseif ($this->options['raw']) {
$this->items = json_decode($this->options['raw']);
}
if (!$this->items) {
return FALSE;
}
unset($this->options['raw']);
if ($this->options['parent']) {
$this->options['parent'] = $this
->formatPath($this->options['parent']);
$this->items = $this
->map($this->items, $this->options['parent']);
}
return TRUE;
}
public function get() {
return array_shift($this->items);
}
}
Classes
Name |
Description |
JSONFIReader |
JSON Reader class, used to read data from json files. |