0 follower

Class Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig

InheritanceYiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig

Method Details

Hide inherited methods

asArray() public method

public array asArray ( )

                public function asArray(): array
{
    return $this->data;
}

            
asPrettyJson() public method

public string asPrettyJson ( )

                public function asPrettyJson(): string
{
    $content = json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    if ($content === false) {
        throw new RuntimeException('Failed to encode JSON.');
    }
    return $content;
}

            
createByArray() public static method

public static self createByArray ( array $config )
$config array

                public static function createByArray(array $config): self
{
    return new self($config);
}

            
createByFilePath() public static method

public static self createByFilePath ( string $path )
$path string

                public static function createByFilePath(string $path): self
{
    $content = file_get_contents($path);
    if ($content === false) {
        throw new RuntimeException('Failed to read file ' . $path);
    }
    return static::createByJson($content);
}

            
createByJson() public static method

public static self createByJson ( string $json )
$json string

                public static function createByJson(string $json): self
{
    $config = json_decode($json, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        throw new RuntimeException('Failed to decode JSON.');
    }
    return static::createByArray($config);
}

            
getAllDependencySections() public static method

public static array getAllDependencySections ( )

                public static function getAllDependencySections(): array
{
    return [
        self::SECTION_REQUIRE,
        self::SECTION_REQUIRE_DEV,
    ];
}

            
getDependencyList() public method

public Yiisoft\YiiDevTool\Infrastructure\Composer\Config\Dependency\ComposerConfigDependencyList getDependencyList ( string $section )
$section string

                public function getDependencyList(string $section): ComposerConfigDependencyList
{
    self::validateDependencySection($section);
    return new ComposerConfigDependencyList($this->getSection($section));
}

            
getPSRNamespaces() public method

public array getPSRNamespaces ( )

                public function getPSRNamespaces(): array
{
    $namespaces = [];
    if (isset($this->data['autoload']['psr-4'])) {
        $namespaces = array_merge($namespaces, array_keys($this->data['autoload']['psr-4']));
    }
    if (isset($this->data['autoload-dev']['psr-4'])) {
        $namespaces = [...$namespaces, ...array_keys($this->data['autoload-dev']['psr-4'])];
    }
    if (isset($this->data['autoload']['psr-0'])) {
        $namespaces = [...$namespaces, ...array_keys($this->data['autoload']['psr-0'])];
    }
    if (isset($this->data['autoload-dev']['psr-0'])) {
        $namespaces = [...$namespaces, ...array_keys($this->data['autoload-dev']['psr-0'])];
    }
    return $namespaces;
}

            
getSection() public method

public mixed getSection ( string $section )
$section string

                public function getSection(string $section)
{
    return $this->hasSection($section) ? $this->data[$section] : null;
}

            
hasSection() public method

public boolean hasSection ( string $section )
$section string

                public function hasSection(string $section): bool
{
    return array_key_exists($section, $this->data);
}

            
removeSection() public method

public void removeSection ( mixed $section )
$section mixed

                public function removeSection($section): void
{
    if ($this->hasSection($section)) {
        unset($this->data[$section]);
    }
}

            
setDependencyList() public method

public self setDependencyList ( string $section, Yiisoft\YiiDevTool\Infrastructure\Composer\Config\Dependency\ComposerConfigDependencyList $dependencyList )
$section string
$dependencyList Yiisoft\YiiDevTool\Infrastructure\Composer\Config\Dependency\ComposerConfigDependencyList

                public function setDependencyList(string $section, ComposerConfigDependencyList $dependencyList): self
{
    self::validateDependencySection($section);
    $this->setSection($section, $dependencyList->asArray());
    return $this;
}

            
setSection() public method

public void setSection ( string $section, mixed $data )
$section string
$data mixed

                public function setSection(string $section, $data): void
{
    $this->data[$section] = $data;
}

            
sortPackagesEnabled() public method

public boolean sortPackagesEnabled ( )

                public function sortPackagesEnabled(): bool
{
    return isset($this->data['config']['sort-packages']) && $this->data['config']['sort-packages'] === true;
}

            
usesNonPSRAutoload() public method

public boolean usesNonPSRAutoload ( )

                public function usesNonPSRAutoload(): bool
{
    return isset($this->data['autoload']['classmap'])
        || isset($this->data['autoload']['files'])
        || isset($this->data['autoload-dev']['classmap'])
        || isset($this->data['autoload-dev']['files']);
}

            
validateDependencySection() public static method

public static void validateDependencySection ( string $section )
$section string

                public static function validateDependencySection(string $section): void
{
    if (!in_array($section, self::getAllDependencySections(), true)) {
        throw new InvalidArgumentException('Invalid section.');
    }
}

            
writeToFile() public method

public self writeToFile ( string $targetPath )
$targetPath string

                public function writeToFile(string $targetPath): self
{
    $result = file_put_contents($targetPath, $this->asPrettyJson() . "\n");
    if ($result === false) {
        throw new RuntimeException('Failed to write file ' . $targetPath);
    }
    return $this;
}