diff --git a/core/core.services.yml b/core/core.services.yml index a194ead..15c7392 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1381,6 +1381,7 @@ services: alias: plugin.manager.element_info file.mime_type.guesser: class: Drupal\Core\File\MimeType\MimeTypeGuesser + arguments: ['@stream_wrapper_manager'] tags: - { name: service_collector, tag: mime_type_guesser, call: addGuesser } lazy: true diff --git a/core/includes/file.inc b/core/includes/file.inc index 4440d41..8228b00 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -331,7 +331,7 @@ function file_create_url($uri) { } else { // Attempt to return an external URL using the appropriate wrapper. - if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) { + if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)) { return $wrapper->getExternalUrl(); } else { diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index e523943..56902a7 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -253,12 +253,11 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Record the fact that it was installed. $modules_installed[] = $module; - // file_get_stream_wrappers() needs to re-register Drupal's stream - // wrappers in case a module-provided stream wrapper is used later in - // the same request. In particular, this happens when installing Drupal - // via Drush, as the 'translations' stream wrapper is provided by - // Interface Translation module and is later used to import - // translations. + // Drupal's stream wrappers needs to be re-registered in case a + // module-provided stream wrapper is used later in the same request. In + // particular, this happens when installing Drupal via Drush, as the + // 'translations' stream wrapper is provided by Interface Translation + // module and is later used to import translations. \Drupal::service('stream_wrapper_manager')->register(); // Update the theme registry to include it. diff --git a/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php b/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php index e003b8c..cac7a66 100644 --- a/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php +++ b/core/lib/Drupal/Core/File/MimeType/MimeTypeGuesser.php @@ -7,6 +7,7 @@ namespace Drupal\Core\File\MimeType; +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; @@ -35,11 +36,28 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface { */ protected $sortedGuessers = NULL; + /** + * The stream wrapper manager. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface + */ + protected $streamWrapperManager; + + /** + * Constructs a MimeTypeGuesser object. + * + * @param StreamWrapperManagerInterface $streamWrapperManager + * The stream wrapper manager. + */ + public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) { + $this->streamWrapperManager = $stream_wrapper_manager; + } + /** * {@inheritdoc} */ public function guess($path) { - if ($wrapper = file_stream_wrapper_get_instance_by_uri($path)) { + if ($wrapper = $this->streamWrapperManager->getViaUri($path)) { // Get the real path from the stream wrapper. $path = $wrapper->realpath(); } diff --git a/core/lib/Drupal/Core/File/file.api.php b/core/lib/Drupal/Core/File/file.api.php index a4fd8e4..43913fb 100644 --- a/core/lib/Drupal/Core/File/file.api.php +++ b/core/lib/Drupal/Core/File/file.api.php @@ -80,7 +80,7 @@ function hook_file_url_alter(&$uri) { } // Public created files. else { - $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme); $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri); } diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php index dc9f4b6..6886bb2 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php @@ -12,7 +12,6 @@ /** * Provides a StreamWrapper manager. * - * @see file_get_stream_wrappers() * @see \Drupal\Core\StreamWrapper\StreamWrapperInterface */ class StreamWrapperManager extends ContainerAware implements StreamWrapperManagerInterface { diff --git a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManagerInterface.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManagerInterface.php index 34e5f81..086e34e 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManagerInterface.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManagerInterface.php @@ -10,7 +10,6 @@ /** * Provides a StreamWrapper manager. * - * @see file_get_stream_wrappers() * @see \Drupal\Core\StreamWrapper\StreamWrapperInterface */ interface StreamWrapperManagerInterface { @@ -39,8 +38,8 @@ * returns only stream wrappers that use local file storage: * * @code - * $local_stream_wrappers = - * file_get_stream_wrappers(StreamWrapperInterface::LOCAL); + * $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); + * $local_stream_wrappers = $stream_wrapper_manager->getWrappers(StreamWrapperInterface::LOCAL); * @endcode * * The $filter parameter can only filter to types containing a particular @@ -50,9 +49,11 @@ * array_diff_key() function can be used to help with this. For example, this * returns only stream wrappers that do not use local file storage: * @code - * $remote_stream_wrappers = - * array_diff_key(file_get_stream_wrappers(StreamWrapperInterface::ALL), - * file_get_stream_wrappers(StreamWrapperInterface::LOCAL)); + * $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); + * $remote_stream_wrappers = array_diff_key( + * $stream_wrapper_manager->getWrappers(StreamWrapperInterface::ALL), + * $stream_wrapper_manager->getWrappers(StreamWrapperInterface::LOCAL) + * ); * @endcode * * @param int $filter diff --git a/core/lib/Drupal/Core/Updater/Updater.php b/core/lib/Drupal/Core/Updater/Updater.php index 177b11d..4f56cd9 100644 --- a/core/lib/Drupal/Core/Updater/Updater.php +++ b/core/lib/Drupal/Core/Updater/Updater.php @@ -365,7 +365,7 @@ public function makeBackup(FileTransfer $filetransfer, $from, $to) { * Returns the full path to a directory where backups should be written. */ public function getBackupDir() { - return file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(); + return \Drupal::service('stream_wrapper_manager')->getViaScheme('temporary')->getDirectoryPath(); } /** diff --git a/core/modules/file/src/Tests/DownloadTest.php b/core/modules/file/src/Tests/DownloadTest.php index 25aab9b..d2df0d2 100644 --- a/core/modules/file/src/Tests/DownloadTest.php +++ b/core/modules/file/src/Tests/DownloadTest.php @@ -30,7 +30,7 @@ function testPublicFileTransfer() { $url = file_create_url($file->getFileUri()); // URLs can't contain characters outside the ASCII set so $filename has to be // encoded. - $filename = $GLOBALS['base_url'] . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); + $filename = $GLOBALS['base_url'] . '/' . \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); $this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.'); $this->drupalHead($url); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the created file.'); @@ -117,7 +117,7 @@ function testFileCreateUrl() { $clean_urls = $clean_url_setting == 'clean'; $request = $this->prepareRequestForGenerator($clean_urls); $base_path = $request->getSchemeAndHttpHost() . $request->getBasePath(); - $this->checkUrl('public', '', $basename, $base_path . '/' . file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath() . '/' . $basename_encoded); + $this->checkUrl('public', '', $basename, $base_path . '/' . \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath() . '/' . $basename_encoded); $this->checkUrl('private', '', $basename, $base_path . '/' . $script_path . 'system/files/' . $basename_encoded); } $this->assertEqual(file_create_url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', t('Generated URL matches expected URL.')); diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module index e7ec56c..7b25af4 100644 --- a/core/modules/file/tests/file_test/file_test.module +++ b/core/modules/file/tests/file_test/file_test.module @@ -222,7 +222,7 @@ function file_test_file_url_alter(&$uri) { } // Public created files. else { - $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme); $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri); } @@ -252,7 +252,7 @@ function file_test_file_url_alter(&$uri) { } // Public created files. else { - $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme); $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri); } @@ -275,7 +275,7 @@ function file_test_file_url_alter(&$uri) { } // Public created files. else { - $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme); $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri); } diff --git a/core/modules/image/image.services.yml b/core/modules/image/image.services.yml index 88770c6..2f17bb5 100644 --- a/core/modules/image/image.services.yml +++ b/core/modules/image/image.services.yml @@ -1,6 +1,7 @@ services: path_processor.image_styles: class: Drupal\image\PathProcessor\PathProcessorImageStyles + arguments: ['@stream_wrapper_manager'] tags: - { name: path_processor_inbound, priority: 300 } plugin.manager.image.effect: diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index a05d3a8..57d4a30 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -226,7 +226,7 @@ public function buildUrl($path, $clean_urls = NULL) { // to the actual file path, this avoids bootstrapping PHP once the files are // built. if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) { - $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath(); + $directory_path = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)->getDirectoryPath(); return Url::fromUri('base:' . $directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query))->toString(); } diff --git a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php index 58cbe75..f3948d8 100644 --- a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php +++ b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php @@ -8,6 +8,7 @@ namespace Drupal\image\PathProcessor; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -28,10 +29,27 @@ class PathProcessorImageStyles implements InboundPathProcessorInterface { /** + * The stream wrapper manager service. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface + */ + protected $streamWrapperManager; + + /** + * Constructs a new PathProcessorImageStyles object. + * + * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager + * The stream wrapper manager service. + */ + public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) { + $this->streamWrapperManager = $stream_wrapper_manager; + } + + /** * {@inheritdoc} */ public function processInbound($path, Request $request) { - $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); + $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath(); if (strpos($path, '/' . $directory_path . '/styles/') === 0) { $path_prefix = '/' . $directory_path . '/styles/'; } diff --git a/core/modules/image/src/Routing/ImageStyleRoutes.php b/core/modules/image/src/Routing/ImageStyleRoutes.php index 32e8f2b..44829ed 100644 --- a/core/modules/image/src/Routing/ImageStyleRoutes.php +++ b/core/modules/image/src/Routing/ImageStyleRoutes.php @@ -7,12 +7,41 @@ namespace Drupal\image\Routing; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; /** * Defines a route subscriber to register a url for serving image styles. */ -class ImageStyleRoutes { +class ImageStyleRoutes implements ContainerInjectionInterface { + + /** + * The stream wrapper manager service. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface + */ + protected $streamWrapperManager; + + /** + * Constructs a new PathProcessorImageStyles object. + * + * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager + * The stream wrapper manager service. + */ + public function __construct(StreamWrapperManagerInterface $stream_wrapper_manager) { + $this->streamWrapperManager = $stream_wrapper_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('stream_wrapper_manager') + ); + } /** * Returns an array of route objects. @@ -26,7 +55,7 @@ public function routes() { // disabled image derivatives will always be served through the menu system. // If clean URLs are enabled and the image derivative already exists, PHP // will be bypassed. - $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); + $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath(); $routes['image.style_public'] = new Route( '/' . $directory_path . '/styles/{image_style}/{scheme}', diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index d16330f..8738500 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -9,8 +9,12 @@ use Drupal\Component\Utility\Color; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\ImageToolkit\ImageToolkitBase; +use Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface; +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; @@ -54,6 +58,36 @@ class GDToolkit extends ImageToolkitBase { protected $preLoadInfo = NULL; /** + * The StreamWrapper manager. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface + */ + protected $streamWrapperManager; + + /** + * Constructs a TestToolkit object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface $operation_manager + * The toolkit operation manager. + * @param \Psr\Log\LoggerInterface $logger + * A logger instance. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory. + * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager + * The StreamWrapper manager. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManagerInterface $stream_wrapper_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $operation_manager, $logger, $config_factory); + $this->streamWrapperManager = $stream_wrapper_manager; + } + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { @@ -63,7 +97,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('image.toolkit.operation.manager'), $container->get('logger.channel.image'), - $container->get('config.factory') + $container->get('config.factory'), + $container->get('stream_wrapper_manager') ); } @@ -172,7 +207,7 @@ public function save($destination) { // Work around lack of stream wrapper support in imagejpeg() and imagepng(). if ($scheme && file_stream_wrapper_valid_scheme($scheme)) { // If destination is not local, save image to temporary local file. - $local_wrappers = file_get_stream_wrappers(StreamWrapperInterface::LOCAL); + $local_wrappers = $this->streamWrapperManager->getWrappers(StreamWrapperInterface::LOCAL); if (!isset($local_wrappers[$scheme])) { $permanent_destination = $destination; $destination = drupal_tempnam('temporary://', 'gd_'); diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php index a9fa3b2..7435949 100644 --- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php @@ -297,14 +297,14 @@ function testModuleMetaData() { public function testModuleStreamWrappers() { // file_test.module provides (among others) a 'dummy' stream wrapper. // Verify that it is not registered yet to prevent false positives. - $stream_wrappers = file_get_stream_wrappers(); + $stream_wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(); $this->assertFalse(isset($stream_wrappers['dummy'])); $this->moduleInstaller()->install(['file_test']); // Verify that the stream wrapper is available even without calling - // file_get_stream_wrappers() again. If the stream wrapper is not available - // file_exists() will raise a notice. + // \Drupal::service('stream_wrapper_manager')->getWrappers() again. + // If the stream wrapper is not available file_exists() will raise a notice. file_exists('dummy://'); - $stream_wrappers = file_get_stream_wrappers(); + $stream_wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(); $this->assertTrue(isset($stream_wrappers['dummy'])); } diff --git a/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php index df9a1ea..4e43d3e 100644 --- a/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php @@ -40,7 +40,7 @@ function testReadOnlyBehavior() { // Generate a read-only stream wrapper instance $uri = $this->scheme . '://' . $filename; - file_stream_wrapper_get_instance_by_scheme($this->scheme); + \Drupal::service('stream_wrapper_manager')->getViaScheme($this->scheme); // Attempt to open a file in read/write mode $handle = @fopen($uri, 'r+'); diff --git a/core/modules/system/src/Tests/File/StreamWrapperTest.php b/core/modules/system/src/Tests/File/StreamWrapperTest.php index 770a40f..343cd83 100644 --- a/core/modules/system/src/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/StreamWrapperTest.php @@ -56,32 +56,32 @@ function setUp() { */ function testGetClassName() { // Check the dummy scheme. - $this->assertEqual($this->classname, file_stream_wrapper_get_class($this->scheme), 'Got correct class name for dummy scheme.'); + $this->assertEqual($this->classname, \Drupal::service('stream_wrapper_manager')->getClass($this->scheme), 'Got correct class name for dummy scheme.'); // Check core's scheme. - $this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', file_stream_wrapper_get_class('public'), 'Got correct class name for public scheme.'); + $this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', \Drupal::service('stream_wrapper_manager')->getClass('public'), 'Got correct class name for public scheme.'); } /** - * Test the file_stream_wrapper_get_instance_by_scheme() function. + * Test the getViaScheme() method. */ function testGetInstanceByScheme() { - $instance = file_stream_wrapper_get_instance_by_scheme($this->scheme); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme($this->scheme); $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy scheme.'); - $instance = file_stream_wrapper_get_instance_by_scheme('public'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaScheme('public'); $this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), 'Got correct class type for public scheme.'); } /** - * Test the URI and target functions. + * Test the getViaUri() and getViaScheme() methods and target functions. */ function testUriFunctions() { $config = $this->config('system.file'); - $instance = file_stream_wrapper_get_instance_by_uri($this->scheme . '://foo'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaUri($this->scheme . '://foo'); $this->assertEqual($this->classname, get_class($instance), 'Got correct class type for dummy URI.'); - $instance = file_stream_wrapper_get_instance_by_uri('public://foo'); + $instance = \Drupal::service('stream_wrapper_manager')->getViaUri('public://foo'); $this->assertEqual('Drupal\Core\StreamWrapper\PublicStream', get_class($instance), 'Got correct class type for public URI.'); // Test file_uri_target(). @@ -94,8 +94,8 @@ function testUriFunctions() { // Test file_build_uri() and // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath(). $this->assertEqual(file_build_uri('foo/bar.txt'), 'public://foo/bar.txt', 'Expected scheme was added.'); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(), PublicStream::basePath(), 'Expected default directory path was returned.'); - $this->assertEqual(file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.'); + $this->assertEqual(\Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath(), PublicStream::basePath(), 'Expected default directory path was returned.'); + $this->assertEqual(\Drupal::service('stream_wrapper_manager')->getViaScheme('temporary')->getDirectoryPath(), $config->get('path.temporary'), 'Expected temporary directory path was returned.'); $config->set('default_scheme', 'private')->save(); $this->assertEqual(file_build_uri('foo/bar.txt'), 'private://foo/bar.txt', 'Got a valid URI from foo/bar.txt.'); diff --git a/core/modules/system/src/Tests/File/UrlRewritingTest.php b/core/modules/system/src/Tests/File/UrlRewritingTest.php index 0df69cc..748e86d 100644 --- a/core/modules/system/src/Tests/File/UrlRewritingTest.php +++ b/core/modules/system/src/Tests/File/UrlRewritingTest.php @@ -80,7 +80,7 @@ function testPublicManagedFileURL() { \Drupal::state()->set('file_test.hook_file_url_alter', 'cdn'); $uri = $this->createUri(); $url = file_create_url($uri); - $public_directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); + $public_directory_path = \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath(); $this->assertEqual(FILE_URL_TEST_CDN_2 . '/' . $public_directory_path . '/' . drupal_basename($uri), $url, 'Correctly generated a CDN URL for a created file.'); // Test alteration of file URLs to use root-relative URLs. @@ -116,7 +116,7 @@ function testRelativeFileURL() { // Managed file. $uri = $this->createUri(); $url = file_create_url($uri); - $public_directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); + $public_directory_path = \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath(); $this->assertIdentical(base_path() . $public_directory_path . '/' . rawurlencode(drupal_basename($uri)), file_url_transform_relative($url)); } diff --git a/core/modules/system/src/Tests/Session/SessionTest.php b/core/modules/system/src/Tests/Session/SessionTest.php index c9eb3ee..c194c79 100644 --- a/core/modules/system/src/Tests/Session/SessionTest.php +++ b/core/modules/system/src/Tests/Session/SessionTest.php @@ -290,7 +290,7 @@ function sessionReset($uid = 0) { $this->loggedInUser = FALSE; // Change cookie file for user. - $this->cookieFile = file_stream_wrapper_get_instance_by_scheme('temporary')->getDirectoryPath() . '/cookie.' . $uid . '.txt'; + $this->cookieFile = \Drupal::service('stream_wrapper_manager')->getViaScheme('temporary')->getDirectoryPath() . '/cookie.' . $uid . '.txt'; $this->additionalCurlOptions[CURLOPT_COOKIEFILE] = $this->cookieFile; $this->additionalCurlOptions[CURLOPT_COOKIESESSION] = TRUE; $this->drupalGet('session-test/get'); diff --git a/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php b/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php index 154c3ec..43ba96a 100644 --- a/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php +++ b/core/tests/Drupal/Tests/Core/File/MimeTypeGuesserTest.php @@ -9,6 +9,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\File\MimeType\MimeTypeGuesser; +use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMimeTypeGuesser; @@ -34,7 +35,7 @@ public function testSymfonyGuesserRegistration() { $this->assertNotInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]); } $container = new ContainerBuilder(); - $container->set('file.mime_type.guesser', new MimeTypeGuesser()); + $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager())); MimeTypeGuesser::registerWithSymfonyGuesser($container); $guessers = $this->readAttribute($symfony_guesser, 'guessers'); $this->assertInstanceOf('Drupal\Core\File\MimeType\MimeTypeGuesser', $guessers[0]);