Class Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig
| Inheritance | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig |
|---|
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| SECTION_DESCRIPTION | 'description' | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig | |
| SECTION_MINIMUM_STABILITY | 'minimum-stability' | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig | |
| SECTION_PROVIDE | 'provide' | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig | |
| SECTION_REQUIRE | 'require' | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig | |
| SECTION_REQUIRE_DEV | 'require-dev' | Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig |
Method Details
| 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;
}
| public static self createByArray ( array $config ) | ||
| $config | array | |
public static function createByArray(array $config): self
{
return new self($config);
}
| 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);
}
| 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);
}
| public static array getAllDependencySections ( ) |
public static function getAllDependencySections(): array
{
return [
self::SECTION_REQUIRE,
self::SECTION_REQUIRE_DEV,
];
}
| 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));
}
| 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;
}
| public mixed getSection ( string $section ) | ||
| $section | string | |
public function getSection(string $section)
{
return $this->hasSection($section) ? $this->data[$section] : null;
}
| public boolean hasSection ( string $section ) | ||
| $section | string | |
public function hasSection(string $section): bool
{
return array_key_exists($section, $this->data);
}
| public void removeSection ( mixed $section ) | ||
| $section | mixed | |
public function removeSection($section): void
{
if ($this->hasSection($section)) {
unset($this->data[$section]);
}
}
| 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;
}
| public void setSection ( string $section, mixed $data ) | ||
| $section | string | |
| $data | mixed | |
public function setSection(string $section, $data): void
{
$this->data[$section] = $data;
}
| public boolean sortPackagesEnabled ( ) |
public function sortPackagesEnabled(): bool
{
return isset($this->data['config']['sort-packages']) && $this->data['config']['sort-packages'] === true;
}
| 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']);
}
| 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.');
}
}
| 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;
}
Signup or Login in order to comment.