abstract class FeedImportVectorReader in Feed Import 8
This class is a helper for vector (n dimensions) reader. Path format is like a/b/c which results in [a, b, c] array.
Hierarchy
- class \Drupal\feed_import_base\FeedImportConfigurable
- class \Drupal\feed_import_base\FeedImportReader
- class \Drupal\feed_import_base\FeedImportVectorReader
- class \Drupal\feed_import_base\FeedImportReader
Expanded class hierarchy of FeedImportVectorReader
File
- feed_import_base/
src/ FeedImportVectorReader.php, line 8
Namespace
Drupal\feed_import_baseView source
abstract class FeedImportVectorReader extends FeedImportReader {
const WILDCARD = '*';
/**
* {@inheritdoc}
*/
public function map(&$vector, &$path) {
$ret = array();
$count = 0;
foreach ($path as $p) {
if (($p = $this
->submap($vector, $p)) !== NULL) {
if ($p instanceof ArrayObject) {
$ret = array_merge($ret, $p
->getArrayCopy());
$count += count($p);
}
else {
$ret[] = $p;
$count++;
}
}
}
return $count == 0 ? NULL : ($count == 1 ? $ret[0] : $ret);
}
/**
* Gets an element by path.
*
* @param mixed $vector
* The vector to search
* @param array $path
* Path parts
* @param int $index
* Path index
*
* @return mixed
* Found value or NULL
*/
public function submap(&$vector, &$path, $index = 0) {
while (isset($path[$index])) {
$p =& $path[$index++];
if ($p == static::WILDCARD) {
if (is_scalar($vector)) {
return NULL;
}
$result = new ArrayObject();
foreach ($vector as &$value) {
if (($res = $this
->submap($value, $path, $index)) !== NULL) {
if ($res instanceof ArrayObject) {
foreach ($res as &$r) {
$result[] = $r;
}
unset($r);
}
else {
$result[] = $res;
}
}
unset($res);
}
return $result ? $result : NULL;
}
elseif (is_array($vector)) {
if (isset($vector[$p])) {
$vector =& $vector[$p];
continue;
}
}
elseif (is_object($vector)) {
if (isset($vector->{$p})) {
$vector =& $vector->{$p};
continue;
}
}
return NULL;
}
return $vector;
}
/**
* {@inheritdoc}
*/
public function formatPath($path) {
$path = preg_split('/(\\s?\\|\\s?)/', $path, -1, PREG_SPLIT_NO_EMPTY);
foreach ($path as &$p) {
$p = explode('/', $p);
}
return $path;
}
}
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:: |
abstract public | function | This method returns the next available item or NULL if there are no items left. | 6 |
FeedImportReader:: |
public | function | Returns a stream context | |
FeedImportReader:: |
abstract public | function | Here you'll init your reader. | 6 |
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 |