public function getBinaryStream($path)
{
$this->assertLoggedIn();
$nodePath = PathHelper::getParentPath($path);
$nodeId = $this->getSystemIdForNode($nodePath);
$propertyName = PathHelper::getNodeName($path);
$data = $this->getConnection()->fetchAll('SELECT data, idx FROM phpcr_binarydata WHERE node_id = ? AND property_name = ? AND workspace_name = ?', array($nodeId, $propertyName, $this->workspaceName));
if (count($data) === 0) {
throw new RepositoryException('No binary data found in stream');
}
$streams = array();
foreach ($data as $row) {
if (is_resource($row['data'])) {
$stream = $row['data'];
} else {
$stream = fopen('php://memory', 'rwb+');
fwrite($stream, $row['data']);
rewind($stream);
}
$streams[] = $stream;
}
if (count($data) === 1) {
// we don't know if this is a multivalue property or not.
// TODO we should have something more efficient to know this. a flag in the database?
// TODO use self::getProperty()->isMultiple() once implemented
$node = $this->getNode($nodePath);
if (!is_array($node->{':' . $propertyName})) {
return reset($streams);
}
}
return $streams;
}