diff --git a/README.md b/README.md index 7745c08..89a0c8c 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,10 @@ All themes fall back to the default laravel folders if a resource is not found o The default theme can be configured in the `theme.php` configuration file. Working with themes is very straightforward. Use: ```php -Theme::set('theme-name'); // switch to 'theme-name' -Theme::get(); // retrieve current theme's name -Theme::config('key'); // read current theme's configuration value for 'key' +Theme::set('theme-name'); // switch to 'theme-name' +Theme::get(); // retrieve current theme's name +Theme::config('key'); // read current theme's configuration value for 'key' +Theme::configSet('key','value'); // assign a key-value pair to current theme's configuration ``` For example this is a Service Provider that will select a different theme for the `/admin/xxx` urls: diff --git a/src/Theme.php b/src/Theme.php index dcf0acc..7c17db1 100644 --- a/src/Theme.php +++ b/src/Theme.php @@ -59,9 +59,10 @@ public function url($url){ * are stored per theme in themes.php config file. * * @param string $key + * @param mixed $defaultValue * @return mixed */ - public function config($key){ + public function config($key, $defaultValue){ //root theme not have configs if(array_key_exists($this->name, $confs = \Config::get("themes.themes"))) { @@ -69,9 +70,24 @@ public function config($key){ return $conf[$key]; } if ($this->getParent()) - return $this->getParent()->config($key); + return $this->getParent()->config($key, $defaultValue); - return null; + return $defaultValue; } + /** + * Return the configuration value of $key for the current theme. Configuration values + * are stored per theme in themes.php config file. + * + * @param string $key + * @param mixed $value + * @return mixed + */ + public function configSet($key, $value){ + $themeName = $this->name; + \Config::set("themes.themes.$themeName.$key",$value); + return $value; + } + + } diff --git a/src/Themes.php b/src/Themes.php index bae0294..e4a3e6e 100644 --- a/src/Themes.php +++ b/src/Themes.php @@ -105,15 +105,26 @@ public function get(){ } /** - * Return current theme's configuration option for $key + * Return current theme's configuration value for $key * * @param string $key * @return mixed */ - public function config($key){ - return $this->activeTheme->config($key); + public function config($key, $defaultValue = null){ + return $this->activeTheme->config($key, $defaultValue); } + /** + * Set current theme's configuration value for $key + * + * @param string $key + * @return mixed + */ + public function configSet($key, $value){ + return $this->activeTheme->configSet($key, $value); + } + + /** * Attach current theme's paths to a local Url. The Url must be a resource located on the asset path * of the current theme or it's parents.