getAppRoot example


  protected function execute(InputInterface $input, OutputInterface $output): int {
    $root = dirname(__DIR__, 5);
    chdir($root);

    $this->classLoader = require 'autoload.php';
    $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
    $kernel::bootEnvironment();
    $kernel->setSitePath($input->getOption('site-path'));
    Settings::initialize($kernel->getAppRoot()$kernel->getSitePath()$this->classLoader);

    $request = Request::createFromGlobals();

    $kernel->boot();
    $kernel->preHandle($request);

    $container = $kernel->getContainer();
    $uid = $input->getArgument('uid');
    if (!is_numeric($uid)) {
      throw new InvalidArgumentException(sprintf('The "uid" argument needs to be an integer, but it is "%s".', $uid));
    }
    

  protected function boot() {
    $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
    $kernel::bootEnvironment();
    $kernel->setSitePath($this->getSitePath());
    Settings::initialize($kernel->getAppRoot()$kernel->getSitePath()$this->classLoader);
    $kernel->boot();
    // Some services require a request to work. For example, CommentManager.     // This is needed as generating the URL fires up entity load hooks.     $kernel->getContainer()
      ->get('request_stack')
      ->push(Request::createFromGlobals());

    return $kernel;
  }

  /** * Finds an available port. * * @param string $host * The host to find a port on. * * @return int|false * The available port or FALSE, if no available port found, */
$container_definition = $dumper->getArray();
      }
    }

    // The container was rebuilt successfully.     $this->containerNeedsRebuild = FALSE;

    // Only create a new class if we have a container definition.     if (isset($container_definition)) {
      // Drupal provides two dynamic parameters to access specific paths that       // are determined from the request.       $container_definition['parameters']['app.root'] = $this->getAppRoot();
      $container_definition['parameters']['site.path'] = $this->getSitePath();
      $class = Settings::get('container_base_class', '\Drupal\Core\DependencyInjection\Container');
      $container = new $class($container_definition);
    }

    $this->attachSynthetic($container);

    $this->container = $container;
    if ($session_started) {
      $this->container->get('session')->start();
    }

    
/** * Returns whether there is already an existing Drupal installation. * * @return bool */
  protected function isDrupalInstalled() {
    try {
      $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
      $kernel::bootEnvironment();
      $kernel->setSitePath($this->getSitePath());
      Settings::initialize($kernel->getAppRoot()$kernel->getSitePath()$this->classLoader);
      $kernel->boot();
    }
    catch (ConnectionNotDefinedException $e) {
      return FALSE;
    }
    return !empty(Database::getConnectionInfo());
  }

  /** * Installs Drupal with specified installation profile. * * @param object $class_loader * The class loader. * @param \Symfony\Component\Console\Style\SymfonyStyle $io * The Symfony output decorator. * @param string $profile * The installation profile to use. * @param string $langcode * The language to install the site in. * @param string $site_path * The path to install the site to, like 'sites/default'. * @param string $site_name * The site name. * * @throws \Exception * Thrown when failing to create the $site_path directory or settings.php. * * @return int * The command exit status. */

  public function __toString(): string {
    // Return the $updateRoot when it is set.     if (isset($this->updateRoot)) {
      return $this->updateRoot;
    }

    // Normally the Update Manager's root path is the same as the app root (the     // directory in which the Drupal site is installed).     $root_path = $this->drupalKernel->getAppRoot();

    // When running in a test site, change the root path to be the testing site     // directory. This ensures that it will always be writable by the webserver     // (thereby allowing the actual extraction and installation of projects by     // the Update Manager to be tested) and also ensures that new project files     // added there won't be visible to the parent site and will be properly     // cleaned up once the test finishes running. This is done here (rather     // than having the tests enable a module which overrides the update root     // factory service) to ensure that the parent site is automatically kept     // clean without relying on test authors to take any explicit steps. See     // also \Drupal\update\Tests\Functional\UpdateTestBase::setUp().
Home | Imprint | This part of the site doesn't use cookies.