Commit e4e1a7f0 authored by webchick's avatar webchick

Revert "- Patch #1475020 by amateescu: Convert stream_wrappers().inc to PSR-0."

This reverts commit 45a4c447.
parent 65f25dc9
......@@ -5,78 +5,14 @@
* API for handling file uploads and server file management.
*/
use Drupal\Core\StreamWrapper\LocalStream;
/**
* Stream wrapper bit flags that are the basis for composite types.
* Manually include stream wrapper code.
*
* Note that 0x0002 is skipped, because it was the value of a constant that has
* since been removed.
*/
/**
* Stream wrapper bit flag -- a filter that matches all wrappers.
*/
const STREAM_WRAPPERS_ALL = 0x0000;
/**
* Stream wrapper bit flag -- refers to a local file system location.
*/
const STREAM_WRAPPERS_LOCAL = 0x0001;
/**
* Stream wrapper bit flag -- wrapper is readable (almost always true).
*/
const STREAM_WRAPPERS_READ = 0x0004;
/**
* Stream wrapper bit flag -- wrapper is writeable.
*/
const STREAM_WRAPPERS_WRITE = 0x0008;
/**
* Stream wrapper bit flag -- exposed in the UI and potentially web accessible.
*/
const STREAM_WRAPPERS_VISIBLE = 0x0010;
/**
* Composite stream wrapper bit flags that are usually used as the types.
*/
/**
* Stream wrapper type flag -- not visible in the UI or accessible via web,
* but readable and writable. E.g. the temporary directory for uploads.
*/
define('STREAM_WRAPPERS_HIDDEN', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_WRITE);
/**
* Stream wrapper type flag -- hidden, readable and writeable using local files.
*/
define('STREAM_WRAPPERS_LOCAL_HIDDEN', STREAM_WRAPPERS_LOCAL | STREAM_WRAPPERS_HIDDEN);
/**
* Stream wrapper type flag -- visible, readable and writeable.
*/
define('STREAM_WRAPPERS_WRITE_VISIBLE', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_WRITE | STREAM_WRAPPERS_VISIBLE);
/**
* Stream wrapper type flag -- visible and read-only.
*/
define('STREAM_WRAPPERS_READ_VISIBLE', STREAM_WRAPPERS_READ | STREAM_WRAPPERS_VISIBLE);
/**
* Stream wrapper type flag -- the default when 'type' is omitted from
* hook_stream_wrappers(). This does not include STREAM_WRAPPERS_LOCAL,
* because PHP grants a greater trust level to local files (for example, they
* can be used in an "include" statement, regardless of the "allow_url_include"
* setting), so stream wrappers need to explicitly opt-in to this.
*/
define('STREAM_WRAPPERS_NORMAL', STREAM_WRAPPERS_WRITE_VISIBLE);
/**
* Stream wrapper type flag -- visible, readable and writeable using local files.
* Stream wrapper code is included here because there are cases where
* File API is needed before a bootstrap, or in an alternate order (e.g.
* maintenance theme).
*/
define('STREAM_WRAPPERS_LOCAL_NORMAL', STREAM_WRAPPERS_LOCAL | STREAM_WRAPPERS_NORMAL);
require_once DRUPAL_ROOT . '/core/includes/stream_wrappers.inc';
/**
* @defgroup file File interface
......@@ -197,7 +133,7 @@ function file_get_stream_wrappers($filter = STREAM_WRAPPERS_ALL) {
$existing = stream_get_wrappers();
foreach ($wrappers as $scheme => $info) {
// We only register classes that implement our interface.
if (in_array('Drupal\Core\StreamWrapper\StreamWrapperInterface', class_implements($info['class']), TRUE)) {
if (in_array('DrupalStreamWrapperInterface', class_implements($info['class']), TRUE)) {
// Record whether we are overriding an existing scheme.
if (in_array($scheme, $existing, TRUE)) {
$wrappers[$scheme]['override'] = TRUE;
......@@ -366,7 +302,7 @@ function file_stream_wrapper_uri_normalize($uri) {
* Returns a new stream wrapper object appropriate for the given URI or FALSE
* if no registered handler could be found. For example, a URI of
* "private://example.txt" would return a new private stream wrapper object
* (Drupal\Core\StreamWrapper\PrivateStream).
* (DrupalPrivateStreamWrapper).
*/
function file_stream_wrapper_get_instance_by_uri($uri) {
$scheme = file_uri_scheme($uri);
......@@ -398,7 +334,7 @@ function file_stream_wrapper_get_instance_by_uri($uri) {
* @return
* Returns a new stream wrapper object appropriate for the given $scheme.
* For example, for the public scheme a stream wrapper object
* (Drupal\Core\StreamWrapper\PublicStream).
* (DrupalPublicStreamWrapper).
* FALSE is returned if no registered handler could be found.
*/
function file_stream_wrapper_get_instance_by_scheme($scheme) {
......@@ -2186,7 +2122,7 @@ function file_get_mimetype($uri, $mapping = NULL) {
else {
// getMimeType() is not implementation specific, so we can directly
// call it without an instance.
return LocalStream::getMimeType($uri, $mapping);
return DrupalLocalStreamWrapper::getMimeType($uri, $mapping);
}
}
......@@ -2299,7 +2235,7 @@ function drupal_unlink($uri, $context = NULL) {
*
* @todo This function is deprecated, and should be removed wherever possible.
*
* @see Drupal\Core\StreamWrapper\StreamWrapperInterface::realpath()
* @see DrupalStreamWrapperInterface::realpath()
* @see http://php.net/manual/function.realpath.php
* @ingroup php_wrappers
*/
......
This diff is collapsed.
......@@ -2714,7 +2714,7 @@ class StreamWrapperTest extends DrupalWebTestCase {
// Check the dummy scheme.
$this->assertEqual($this->classname, file_stream_wrapper_get_class($this->scheme), t('Got correct class name for dummy scheme.'));
// Check core's scheme.
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', file_stream_wrapper_get_class('public'), t('Got correct class name for public scheme.'));
$this->assertEqual('DrupalPublicStreamWrapper', file_stream_wrapper_get_class('public'), t('Got correct class name for public scheme.'));
}
/**
......@@ -2725,7 +2725,7 @@ class StreamWrapperTest extends DrupalWebTestCase {
$this->assertEqual($this->classname, get_class($instance), t('Got correct class type for dummy scheme.'));
$instance = file_stream_wrapper_get_instance_by_scheme('public');
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), t('Got correct class type for public scheme.'));
$this->assertEqual('DrupalPublicStreamWrapper', get_class($instance), t('Got correct class type for public scheme.'));
}
/**
......@@ -2736,14 +2736,13 @@ class StreamWrapperTest extends DrupalWebTestCase {
$this->assertEqual($this->classname, get_class($instance), t('Got correct class type for dummy URI.'));
$instance = file_stream_wrapper_get_instance_by_uri('public://foo');
$this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), t('Got correct class type for public URI.'));
$this->assertEqual('DrupalPublicStreamWrapper', get_class($instance), t('Got correct class type for public URI.'));
// Test file_uri_target().
$this->assertEqual(file_uri_target('public://foo/bar.txt'), 'foo/bar.txt', t('Got a valid stream target from public://foo/bar.txt.'));
$this->assertFalse(file_uri_target('foo/bar.txt'), t('foo/bar.txt is not a valid stream.'));
// Test file_build_uri() and
// Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath().
// Test file_build_uri() and DrupalLocalStreamWrapper::getDirectoryPath().
$this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', t('Expected scheme was added.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), variable_get('file_public_path'), t('Expected default directory path was returned.'));
$this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), variable_get('file_temporary_path'), t('Expected temporary directory path was returned.'));
......
......@@ -8,8 +8,6 @@
* calling file_test_get_calls() or file_test_set_return().
*/
use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\PublicStream;
const FILE_URL_TEST_CDN_1 = 'http://cdn1.example.com';
const FILE_URL_TEST_CDN_2 = 'http://cdn2.example.com';
......@@ -425,7 +423,7 @@ function file_test_file_mimetype_mapping_alter(&$mapping) {
*
* Dummy stream wrapper implementation (dummy://).
*/
class DrupalDummyStreamWrapper extends LocalStream {
class DrupalDummyStreamWrapper extends DrupalLocalStreamWrapper {
function getDirectoryPath() {
return variable_get('stream_public_path', 'sites/default/files');
}
......@@ -456,7 +454,7 @@ function getExternalUrl() {
*
* Basically just the public scheme but not returning a local file for realpath.
*/
class DrupalDummyRemoteStreamWrapper extends PublicStream {
class DrupalDummyRemoteStreamWrapper extends DrupalPublicStreamWrapper {
function realpath() {
return FALSE;
}
......
......@@ -2207,11 +2207,11 @@ function hook_modules_uninstalled($modules) {
* then keyed by the following values:
* - 'name' A short string to name the wrapper.
* - 'class' A string specifying the PHP class that implements the
* Drupal\Core\StreamWrapper\StreamWrapperInterface interface.
* DrupalStreamWrapperInterface interface.
* - 'description' A string with a short description of what the wrapper does.
* - 'type' (Optional) A bitmask of flags indicating what type of streams this
* wrapper will access - local or remote, readable and/or writeable, etc.
* Many shortcut constants are defined in file.inc. Defaults to
* Many shortcut constants are defined in stream_wrappers.inc. Defaults to
* STREAM_WRAPPERS_NORMAL which includes all of these bit flags:
* - STREAM_WRAPPERS_READ
* - STREAM_WRAPPERS_WRITE
......@@ -2225,33 +2225,31 @@ function hook_stream_wrappers() {
return array(
'public' => array(
'name' => t('Public files'),
'class' => 'Drupal\Core\StreamWrapper\PublicStream',
'class' => 'DrupalPublicStreamWrapper',
'description' => t('Public local files served by the webserver.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
),
'private' => array(
'name' => t('Private files'),
'class' => 'Drupal\Core\StreamWrapper\PrivateStream',
'class' => 'DrupalPrivateStreamWrapper',
'description' => t('Private local files served by Drupal.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
),
'temp' => array(
'name' => t('Temporary files'),
'class' => 'Drupal\Core\StreamWrapper\TemporaryStream',
'class' => 'DrupalTempStreamWrapper',
'description' => t('Temporary local files for upload and previews.'),
'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
),
'cdn' => array(
'name' => t('Content delivery network files'),
// @todo: Fix the name of this class when we decide on module PSR-0 usage.
'class' => 'MyModuleCDNStream',
'class' => 'MyModuleCDNStreamWrapper',
'description' => t('Files served by a content delivery network.'),
// 'type' can be omitted to use the default of STREAM_WRAPPERS_NORMAL
),
'youtube' => array(
'name' => t('YouTube video'),
// @todo: Fix the name of this class when we decide on module PSR-0 usage.
'class' => 'MyModuleYouTubeStream',
'class' => 'MyModuleYouTubeStreamWrapper',
'description' => t('Video streamed from YouTube.'),
// A module implementing YouTube integration may decide to support using
// the YouTube API for uploading video, but here, we assume that this
......
......@@ -1679,13 +1679,13 @@ function system_stream_wrappers() {
$wrappers = array(
'public' => array(
'name' => t('Public files'),
'class' => 'Drupal\Core\StreamWrapper\PublicStream',
'class' => 'DrupalPublicStreamWrapper',
'description' => t('Public local files served by the webserver.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
),
'temporary' => array(
'name' => t('Temporary files'),
'class' => 'Drupal\Core\StreamWrapper\TemporaryStream',
'class' => 'DrupalTemporaryStreamWrapper',
'description' => t('Temporary local files for upload and previews.'),
'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
),
......@@ -1695,7 +1695,7 @@ function system_stream_wrappers() {
if (variable_get('file_private_path', FALSE)) {
$wrappers['private'] = array(
'name' => t('Private files'),
'class' => 'Drupal\Core\StreamWrapper\PrivateStream',
'class' => 'DrupalPrivateStreamWrapper',
'description' => t('Private local files served by Drupal.'),
'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment