Completed
Push — master ( e04fb5...4bd9a0 )
by Loz
46:36 queued 33:59
created

SilverStripeServiceConfigurationLocator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A locateConfigFor() 0 16 4
A configFor() 0 10 2
1
<?php
2
3
/**
4
 * Use the SilverStripe configuration system to lookup config for a
5
 * particular service.
6
 *
7
 * @package framework
8
 * @subpackage injector
9
 */
10
class SilverStripeServiceConfigurationLocator extends ServiceConfigurationLocator {
11
12
	/**
13
	 * List of Injector configurations cached from Config in class => config format.
14
	 * If any config is false, this denotes that this class and all its parents
15
	 * have no configuration specified.
16
	 *
17
	 * @var array
18
	 */
19
	protected $configs = array();
20
21
	public function locateConfigFor($name) {
22
		// Check direct or cached result
23
		$config = $this->configFor($name);
24
		if(!$config) {
25
			return null;
26
		}
27
28
		// If config is in `%$Source` format then inherit from the named config
29
		if(is_string($config) && stripos($config, '%$') === 0) {
30
			$name = substr($config, 2);
31
			return $this->locateConfigFor($name);
32
		}
33
34
		// Return the located config
35
		return $config;
36
	}
37
38
	/**
39
	 * Retrieves the config for a named service without performing a hierarchy walk
40
	 *
41
	 * @param string $name Name of service
42
	 * @return mixed Get config for this service
43
	 */
44
	protected function configFor($name) {
45
		// Return cached result
46
		if (array_key_exists($name, $this->configs)) {
47
			return $this->configs[$name];
48
		}
49
50
		$config = Config::inst()->get('Injector', $name);
51
		$this->configs[$name] = $config;
52
		return $config;
53
	}
54
}
55