Completed
Push — master ( 06e70d...2d152a )
by Peter
03:59
created

Sitcom::getVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL, Commercial license.
5
 *
6
 * @package maslosoft/sitcom
7
 * @licence AGPL, Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @link http://maslosoft.com/sitcom/
11
 */
12
13
namespace Maslosoft\Sitcom;
14
15
use Maslosoft\Cli\Shared\ConfigReader;
16
use Maslosoft\Signals\Signal;
17
use Maslosoft\Sitcom\Helpers\CommandWrapper;
18
use Symfony\Component\Console\Application;
19
20
class Sitcom
21
{
22
23
	/**
24
	 * Config file name
25
	 */
26
	const ConfigName = "sitcom";
27
28
	/**
29
	 * Version number holder
30
	 * @var string
31
	 */
32
	private static $_version = null;
33
34
	public function __construct($configName = self::ConfigName)
35
	{
36
		$config = new ConfigReader($configName);
37
		$cfg = (object) $config->toArray();
38
		if (!empty($cfg->require))
39
		{
40
			$cwd = getcwd();
41
			foreach ($cfg->require as $require)
42
			{
43
				require_once(sprintf('%s/%s', $cwd, $require));
44
			}
45
		}
46
	}
47
48
	public function addCommands(Application $app)
49
	{
50
		$signal = new Signal();
51
		$signal->init();
52
		$signal->emit(new Command(new CommandWrapper($app)));
53
	}
54
55
	public function __get($name)
56
	{
57
		return $this->{'get' . ucfirst($name)}();
58
	}
59
60
	public function __set($name, $value)
61
	{
62
		$this->{'set' . ucfirst($name)}($value);
63
	}
64
65
	/**
66
	 * Get version number
67
	 * @return string
68
	 */
69
	public function getVersion()
70
	{
71
		if (null === self::$_version)
72
		{
73
			self::$_version = require __DIR__ . '/version.php';
74
		}
75
		return self::$_version;
76
	}
77
78
}
79