The binary data type.
The plain value of binary data is a PHP file resource, see http://php.net/manual/en/language.types.resource.php. For setting the value a PHP file resource or a (absolute) stream resource URI may be passed.
Expanded class hierarchy of Binary
class Binary extends TypedData implements TypedDataInterface {
/**
* The file resource URI.
*
* @var string
*/
protected $uri;
/**
* A generic file resource handle.
*
* @var resource
*/
public $handle = NULL;
/**
* Implements TypedDataInterface::getValue().
*/
public function getValue() {
if (!isset($this->handle) && isset($this->uri)) {
$this->handle = fopen($this->uri, 'rb');
}
return $this->handle;
}
/**
* Implements TypedDataInterface::setValue().
*/
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.");
}
}
/**
* Implements TypedDataInterface::getString().
*/
public function getString() {
$contents = '';
while (!feof($this
->getValue())) {
$contents .= fread($this->handle, 8192);
}
return $contents;
}
/**
* Implements TypedDataInterface::validate().
*/
public function validate() {
// TODO: Implement validate() method.
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Binary:: |
public | property | A generic file resource handle. | |
Binary:: |
protected | property | The file resource URI. | |
Binary:: |
public | function |
Implements TypedDataInterface::getString(). Overrides TypedData:: |
|
Binary:: |
public | function |
Implements TypedDataInterface::getValue(). Overrides TypedData:: |
|
Binary:: |
public | function |
Implements TypedDataInterface::setValue(). Overrides TypedData:: |
|
Binary:: |
public | function |
Implements TypedDataInterface::validate(). Overrides TypedDataInterface:: |
|
TypedData:: |
protected | property | The data definition. | |
TypedData:: |
public | function |
Implements TypedDataInterface::getDefinition(). Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Implements TypedDataInterface::getType(). Overrides TypedDataInterface:: |
|
TypedData:: |
public | function | Constructs a TypedData object given its definition. | 3 |