Aimeos::getVersion()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
rs 9.2222
c 0
b 0
f 0
cc 6
nc 3
nop 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
/**
14
 * Service providing the Aimeos object
15
 *
16
 * @package laravel
17
 * @subpackage Base
18
 */
19
class Aimeos
20
{
21
	/**
22
	 * @var \Illuminate\Contracts\Config\Repository
23
	 */
24
	private $config;
25
26
	/**
27
	 * @var \Aimeos\Bootstrap
28
	 */
29
	private $object;
30
31
32
	/**
33
	 * Initializes the object
34
	 *
35
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
36
	 */
37
	public function __construct( \Illuminate\Contracts\Config\Repository $config )
38
	{
39
		$this->config = $config;
40
	}
41
42
43
	/**
44
	 * Returns the Aimeos object.
45
	 *
46
	 * @return \Aimeos\Bootstrap Aimeos bootstrap object
47
	 */
48
	public function get()
49
	{
50
		if( $this->object === null )
51
		{
52
			$dir = base_path( 'ext' );
53
54
			if( !is_dir( $dir ) ) {
55
				$dir = dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . DIRECTORY_SEPARATOR . 'ext';
56
			}
57
58
			$extDirs = (array) $this->config->get( 'shop.extdir', $dir );
59
			$this->object = new \Aimeos\Bootstrap( $extDirs, false );
60
		}
61
62
		return $this->object;
63
	}
64
65
66
	/**
67
	 * Returns the version of the Aimeos package
68
	 *
69
	 * @return string Version string
70
	 */
71
	public function getVersion()
72
	{
73
		if( ( $content = @file_get_contents( base_path( 'composer.lock' ) ) ) !== false
74
			&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
75
		) {
76
			foreach( (array) $content['packages'] as $item )
77
			{
78
				if( $item['name'] === 'aimeos/aimeos-laravel' ) {
79
					return $item['version'];
80
				}
81
			}
82
		}
83
84
		return '';
85
	}
86
}