diff --git a/composer.json b/composer.json index 30fd2f3f7..dbee89c80 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "doctrine/dbal": "dev-2.5-pg10", "guzzlehttp/guzzle": "6.3.3", "icewind/searchdav": "1.0.1", - "icewind/Streams": "0.6.1", + "icewind/Streams": "v0.7.1", "interfasys/lognormalizer": "^v1.0", "jeremeamia/superclosure": "2.1.0", "leafo/scssphp": "0.7.7", diff --git a/composer.lock b/composer.lock index efda3dd2f..ad30169ea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b526d05dca797bb55382859f43ab5e36", + "content-hash": "a138537ec798c1c927c3b7053a72a640", "packages": [ { "name": "aws/aws-sdk-php", @@ -1087,16 +1087,16 @@ }, { "name": "icewind/streams", - "version": "0.6.1", + "version": "v0.7.1", "source": { "type": "git", "url": "https://github.com/icewind1991/Streams.git", - "reference": "0a78597117d8a02937ea05206f219294449fb06e" + "reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/icewind1991/Streams/zipball/0a78597117d8a02937ea05206f219294449fb06e", - "reference": "0a78597117d8a02937ea05206f219294449fb06e", + "url": "https://api.github.com/repos/icewind1991/Streams/zipball/4db3ed6c366e90b958d00e1d4c6360a9b39b2121", + "reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121", "shasum": "" }, "require": { @@ -1124,7 +1124,7 @@ } ], "description": "A set of generic stream wrappers", - "time": "2018-04-24T09:07:38+00:00" + "time": "2019-02-15T12:57:29+00:00" }, { "name": "interfasys/lognormalizer", diff --git a/composer/installed.json b/composer/installed.json index 04a0f6177..adbadece0 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -1116,17 +1116,17 @@ }, { "name": "icewind/streams", - "version": "0.6.1", - "version_normalized": "0.6.1.0", + "version": "v0.7.1", + "version_normalized": "0.7.1.0", "source": { "type": "git", "url": "https://github.com/icewind1991/Streams.git", - "reference": "0a78597117d8a02937ea05206f219294449fb06e" + "reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/icewind1991/Streams/zipball/0a78597117d8a02937ea05206f219294449fb06e", - "reference": "0a78597117d8a02937ea05206f219294449fb06e", + "url": "https://api.github.com/repos/icewind1991/Streams/zipball/4db3ed6c366e90b958d00e1d4c6360a9b39b2121", + "reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121", "shasum": "" }, "require": { @@ -1136,7 +1136,7 @@ "phpunit/phpunit": "^4.8", "satooshi/php-coveralls": "v1.0.0" }, - "time": "2018-04-24T09:07:38+00:00", + "time": "2019-02-15T12:57:29+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/icewind/streams/src/CallbackWrapper.php b/icewind/streams/src/CallbackWrapper.php index 4eef55681..67f9110d1 100644 --- a/icewind/streams/src/CallbackWrapper.php +++ b/icewind/streams/src/CallbackWrapper.php @@ -44,6 +44,11 @@ class CallbackWrapper extends Wrapper { */ protected $readDirCallBack; + /** + * @var callable + */ + protected $preCloseCallback; + /** * Wraps a stream with the provided callbacks * @@ -56,14 +61,15 @@ class CallbackWrapper extends Wrapper { * * @throws \BadMethodCallException */ - public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null) { + public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) { $context = stream_context_create(array( 'callback' => array( 'source' => $source, 'read' => $read, 'write' => $write, 'close' => $close, - 'readDir' => $readDir + 'readDir' => $readDir, + 'preClose' => $preClose, ) )); return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CallbackWrapper'); @@ -76,6 +82,7 @@ protected function open() { $this->writeCallback = $context['write']; $this->closeCallback = $context['close']; $this->readDirCallBack = $context['readDir']; + $this->preCloseCallback = $context['preClose']; return true; } @@ -90,7 +97,7 @@ public function stream_open($path, $mode, $options, &$opened_path) { public function stream_read($count) { $result = parent::stream_read($count); if (is_callable($this->readCallback)) { - call_user_func($this->readCallback, $count); + call_user_func($this->readCallback, strlen($result)); } return $result; } @@ -104,6 +111,11 @@ public function stream_write($data) { } public function stream_close() { + if (is_callable($this->preCloseCallback)) { + call_user_func($this->preCloseCallback, $this->loadContext('callback')['source']); + // prevent further calls by potential PHP 7 GC ghosts + $this->preCloseCallback = null; + } $result = parent::stream_close(); if (is_callable($this->closeCallback)) { call_user_func($this->closeCallback);