Config   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 1
b 0
f 0
dl 0
loc 60
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 23 4
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
/**
14
 * Service providing the config object
15
 *
16
 * @package laravel
17
 * @subpackage Base
18
 */
19
class Config
20
{
21
	/**
22
	 * @var \Aimeos\Shop\Base\Config[]
23
	 */
24
	private $objects = array();
25
26
	/**
27
	 * @var \Aimeos\Shop\Base\Aimeos
28
	 */
29
	private $aimeos;
30
31
	/**
32
	 * @var \Illuminate\Contracts\Config\Repository
33
	 */
34
	private $config;
35
36
37
	/**
38
	 * Initializes the object
39
	 *
40
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
41
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
42
	 */
43
	public function __construct( \Illuminate\Contracts\Config\Repository $config, \Aimeos\Shop\Base\Aimeos $aimeos )
44
	{
45
		$this->aimeos = $aimeos;
46
		$this->config = $config;
47
	}
48
49
50
	/**
51
	 * Creates a new configuration object.
52
	 *
53
	 * @param integer $type Configuration type ("frontend" or "backend")
54
	 * @return \Aimeos\MW\Config\Iface Configuration object
55
	 */
56
	public function get( $type = 'frontend' )
57
	{
58
		if( !isset( $this->objects[$type] ) )
59
		{
60
			$configPaths = $this->aimeos->get()->getConfigPaths();
61
			$cfgfile = dirname( dirname( dirname( __DIR__ ) ) ) . DIRECTORY_SEPARATOR . 'default.php';
62
63
			$config = new \Aimeos\MW\Config\PHPArray( require $cfgfile, $configPaths );
64
65
			if( $this->config->get( 'shop.apc_enabled', false ) == true ) {
66
				$config = new \Aimeos\MW\Config\Decorator\APC( $config, $this->config->get( 'shop.apc_prefix', 'laravel:' ) );
67
			}
68
69
			$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $this->config->get( 'shop' ) );
70
71
			if( ( $conf = $this->config->get( 'shop.' . $type, array() ) ) !== array() ) {
72
				$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $conf );
73
			}
74
75
			$this->objects[$type] = $config;
76
		}
77
78
		return $this->objects[$type];
79
	}
80
}
81