Completed
Push — master ( f7149b...10b3eb )
by Aimeos
02:17
created

Config::get()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
cc 6
eloc 15
nc 16
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package flow
7
 * @subpackage Base
8
 */
9
10
11
namespace Aimeos\Shop\Base;
12
13
use TYPO3\Flow\Annotations as Flow;
14
15
16
/**
17
 * Class providing the config object
18
 *
19
 * @package flow
20
 * @subpackage Base
21
 * @Flow\Scope("singleton")
22
 */
23
class Config
24
{
25
	/**
26
	 * @var \Aimeos\Shop\Base\Aimeos
27
	 * @Flow\Inject
28
	 */
29
	protected $aimeos;
30
31
	/**
32
	 * @var array
33
	 */
34
	private $settings;
35
36
37
	/**
38
	 * Returns the Aimeos object.
39
	 *
40
	 * @return \Aimeos\Bootstrap Aimeos object
41
	 */
42
	public function get( $type = 'frontend' )
43
	{
44
		$this->settings['resource']['db']['host'] = $this->resource['host'];
0 ignored issues
show
Bug introduced by
The property resource does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
		$this->settings['resource']['db']['database'] = $this->resource['dbname'];
46
		$this->settings['resource']['db']['username'] = $this->resource['user'];
47
		$this->settings['resource']['db']['password'] = $this->resource['password'];
48
49
		$configPaths = $this->aimeos->get()->getConfigPaths();
50
		$config = new \Aimeos\MW\Config\PHPArray( array(), $configPaths );
51
52
		$apc = (bool) ( isset( $this->settings['flow']['apc']['enable'] ) ? $this->settings['flow']['apc']['enable'] : false );
53
		$prefix = (string) ( isset( $this->settings['flow']['apc']['prefix'] ) ? $this->settings['flow']['apc']['prefix'] : 'flow:' );
54
55
		if( function_exists( 'apc_store' ) === true && $apc === true ) {
56
			$config = new \Aimeos\MW\Config\Decorator\APC( $config, $prefix );
57
		}
58
59
		$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $this->settings );
60
61
		if( isset( $this->settings[$type] ) ) {
62
			$config = new \Aimeos\MW\Config\Decorator\Memory( $config, $this->settings[$type] );
63
		}
64
65
		return $config;
66
	}
67
68
69
	/**
70
	 * Inject the settings
71
	 *
72
	 * @param array $settings
73
	 * @return void
74
	 */
75
	public function injectSettings( array $settings )
76
	{
77
		$this->settings = $settings;
78
	}
79
}
80