Aimeos::injectSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package flow
7
 * @subpackage Base
8
 */
9
10
11
namespace Aimeos\Shop\Base;
12
13
use Neos\Flow\Annotations as Flow;
14
15
16
/**
17
 * Class providing the Aimeos object
18
 *
19
 * @package flow
20
 * @subpackage Base
21
 * @Flow\Scope("singleton")
22
 */
23
class Aimeos
24
{
25
	/**
26
	 * @var \Aimeos\Bootstrap
27
	 */
28
	private $aimeos;
29
30
	/**
31
	 * @var array
32
	 */
33
	private $settings;
34
35
36
	/**
37
	 * Returns the Aimeos object.
38
	 *
39
	 * @return \Aimeos\Bootstrap Aimeos object
40
	 */
41
	public function get()
42
	{
43
		if( $this->aimeos === null )
44
		{
45
			$extDirs = ( isset( $this->settings['flow']['extdir'] ) ? (array) $this->settings['flow']['extdir'] : array() );
46
			$this->aimeos = new \Aimeos\Bootstrap( $extDirs, false );
47
		}
48
49
		return $this->aimeos;
50
	}
51
52
53
	/**
54
	 * Returns the version of the Aimeos package
55
	 *
56
	 * @return string Version string
57
	 */
58
	public function getVersion()
59
	{
60
		if( ( $content = @file_get_contents( FLOW_PATH_ROOT . 'composer.lock' ) ) !== false
61
				&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
62
		) {
63
			foreach( (array) $content['packages'] as $item )
64
			{
65
				if( $item['name'] === 'aimeos/aimeos-flow' ) {
66
					return $item['version'];
67
				}
68
			}
69
		}
70
		return '';
71
	}
72
73
74
	/**
75
	 * Inject the settings
76
	 *
77
	 * @param array $settings
78
	 * @return void
79
	 */
80
	public function injectSettings( array $settings )
81
	{
82
		$this->settings = $settings;
83
	}
84
}
85