Completed
Push — master ( 0a4763...f5ea6d )
by Aimeos
49:24 queued 18:11
created

Aimeos::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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
			$extDirs = (array) $this->config->get( 'shop.extdir', array() );
53
			$this->object = new \Aimeos\Bootstrap( $extDirs, false );
54
		}
55
56
		return $this->object;
57
	}
58
59
60
	/**
61
	 * Returns the version of the Aimeos package
62
	 *
63
	 * @return string Version string
64
	 */
65
	public function getVersion()
66
	{
67
		if( ( $content = @file_get_contents( base_path( 'composer.lock' ) ) ) !== false
68
			&& ( $content = json_decode( $content, true ) ) !== null && isset( $content['packages'] )
69
		) {
70
			foreach( (array) $content['packages'] as $item )
71
			{
72
				if( $item['name'] === 'aimeos/aimeos-laravel' ) {
73
					return $item['version'];
74
				}
75
			}
76
		}
77
78
		return '';
79
	}
80
}