Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Platform.php

function Platform::isVirtualBoxGuest

Attempts detection of VirtualBox guest VMs

This works based on the process' user being "vagrant", the COMPOSER_RUNTIME_ENV env var being set to "virtualbox", or lsmod showing the virtualbox guest additions are loaded

1 call to Platform::isVirtualBoxGuest()
Platform::workaroundFilesystemIssues in vendor/composer/composer/src/Composer/Util/Platform.php

File

vendor/composer/composer/src/Composer/Util/Platform.php, line 302

Class

Platform
Platform helper for uniform platform-specific tests.

Namespace

Composer\Util

Code

private static function isVirtualBoxGuest() : bool {
    if (null === self::$isVirtualBoxGuest) {
        self::$isVirtualBoxGuest = false;
        if (self::isWindows()) {
            return self::$isVirtualBoxGuest;
        }
        if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
            $processUser = posix_getpwuid(posix_geteuid());
            if (is_array($processUser) && $processUser['name'] === 'vagrant') {
                return self::$isVirtualBoxGuest = true;
            }
        }
        if (self::getEnv('COMPOSER_RUNTIME_ENV') === 'virtualbox') {
            return self::$isVirtualBoxGuest = true;
        }
        if (defined('PHP_OS_FAMILY') && PHP_OS_FAMILY === 'Linux') {
            $process = new ProcessExecutor();
            try {
                if (0 === $process->execute([
                    'lsmod',
                ], $output) && str_contains($output, 'vboxguest')) {
                    return self::$isVirtualBoxGuest = true;
                }
            } catch (\Exception $e) {
                // noop
            }
        }
    }
    return self::$isVirtualBoxGuest;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal