private function init_stream()
{
if (null === $this->stream) {
if ($this->session && !$this->session->isLive()) {
throw new LogicException('Trying to read a stream from a closed transport.');
}
$url = parse_url($this->path);
$this->session = Session::getSessionFromRegistry($url['host']);
if (!$this->session) {
throw new LogicException('Trying to read a stream from a closed transport');
}
$property_path = $url['path'];
if (!empty($url['query'])) {
$property_path .= '?' . $url['query'];
} elseif ('?' === $this->path[strlen($this->path) - 1]) {
$property_path .= '?';
}
$token = isset($url['user']) ? $url['user'] : null;
if (null === $token) {
$this->stream = $this->session->getObjectManager()->getBinaryStream($property_path);
} else {
// check if streams have been loaded for multivalued properties
if (!isset(self::$multiValueMap[$token])) {
self::$multiValueMap[$token] = $this->session->getObjectManager()->getBinaryStream($property_path);
}
$index = isset($url['port']) ? $url['port'] - 1 : 0;
if (!isset(self::$multiValueMap[$token][$index])) {
throw new LogicException("Trying to read a stream from a non existent token '{$token}' or token index '{$index}'.");
}
$this->stream = self::$multiValueMap[$token][$index];
}
}
}