Skip to content

Commit

Permalink
fixing changes made in fa7fe18 to do what was intended: stream wrappe…
Browse files Browse the repository at this point in the history
…r is a per session setting.
  • Loading branch information
dbu committed Sep 20, 2011
1 parent dad9356 commit b3d23ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 11 additions & 12 deletions src/Jackalope/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ class Property extends Item implements \IteratorAggregate, \PHPCR\PropertyInterf
{
/**
* flag to know if binary streams should be wrapped or retrieved
* immediately.
*
* limit the call to stream_get_wrappers to one per session. can not be
* static as this is a per session setting.
* immediately. this is a per session setting.
*
* @var boolean
* @see Property::__construct()
*/
protected $binaryStreamWrapperRegistered;
protected $wrapBinaryStreams;

/**
* All binary stream wrapper instances
Expand Down Expand Up @@ -90,9 +87,7 @@ public function __construct($factory, array $data, $path, Session $session,
{
parent::__construct($factory, $path, $session, $objectManager, $new);

if (null === $this->binaryStreamWrapperRegistered) {
$this->binaryStreamWrapperRegistered = in_array('jackalope', stream_get_wrappers());
}
$this->wrapBinaryStreams = $session->getRepository()->getDescriptor(Repository::JACKALOPE_OPTION_STREAM_WRAPPER);

if (empty($data) && $new) {
return;
Expand Down Expand Up @@ -254,11 +249,14 @@ public function getBinary()
if ($this->type != PropertyType::BINARY) {
return PropertyType::convertType($this->value, PropertyType::BINARY, $this->type);
}
if (! $this->binaryStreamWrapperRegistered && null == $this->value) {
if (! $this->wrapBinaryStreams && null == $this->value) {
// no caching the stream. we need to fetch the stream and then copy
// it into a memory stream so it can be accessed more than once.
$this->value = $this->objectManager->getBinaryStream($this->path);
}
if ($this->value != null) {
// new or updated property
// we have the stream locally: no wrapping or new or updated property
// copy the stream so the original stream stays usable for storing, fetching again...
$val = is_array($this->value) ? $this->value : array($this->value);
foreach ($val as $s) {
$stream = fopen('php://memory', 'rwb+');
Expand All @@ -270,8 +268,9 @@ public function getBinary()
}
return is_array($this->value) ? $ret : $ret[0];
}
if (! $this->binaryStreamWrapperRegistered) {
throw new \LogicException("Attempting to create 'jackalope' stream instances but stream wrapper is not registered");

if (! $this->wrapBinaryStreams) {
throw new \LogicException("Attempting to create 'jackalope' stream instances but stream wrapper is not activated");
}
// return wrapped stream
if ($this->isMultiple()) {
Expand Down
12 changes: 11 additions & 1 deletion src/Jackalope/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
*/
class Repository implements \PHPCR\RepositoryInterface
{
/**
* The descriptor key for the version of the specification
* that this repository implements. For JCR 2.0
* the value of this descriptor is the string "2.0".
* @api
*/
const JACKALOPE_OPTION_STREAM_WRAPPER = "jackalope.option.stream_wrapper";

/**
* flag to call stream_wrapper_register only once
*/
Expand All @@ -36,7 +44,7 @@ class Repository implements \PHPCR\RepositoryInterface
protected $options = array(
// this is OPTION_TRANSACTIONS_SUPPORTED
'transactions' => true,
// TODO: we could expose this as a custom descriptor
// this is JACKALOPE_OPTION_STREAM_WRAPPER
'stream_wrapper' => true,
);

Expand Down Expand Up @@ -132,6 +140,8 @@ public function getDescriptor($key)
{
// handle some of the keys locally
switch($key) {
case self::JACKALOPE_OPTION_STREAM_WRAPPER:
return $this->options['stream_wrapper'];
case self::OPTION_TRANSACTIONS_SUPPORTED:
return $this->options['transactions'];
// TODO: return false for everything we know is not implemented in jackalope
Expand Down

0 comments on commit b3d23ea

Please sign in to comment.