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

Breadcrumb

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

function FilesystemRepository::safelyLoadInstalledVersions

As we load the file from vendor dir during bootstrap, we need to make sure it contains only expected code before executing it

@internal

1 call to FilesystemRepository::safelyLoadInstalledVersions()
Factory::createComposer in vendor/composer/composer/src/Composer/Factory.php
Creates a Composer instance

File

vendor/composer/composer/src/Composer/Repository/FilesystemRepository.php, line 182

Class

FilesystemRepository
Filesystem repository.

Namespace

Composer\Repository

Code

public static function safelyLoadInstalledVersions(string $path) : bool {
    $installedVersionsData = @file_get_contents($path);
    $pattern = <<<'REGEX'
{(?(DEFINE)
   (?<number>  -? \s*+ \d++ (?:\.\d++)? )
   (?<boolean> true | false | null )
   (?<strings> (?&string) (?: \s*+ \. \s*+ (?&string))*+ )
   (?<string>  (?: " (?:[^"\\$]*+ | \\ ["\\0] )* " | ' (?:[^'\\]*+ | \\ ['\\] )* ' ) )
   (?<array>   array\( \s*+ (?: (?:(?&number)|(?&strings)) \s*+ => \s*+ (?: (?:__DIR__ \s*+ \. \s*+)? (?&strings) | (?&value) ) \s*+, \s*+ )*+  \s*+ \) )
   (?<value>   (?: (?&number) | (?&boolean) | (?&strings) | (?&array) ) )
)
^<\?php\s++return\s++(?&array)\s*+;$}ix
REGEX;
    if (is_string($installedVersionsData) && Preg::isMatch($pattern, trim($installedVersionsData))) {
        \Composer\InstalledVersions::reload(eval('?>' . Preg::replace('{=>\\s*+__DIR__\\s*+\\.\\s*+([\'"])}', '=> ' . var_export(dirname($path), true) . ' . $1', $installedVersionsData)));
        return true;
    }
    return false;
}

API Navigation

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