Config::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Slim
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Slim\Base;
11
12
use Psr\Container\ContainerInterface;
13
14
15
/**
16
 * Service providing the config objects
17
 *
18
 * @package Slim
19
 * @subpackage Base
20
 */
21
class Config
22
{
23
	private $container;
24
	private $settings;
25
26
27
	/**
28
	 * Initializes the object
29
	 *
30
	 * @param ContainerInterface $container Dependency container
31
	 */
32
	public function __construct( ContainerInterface $container, array $settings )
33
	{
34
		$this->container = $container;
35
		$this->settings = $settings;
36
	}
37
38
39
	/**
40
	 * Returns the config object
41
	 *
42
	 * @param string $type Configuration type ("frontend" or "backend")
43
	 * @return \Aimeos\MW\Config\Iface Config object
44
	 */
45
	public function get( string $type = 'frontend' ) : \Aimeos\MW\Config\Iface
46
	{
47
		$paths = $this->container->get( 'aimeos' )->getConfigPaths();
48
		$config = new \Aimeos\MW\Config\PHPArray( array(), $paths );
49
50
		if( function_exists( 'apcu_store' ) === true && $config->get( 'apc_enabled', false ) == true ) {
51
			$config = new \Aimeos\MW\Config\Decorator\APC( $config, $config->get( 'apc_prefix', 'slim:' ) );
52
		}
53
54
		$config = new \Aimeos\MW\Config\Decorator\Memory( $config, (array) $this->settings );
55
56
		if( isset( $this->settings[$type] ) ) {
57
			$config = new \Aimeos\MW\Config\Decorator\Memory( $config, (array) $this->settings[$type] );
58
		}
59
60
		return $config;
61
	}
62
}
63