function GenerateAutoloadRuntimeReferenceFile::autoLoadRuntimeContents

Same name and namespace in other branches
  1. 11.x composer/Plugin/Scaffold/GenerateAutoloadRuntimeReferenceFile.php \Drupal\Composer\Plugin\Scaffold\GenerateAutoloadRuntimeReferenceFile::autoLoadRuntimeContents()

Builds the contents of the autoload_runtime file.

Parameters

string $relative_autoload_runtime_path: The relative path to the runtime loader in vendor.

Return value

string Return the contents for the autoload_runtime.php.

File

composer/Plugin/Scaffold/GenerateAutoloadRuntimeReferenceFile.php, line 105

Class

GenerateAutoloadRuntimeReferenceFile
Generates an 'autoload_runtime.php' that includes the Symfony_runtime loader.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

protected static function autoLoadRuntimeContents(string $relative_autoload_runtime_path) : string {
  $relative_autoload_runtime_path = preg_replace('#^\\./#', '', $relative_autoload_runtime_path);
  return <<<EOF
  <?php
  
  /**
   * @file
   * Includes the autoload_runtime created by the Symfony Runtime component.
   *
   * This file was generated by drupal-scaffold.
   *
   * @see composer.json
   * @see index.php
   * @see core/install.php
   * @see core/rebuild.php
   */
  
  use Drupal\\Core\\Runtime\\DrupalRuntime;
  
  // By default, the symfony/runtime component would load SymfonyRuntime as its
  // runtime. However, Drupal's Kernel has a lot of runtime components that it
  // expects to be prepared. Thus, we default Drupal applications to DrupalRuntime
  // instead to make this easily accessible.
  \$_ENV['APP_RUNTIME'] ??= \$_SERVER['APP_RUNTIME'] ?? DrupalRuntime::class;
  return require __DIR__ . '/{<span class="php-variable">$relative_autoload_runtime_path</span>}';
  
  EOF;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.