silverstripe-framework/control/injector/SilverStripeServiceConfigurationLocator.php

55 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/**
2015-02-27 01:10:32 +01:00
* Use the SilverStripe configuration system to lookup config for a
* particular service.
*
* @package framework
* @subpackage injector
*/
class SilverStripeServiceConfigurationLocator extends ServiceConfigurationLocator {
2015-02-27 01:10:32 +01:00
/**
* List of Injector configurations cached from Config in class => config format.
2015-02-27 01:10:32 +01:00
* If any config is false, this denotes that this class and all its parents
* have no configuration specified.
2015-02-27 01:10:32 +01:00
*
* @var array
*/
protected $configs = array();
2015-02-27 01:10:32 +01:00
public function locateConfigFor($name) {
// Check direct or cached result
$config = $this->configFor($name);
if(!$config) {
return null;
}
// If config is in `%$Source` format then inherit from the named config
if(is_string($config) && stripos($config, '%$') === 0) {
$name = substr($config, 2);
return $this->locateConfigFor($name);
}
2015-02-27 01:10:32 +01:00
// Return the located config
return $config;
}
2015-02-27 01:10:32 +01:00
/**
* Retrieves the config for a named service without performing a hierarchy walk
2015-02-27 01:10:32 +01:00
*
* @param string $name Name of service
* @return mixed Get config for this service
*/
protected function configFor($name) {
// Return cached result
if (array_key_exists($name, $this->configs)) {
return $this->configs[$name];
}
2015-02-27 01:10:32 +01:00
$config = Config::inst()->get('Injector', $name);
$this->configs[$name] = $config;
return $config;
}
}