Completed
Push — master ( 844367...ab725b )
by Aimeos
02:57
created

Config::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.2
cc 4
eloc 9
nc 4
nop 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\Aimeos
23
	 */
24
	private $aimeos;
25
26
	/**
27
	 * @var \Illuminate\Contracts\Config\Repository
28
	 */
29
	private $config;
30
31
32
	/**
33
	 * Initializes the object
34
	 *
35
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
36
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
37
	 */
38
	public function __construct( \Illuminate\Contracts\Config\Repository $config, \Aimeos\Shop\Base\Aimeos $aimeos )
39
	{
40
		$this->aimeos = $aimeos;
41
		$this->config = $config;
42
	}
43
44
45
	/**
46
	 * Creates a new configuration object.
47
	 *
48
	 * @param integer $type Configuration type ("frontend" or "backend")
49
	 * @return \Aimeos\MW\Config\Iface Configuration object
50
	 */
51
	public function get( $type = 'frontend' )
52
	{
53
		$configPaths = $this->aimeos->get()->getConfigPaths();
54
		$config = new \Aimeos\MW\Config\PHPArray( array(), $configPaths );
55
56
		if( function_exists( 'apc_store' ) === true && $this->config->get( 'shop.apc_enabled', false ) == true ) {
57
			$config = new \Aimeos\MW\Config\Decorator\APC( $config, $this->config->get( 'shop.apc_prefix', 'laravel:' ) );
58
		}
59
60
		$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $this->config->get( 'shop' ) );
61
62
		if( ( $conf = $this->config->get( 'shop.' . $type, array() ) ) !== array() ) {
63
			$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $conf );
64
		}
65
66
		return $config;
67
	}
68
}
69