generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Config\Composer; | ||
|
||
use Yiisoft\Config\Options; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MergePlanCollector | ||
{ | ||
/** | ||
* @psalm-var array<string, array<string, array<string, string[]>>> | ||
*/ | ||
private array $mergePlan = []; | ||
|
||
/** | ||
* Adds an item to the merge plan. | ||
* | ||
* @param string $file The config file. | ||
* @param string $package The package name. | ||
* @param string $group The group name. | ||
* @param string $environment The environment name. | ||
*/ | ||
public function add( | ||
string $file, | ||
string $package, | ||
string $group, | ||
string $environment = Options::DEFAULT_ENVIRONMENT | ||
): void { | ||
$this->mergePlan[$environment][$group][$package][] = $file; | ||
} | ||
|
||
/** | ||
* Adds a multiple items to the merge plan. | ||
* | ||
* @param string[] $files The config files. | ||
* @param string $package The package name. | ||
* @param string $group The group name. | ||
* @param string $environment The environment name. | ||
*/ | ||
public function addMultiple( | ||
array $files, | ||
string $package, | ||
string $group, | ||
string $environment = Options::DEFAULT_ENVIRONMENT | ||
): void { | ||
$this->mergePlan[$environment][$group][$package] = $files; | ||
} | ||
|
||
/** | ||
* Adds an empty environment item to the merge plan. | ||
* | ||
* @param string $environment The environment name. | ||
*/ | ||
public function addEnvironmentWithoutConfigs(string $environment): void | ||
{ | ||
$this->mergePlan[$environment] = []; | ||
} | ||
|
||
/** | ||
* Add empty group if it not exists. | ||
* | ||
* @param string $group The group name. | ||
* @param string $environment The environment name. | ||
*/ | ||
public function addGroup(string $group, string $environment = Options::DEFAULT_ENVIRONMENT): void | ||
{ | ||
if (!isset($this->mergePlan[$environment][$group])) { | ||
$this->mergePlan[$environment][$group] = []; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the merge plan group. | ||
* | ||
* @param string $group The group name. | ||
* @param string $environment The environment name. | ||
* | ||
* @return array<string, string[]> | ||
*/ | ||
public function getGroup(string $group, string $environment = Options::DEFAULT_ENVIRONMENT): array | ||
{ | ||
return $this->mergePlan[$environment][$group] ?? []; | ||
} | ||
|
||
/** | ||
* Returns the merge plan as an array. | ||
* | ||
* @psalm-return array<string, array<string, array<string, string[]>>> | ||
*/ | ||
public function generate(): array | ||
{ | ||
return $this->mergePlan; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters