Skip to content

Commit

Permalink
Load config automatically if named composer-dependency-analyser.php (#15
Browse files Browse the repository at this point in the history
)
  • Loading branch information
janedbal authored Jan 10, 2024
1 parent 8bd7b58 commit c23589d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Currently, it only supports those autoload sections: `psr-4`, `psr-0`, `files`.

## Configuration:
You can provide custom path to config file by `--config=path/to/config.php` where the config file is PHP file returning `ShipMonk\ComposerDependencyAnalyser\Config\Configuration` object.
It gets loaded automatically if it is located in cwd as `composer-dependency-analyser.php`.
Here is example of what you can do:

```php
Expand Down
13 changes: 9 additions & 4 deletions bin/composer-dependency-analyser
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,22 @@ if (isset($providedOptions['help'])) {
}

if (isset($providedOptions['config'])) {
$printer->printLine('Using config ' . $providedOptions['config'] . PHP_EOL);

$configPath = $cwd . "/" . $providedOptions['config'];

if (!is_file($configPath)) {
$exit("Invalid config path given, {$providedOptions['config']} is not a file.");
$exit("Invalid config path given, {$configPath} is not a file.");
}
} else {
$configPath = $cwd . "/composer-dependency-analyser.php";
}

if (is_file($configPath)) {
$printer->printLine('Using config ' . $configPath . PHP_EOL);

$config = require $configPath;

if (!$config instanceof Configuration) {
$exit("Invalid config file, must return instance of " . Configuration::class);
$exit("Invalid config file, it must return instance of " . Configuration::class);
}
} else {
$config = new Configuration();
Expand Down

0 comments on commit c23589d

Please sign in to comment.