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

Breadcrumb

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

function FilesystemRepository::dumpToPhpCode

Parameters

array<mixed> $array:

1 call to FilesystemRepository::dumpToPhpCode()
FilesystemRepository::write in vendor/composer/composer/src/Composer/Repository/FilesystemRepository.php
Writes writable repository.

File

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

Class

FilesystemRepository
Filesystem repository.

Namespace

Composer\Repository

Code

private function dumpToPhpCode(array $array = [], int $level = 0) : string {
    $lines = "array(\n";
    $level++;
    foreach ($array as $key => $value) {
        $lines .= str_repeat('    ', $level);
        $lines .= is_int($key) ? $key . ' => ' : var_export($key, true) . ' => ';
        if (is_array($value)) {
            if (!empty($value)) {
                $lines .= $this->dumpToPhpCode($value, $level);
            }
            else {
                $lines .= "array(),\n";
            }
        }
        elseif ($key === 'install_path' && is_string($value)) {
            if ($this->filesystem
                ->isAbsolutePath($value)) {
                $lines .= var_export($value, true) . ",\n";
            }
            else {
                $lines .= "__DIR__ . " . var_export('/' . $value, true) . ",\n";
            }
        }
        elseif (is_string($value)) {
            $lines .= var_export($value, true) . ",\n";
        }
        elseif (is_bool($value)) {
            $lines .= ($value ? 'true' : 'false') . ",\n";
        }
        elseif (is_null($value)) {
            $lines .= "null,\n";
        }
        else {
            throw new \UnexpectedValueException('Unexpected type ' . gettype($value));
        }
    }
    $lines .= str_repeat('    ', $level - 1) . ')' . ($level - 1 === 0 ? '' : ",\n");
    return $lines;
}
RSS feed
Powered by Drupal