getFileInfo example


        $directory = __DIR__.'/../fixtures/extractor/';
        $phpFiles = [];
        $splFiles = [];
        foreach (new \DirectoryIterator($directory) as $fileInfo) {
            if ($fileInfo->isDot()) {
                continue;
            }
            if (\in_array($fileInfo->getBasename()['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translation.html.php'], true)) {
                $phpFiles[] = $fileInfo->getPathname();
            }
            $splFiles[] = $fileInfo->getFileInfo();
        }

        return [
            [$directory],
            [$phpFiles],
            [glob($directory.'*')],
            [$splFiles],
            [new \ArrayObject(glob($directory.'*'))],
            [new \ArrayObject($splFiles)],
        ];
    }
}

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->getFileInfo()->getMTime();
  }
}

/** * Perform necessary actions before a module is installed. * * @param string $module * The name of the module about to be installed. */
function hook_module_preinstall($module) {
  mymodule_cache_clear();
}

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());
  }

}
continue;
      }

      // If we don't already know it, grab the change time on the .info.yml file       // itself. Note: we need to use the ctime, not the mtime (modification       // time) since many (all?) tar implementations will go out of their way to       // set the mtime on the files it creates to the timestamps recorded in the       // tarball. We want to see the last time the file was changed on disk,       // 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->getFileInfo()->getCTime();
      }

      if (!isset($file->info['datestamp'])) {
        $file->info['datestamp'] = 0;
      }

      $project_name = $file->info['project'];

      // Figure out what project type we're going to use to display this module       // or theme. If the project name is 'drupal', we don't want it to show up       // under the usual "Modules" section, we put it at a special "Drupal Core"

        $directory = __DIR__.'/../fixtures/extractor-ast/';
        $phpFiles = [];
        $splFiles = [];
        foreach (new \DirectoryIterator($directory) as $fileInfo) {
            if ($fileInfo->isDot()) {
                continue;
            }
            if (\in_array($fileInfo->getBasename()['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translation.html.php', 'validator-constraints.php'], true)) {
                $phpFiles[] = $fileInfo->getPathname();
            }
            $splFiles[] = $fileInfo->getFileInfo();
        }

        return [
            [$directory],
            [$phpFiles],
            [glob($directory.'*')],
            [$splFiles],
            [new \ArrayObject(glob($directory.'*'))],
            [new \ArrayObject($splFiles)],
        ];
    }
}

  protected function createExtensionInfo(Extension $extension) {
    $info = $this->infoParser->parse($extension->getPathname());

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

    // Merge extension type-specific defaults, making sure to replace NULL     // values.     foreach ($this->defaults as $key => $default_value) {
      if (!isset($info[$key])) {
        $info[$key] = $default_value;
      }
    }

    return $info;
  }

  

  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 {
    
// reset the array and make sure $source_dir has a trailing slash on the initial call             if ($_recursion === false) {
                $_filedata = [];
                $sourceDir = rtrim(realpath($sourceDir) ?: $sourceDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
            }

            // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast             while (false !== ($file = readdir($fp))) {
                if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) {
                    $this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true);
                } elseif (is_dir($sourceDir . $file) && $file[0] !== '.') {
                    $_filedata[$file]                  = $this->getFileInfo($sourceDir . $file);
                    $_filedata[$file]['relative_path'] = $relativePath;
                }
            }

            closedir($fp);

            return $_filedata;
        }

        return false;
    }

    
Home | Imprint | This part of the site doesn't use cookies.