Skip to content

Commit

Permalink
added theme::configSet()
Browse files Browse the repository at this point in the history
  • Loading branch information
igaster committed Dec 11, 2015
1 parent f7b8c04 commit 64f03a6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 19 additions & 3 deletions src/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,35 @@ 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")))
{
if (array_key_exists($key, $conf = $confs[$this->name]))
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;
}


}
17 changes: 14 additions & 3 deletions src/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 64f03a6

Please sign in to comment.