diff --git a/Helper/ContextHelper.php b/Helper/ContextHelper.php index b10ac69d..d7eaa1ed 100644 --- a/Helper/ContextHelper.php +++ b/Helper/ContextHelper.php @@ -1,10 +1,19 @@ initialize($config); $this->router = $router; } - + /** - * @param array $config + * Create a OptionResolver with default parameters and overwrite the context + * with the default options in avanzu_admin_theme.options + * + * @param array $config The data under avanzu_admin_theme.options config */ protected function initialize(array $config = []) { + // Create a resolve and configure the defaults $resolver = new OptionsResolver(); $this->configureDefaults($resolver); - if(!empty($config)) + try { - try - { - $newConfig = $resolver->resolve($config); - - foreach($newConfig as $configKey => $configValue) - { - //if(!is_array($configValue)) - //{ - $this->setOption($configKey, $configValue); - //} - //else @todo Not sure if it is needed handle second level index of arrays - //{ - - //} - } - } - catch(UndefinedOptionsException $e) - { - echo $e->getMessage() . PHP_EOL; - print_r($config, TRUE); - } + // Parse the config in avanzu_admin_theme.options as array object in avanzu_admin_context.options + $newConfig = $resolver->resolve($config); + // Change the internal storage array in the ArrayObject + $this->exchangeArray($newConfig); } + catch(UndefinedOptionsException $e) + { + echo $e->getMessage() . PHP_EOL; + print_r($config, TRUE); + } + } - + /** + * Get attribute method for options. It uses a interal copy array of the + * storage in the ArrayObject + * * @return array */ public function getOptions() { return $this->getArrayCopy(); } - + /** * @param $name * @param $value @@ -81,10 +86,10 @@ public function getOptions() public function setOption($name, $value) { $this->offsetSet($name, $value); - + return $this; } - + /** * @param $name * @@ -94,7 +99,7 @@ public function hasOption($name) { return $this->offsetExists($name); } - + /** * @param $name * @param null $default @@ -105,7 +110,7 @@ public function getOption($name, $default = null) { return $this->offsetExists($name) ? $this->offsetGet($name) : $default; } - + /** * @param $name * @@ -115,7 +120,7 @@ public function hasAlias($name) { return $this->router->hasAlias($name); } - + /** * @param $name * @@ -125,7 +130,7 @@ public function fromAlias($name) { return $this->router->getRouteByAlias($name); } - + /** * @param OptionsResolver $resolver */