getSitePath example

/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests the default behavior to restrict directory permissions is enforced. * * Checks both the current sites directory and settings.php. */
  public function testSitesDirectoryHardening() {
    $site_path = $this->kernel->getSitePath();
    $settings_file = $this->settingsFile($site_path);

    // First, we check based on what the initial install has set.     $this->assertTrue(drupal_verify_install_file($site_path, FILE_NOT_WRITABLE, 'dir')new FormattableMarkup('Verified permissions for @file.', ['@file' => $site_path]));

    // We intentionally don't check for settings.local.php as that file is     // not created by Drupal.     $this->assertTrue(drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE)new FormattableMarkup('Verified permissions for @file.', ['@file' => $settings_file]));

    $this->makeWritable($site_path);
    $this->checkSystemRequirements();

    

  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));
    }
    
return 0;
    }

    $install_profile = $input->getArgument('install-profile');
    if ($install_profile && !$this->validateProfile($install_profile$io)) {
      return 1;
    }
    if (!$install_profile) {
      $install_profile = $this->selectProfile($io);
    }

    return $this->install($this->classLoader, $io$install_profile$input->getOption('langcode')$this->getSitePath()$input->getOption('site-name'));
  }

  /** * Returns whether there is already an existing Drupal installation. * * @return bool */
  protected function isDrupalInstalled() {
    try {
      $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
      $kernel::bootEnvironment();
      

    }

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

    

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

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

  /** * Data provider for self::testClassLoaderAutoDetect. * @return array */
  public function providerClassLoaderAutoDetect() {
    return [
      'TRUE' => [TRUE],
      'FALSE' => [FALSE],
    ];
Home | Imprint | This part of the site doesn't use cookies.