rfc:linking_in_stream_wrappers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:linking_in_stream_wrappers [2014/10/25 11:20] – List formatting thekidrfc:linking_in_stream_wrappers [2017/09/22 13:28] – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2014-10-25   * Date: 2014-10-25
   * Author: Timm Friebe, thekid@php.net   * Author: Timm Friebe, thekid@php.net
 +  * Contributor: Frank Kleine, https://github.com/mikey179/
   * Status: Draft   * Status: Draft
   * First Published at: https://wiki.php.net/rfc/linking_in_stream_wrappers   * First Published at: https://wiki.php.net/rfc/linking_in_stream_wrappers
Line 19: Line 20:
 Currently, #2 and #3 are already supported by [[http://php.net/manual/en/streamwrapper.url-stat.php|streamWrapper::url_stat()]]. With this accomplished, frameworks such as [[http://vfs.bovigo.org/|vfsStream]] can support testability of symlinking correctly. Currently, #2 and #3 are already supported by [[http://php.net/manual/en/streamwrapper.url-stat.php|streamWrapper::url_stat()]]. With this accomplished, frameworks such as [[http://vfs.bovigo.org/|vfsStream]] can support testability of symlinking correctly.
  
 +Use case #1 - **new functionality**:
 <PHP>  <PHP> 
 class wrapper { class wrapper {
  
   /**   /**
-   1 - Creates a symbolic link to the existing target with the specified name link. +   * Creates a hard link to the existing target with the specified name link. 
    *    *
    * @param  string $target    * @param  string $target
Line 34: Line 36:
  
   /**   /**
-   1 - Creates a symbolic link to the existing target with the specified name link. +   * Creates a symbolic link to the existing target with the specified name link. 
    *    *
    * @param  string $target    * @param  string $target
Line 43: Line 45:
     // ...     // ...
   }   }
 +}
 +</PHP>
 +
 +Use cases #2 and #3 - //already possible today//:
 +<PHP>
 +class wrapper {
 +
 +  /**
 +   * See http://php.net/manual/en/streamwrapper.url-stat.php
 +   *
 +   * @param  string $url
 +   * @param  int $flags
 +   * @return array or FALSE on error
 +   */
 +  function url_stat($url, $flags) {
 +    if ($flags & STREAM_URL_STAT_LINK) {
 +      // Stat the link, not the file it points to
 +    }
 +
 +    // ...
 + 
 +    return [
 +      // ...
 +      'mode' => $permissions & 0120000  // S_ISLINK
 +    ]; 
 +  }
 +}
 +</PHP>
 +
 +Use case #4 - **new functionality**:
 +<PHP>
 +class wrapper {
  
   /**   /**
-   4 - Reads a link and returns the target+   * Reads a link and returns the target
    *    *
    * @param  string $link    * @param  string $link
-   * @return string The link target or NULL+   * @return string The link target or FALSE if the does not exist
    */    */
   function url_readlink($link) {   function url_readlink($link) {
Line 54: Line 88:
   }   }
 } }
 +</PHP>
 +
 +  * When url_readlink() returns a string, it will be used as readlink()'s return value.
 +  * When url_readlink() returns FALSE, readlink() quietly returns FALSE
 +  * For all other return values of url_readlink(), a warning is raised and readlink() returns FALSE
 +  * When url_readlink() is not implemented, a warning is raised an readlink() returns FALSE.
 +
 +==== Limitations ====
 +
 +It will not be possible to create links between two different stream wrappers like this: 
 +
 +<PHP>
 +symlink('foo://some/resource', 'bar://another/resource'); // will yield a PHP_WARNING and return false
 </PHP> </PHP>
  
Line 89: Line 136:
 ===== Patches and Tests ===== ===== Patches and Tests =====
 TODO: Implement and submit GitHub pull request. TODO: Implement and submit GitHub pull request.
 +https://github.com/thekid/php-src/compare/rfc/linking_in_stream_wrappers
  
 ===== References ===== ===== References =====
-See http://php.net/manual/en/class.streamwrapper.php +  * http://php.net/manual/en/class.streamwrapper.php 
-See https://github.com/mikey179/vfsStream/wiki/Known-Issues +  * [[https://github.com/mikey179/vfsStream/wiki/Known-Issues|List of known issues in vfsStream]] 
 +  * [[https://github.com/mikey179/vfsStream/tree/linking|vfsStream reference userland implementation]]
rfc/linking_in_stream_wrappers.txt · Last modified: 2021/03/27 14:47 by ilutov