Commit cb550768 authored by catch's avatar catch
Browse files

Issue #3260778 by andypost, daffie: Remove deprecated code from bootstrap.inc

parent 61bc211b
Loading
Loading
Loading
Loading
+0 −161
Original line number Diff line number Diff line
@@ -10,69 +10,6 @@
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Utility\Error;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

/**
 * Minimum allowed version of PHP for Drupal to be bootstrapped.
 *
 * Below this version:
 * - The installer cannot be run.
 * - Updates cannot be run.
 * - Modules and themes cannot be enabled.
 * - If a site managed to bypass all of the above, then an error is shown in
 *   the status report and various fatal errors occur on various pages.
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
 *   \Drupal::MINIMUM_PHP instead.
 *
 * @see https://www.drupal.org/node/2909361
 * @see install.php
 */
const DRUPAL_MINIMUM_PHP = \Drupal::MINIMUM_PHP;

/**
 * Minimum supported version of PHP.
 *
 * Below this version:
 * - New sites cannot be installed, except from within tests.
 * - Updates from previous Drupal versions can be run, but users are warned
 *   that Drupal no longer supports that PHP version.
 * - An error is shown in the status report that the PHP version is too old.
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
 *   \Drupal::MINIMUM_SUPPORTED_PHP instead.
 *
 * @see https://www.drupal.org/node/2909361
 */
const DRUPAL_MINIMUM_SUPPORTED_PHP = \Drupal::MINIMUM_SUPPORTED_PHP;

/**
 * Minimum recommended version of PHP.
 *
 * Sites installing Drupal on PHP versions lower than this will see a warning
 * message, but Drupal can still be installed. Used for (e.g.) PHP versions
 * that have reached their EOL or will in the near future.
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
 *   \Drupal::RECOMMENDED_PHP instead.
 *
 * @see https://www.drupal.org/node/2909361
 */
const DRUPAL_RECOMMENDED_PHP = \Drupal::RECOMMENDED_PHP;

/**
 * Minimum recommended value of PHP memory_limit.
 *
 * 64M was chosen as a minimum requirement in order to allow for additional
 * contributed modules to be installed prior to hitting the limit. However,
 * 40M is the target for the Standard installation profile.
 *
 * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
 *   \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead.
 *
 * @see https://www.drupal.org/node/2909361
 */
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = \Drupal::MINIMUM_PHP_MEMORY_LIMIT;

/**
 * Error reporting level: display no errors.
@@ -123,104 +60,6 @@
 */
define('DRUPAL_ROOT', dirname(__DIR__, 2));

/**
 * Returns and optionally sets the filename for a system resource.
 *
 * The filename, whether provided, cached, or retrieved from the database, is
 * only returned if the file exists.
 *
 * This function plays a key role in allowing Drupal's resources (modules
 * and themes) to be located in different places depending on a site's
 * configuration. For example, a module 'foo' may legally be located
 * in any of these three places:
 *
 * core/modules/foo/foo.info.yml
 * modules/foo/foo.info.yml
 * sites/example.com/modules/foo/foo.info.yml
 *
 * Calling drupal_get_filename('module', 'foo') will give you one of
 * the above, depending on where the module is located.
 *
 * @param $type
 *   The type of the item; one of 'core', 'profile', 'module', 'theme', or
 *   'theme_engine'.
 * @param $name
 *   The name of the item for which the filename is requested. Ignored for
 *   $type 'core'.
 * @param $filename
 *   The filename of the item if it is to be set explicitly rather
 *   than by consulting the database.
 *
 * @return string
 *   The filename of the requested item or NULL if the item is not found.
 *
 * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
 *   \Drupal\Core\Extension\ExtensionPathResolver::getPathname() instead.
 *
 * @see https://www.drupal.org/node/2940438
 */
function drupal_get_filename($type, $name, $filename = NULL) {
  @trigger_error('drupal_get_filename() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPathname() instead. See https://www.drupal.org/node/2940438', E_USER_DEPRECATED);
  // Type 'core' only exists to simplify application-level logic; it always maps
  // to the /core directory, whereas $name is ignored. It is only requested via
  // \Drupal\Core\Extension\ExtensionList::getPath(). The file
  // /core/core.info.yml does not exist, but is required since
  // ExtensionList::getPath() returns the dirname() of the returned pathname.
  if ($type === 'core') {
    return 'core/core.info.yml';
  }

  try {
    /** @var \Drupal\Core\Extension\ExtensionList $extension_list */
    $extension_list = \Drupal::service("extension.list.$type");
    if (isset($filename)) {
      // Manually add the info file path of an extension.
      $extension_list->setPathname($name, $filename);
    }
    return $extension_list->getPathname($name);
  }
  catch (ServiceNotFoundException $e) {
    // Catch the exception. This will result in triggering an error.
    // If the service is unknown, create a user-level error message.
    trigger_error(
      sprintf('Unknown type specified: "%s". Must be one of: "core", "profile", "module", "theme", or "theme_engine".', $type),
      E_USER_WARNING
    );
  }
  catch (\InvalidArgumentException $e) {
    // Catch the exception. This will result in triggering an error.
    // If the filename is still unknown, create a user-level error message.
    trigger_error(
      sprintf('The following %s is missing from the file system: %s', $type, $name),
      E_USER_WARNING
    );
  }
}

/**
 * Returns the path to a system item (module, theme, etc.).
 *
 * @param $type
 *   The type of the item; one of 'core', 'profile', 'module', 'theme', or
 *   'theme_engine'.
 * @param $name
 *   The name of the item for which the path is requested. Ignored for
 *   $type 'core'.
 *
 * @return string
 *   The path to the requested item or an empty string if the item is not found.
 *
 * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
 *   \Drupal\Core\Extension\ExtensionPathResolver::getPath() instead.
 *
 * @see https://www.drupal.org/node/2940438
 * @see \Drupal\Core\Extension\ExtensionList::getPath()
 */
function drupal_get_path($type, $name) {
  @trigger_error('drupal_get_path() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPath() instead. See https://www.drupal.org/node/2940438', E_USER_DEPRECATED);
  return dirname(drupal_get_filename($type, $name));
}

/**
 * Translates a string to the current language or to a given language.
 *
+0 −13
Original line number Diff line number Diff line
@@ -446,19 +446,6 @@ protected function applyLibrariesOverride($libraries, $extension) {
    return $libraries;
  }

  /**
   * Wraps drupal_get_path().
   *
   * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
   *   \Drupal\Core\Extension\ExtensionList::getPath() instead.
   *
   * @see https://www.drupal.org/node/2940438
   */
  protected function drupalGetPath($type, $name) {
    @trigger_error(__METHOD__ . ' is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPath() instead. See https://www.drupal.org/node/2940438', E_USER_DEPRECATED);
    return $this->extensionPathResolver->getPath($type, $name);
  }

  /**
   * Determines if the supplied string is a valid URI.
   */
+0 −37
Original line number Diff line number Diff line
<?php

namespace Drupal\KernelTests\Core\Bootstrap;

use Drupal\KernelTests\KernelTestBase;

/**
 * Tests that drupal_get_filename() works correctly.
 *
 * @group Bootstrap
 * @group legacy
 */
class GetFilenameTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['system'];

  /**
   * Tests drupal_get_filename() deprecation.
   */
  public function testDrupalGetFilename(): void {
    $this->expectDeprecation('drupal_get_filename() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPathname() instead. See https://www.drupal.org/node/2940438');
    $this->assertEquals('core/modules/system/system.info.yml', drupal_get_filename('module', 'system'));
  }

  /**
   * Tests drupal_get_path() deprecation.
   */
  public function testDrupalGetPath(): void {
    $this->expectDeprecation('drupal_get_path() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPath() instead. See https://www.drupal.org/node/2940438');
    $this->expectDeprecation('drupal_get_filename() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Extension\ExtensionPathResolver::getPathname() instead. See https://www.drupal.org/node/2940438');
    $this->assertEquals('core/modules/system', drupal_get_path('module', 'system'));
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -29,12 +29,12 @@ public function testEnsureComposerVersion() {
   * Ensure that the configured php version matches the minimum php version.
   *
   * Also ensure that the minimum php version in the root-level composer.json
   * file exactly matches DRUPAL_MINIMUM_PHP.
   * file exactly matches \Drupal::MINIMUM_PHP.
   */
  public function testEnsurePhpConfiguredVersion() {
    $composer_json = json_decode(file_get_contents($this->root . '/composer.json'), TRUE);
    $composer_core_json = json_decode(file_get_contents($this->root . '/core/composer.json'), TRUE);
    $this->assertEquals(DRUPAL_MINIMUM_PHP, $composer_json['config']['platform']['php'], 'The DRUPAL_MINIMUM_PHP constant should always be exactly the same as the config.platform.php in the root composer.json.');
    $this->assertEquals(\Drupal::MINIMUM_PHP, $composer_json['config']['platform']['php'], 'The \Drupal::MINIMUM_PHP constant should always be exactly the same as the config.platform.php in the root composer.json.');
    $this->assertEquals($composer_core_json['require']['php'], '>=' . $composer_json['config']['platform']['php'], 'The config.platform.php configured version in the root composer.json file should always be exactly the same as the minimum php version configured in core/composer.json.');
  }