Completed
Push — master ( 6114e5...8f259d )
by Aimeos
07:23
created

Aimeos::getVersion()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 17
Code Lines 8

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 8.2222
cc 7
eloc 8
nc 3
nop 0
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
		{
47
			$extDirs = (array) $this->container->getParameter( 'aimeos_shop.extdir' );
48
			$this->object = new \Aimeos\Bootstrap( $extDirs, false );
49
		}
50
51
		return $this->object;
52
	}
53
54
55
	/**
56
	 * Returns the version of the Aimeos package
57
	 *
58
	 * @return string Version string
59
	 */
60
	public function getVersion()
61
	{
62
		$filename = dirname( $this->container->get( 'kernel' )->getRootDir() ) . DIRECTORY_SEPARATOR . 'composer.lock';
63
64
		if( file_exists( $filename ) === true && ( $content = file_get_contents( $filename ) ) !== false
65
			&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
66
		) {
67
			foreach( (array) $content['packages'] as $item )
68
			{
69
				if( $item['name'] === 'aimeos/aimeos-symfony2' ) {
70
					return $item['version'];
71
				}
72
			}
73
		}
74
75
		return '';
76
	}
77
}
78