StreamWrapperInterface.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace Drupal\Core\StreamWrapper;
  3. /**
  4. * Defines a Drupal stream wrapper extension.
  5. *
  6. * Provides a Drupal interface and classes to implement PHP stream wrappers for
  7. * public, private, and temporary files. Extends the PhpStreamWrapperInterface
  8. * with methods expected by Drupal stream wrapper classes.
  9. *
  10. * A stream wrapper is an abstraction of a file system that allows Drupal to
  11. * use the same set of methods to access both local files and remote resources.
  12. *
  13. * Note that PHP 5.2 fopen() only supports URIs of the form "scheme://target"
  14. * despite the fact that according to RFC 3986 a URI's scheme component
  15. * delimiter is in general just ":", not "://". Because of this PHP limitation
  16. * and for consistency Drupal will only accept URIs of form "scheme://target".
  17. *
  18. * @see http://www.faqs.org/rfcs/rfc3986.html
  19. * @see http://bugs.php.net/bug.php?id=47070
  20. */
  21. interface StreamWrapperInterface extends PhpStreamWrapperInterface {
  22. /**
  23. * Stream wrapper bit flags that are the basis for composite types.
  24. *
  25. * Note that 0x0002 is skipped, because it was the value of a constant that
  26. * has since been removed.
  27. */
  28. /**
  29. * A filter that matches all wrappers.
  30. */
  31. const ALL = 0x0000;
  32. /**
  33. * Refers to a local file system location.
  34. */
  35. const LOCAL = 0x0001;
  36. /**
  37. * Wrapper is readable (almost always true).
  38. */
  39. const READ = 0x0004;
  40. /**
  41. * Wrapper is writeable.
  42. */
  43. const WRITE = 0x0008;
  44. /**
  45. * Exposed in the UI and potentially web accessible.
  46. */
  47. const VISIBLE = 0x0010;
  48. /**
  49. * Composite stream wrapper bit flags that are usually used as the types.
  50. */
  51. /**
  52. * Defines the stream wrapper bit flag for a hidden file.
  53. *
  54. * This is not visible in the UI or accessible via web, but readable and
  55. * writable; for instance, the temporary directory for file uploads.
  56. */
  57. const HIDDEN = 0x000C;
  58. /**
  59. * Hidden, readable and writeable using local files.
  60. */
  61. const LOCAL_HIDDEN = 0x000D;
  62. /**
  63. * Visible, readable and writeable.
  64. */
  65. const WRITE_VISIBLE = 0x001C;
  66. /**
  67. * Visible and read-only.
  68. */
  69. const READ_VISIBLE = 0x0014;
  70. /**
  71. * This is the default 'type' flag. This does not include
  72. * StreamWrapperInterface::LOCAL, because PHP grants a greater trust level to
  73. * local files (for example, they can be used in an "include" statement,
  74. * regardless of the "allow_url_include" setting), so stream wrappers need to
  75. * explicitly opt-in to this.
  76. */
  77. const NORMAL = 0x001C;
  78. /**
  79. * Visible, readable and writeable using local files.
  80. */
  81. const LOCAL_NORMAL = 0x001D;
  82. /**
  83. * Returns the type of stream wrapper.
  84. *
  85. * @return int
  86. */
  87. public static function getType();
  88. /**
  89. * Returns the name of the stream wrapper for use in the UI.
  90. *
  91. * @return string
  92. * The stream wrapper name.
  93. */
  94. public function getName();
  95. /**
  96. * Returns the description of the stream wrapper for use in the UI.
  97. *
  98. * @return string
  99. * The stream wrapper description.
  100. */
  101. public function getDescription();
  102. /**
  103. * Sets the absolute stream resource URI.
  104. *
  105. * This allows you to set the URI. Generally is only called by the factory
  106. * method.
  107. *
  108. * @param string $uri
  109. * A string containing the URI that should be used for this instance.
  110. */
  111. public function setUri($uri);
  112. /**
  113. * Returns the stream resource URI.
  114. *
  115. * @return string
  116. * Returns the current URI of the instance.
  117. */
  118. public function getUri();
  119. /**
  120. * Returns a web accessible URL for the resource.
  121. *
  122. * This function should return a URL that can be embedded in a web page
  123. * and accessed from a browser. For example, the external URL of
  124. * "youtube://xIpLd0WQKCY" might be
  125. * "http://www.youtube.com/watch?v=xIpLd0WQKCY".
  126. *
  127. * @return string
  128. * Returns a string containing a web accessible URL for the resource.
  129. */
  130. public function getExternalUrl();
  131. /**
  132. * Returns canonical, absolute path of the resource.
  133. *
  134. * Implementation placeholder. PHP's realpath() does not support stream
  135. * wrappers. We provide this as a default so that individual wrappers may
  136. * implement their own solutions.
  137. *
  138. * @return string
  139. * Returns a string with absolute pathname on success (implemented
  140. * by core wrappers), or FALSE on failure or if the registered
  141. * wrapper does not provide an implementation.
  142. */
  143. public function realpath();
  144. /**
  145. * Gets the name of the directory from a given path.
  146. *
  147. * This method is usually accessed through drupal_dirname(), which wraps
  148. * around the normal PHP dirname() function, which does not support stream
  149. * wrappers.
  150. *
  151. * @param string $uri
  152. * An optional URI.
  153. *
  154. * @return string
  155. * A string containing the directory name, or FALSE if not applicable.
  156. *
  157. * @see drupal_dirname()
  158. */
  159. public function dirname($uri = NULL);
  160. }