forked from HermanPeeren/releasemaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.php
More file actions
115 lines (92 loc) · 3.37 KB
/
Configuration.php
File metadata and controls
115 lines (92 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* @package AkeebaReleaseMaker
* @copyright Copyright (c)2012-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace Akeeba\ReleaseMaker\Configuration;
use Akeeba\ReleaseMaker\Configuration\Section\Api;
use Akeeba\ReleaseMaker\Configuration\Section\Connection;
use Akeeba\ReleaseMaker\Configuration\Section\Release;
use Akeeba\ReleaseMaker\Configuration\Section\Sources;
use Akeeba\ReleaseMaker\Configuration\Section\Steps;
use Akeeba\ReleaseMaker\Configuration\Section\Updates;
use Akeeba\ReleaseMaker\Configuration\Section\Volatile;
use Akeeba\ReleaseMaker\Contracts\ExceptionCode;
use Akeeba\ReleaseMaker\Exception\ConfigurationError;
use Akeeba\ReleaseMaker\Mixin\MagicGetterAware;
use LogicException;
/**
* Akeeba Release Maker configuration
*
* @property-read Release $release Release configuration
* @property-read Api $api ARS API connection configuration
* @property-read Steps $steps Release Maker steps configuration
* @property-read Connection $connection Connections configuration, for uploading to remote servers
* @property-read Updates $updates Configuration for publishing updates to a remote server
* @property-read Sources $sources File sources configuration
* @property-read Volatile $volatile Volatile information shared between steps
*
* @since 2.0.0
*/
final class Configuration
{
use MagicGetterAware;
private static $instance = null;
private Release $release;
private Api $api;
private Steps $steps;
private Connection $connection;
private Updates $updates;
private Sources $sources;
private Volatile $volatile;
final private function __construct(array $configuration)
{
$this->release = new Release($configuration['release'] ?? [], $this);
$this->api = new Api($configuration['api'] ?? [], $this);
$this->steps = new Steps($configuration['steps'] ?? [], $this);
$this->connection = new Connection($configuration['connections'] ?? [], $this);
$this->updates = new Updates($configuration['updates'] ?? [], $this);
$this->sources = new Sources($configuration['files'] ?? [], $this);
$this->volatile = new Volatile([], $this);
}
final public static function getInstance(?array $configuration = null): self
{
if (!is_null(self::$instance))
{
return self::$instance;
}
if (is_null($configuration))
{
throw new LogicException("Release Maker configuration has not been initialised yet.");
}
self::$instance = new self($configuration);
return self::$instance;
}
final public static function fromFile(string $configurationFile): self
{
$sourceFile = $configurationFile;
if (!is_file($sourceFile) || !is_readable($sourceFile))
{
$sourceFile = __DIR__ . '/' . $configurationFile;
}
if (!is_file($sourceFile) || !is_readable($sourceFile))
{
$sourceFile = getcwd() . '/' . $configurationFile;
}
if (!is_file($sourceFile) || !is_readable($sourceFile))
{
throw new ConfigurationError(sprintf('Cannot locate configuration file %s', $configurationFile));
}
try
{
$parser = new Parser();
$configuration = $parser->parseFile($sourceFile);
}
catch (\Exception $e)
{
throw new ConfigurationError(sprintf("Cannot parse configuration file %s", $sourceFile), ExceptionCode::CONFIG_GENERIC_ERROR, $e);
}
return self::getInstance($configuration);
}
}