You are here

class DrupalAltStreamWrapper in Alternative Stream Wrappers 7

Drupal alternative stream wrapper class.

Provides support for alternative file storage locations.

This is a generic class which should work for all of the one or more Alternative Stream Wrappers provided by this module.

Extends DrupalLocalStreamWrapper.

Hierarchy

Expanded class hierarchy of DrupalAltStreamWrapper

1 string reference to 'DrupalAltStreamWrapper'
alt_stream_wrappers_stream_wrappers in ./alt_stream_wrappers.module
Implements hook_stream_wrappers().

File

./alt_stream_wrappers.module, line 55
Provides one or more configurable alternative stream wrappers for file storage.

View source
class DrupalAltStreamWrapper extends DrupalLocalStreamWrapper {

  /**
   * Overrides getLocalPath().
   */
  protected function getLocalPath($uri = NULL) {
    if (empty($this->uri) && !empty($uri)) {

      // sometimes necessary for the file_uri_scheme and variable_get
      //  in DrupalAltStreamWrapper's getDirectoryPath method to work
      //  when called from parent::getLocalPath
      $this->uri = $uri;
    }
    return parent::getLocalPath($uri);
  }

  /**
   * Implements abstract public function getDirectoryPath()
   */
  public function getDirectoryPath() {
    $scheme = file_uri_scheme($this->uri);

    // todo: is temp a sensible default here or should it just be FALSE?
    return variable_get('alt_stream_wrappers_' . $scheme . '_path', file_directory_temp());
  }

  /**
   * Overrides getExternalUrl().
   */
  public function getExternalUrl() {
    $scheme = file_uri_scheme($this->uri);

    // What kind of wrapper is this?
    $wrappers = file_get_stream_wrappers();
    $wrapper = isset($wrappers[$scheme]) ? $wrappers[$scheme] : FALSE;
    if ($wrapper) {
      if ($wrapper['type'] & STREAM_WRAPPERS_LOCAL_NORMAL) {

        // Same as public:// stream wrapper
        $path = str_replace('\\', '/', $this
          ->getTarget());
        return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path);
      }
      else {

        // Go through the system module like temporary:// and private://
        //  In order for this file to be downloadable, a module will have to
        //  implement hook_file_download() and return headers for this scheme.
        $path = str_replace('\\', '/', $this
          ->getTarget());
        return url('system/' . $scheme . '/' . $path, array(
          'absolute' => TRUE,
        ));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalAltStreamWrapper::getDirectoryPath public function Implements abstract public function getDirectoryPath() Overrides DrupalLocalStreamWrapper::getDirectoryPath
DrupalAltStreamWrapper::getExternalUrl public function Overrides getExternalUrl(). Overrides DrupalStreamWrapperInterface::getExternalUrl
DrupalAltStreamWrapper::getLocalPath protected function Overrides getLocalPath(). Overrides DrupalLocalStreamWrapper::getLocalPath
DrupalLocalStreamWrapper::$context public property Stream context resource.
DrupalLocalStreamWrapper::$handle public property A generic resource handle.
DrupalLocalStreamWrapper::$uri protected property Instance URI (stream).
DrupalLocalStreamWrapper::chmod function Base implementation of chmod(). Overrides DrupalStreamWrapperInterface::chmod
DrupalLocalStreamWrapper::dirname public function Gets the name of the directory from a given path. Overrides DrupalStreamWrapperInterface::dirname
DrupalLocalStreamWrapper::dir_closedir public function Support for closedir(). Overrides StreamWrapperInterface::dir_closedir
DrupalLocalStreamWrapper::dir_opendir public function Support for opendir(). Overrides StreamWrapperInterface::dir_opendir
DrupalLocalStreamWrapper::dir_readdir public function Support for readdir(). Overrides StreamWrapperInterface::dir_readdir
DrupalLocalStreamWrapper::dir_rewinddir public function Support for rewinddir(). Overrides StreamWrapperInterface::dir_rewinddir
DrupalLocalStreamWrapper::getMimeType static function Base implementation of getMimeType(). Overrides DrupalStreamWrapperInterface::getMimeType
DrupalLocalStreamWrapper::getTarget protected function Returns the local writable target of the resource within the stream.
DrupalLocalStreamWrapper::getUri function Base implementation of getUri(). Overrides DrupalStreamWrapperInterface::getUri
DrupalLocalStreamWrapper::mkdir public function Support for mkdir(). Overrides StreamWrapperInterface::mkdir
DrupalLocalStreamWrapper::realpath function Base implementation of realpath(). Overrides DrupalStreamWrapperInterface::realpath 1
DrupalLocalStreamWrapper::rename public function Support for rename(). Overrides StreamWrapperInterface::rename
DrupalLocalStreamWrapper::rmdir public function Support for rmdir(). Overrides StreamWrapperInterface::rmdir
DrupalLocalStreamWrapper::setUri function Base implementation of setUri(). Overrides DrupalStreamWrapperInterface::setUri
DrupalLocalStreamWrapper::stream_cast public function Retrieve the underlying stream resource.
DrupalLocalStreamWrapper::stream_close public function Support for fclose(). Overrides StreamWrapperInterface::stream_close
DrupalLocalStreamWrapper::stream_eof public function Support for feof(). Overrides StreamWrapperInterface::stream_eof
DrupalLocalStreamWrapper::stream_flush public function Support for fflush(). Overrides StreamWrapperInterface::stream_flush
DrupalLocalStreamWrapper::stream_lock public function Support for flock(). Overrides StreamWrapperInterface::stream_lock
DrupalLocalStreamWrapper::stream_metadata public function Sets metadata on the stream.
DrupalLocalStreamWrapper::stream_open public function Support for fopen(), file_get_contents(), file_put_contents() etc. Overrides StreamWrapperInterface::stream_open
DrupalLocalStreamWrapper::stream_read public function Support for fread(), file_get_contents() etc. Overrides StreamWrapperInterface::stream_read
DrupalLocalStreamWrapper::stream_seek public function Support for fseek(). Overrides StreamWrapperInterface::stream_seek
DrupalLocalStreamWrapper::stream_set_option public function Change stream options.
DrupalLocalStreamWrapper::stream_stat public function Support for fstat(). Overrides StreamWrapperInterface::stream_stat
DrupalLocalStreamWrapper::stream_tell public function Support for ftell(). Overrides StreamWrapperInterface::stream_tell
DrupalLocalStreamWrapper::stream_truncate public function Truncate stream.
DrupalLocalStreamWrapper::stream_write public function Support for fwrite(), file_put_contents() etc. Overrides StreamWrapperInterface::stream_write
DrupalLocalStreamWrapper::unlink public function Support for unlink(). Overrides StreamWrapperInterface::unlink
DrupalLocalStreamWrapper::url_stat public function Support for stat(). Overrides StreamWrapperInterface::url_stat