Skip to content

Commit

Permalink
Added extension configuration manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Blaschke committed Oct 7, 2015
1 parent 0b6b538 commit 98a7ce0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
59 changes: 59 additions & 0 deletions ContextLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ class ContextLoader {
*/
protected $cacheFile;

/**
* List of extension configuration overrides
*
* @var array
*/
protected $extensionConfList = array();

/**
* Construct
*/
Expand Down Expand Up @@ -146,6 +153,7 @@ public function loadConfiguration() {
if (!$this->loadCache()) {
$this->loadContextConfiguration();
$this->loadFileConfiguration();
$this->injectExtensionConfiguration();
$this->buildCache();
}

Expand Down Expand Up @@ -230,6 +238,9 @@ protected function loadFileConfiguration() {
protected function loadConfigurationFile($configurationFile) {
// Load config file
if (file_exists($configurationFile)) {
// Keep this variable for automatic injection into requried files!
$contextLoader = $this;

// Load configuration file
$retConf = require $configurationFile;

Expand All @@ -242,6 +253,23 @@ protected function loadConfigurationFile($configurationFile) {
return $this;
}

/**
* Inject dynamic extension configuration
*/
protected function injectExtensionConfiguration() {
if (!empty($this->extensionConfList)) {
$extConf = &$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'];

foreach ($this->extensionConfList as $extension => $settingList) {
if (!empty($extConf[$extension])) {
$conf = unserialize($extConf[$extension]);
$conf = array_merge($conf, $settingList);
$extConf[$extension] = serialize($conf);
}
}
}
}

/**
* Append context name to sitename (if not production)
*
Expand All @@ -253,4 +281,35 @@ public function appendContextNameToSitename() {
}
return $this;
}

/**
* Set extension configuration value
*
* @param string $extension Extension name
* @param string $setting Configuration setting name
* @param mixed $value Configuration value
* @return $this
*/
public function setExtensionConfiguration($extension, $setting, $value = null) {
$this->extensionConfList[$extension][$setting] = $value;

return $this;
}

/**
* Set extension configuration value (by list)
*
* @param string $extension Extension name
* @param array $settingList List of settings
* @return $this
*/
public function setExtensionConfigurationList($extension, array $settingList) {
if (empty($this->extensionConfList[$extension])) {
$this->extensionConfList[$extension] = $settingList;
} else {
$this->extensionConfList[$extension] = array_merge($this->extensionConfList[$extension], $settingList);
}

return $this;
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,13 @@ If you don't want to use `EXT:cron_context/Configuration/` you can customize you
unset($confLoader);


For extension configuration manipulation:

<?php
/** @var \Cron\CronContext\ContextLoader $contextLoader */
$contextLoader
->setExtensionConfiguration('foobar', 'key', 'value');
->setExtensionConfigurationList('bar', array(
'setting1' => 'value1',
'setting2' => 'value2',
));

0 comments on commit 98a7ce0

Please sign in to comment.