From 1232c2c6ef58e21792635926549b5e06e432c380 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 12:29:20 +0200
Subject: [PATCH 1/6] Sort *existing* PhpStreamWrapperInterface methods
 alphabetically to match php.net.

---
 .../StreamWrapper/PhpStreamWrapperInterface.php    | 28 +++++++++++-----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index ba19159..c709ffa 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -13,16 +13,17 @@
  * @see http://www.php.net/manual/class.streamwrapper.php
  */
 interface PhpStreamWrapperInterface {
-  public function stream_open($uri, $mode, $options, &$opened_url);
+  public function dir_closedir();
+  public function dir_opendir($uri, $options);
+  public function dir_readdir();
+  public function dir_rewinddir();
+  public function mkdir($uri, $mode, $options);
+  public function rename($from_uri, $to_uri);
+  public function rmdir($uri, $options);
   public function stream_close();
-  public function stream_lock($operation);
-  public function stream_read($count);
-  public function stream_write($data);
   public function stream_eof();
-  public function stream_seek($offset, $whence);
   public function stream_flush();
-  public function stream_tell();
-  public function stream_stat();
+  public function stream_lock($operation);
 
   /**
    * Sets metadata on the stream.
@@ -56,13 +57,12 @@ public function stream_stat();
    */
   public function stream_metadata($uri, $option, $value);
 
+  public function stream_open($uri, $mode, $options, &$opened_url);
+  public function stream_read($count);
+  public function stream_seek($offset, $whence);
+  public function stream_stat();
+  public function stream_tell();
+  public function stream_write($data);
   public function unlink($uri);
-  public function rename($from_uri, $to_uri);
-  public function mkdir($uri, $mode, $options);
-  public function rmdir($uri, $options);
   public function url_stat($uri, $flags);
-  public function dir_opendir($uri, $options);
-  public function dir_readdir();
-  public function dir_rewinddir();
-  public function dir_closedir();
 }
-- 
1.7.11.msysgit.1


From 676261e79e3a79aee28cfa97f8339c2b7a3879ef Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 12:35:08 +0200
Subject: [PATCH 2/6] Updated PhpStreamWrapperInterface with current interface
 methods.

---
 .../StreamWrapper/PhpStreamWrapperInterface.php    | 111 +++++++++++++++++++--
 1 file changed, 102 insertions(+), 9 deletions(-)

diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index c709ffa..b50c610 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -13,16 +13,67 @@
  * @see http://www.php.net/manual/class.streamwrapper.php
  */
 interface PhpStreamWrapperInterface {
+
+  /* public $context; */
+
+  /**
+   * @return bool
+   */
   public function dir_closedir();
-  public function dir_opendir($uri, $options);
+
+  /**
+   * @return bool
+   */
+  public function dir_opendir($path, $options);
+
+  /**
+   * @return string
+   */
   public function dir_readdir();
+
+  /**
+   * @return bool
+   */
   public function dir_rewinddir();
-  public function mkdir($uri, $mode, $options);
-  public function rename($from_uri, $to_uri);
-  public function rmdir($uri, $options);
+
+  /**
+   * @return bool
+   */
+  public function mkdir($path, $mode, $options);
+
+  /**
+   * @return bool
+   */
+  public function rename($path_from, $path_to);
+
+  /**
+   * @return bool
+   */
+  public function rmdir($path, $options);
+
+  /**
+   * @return bool
+   */
+  public function stream_cast($cast_as);
+
+  /**
+   * @return void
+   */
   public function stream_close();
+
+  /**
+   * @return bool
+   */
   public function stream_eof();
+
+  /**
+   * @return bool
+   */
   public function stream_flush();
+
+  /**
+   * @return bool
+   */
   public function stream_lock($operation);
 
   /**
@@ -55,14 +106,56 @@ public function stream_lock($operation);
    *
    * @see http://www.php.net/manual/streamwrapper.stream-metadata.php
    */
-  public function stream_metadata($uri, $option, $value);
+  public function stream_metadata($path, $option, $value);
 
-  public function stream_open($uri, $mode, $options, &$opened_url);
+  /**
+   * @return bool
+   */
+  public function stream_open($path, $mode, $options, &$opened_path);
+
+  /**
+   * @return string
+   */
   public function stream_read($count);
-  public function stream_seek($offset, $whence);
+
+  /**
+   * @return bool
+   */
+  public function stream_seek($offset, $whence = SEEK_SET);
+
+  /**
+   * @return bool
+   */
+  public function stream_set_option($option, $arg1, $arg2);
+
+  /**
+   * @return array
+   */
   public function stream_stat();
+
+  /**
+   * @return int
+   */
   public function stream_tell();
+
+  /**
+   * @return bool
+   */
+  public function stream_truncate($new_size);
+
+  /**
+   * @return int
+   */
   public function stream_write($data);
-  public function unlink($uri);
-  public function url_stat($uri, $flags);
+
+  /**
+   * @return bool
+   */
+  public function unlink($path);
+
+  /**
+   * @return array
+   */
+  public function url_stat($path, $flags);
+
 }
-- 
1.7.11.msysgit.1


From 6dd9ca6894d8b09f0c005a8fb7fc28da5cf7b83c Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 13:22:25 +0200
Subject: [PATCH 3/6] Added stream_cast() to interface.

---
 core/lib/Drupal/Core/StreamWrapper/LocalStream.php       | 11 +----------
 .../Core/StreamWrapper/PhpStreamWrapperInterface.php     | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
index 86d0e63..d9f0e0e 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -328,16 +328,7 @@ public function stream_close() {
   }
 
   /**
-   * Gets the underlying stream resource for stream_select().
-   *
-   * @param int $cast_as
-   *   Can be STREAM_CAST_FOR_SELECT or STREAM_CAST_AS_STREAM.
-   *
-   * @return resource|false
-   *   The underlying stream resource or FALSE if stream_select() is not
-   *   supported.
-   *
-   * @see http://php.net/manual/streamwrapper.stream-cast.php
+   * {@inheritdoc}
    */
   public function stream_cast($cast_as) {
     return false;
diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index b50c610..a5b851f 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -52,7 +52,21 @@ public function rename($path_from, $path_to);
   public function rmdir($path, $options);
 
   /**
-   * @return bool
+   * Retrieve the underlying stream resource.
+   *
+   * This method is called in response to stream_select().
+   *
+   * @param int $cast_as
+   *   Can be STREAM_CAST_FOR_SELECT when stream_select() is calling
+   *   stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for
+   *   other uses.
+   *
+   * @return resource|false
+   *   The underlying stream resource or FALSE if stream_select() is not
+   *   supported.
+   *
+   * @see stream_select()
+   * @see http://php.net/manual/streamwrapper.stream-cast.php
    */
   public function stream_cast($cast_as);
 
-- 
1.7.11.msysgit.1


From f44d0bafbf5fc9a0fbcbdf098ebcb3b84a510971 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 13:23:20 +0200
Subject: [PATCH 4/6] Updated stream_seek().

---
 core/lib/Drupal/Core/StreamWrapper/LocalStream.php    | 14 ++------------
 .../Core/StreamWrapper/PhpStreamWrapperInterface.php  | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
index d9f0e0e..1d75974 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -260,19 +260,9 @@ public function stream_eof() {
   }
 
   /**
-   * Support for fseek().
-   *
-   * @param int $offset
-   *   The byte offset to got to.
-   * @param int $whence
-   *   SEEK_SET, SEEK_CUR, or SEEK_END.
-   *
-   * @return bool
-   *   TRUE on success.
-   *
-   * @see http://php.net/manual/streamwrapper.stream-seek.php
+   * {@inheritdoc}
    */
-  public function stream_seek($offset, $whence) {
+  public function stream_seek($offset, $whence = SEEK_SET) {
     // fseek returns 0 on success and -1 on a failure.
     // stream_seek   1 on success and  0 on a failure.
     return !fseek($this->handle, $offset, $whence);
diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index a5b851f..c3a733f 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -133,7 +133,26 @@ public function stream_open($path, $mode, $options, &$opened_path);
   public function stream_read($count);
 
   /**
+   * Seeks to specific location in a stream.
+   *
+   * This method is called in response to fseek().
+   *
+   * The read/write position of the stream should be updated according to the
+   * offset and whence.
+   *
+   * @param int $offset
+   *   The byte offset to seek to.
+   * @param int $whence
+   *   Possible values:
+   *   - SEEK_SET: Set position equal to offset bytes.
+   *   - SEEK_CUR: Set position to current location plus offset.
+   *   - SEEK_END: Set position to end-of-file plus offset.
+   *   Defaults to SEEK_SET.
+   *
    * @return bool
+   *   TRUE if the position was updated, FALSE otherwise.
+   *
+   * @see http://php.net/manual/streamwrapper.stream-seek.php
    */
   public function stream_seek($offset, $whence = SEEK_SET);
 
-- 
1.7.11.msysgit.1


From 020e4574816b1a95d42603ecedfdc009a8cd9c20 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 13:24:10 +0200
Subject: [PATCH 5/6] Added stream_set_option() to interface.

---
 core/lib/Drupal/Core/StreamWrapper/LocalStream.php |  7 ++++++
 .../StreamWrapper/PhpStreamWrapperInterface.php    | 28 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
index 1d75974..127085f 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -353,6 +353,13 @@ public function stream_metadata($uri, $option, $value) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function stream_set_option($option, $arg1, $arg2) {
+    return FALSE;
+  }
+
+  /**
    * Support for unlink().
    *
    * @param string $uri
diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index c3a733f..0627e21 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -157,7 +157,35 @@ public function stream_read($count);
   public function stream_seek($offset, $whence = SEEK_SET);
 
   /**
+   * Change stream options.
+   *
+   * This method is called to set options on the stream.
+   *
+   * @param int $option
+   *   One of:
+   *   - STREAM_OPTION_BLOCKING: The method was called in response to
+   *     stream_set_blocking().
+   *   - STREAM_OPTION_READ_TIMEOUT: The method was called in response to
+   *     stream_set_timeout().
+   *   - STREAM_OPTION_WRITE_BUFFER: The method was called in response to
+   *     stream_set_write_buffer().
+   * @param int $arg1
+   *   If option is:
+   *   - STREAM_OPTION_BLOCKING: The requested blocking mode:
+   *     - 1 means blocking.
+   *     - 0 means not blocking.
+   *   - STREAM_OPTION_READ_TIMEOUT: The timeout in seconds.
+   *   - STREAM_OPTION_WRITE_BUFFER: The buffer mode, STREAM_BUFFER_NONE or
+   *     STREAM_BUFFER_FULL.
+   * @param int $arg2
+   *   If option is:
+   *   - STREAM_OPTION_BLOCKING: This option is not set.
+   *   - STREAM_OPTION_READ_TIMEOUT: The timeout in microseconds.
+   *   - STREAM_OPTION_WRITE_BUFFER: The requested buffer size.
+   *
    * @return bool
+   *   TRUE on success, FALSE otherwise. If $option is not implemented, FALSE
+   *   should be returned.
    */
   public function stream_set_option($option, $arg1, $arg2);
 
-- 
1.7.11.msysgit.1


From 6fdb385b05b7f5a9a937ff91ccc8a692589a5992 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sun, 30 Mar 2014 13:24:34 +0200
Subject: [PATCH 6/6] Added stream_truncate().

---
 core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php       | 8 ++++++++
 core/lib/Drupal/Core/StreamWrapper/LocalStream.php               | 7 +++++++
 core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php | 8 ++++++++
 core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php            | 8 ++++++++
 4 files changed, 31 insertions(+)

diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
index b4aede3..f55591b 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
@@ -138,6 +138,14 @@ public function stream_metadata($uri, $option, $value) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function stream_truncate($new_size) {
+    trigger_error('stream_truncate() not supported for read-only stream wrappers', E_USER_WARNING);
+    return FALSE;
+  }
+
+  /**
    * Support for unlink().
    *
    * The file will not be deleted from the stream as this is a read-only stream
diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
index 127085f..4517876 100644
--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -360,6 +360,13 @@ public function stream_set_option($option, $arg1, $arg2) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function stream_truncate($new_size) {
+    return FALSE;
+  }
+
+  /**
    * Support for unlink().
    *
    * @param string $uri
diff --git a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
index 0627e21..dadeb64 100644
--- a/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
+++ b/core/lib/Drupal/Core/StreamWrapper/PhpStreamWrapperInterface.php
@@ -200,7 +200,15 @@ public function stream_stat();
   public function stream_tell();
 
   /**
+   * Truncate stream.
+   *
+   * Will respond to truncation; e.g., through ftruncate().
+   *
+   * @param int $new_size
+   *   The new size.
+   *
    * @return bool
+   *   TRUE on success, FALSE otherwise.
    */
   public function stream_truncate($new_size);
 
diff --git a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
index c45ef6e..c841444 100644
--- a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php
@@ -172,6 +172,14 @@ public function stream_metadata($uri, $option, $value) {
   }
 
   /**
+   * {@inheritdoc}
+   */
+  public function stream_truncate($new_size) {
+    trigger_error('stream_truncate() not supported for read-only stream wrappers', E_USER_WARNING);
+    return FALSE;
+  }
+
+  /**
    * Support for unlink().
    *
    * The file will not be deleted from the stream as this is a read-only stream
-- 
1.7.11.msysgit.1

