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-2023
6
 */
7
8
namespace Aimeos\Shop\Base;
9
10
11
/**
12
 * Service providing the Aimeos object
13
 */
14
class Aimeos
15
{
16
	/**
17
	 * @var \Illuminate\Contracts\Config\Repository
18
	 */
19
	private $config;
20
21
	/**
22
	 * @var \Aimeos\Bootstrap
23
	 */
24
	private $object;
25
26
27
	/**
28
	 * Initializes the object
29
	 *
30
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
31
	 */
32
	public function __construct( \Illuminate\Contracts\Config\Repository $config )
33
	{
34
		$this->config = $config;
35
	}
36
37
38
	/**
39
	 * Returns the Aimeos object.
40
	 *
41
	 * @return \Aimeos\Bootstrap Aimeos bootstrap object
42
	 */
43
	public function get() : \Aimeos\Bootstrap
44
	{
45
		if( $this->object === null )
46
		{
47
			$dir = base_path( 'ext' );
48
49
			if( !is_dir( $dir ) ) {
50
				$dir = dirname( __DIR__, 4 ) . DIRECTORY_SEPARATOR . 'ext';
51
			}
52
53
			$extDirs = (array) $this->config->get( 'shop.extdir', $dir );
54
			$this->object = new \Aimeos\Bootstrap( $extDirs, false );
55
		}
56
57
		return $this->object;
58
	}
59
60
61
	/**
62
	 * Returns the version of the Aimeos package
63
	 *
64
	 * @return string Version string
65
	 */
66
	public function getVersion() : string
67
	{
68
		if( ( $content = @file_get_contents( base_path( 'composer.lock' ) ) ) !== false
69
			&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
70
		) {
71
			foreach( (array) $content['packages'] as $item )
72
			{
73
				if( $item['name'] === 'aimeos/aimeos-laravel' ) {
74
					return $item['version'];
75
				}
76
			}
77
		}
78
79
		return '';
80
	}
81
}