Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
53692e5f
Commit
53692e5f
authored
Mar 10, 2012
by
Angie Byron
Browse files
BAH. I hate my life.
parent
b27e9069
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
core/includes/file.inc
View file @
53692e5f
...
...
@@ -5,14 +5,78 @@
* API for handling file uploads and server file management.
*/
use
Drupal\Core\StreamWrapper\LocalStream
;
/**
*
Manually include stream wrapper code
.
*
Stream wrapper bit flags that are the basis for composite types
.
*
* 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).
* 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.
*/
require_once
DRUPAL_ROOT
.
'/core/includes/stream_wrappers.inc'
;
define
(
'STREAM_WRAPPERS_LOCAL_NORMAL'
,
STREAM_WRAPPERS_LOCAL
|
STREAM_WRAPPERS_NORMAL
)
;
/**
* @defgroup file File interface
...
...
@@ -133,7 +197,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
(
'DrupalStreamWrapperInterface'
,
class_implements
(
$info
[
'class'
]),
TRUE
))
{
if
(
in_array
(
'Drupal
\Core\StreamWrapper\
StreamWrapperInterface'
,
class_implements
(
$info
[
'class'
]),
TRUE
))
{
// Record whether we are overriding an existing scheme.
if
(
in_array
(
$scheme
,
$existing
,
TRUE
))
{
$wrappers
[
$scheme
][
'override'
]
=
TRUE
;
...
...
@@ -302,7 +366,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
Private
StreamWrapper).
* (Drupal
\Core\
StreamWrapper
\PrivateStream
).
*/
function
file_stream_wrapper_get_instance_by_uri
(
$uri
)
{
$scheme
=
file_uri_scheme
(
$uri
);
...
...
@@ -334,7 +398,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
Public
StreamWrapper).
* (Drupal
\Core\
StreamWrapper
\PublicStream
).
* FALSE is returned if no registered handler could be found.
*/
function
file_stream_wrapper_get_instance_by_scheme
(
$scheme
)
{
...
...
@@ -2122,7 +2186,7 @@ function file_get_mimetype($uri, $mapping = NULL) {
else
{
// getMimeType() is not implementation specific, so we can directly
// call it without an instance.
return
Drupal
LocalStream
Wrapper
::
getMimeType
(
$uri
,
$mapping
);
return
LocalStream
::
getMimeType
(
$uri
,
$mapping
);
}
}
...
...
@@ -2235,7 +2299,7 @@ function drupal_unlink($uri, $context = NULL) {
*
* @todo This function is deprecated, and should be removed wherever possible.
*
* @see DrupalStreamWrapperInterface::realpath()
* @see Drupal
\Core\StreamWrapper\
StreamWrapperInterface::realpath()
* @see http://php.net/manual/function.realpath.php
* @ingroup php_wrappers
*/
...
...
core/includes/stream_wrappers.inc
deleted
100644 → 0
View file @
b27e9069
This diff is collapsed.
Click to expand it.
core/modules/simpletest/tests/file.test
View file @
53692e5f
...
...
@@ -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
Public
StreamWrapper'
,
file_stream_wrapper_get_class
(
'public'
),
t
(
'Got correct class name for public scheme.'
));
$this
->
assertEqual
(
'Drupal
\Core\
StreamWrapper
\PublicStream
'
,
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
Public
StreamWrapper'
,
get_class
(
$instance
),
t
(
'Got correct class type for public scheme.'
));
$this
->
assertEqual
(
'Drupal
\Core\
StreamWrapper
\PublicStream
'
,
get_class
(
$instance
),
t
(
'Got correct class type for public scheme.'
));
}
/**
...
...
@@ -2736,13 +2736,14 @@ 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
Public
StreamWrapper'
,
get_class
(
$instance
),
t
(
'Got correct class type for public URI.'
));
$this
->
assertEqual
(
'Drupal
\Core\
StreamWrapper
\PublicStream
'
,
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 DrupalLocalStreamWrapper::getDirectoryPath().
// Test file_build_uri() and
// Drupal\Core\StreamWrapper\LocalStream::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.'
));
...
...
core/modules/simpletest/tests/file_test.module
View file @
53692e5f
...
...
@@ -8,6 +8,8 @@
* 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'
;
...
...
@@ -423,7 +425,7 @@ function file_test_file_mimetype_mapping_alter(&$mapping) {
*
* Dummy stream wrapper implementation (dummy://).
*/
class
DrupalDummyStreamWrapper
extends
Drupal
LocalStream
Wrapper
{
class
DrupalDummyStreamWrapper
extends
LocalStream
{
function
getDirectoryPath
()
{
return
variable_get
(
'stream_public_path'
,
'sites/default/files'
);
}
...
...
@@ -454,7 +456,7 @@ function getExternalUrl() {
*
* Basically just the public scheme but not returning a local file for realpath.
*/
class
DrupalDummyRemoteStreamWrapper
extends
Drupal
PublicStream
Wrapper
{
class
DrupalDummyRemoteStreamWrapper
extends
PublicStream
{
function
realpath
()
{
return
FALSE
;
}
...
...
core/modules/system/system.api.php
View file @
53692e5f
...
...
@@ -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
* DrupalStreamWrapperInterface interface.
* Drupal
\Core\StreamWrapper\
StreamWrapperInterface 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
stream_wrappers
.inc. Defaults to
* Many shortcut constants are defined in
file
.inc. Defaults to
* STREAM_WRAPPERS_NORMAL which includes all of these bit flags:
* - STREAM_WRAPPERS_READ
* - STREAM_WRAPPERS_WRITE
...
...
@@ -2225,31 +2225,33 @@ function hook_stream_wrappers() {
return
array
(
'public'
=>
array
(
'name'
=>
t
(
'Public files'
),
'class'
=>
'Drupal
Public
StreamWrapper'
,
'class'
=>
'Drupal
\Core\
StreamWrapper
\PublicStream
'
,
'description'
=>
t
(
'Public local files served by the webserver.'
),
'type'
=>
STREAM_WRAPPERS_LOCAL_NORMAL
,
),
'private'
=>
array
(
'name'
=>
t
(
'Private files'
),
'class'
=>
'Drupal
Private
StreamWrapper'
,
'class'
=>
'Drupal
\Core\
StreamWrapper
\PrivateStream
'
,
'description'
=>
t
(
'Private local files served by Drupal.'
),
'type'
=>
STREAM_WRAPPERS_LOCAL_NORMAL
,
),
'temp'
=>
array
(
'name'
=>
t
(
'Temporary files'
),
'class'
=>
'Drupal
Temp
StreamWrapper'
,
'class'
=>
'Drupal
\Core\
StreamWrapper
\TemporaryStream
'
,
'description'
=>
t
(
'Temporary local files for upload and previews.'
),
'type'
=>
STREAM_WRAPPERS_LOCAL_HIDDEN
,
),
'cdn'
=>
array
(
'name'
=>
t
(
'Content delivery network files'
),
'class'
=>
'MyModuleCDNStreamWrapper'
,
// @todo: Fix the name of this class when we decide on module PSR-0 usage.
'class'
=>
'MyModuleCDNStream'
,
'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'
),
'class'
=>
'MyModuleYouTubeStreamWrapper'
,
// @todo: Fix the name of this class when we decide on module PSR-0 usage.
'class'
=>
'MyModuleYouTubeStream'
,
'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
...
...
core/modules/system/system.module
View file @
53692e5f
...
...
@@ -1679,13 +1679,13 @@ function system_stream_wrappers() {
$wrappers
=
array
(
'public'
=>
array
(
'name'
=>
t
(
'Public files'
),
'class'
=>
'Drupal
Public
StreamWrapper'
,
'class'
=>
'Drupal
\Core\
StreamWrapper
\PublicStream
'
,
'description'
=>
t
(
'Public local files served by the webserver.'
),
'type'
=>
STREAM_WRAPPERS_LOCAL_NORMAL
,
),
'temporary'
=>
array
(
'name'
=>
t
(
'Temporary files'
),
'class'
=>
'DrupalTemporaryStream
Wrapper
'
,
'class'
=>
'Drupal
\Core\StreamWrapper\
TemporaryStream'
,
'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
Private
StreamWrapper'
,
'class'
=>
'Drupal
\Core\
StreamWrapper
\PrivateStream
'
,
'description'
=>
t
(
'Private local files served by Drupal.'
),
'type'
=>
STREAM_WRAPPERS_LOCAL_NORMAL
,
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment