6 use Consolidation\Config\ConfigInterface;
11 * @var ConfigInterface
16 * Set the config management object.
18 * @param ConfigInterface $config
22 * @see \Robo\Contract\ConfigAwareInterface::setConfig()
24 public function setConfig(ConfigInterface $config)
26 $this->config = $config;
32 * Get the config management object.
34 * @return ConfigInterface
36 * @see \Robo\Contract\ConfigAwareInterface::getConfig()
38 public function getConfig()
44 * Any class that uses ConfigAwareTrait SHOULD override this method
45 * , and define a prefix for its configuration items. This is usually
46 * done in a base class. When used, this method should return a string
47 * that ends with a "."; see BaseTask::configPrefix().
51 protected static function configPrefix()
56 protected static function configClassIdentifier($classname)
58 $configIdentifier = strtr($classname, '\\', '.');
59 $configIdentifier = preg_replace('#^(.*\.Task\.|\.)#', '', $configIdentifier);
61 return $configIdentifier;
64 protected static function configPostfix()
74 private static function getClassKey($key)
76 $configPrefix = static::configPrefix(); // task.
77 $configClass = static::configClassIdentifier(get_called_class()); // PARTIAL_NAMESPACE.CLASSNAME
78 $configPostFix = static::configPostfix(); // .settings
80 return sprintf('%s%s%s.%s', $configPrefix, $configClass, $configPostFix, $key);
86 * @param Config|null $config
88 public static function configure($key, $value, $config = null)
91 $config = Robo::config();
93 $config->setDefault(static::getClassKey($key), $value);
98 * @param mixed|null $default
102 protected function getConfigValue($key, $default = null)
104 if (!$this->getConfig()) {
107 return $this->getConfig()->get(static::getClassKey($key), $default);