Skip to content

Commit

Permalink
Cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Thompson committed Dec 8, 2015
1 parent 86e96bf commit 2fb8cd3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Expand Up @@ -4,14 +4,14 @@
use Illuminate\Contracts\Bus\SelfHandling;

/**
* Class GetSetting
* Class GetSettingValueFieldType
*
* @link http://anomaly.is/streams-platform
* @author AnomalyLabs, Inc. <hello@anomaly.is>
* @author Ryan Thompson <ryan@anomaly.is>
* @package Anomaly\SettingsModule\Setting\Plugin\Command
*/
class GetSetting implements SelfHandling
class GetSettingValueFieldType implements SelfHandling
{

/**
Expand All @@ -22,7 +22,7 @@ class GetSetting implements SelfHandling
protected $key;

/**
* Create a new GetSetting instance.
* Create a new GetSettingValueFieldType instance.
*
* @param $key
*/
Expand All @@ -35,10 +35,14 @@ public function __construct($key)
* Handle the command.
*
* @param SettingRepositoryInterface $settings
* @return \Anomaly\SettingsModule\Setting\Contract\SettingInterface|null
* @return \Anomaly\Streams\Platform\Addon\FieldType\FieldType|null
*/
public function handle(SettingRepositoryInterface $settings)
{
return $settings->get($this->key);
if (!$setting = $settings->get($this->key)) {
return null;
}

return $setting->getFieldType('value');
}
}
15 changes: 8 additions & 7 deletions src/SettingsModulePlugin.php
Expand Up @@ -2,8 +2,9 @@

use Anomaly\SettingsModule\Setting\Command\GetSetting;
use Anomaly\SettingsModule\Setting\Command\GetSettingValue;
use Anomaly\SettingsModule\Setting\Command\GetValuePresenter;
use Anomaly\SettingsModule\Setting\Command\GetSettingValueFieldType;
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Anomaly\Streams\Platform\Support\Decorator;

/**
* Class SettingsModulePlugin
Expand All @@ -24,17 +25,17 @@ class SettingsModulePlugin extends Plugin
public function getFunctions()
{
return [
new \Twig_SimpleFunction(
'setting',
function ($key) {
return $this->dispatch(new GetValuePresenter($this->dispatch(new GetSetting($key))));
}
),
new \Twig_SimpleFunction(
'setting_value',
function ($key, $default = null) {
return $this->dispatch(new GetSettingValue($key, $default));
}
),
new \Twig_SimpleFunction(
'setting',
function ($key) {
return (new Decorator())->decorate($this->dispatch(new GetSettingValueFieldType($key)));
}
)
];
}
Expand Down

0 comments on commit 2fb8cd3

Please sign in to comment.