-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from openeuropa/custom-configs
Allow 3rd party to add and alter the configuration
- Loading branch information
Showing
14 changed files
with
474 additions
and
43 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEuropa\TaskRunner\Commands; | ||
|
||
use Robo\Exception\AbortTasksException; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
/** | ||
* Commands to interact with the task runner itself. | ||
*/ | ||
class RunnerCommands extends AbstractCommands | ||
{ | ||
|
||
/** | ||
* Displays the current configuration in YAML format. | ||
* | ||
* If no argument is passed the whole configuration is outputted. To display | ||
* a specific configuration, pass the key as argument (e.g. `drupal.root`). | ||
* | ||
* @command config | ||
* | ||
* @param string|null $key Optional configuration key | ||
* @return string | ||
* @throws \Robo\Exception\AbortTasksException | ||
* | ||
* @todo Implement a `--format` option to allow different output formats. | ||
*/ | ||
public function config(?string $key = null): string | ||
{ | ||
if (!$key) { | ||
$config = $this->getConfig()->export(); | ||
} else { | ||
if (!$this->getConfig()->has($key)) { | ||
throw new AbortTasksException("Invalid '$key' key."); | ||
} | ||
$config = $this->getConfig()->get($key); | ||
} | ||
return trim(Yaml::dump($config, 10, 2)); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEuropa\TaskRunner\Contract; | ||
|
||
use OpenEuropa\TaskRunner\Traits\ConfigFromFilesTrait; | ||
use Robo\Config\Config; | ||
|
||
/** | ||
* Interface for configuration providers. | ||
* | ||
* Classes implementing this interface: | ||
* - Should have `TaskRunner\ConfigProviders` as relative namespace. For | ||
* instance when `Some\Namespace` points to the `src/` directory, then the | ||
* class should be placed in `src/TaskRunner/ConfigProviders` and will have | ||
* `Some\Namespace\TaskRunner\ConfigProviders` as namespace. | ||
* - The class name should end with the `ConfigProvider` suffix. | ||
*/ | ||
interface ConfigProviderInterface | ||
{ | ||
/** | ||
* The relative path for an environment specific config file. | ||
* | ||
* If this file is found in the local environment's default configuration | ||
* path (such as $XDG_CONFIG_HOME or $HOME/.config/) then it will | ||
* automatically be included. | ||
* | ||
* Any custom config providers that read config from a hierarchical data | ||
* storage are suggested to use this path. | ||
* | ||
* @var string | ||
*/ | ||
const DEFAULT_CONFIG_LOCATION = 'openeuropa/taskrunner/runner.yml'; | ||
|
||
/** | ||
* Adds or overrides configuration. | ||
* | ||
* Implementations should alter the `$config` object, passed to the method. | ||
* A convenient way to provide additional config or override the existing | ||
* one is to use the `ConfigFromFilesTrait::importFromFiles()` method and | ||
* load overrides form custom config .yml files. But the $config object can | ||
* be manipulated also directly using its methods, e.g. $config->(). | ||
* | ||
* @param \Robo\Config\Config $config | ||
* | ||
* @see ConfigFromFilesTrait::importFromFiles() | ||
*/ | ||
public static function provide(Config $config): void; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEuropa\TaskRunner\TaskRunner\ConfigProviders; | ||
|
||
use OpenEuropa\TaskRunner\Contract\ConfigProviderInterface; | ||
use OpenEuropa\TaskRunner\Traits\ConfigFromFilesTrait; | ||
use Robo\Config\Config; | ||
|
||
/** | ||
* Provides the basic default configuration for the task runner. | ||
* | ||
* This will import the following files: | ||
* - The example configuration provided in the task runner library itself. | ||
* - The default configuration "runner.yml.dist" shipped in the root folder of | ||
* the project which uses the task runner. | ||
* | ||
* This serves as a safe default implementation which can be overridden by | ||
* environment specific configuration and user preferences. | ||
* | ||
* The config provider priority is very high in order to ensure that will run at | ||
* the very beginning. However, in some very special circumstances, third-party | ||
* config providers are abie to set priorities higher than this. | ||
* | ||
* @priority 1500 | ||
*/ | ||
class DefaultConfigProvider implements ConfigProviderInterface | ||
{ | ||
use ConfigFromFilesTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function provide(Config $config): void | ||
{ | ||
static::importFromFiles($config, [ | ||
__DIR__.'/../../../config/runner.yml', | ||
'runner.yml.dist', | ||
]); | ||
} | ||
} |
Oops, something went wrong.