class SampleDataSet in YAML Content 8.2
Provides methods for retrieving sample data to be used in demo content.
Hierarchy
- class \Drupal\sample_data\SampleDataSet
Expanded class hierarchy of SampleDataSet
File
- modules/
sample_data/ src/ SampleDataSet.php, line 8
Namespace
Drupal\sample_dataView source
class SampleDataSet {
protected $data;
/**
* SampleData constructor.
*
* @param array $data
* The data to be wrapped and returned.
*/
public function __construct(array $data) {
$this->data = $data;
}
/**
* Retrieves a sample data for the given type and advances the data counter.
*
* @param string $type
* The type of sample data to retrieve.
*
* @return string|array|false
* The sample data or FALSE if it does not exist.
*/
public function get($type) {
if (isset($this->data[$type])) {
$sample = current($this->data[$type]);
if (next($this->data[$type]) === FALSE) {
reset($this->data[$type]);
}
return $sample;
}
return FALSE;
}
/**
* Sets sample data for the given type.
*
* @param string $type
* The type of sample data to set.
* @param string|array $value
* The sample data.
*/
public function set($type, $value) {
$this->data[$type] = (array) $value;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SampleDataSet:: |
protected | property | ||
SampleDataSet:: |
public | function | Retrieves a sample data for the given type and advances the data counter. | |
SampleDataSet:: |
public | function | Sets sample data for the given type. | |
SampleDataSet:: |
public | function | SampleData constructor. |