You are here

class SampleDataSet in YAML Content 8.2

Provides methods for retrieving sample data to be used in demo content.

Hierarchy

Expanded class hierarchy of SampleDataSet

File

modules/sample_data/src/SampleDataSet.php, line 8

Namespace

Drupal\sample_data
View 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

Namesort descending Modifiers Type Description Overrides
SampleDataSet::$data protected property
SampleDataSet::get public function Retrieves a sample data for the given type and advances the data counter.
SampleDataSet::set public function Sets sample data for the given type.
SampleDataSet::__construct public function SampleData constructor.