2016-01-27 13:46:43 +13:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 10:51:35 +12:00
|
|
|
namespace SilverStripe\Core\Config;
|
2016-01-27 13:46:43 +13:00
|
|
|
|
2017-02-22 16:12:46 +13:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
|
|
|
|
2016-01-27 13:46:43 +13:00
|
|
|
/**
|
|
|
|
* Provides extensions to this object to integrate it with standard config API methods.
|
|
|
|
*
|
|
|
|
* Note that all classes can have configuration applied to it, regardless of whether it
|
|
|
|
* uses this trait.
|
|
|
|
*/
|
2016-11-29 12:31:16 +13:00
|
|
|
trait Configurable
|
|
|
|
{
|
2016-01-27 13:46:43 +13:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
|
|
|
|
* @return Config_ForClass
|
|
|
|
*/
|
|
|
|
public static function config()
|
|
|
|
{
|
2017-02-22 16:12:46 +13:00
|
|
|
return Config::forClass(get_called_class());
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2016-01-27 13:46:43 +13:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
2017-02-22 16:12:46 +13:00
|
|
|
* Get inherited config value
|
2016-11-29 12:31:16 +13:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function stat($name)
|
|
|
|
{
|
2017-02-22 16:12:46 +13:00
|
|
|
Deprecation::notice('5.0', 'Use ->get');
|
|
|
|
return $this->config()->get($name);
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2016-01-27 13:46:43 +13:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
2017-02-22 16:12:46 +13:00
|
|
|
* Gets the uninherited value for the given config option
|
2016-11-29 12:31:16 +13:00
|
|
|
*
|
|
|
|
* @param string $name
|
2017-02-22 16:12:46 +13:00
|
|
|
* @return mixed
|
2016-11-29 12:31:16 +13:00
|
|
|
*/
|
2017-02-22 16:12:46 +13:00
|
|
|
public function uninherited($name)
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-02-22 16:12:46 +13:00
|
|
|
return $this->config()->uninherited($name);
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2016-01-27 13:46:43 +13:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
2017-02-22 16:12:46 +13:00
|
|
|
* Update the config value for a given property
|
2016-11-29 12:31:16 +13:00
|
|
|
*
|
|
|
|
* @param string $name
|
2017-02-22 16:12:46 +13:00
|
|
|
* @param mixed $value
|
|
|
|
* @return $this
|
2016-11-29 12:31:16 +13:00
|
|
|
*/
|
2017-02-22 16:12:46 +13:00
|
|
|
public function set_stat($name, $value)
|
2016-11-29 12:31:16 +13:00
|
|
|
{
|
2017-02-22 16:12:46 +13:00
|
|
|
Deprecation::notice('5.0', 'Use ->config()->set()');
|
|
|
|
$this->config()->set($name, $value);
|
|
|
|
return $this;
|
2016-11-29 12:31:16 +13:00
|
|
|
}
|
2016-01-27 13:46:43 +13:00
|
|
|
}
|