setSitePath example


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

  

  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));
    }
/** * Locate site path and initialize settings singleton. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * In case the host name in the request is not trusted. */
  protected function initializeSettings(Request $request) {
    $site_path = static::findSitePath($request);
    $this->setSitePath($site_path);
    Settings::initialize($this->root, $site_path$this->classLoader);

    // Initialize our list of trusted HTTP Host headers to protect against     // header attacks.     $host_patterns = Settings::get('trusted_host_patterns', []);
    if (PHP_SAPI !== 'cli' && !empty($host_patterns)) {
      if (static::setupTrustedHosts($request$host_patterns) === FALSE) {
        throw new BadRequestHttpException('The provided host name is not valid for this server.');
      }
    }
  }

  


  /** * 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 testPreventChangeOfSitePath() {
    // @todo: write a memory based storage backend for testing.     $modules_enabled = [
      'system' => 'system',
      'user' => 'user',
    ];

    $request = Request::createFromGlobals();
    $kernel = $this->getTestKernel($request$modules_enabled);
    $pass = FALSE;
    try {
      $kernel->setSitePath('/dev/null');
    }
    catch (\LogicException $e) {
      $pass = TRUE;
    }
    $this->assertTrue($pass, 'Throws LogicException if DrupalKernel::setSitePath() is called after boot');

    // Ensure no LogicException if DrupalKernel::setSitePath() is called with     // identical path after boot.     $path = $kernel->getSitePath();
    $kernel->setSitePath($path);
  }

  
if (str_contains($autoload, 'src/Driver/Database/')) {
      [$first$second] = explode('\\', $namespace, 3);
      if ($first === 'Drupal' && strtolower($second) === $second) {
        // Add the module that provides the database driver to the list of         // modules as the first to be enabled.         array_unshift($modules$second);
      }
    }

    // Bootstrap the kernel. Do not use createFromRequest() to retain Settings.     $kernel = new DrupalKernel('testing', $this->classLoader, FALSE);
    $kernel->setSitePath($this->siteDirectory);
    // Boot a new one-time container from scratch. Set the module list upfront     // to avoid a subsequent rebuild or setting the kernel into the     // pre-installer mode.     $extensions = $modules ? $this->getExtensionsForModules($modules) : [];
    $kernel->updateModules($extensions$extensions);

    // DrupalKernel::boot() is not sufficient as it does not invoke preHandle(),     // which is required to initialize legacy global variables.     $request = Request::create('/');
    $kernel->boot();
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
    
Home | Imprint | This part of the site doesn't use cookies.