Aimeos   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 53
rs 10
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A __construct() 0 3 1
B getVersion() 0 16 7
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2014-2016
6
 * @package symfony
7
 * @subpackage Service
8
 */
9
10
namespace Aimeos\ShopBundle\Service;
11
12
use Symfony\Component\DependencyInjection\Container;
13
14
15
/**
16
 * Service providing the Aimeos object
17
 *
18
 * @package symfony
19
 * @subpackage Service
20
 */
21
class Aimeos
22
{
23
	private $object;
24
	private $container;
25
26
27
	/**
28
	 * Initializes the Aimeos object
29
	 *
30
	 * @param Container $container Container object to access parameters
31
	 */
32
	public function __construct( Container $container )
33
	{
34
		$this->container = $container;
35
	}
36
37
38
	/**
39
	 * Returns the Aimeos object.
40
	 *
41
	 * @return \Aimeos Aimeos object
42
	 */
43
	public function get()
44
	{
45
		if( $this->object === null ) {
46
			$this->object = new \Aimeos\Bootstrap( [], false );
47
		}
48
49
		return $this->object;
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
		$filename = dirname( $this->container->get( 'kernel' )->getProjectDir() ) . DIRECTORY_SEPARATOR . 'composer.lock';
61
62
		if( file_exists( $filename ) === true && ( $content = file_get_contents( $filename ) ) !== false
63
			&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
64
		) {
65
			foreach( (array) $content['packages'] as $item )
66
			{
67
				if( $item['name'] === 'aimeos/aimeos-symfony' ) {
68
					return $item['version'];
69
				}
70
			}
71
		}
72
73
		return '';
74
	}
75
}
76