class JSONFIReader in Feed Import 8
JSON Reader class, used to read data from json files.
Hierarchy
- class \Drupal\feed_import_base\FeedImportConfigurable
- class \Drupal\feed_import_base\FeedImportReader
- class \Drupal\feed_import_base\FeedImportVectorReader
- class \Drupal\feed_import_base\JSONFIReader
- class \Drupal\feed_import_base\FeedImportVectorReader
- class \Drupal\feed_import_base\FeedImportReader
Expanded class hierarchy of JSONFIReader
File
- feed_import_base/
src/ JSONFIReader.php, line 7
Namespace
Drupal\feed_import_baseView source
class JSONFIReader extends FeedImportVectorReader {
/**
* {@inheritdoc}
*/
public function init() {
// Set default params
$this->options += array(
'stream' => NULL,
'parent' => NULL,
'raw' => NULL,
'url' => NULL,
);
if ($this->options['url']) {
// Check for stream options.
if ($ctx = $this
->getStreamContext($this->options['stream'])) {
// Open the file using stream options.
$this->items = json_decode(file_get_contents($this->options['url'], FALSE, $ctx));
}
else {
// Open the file.
$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']);
// Check for parent
if ($this->options['parent']) {
$this->options['parent'] = $this
->formatPath($this->options['parent']);
$this->items = $this
->map($this->items, $this->options['parent']);
}
return TRUE;
}
/**
* {@inheritdoc}
*/
public function get() {
return array_shift($this->items);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedImportConfigurable:: |
protected | property | ||
FeedImportConfigurable:: |
public static | function | Helper function to get lines of a string | |
FeedImportConfigurable:: |
public | function | Sets options for this instance | 4 |
FeedImportReader:: |
protected | property | ||
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 |
FeedImportVectorReader:: |
public | function |
Override this to preprocess your paths before they are used in map(). Overrides FeedImportReader:: |
|
FeedImportVectorReader:: |
public | function |
Returns a value mapped from obj by path. Overrides FeedImportReader:: |
|
FeedImportVectorReader:: |
public | function | Gets an element by path. | |
FeedImportVectorReader:: |
constant | |||
JSONFIReader:: |
public | function |
This method returns the next available item or NULL if there are no items
left. Overrides FeedImportReader:: |
|
JSONFIReader:: |
public | function |
Here you'll init your reader. Overrides FeedImportReader:: |