Skip to content

Commit

Permalink
Changes as suggested by dbu
Browse files Browse the repository at this point in the history
Some documentation changes and some code style changes
  • Loading branch information
uwej711 committed Jun 27, 2011
1 parent 49e09aa commit 4c70f8e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
29 changes: 17 additions & 12 deletions src/Jackalope/BinaryStreamWrapper.php
Expand Up @@ -15,6 +15,9 @@
*
* The loading from the backend is deferred until the stream is accessed. Then it is loaded and all
* stream functions are passed on to the underlying stream.
*
* @package jackalope
* @private
*/
class BinaryStreamWrapper
{
Expand All @@ -23,6 +26,7 @@ class BinaryStreamWrapper

private $path = null;
private $stream = null;
private $session = null;

/**
* Parse the url and store the information.
Expand Down Expand Up @@ -90,12 +94,17 @@ public function stream_flush()
*
* Multivalued properties have a special handling since the backend returns all
* streams in a single call.
*
* Always checks that the current session is still alive.
*/
private function init_stream()
{
if ($this->session && !$this->session->isLive()) {
throw new \LogicException("Trying to read a stream from a closed transport.");
}
if (null === $this->stream) {
$url = parse_url($this->path);
$session = Session::getSessionFromRegistry($url['host']);
$this->session = Session::getSessionFromRegistry($url['host']);
$property_path = $url['path'];
$token = null;
if (isset($url['user'])) {
Expand All @@ -104,18 +113,14 @@ private function init_stream()
if (isset($url['port'])) {
$index = $url['port'] - 1;
}
if ($session->isLive()) {
if (null === $token) {
$this->stream = $session->getObjectManager()->getBinaryStream($property_path);
} else {
// check if streams have been loaded for multivalued properties
if (!isset(self::$multiValueMap[$token])) {
self::$multiValueMap[$token] = $session->getObjectManager()->getBinaryStream($property_path);
}
$this->stream = self::$multiValueMap[$token][$index];
}
if (null === $token) {
$this->stream = $this->session->getObjectManager()->getBinaryStream($property_path);
} else {
// TODO proper exception?
// check if streams have been loaded for multivalued properties
if (!isset(self::$multiValueMap[$token])) {
self::$multiValueMap[$token] = $this->session->getObjectManager()->getBinaryStream($property_path);
}
$this->stream = self::$multiValueMap[$token][$index];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Jackalope/Property.php
Expand Up @@ -262,9 +262,7 @@ public function getBinary()
self::$binaryStreamWrapperRegistered = true;
}
// return wrapped stream
if (!$this->isMultiple()) {
return fopen('jackalope://' . $this->session->getRegistryKey() . $this->path , 'rwb+');
} else {
if ($this->isMultiple()) {
$results = array();
// identifies all streams loaded by one backend call
$token = md5(uniqid(mt_rand(), true));
Expand All @@ -274,6 +272,8 @@ public function getBinary()
}
return $results;
}
// single property case
return fopen('jackalope://' . $this->session->getRegistryKey() . $this->path , 'rwb+');
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/Jackalope/Session.php
Expand Up @@ -950,6 +950,7 @@ public function getRetentionManager()
/**
* Implementation specific: The object manager is also used by other components, i.e. the QueryManager.
* DO NOT USE if you are a consumer of the api
* @private
*/
public function getObjectManager()
{
Expand All @@ -958,6 +959,7 @@ public function getObjectManager()

/**
* Implementation specific: The transport implementation is also used by other components, i.e. the NamespaceRegistry
* @private
*/
public function getTransport()
{
Expand All @@ -966,6 +968,7 @@ public function getTransport()

/**
* Implementation specific: register session in session registry
* @private
*/
protected static function registerSession(Session $session)
{
Expand All @@ -975,6 +978,7 @@ protected static function registerSession(Session $session)

/**
* Implementation specific: unregister session in session registry
* @private
*/
protected static function unregisterSession(Session $session)
{
Expand All @@ -984,6 +988,8 @@ protected static function unregisterSession(Session $session)

/**
* Implementation specific: create an id for the session registry
* @private
* @return an id for this session
*/
public function getRegistryKey()
{
Expand All @@ -993,6 +999,7 @@ public function getRegistryKey()
/**
* Implementation specific: get a session from the session registry
*
* @private
* @param $key key for the session
* @return the session or null if none is registered with the given key
*/
Expand Down

0 comments on commit 4c70f8e

Please sign in to comment.