Skip to content

Commit

Permalink
Merge pull request #1423 from akrabat/fix-stream-metadata
Browse files Browse the repository at this point in the history
Update the meta information when getMetadata() is called
  • Loading branch information
silentworks committed Aug 10, 2015
2 parents 764fe2b + dab6847 commit 593fd92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 10 additions & 4 deletions Slim/Http/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function __construct($stream)
*/
public function getMetadata($key = null)
{
$this->meta = stream_get_meta_data($this->stream);
if (is_null($key) === true) {
return $this->meta;
}
Expand Down Expand Up @@ -139,7 +140,6 @@ protected function attach($newStream)
}

$this->stream = $newStream;
$this->meta = stream_get_meta_data($newStream);
}

/**
Expand Down Expand Up @@ -253,8 +253,9 @@ public function isReadable()
if ($this->readable === null) {
$this->readable = false;
if ($this->isAttached()) {
$meta = $this->getMetadata();
foreach (self::$modes['readable'] as $mode) {
if (strpos($this->meta['mode'], $mode) === 0) {
if (strpos($meta['mode'], $mode) === 0) {
$this->readable = true;
break;
}
Expand All @@ -275,8 +276,9 @@ public function isWritable()
if ($this->writable === null) {
$this->writable = false;
if ($this->isAttached()) {
$meta = $this->getMetadata();
foreach (self::$modes['writable'] as $mode) {
if (strpos($this->meta['mode'], $mode) === 0) {
if (strpos($meta['mode'], $mode) === 0) {
$this->writable = true;
break;
}
Expand All @@ -297,7 +299,8 @@ public function isSeekable()
if ($this->seekable === null) {
$this->seekable = false;
if ($this->isAttached()) {
$this->seekable = $this->meta['seekable'];
$meta = $this->getMetadata();
$this->seekable = $meta['seekable'];
}
}

Expand Down Expand Up @@ -381,6 +384,9 @@ public function write($string)
throw new RuntimeException('Could not write to stream');
}

// reset size so that it will be recalculated on next call to getSize()
$this->size = null;

return $written;
}

Expand Down
11 changes: 0 additions & 11 deletions tests/Http/BodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ public function testConstructorInvalidStream()
$body = new Body($this->stream);
}

public function testConstructorSetsMetadata()
{
$this->stream = $this->resourceFactory();
$body = new Body($this->stream);

$bodyMetadata = new ReflectionProperty($body, 'meta');
$bodyMetadata->setAccessible(true);

$this->assertTrue(is_array($bodyMetadata->getValue($body)));
}

public function testGetMetadata()
{
$this->stream = $this->resourceFactory();
Expand Down

0 comments on commit 593fd92

Please sign in to comment.