file_stream_wrapper_get_instance_by_scheme

  1. drupal
    1. 8
    2. 7
Versions
7 – 8 file_stream_wrapper_get_instance_by_scheme($scheme)

Returns a reference to the stream wrapper class responsible for a given scheme.

This helper method returns a stream instance using a scheme. That is, the passed string does not contain a "://". For example, "public" is a scheme but "public://" is a URI (stream). This is because the later contains both a scheme and target despite target being empty.

Note: the instance URI will be initialized to "scheme://" so that you can make the customary method calls as if you had retrieved an instance by URI.

Parameters

$scheme If the stream was "public://target", "public" would be the scheme.

Return value

Returns a new stream wrapper object appropriate for the given $scheme. For example, for the public scheme a stream wrapper object (DrupalPublicStreamWrapper). FALSE is returned if no registered handler could be found.

Related topics

▾ 12 functions call file_stream_wrapper_get_instance_by_scheme()

drupal_dirname in includes/file.inc
Gets the name of the directory from a given path.
drupal_tempnam in includes/file.inc
Creates a file with a unique filename in the specified directory.
FileDownloadTest::testFileCreateUrl in modules/simpletest/tests/file.test
Test file_create_url().
FileDownloadTest::testPublicFileTransfer in modules/simpletest/tests/file.test
Test the public file transfer system.
FileURLRewritingTest::testPublicCreatedFileURL in modules/simpletest/tests/file.test
Test the generating of rewritten public created file URLs.
file_test_file_url_alter in modules/simpletest/tests/file_test.module
Implements hook_file_url_alter().
hook_file_url_alter in modules/system/system.api.php
Alter the URL to a file.
image_menu in modules/image/image.module
Implements hook_menu().
SessionTestCase::sessionReset in modules/simpletest/tests/session.test
Reset the cookie file so that it refers to the specified user.
StreamWrapperTest::testGetInstanceByScheme in modules/simpletest/tests/file.test
Test the file_stream_wrapper_get_instance_by_scheme() function.
StreamWrapperTest::testUriFunctions in modules/simpletest/tests/file.test
Test the URI and target functions.
Updater::getBackupDir in includes/updater.inc
Return the full path to a directory where backups should be written.

Code

includes/file.inc, line 344

<?php
function file_stream_wrapper_get_instance_by_scheme($scheme) {
  $class = file_stream_wrapper_get_class($scheme);
  if (class_exists($class)) {
    $instance = new $class();
    $instance->setUri($scheme . '://');
    return $instance;
  }
  else {
    return FALSE;
  }
}
?>