Verified Commit 5b8e018a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2959989 by andypost: Deprecate Extension::__call() magic

parent 6a0ea57c
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -160,12 +160,30 @@ public function load() {
   * Re-routes method calls to SplFileInfo.
   *
   * Offers all SplFileInfo methods to consumers; e.g., $extension->getMTime().
   *
   * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use
   *   \Drupal\Core\Extension\Extension::getFileInfo() instead.
   *
   * @see https://www.drupal.org/node/2959989
   */
  public function __call($method, array $args) {
    @trigger_error(__METHOD__ . "('$method')" . ' is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608', E_USER_DEPRECATED);
    return call_user_func_array([$this->getFileInfo(), $method], $args);
  }

  /**
   * Returns SplFileInfo instance for the extension's info file.
   *
   * @return \SplFileInfo
   *   The object to access a file information of info file.
   *
   * @see https://www.php.net/manual/class.splfileinfo.php
   */
  public function getFileInfo(): \SplFileInfo {
    if (!isset($this->splFileInfo)) {
      $this->splFileInfo = new \SplFileInfo($this->root . '/' . $this->pathname);
    }
    return call_user_func_array([$this->splFileInfo, $method], $args);
    return $this->splFileInfo;
  }

  /**
+1 −1
Original line number Diff line number Diff line
@@ -555,7 +555,7 @@ protected function createExtensionInfo(Extension $extension) {

    // Add the info file modification time, so it becomes available for
    // contributed extensions to use for ordering extension lists.
    $info['mtime'] = $extension->getMTime();
    $info['mtime'] = $extension->getFileInfo()->getMTime();

    // Merge extension type-specific defaults.
    $info += $this->defaults;
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ function hook_module_implements_alter(&$implementations, $hook) {
function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $file, $type) {
  // Only fill this in if the .info.yml file does not define a 'datestamp'.
  if (empty($info['datestamp'])) {
    $info['datestamp'] = $file->getMTime();
    $info['datestamp'] = $file->getFileInfo()->getMTime();
  }
}

+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public function processInfoList(array &$projects, array $list, $project_type, $s
      // which is left alone by tar and correctly set to the time the .info.yml
      // file was unpacked.
      if (!isset($file->info['_info_file_ctime'])) {
        $file->info['_info_file_ctime'] = $file->getCTime();
        $file->info['_info_file_ctime'] = $file->getFileInfo()->getCTime();
      }

      if (!isset($file->info['datestamp'])) {
+27 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\Core\Extension;

use Drupal\Core\Extension\Extension;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\Extension\Extension
 * @group Extension
 * @group legacy
 */
class LegacyExtensionTest extends UnitTestCase {

  /**
   * @covers ::__call
   */
  public function testDeprecatedCall() {
    $extension = new Extension($this->root, 'theme', 'core/themes/stark/stark.info.yml', 'stark.theme');
    $file = $extension->getFileInfo();
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getCTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getCTime(), $extension->getCTime());
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getMTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getMTime(), $extension->getMTime());
  }

}