public function Binary::setValue

Implements TypedDataInterface::setValue().

Overrides TypedData::setValue

File

drupal/core/lib/Drupal/Core/TypedData/Type/Binary.php, line 49
Definition of Drupal\Core\TypedData\Type\Binary.

Class

Binary
The binary data type.

Namespace

Drupal\Core\TypedData\Type

Code

public function setValue($value) {
  if (!isset($value)) {
    $this->handle = NULL;
    $this->uri = NULL;
  }
  elseif (is_resource($value)) {
    $this->handle = $value;
  }
  elseif (is_string($value)) {

    // Note: For performance reasons we store the given URI and access the
    // resource upon request. See Binary::getValue()
    $this->uri = $value;
  }
  else {
    throw new InvalidArgumentException("Invalid value for binary data given.");
  }
}