diff --git a/core/core.services.yml b/core/core.services.yml index 9f35c9d..5d6d7a4 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1144,6 +1144,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 } file.mime_type.guesser.extension: diff --git a/core/includes/file.inc b/core/includes/file.inc index effb71c..3754a33 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -162,7 +162,7 @@ function file_uri_scheme($uri) { * or FALSE if the scheme does not have a registered handler. */ function file_stream_wrapper_valid_scheme($scheme) { - return $scheme && class_exists(file_stream_wrapper_get_class($scheme)); + return $scheme && class_exists(\Drupal::service('stream_wrapper_manager')->getClass($scheme)); } @@ -344,7 +344,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 { @@ -1275,7 +1275,7 @@ function drupal_realpath($uri) { // If this URI is a stream, pass it off to the appropriate stream wrapper. // Otherwise, attempt PHP's realpath. This allows use of drupal_realpath even // for unmanaged files outside of the stream wrapper interface. - if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) { + if ($wrapper = \Drupal::service('stream_wrapper_manager')->getViaUri($uri)) { return $wrapper->realpath(); } @@ -1305,7 +1305,7 @@ function drupal_dirname($uri) { $scheme = file_uri_scheme($uri); if (file_stream_wrapper_valid_scheme($scheme)) { - return file_stream_wrapper_get_instance_by_scheme($scheme)->dirname($uri); + return \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme)->dirname($uri); } else { return dirname($uri); @@ -1498,7 +1498,7 @@ function drupal_tempnam($directory, $prefix) { $scheme = file_uri_scheme($directory); if (file_stream_wrapper_valid_scheme($scheme)) { - $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme); + $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme); if ($filename = tempnam($wrapper->getDirectoryPath(), $prefix)) { return $scheme . '://' . drupal_basename($filename); diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 73278d3..2cb5357 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -255,12 +255,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 2054463..0cd49fa 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\StreamWrapperManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser as SymfonyMimeTypeGuesser; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; @@ -36,10 +37,27 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface { protected $sortedGuessers = NULL; /** + * The stream wrapper manager. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManager + */ + protected $streamWrapperManager; + + /** + * Constructs a MimeTypeGuesser object. + * + * @param StreamWrapperManager $streamWrapperManager + * The stream wrapper manager. + */ + public function __construct(StreamWrapperManager $streamWrapperManager) { + $this->streamWrapperManager = $streamWrapperManager; + } + + /** * {@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/StreamWrapper/StreamWrapperManager.php b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php index 101980d..524dd1f 100644 --- a/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php +++ b/core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php @@ -13,7 +13,6 @@ /** * Provides a StreamWrapper manager. * - * @see file_get_stream_wrappers() * @see \Drupal\Core\StreamWrapper\StreamWrapperInterface */ class StreamWrapperManager extends ContainerAware { @@ -69,7 +68,7 @@ class StreamWrapperManager extends ContainerAware { * returns only stream wrappers that use local file storage: * * @code - * $local_stream_wrappers = file_get_stream_wrappers(StreamWrapperInterface::LOCAL); + * $local_stream_wrappers = $this->getWrappers(StreamWrapperInterface::LOCAL); * @endcode * * The $filter parameter can only filter to types containing a particular @@ -79,7 +78,7 @@ class StreamWrapperManager extends ContainerAware { * 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)); + * $remote_stream_wrappers = array_diff_key($this->getWrappers(StreamWrapperInterface::ALL), $this->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 bbaecfb..a2d31c4 100644 --- a/core/lib/Drupal/Core/Updater/Updater.php +++ b/core/lib/Drupal/Core/Updater/Updater.php @@ -343,7 +343,7 @@ public function makeBackup(FileTransferInterface $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/file.module b/core/modules/file/file.module index 9438f4a..5612db9 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -756,7 +756,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination 'uri' => $file_info->getRealPath(), 'filesize' => $file_info->getSize(), ); - $values['filemime'] = file_get_mimetype($values['filename']); + $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['filename']); $file = entity_create('file', $values); $extensions = ''; diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index 7cf5058..2dbbf31 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -185,7 +185,7 @@ public static function preCreate(EntityStorageInterface $storage, array &$values // Automatically detect filemime if not set. if (!isset($values['filemime']) && isset($values['uri'])) { - $values['filemime'] = file_get_mimetype($values['uri']); + $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['uri']); } } diff --git a/core/modules/file/src/Tests/DownloadTest.php b/core/modules/file/src/Tests/DownloadTest.php index 1aece59..4e8dd5d 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.'); @@ -123,7 +123,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 6ee2ecc..578a7a1 100644 --- a/core/modules/file/tests/file_test/file_test.module +++ b/core/modules/file/tests/file_test/file_test.module @@ -217,7 +217,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); } @@ -247,7 +247,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); } @@ -270,7 +270,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/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index a87554c..c1d2efd 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -221,7 +221,7 @@ public function buildUrl($path, $clean_urls = NULL) { // that it is included. Once the file exists it's fine to fall back 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($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query)); } diff --git a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php index 4418476..eb820f9 100644 --- a/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php +++ b/core/modules/image/src/PathProcessor/PathProcessorImageStyles.php @@ -31,7 +31,7 @@ class PathProcessorImageStyles implements InboundPathProcessorInterface { * {@inheritdoc} */ public function processInbound($path, Request $request) { - $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); + $directory_path = \Drupal::service('stream_wrapper_manager')->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 39b2379..d862f29 100644 --- a/core/modules/image/src/Routing/ImageStyleRoutes.php +++ b/core/modules/image/src/Routing/ImageStyleRoutes.php @@ -26,7 +26,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 = \Drupal::service('stream_wrapper_manager')->getViaScheme('public')->getDirectoryPath(); $routes['image.style_public'] = new Route( '/' . $directory_path . '/styles/{image_style}/{scheme}', diff --git a/core/modules/system/file.api.php b/core/modules/system/file.api.php index a4fd8e4..43913fb 100644 --- a/core/modules/system/file.api.php +++ b/core/modules/system/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/modules/system/src/Form/ThemeSettingsForm.php b/core/modules/system/src/Form/ThemeSettingsForm.php index 36bf64a..01e588c 100644 --- a/core/modules/system/src/Form/ThemeSettingsForm.php +++ b/core/modules/system/src/Form/ThemeSettingsForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\StreamWrapper\PublicStream; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactoryInterface; @@ -38,20 +39,30 @@ class ThemeSettingsForm extends ConfigFormBase { protected $themeHandler; /** + * The MIME type guesser. + * + * @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface + */ + protected $mimeTypeGuesser; + + /** * Constructs a ThemeSettingsForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler instance to use. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler - * The theme handler. + * The theme handler. + * @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser + * The MIME type guesser instance to use. */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) { + public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, MimeTypeGuesserInterface $mime_type_guesser) { parent::__construct($config_factory); $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; + $this->mimeTypeGuesser = $mime_type_guesser; } /** @@ -61,7 +72,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), $container->get('module_handler'), - $container->get('theme_handler') + $container->get('theme_handler'), + $container->get('file.mime_type.guesser') ); } @@ -426,7 +438,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } if (empty($values['default_favicon']) && !empty($values['favicon_path'])) { - $values['favicon_mimetype'] = file_get_mimetype($values['favicon_path']); + $values['favicon_mimetype'] = $this->mimeTypeGuesser->guess($values['favicon_path']); } } diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 7aa56d0..8d3363b 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\StreamWrapperManager; +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\StreamWrapperManager + */ + 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\StreamWrapperManager $stream_wrapper_manager + * The StreamWrapper manager. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory, StreamWrapperManager $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 130ffd2..95189af 100644 --- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Extension; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\simpletest\KernelTestBase; use \Drupal\Core\Extension\ModuleUninstallValidatorException; @@ -279,14 +280,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 242a378..9e8bb35 100644 --- a/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/ReadOnlyStreamWrapperTest.php @@ -39,7 +39,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 fb3c805..b13c4c6 100644 --- a/core/modules/system/src/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/StreamWrapperTest.php @@ -56,19 +56,19 @@ 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() function. */ 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.'); } @@ -78,10 +78,10 @@ function testGetInstanceByScheme() { 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 aa0d3d2..5fa4578 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 bbe23f6..16824fa 100644 --- a/core/modules/system/src/Tests/Session/SessionTest.php +++ b/core/modules/system/src/Tests/Session/SessionTest.php @@ -273,7 +273,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 a1bf9c2..2f5406f 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]);