forked from HermanPeeren/releasemaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.php
More file actions
92 lines (73 loc) · 2.75 KB
/
Copy pathSource.php
File metadata and controls
92 lines (73 loc) · 2.75 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
<?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\Update;
use Akeeba\ReleaseMaker\Configuration\Configuration;
use Akeeba\ReleaseMaker\Contracts\Uploader;
use Akeeba\ReleaseMaker\Exception\InvalidConnectionKey;
use Akeeba\ReleaseMaker\Exception\InvalidUpdateFormat;
use Akeeba\ReleaseMaker\Exception\InvalidUpdateStream;
use Akeeba\ReleaseMaker\Mixin\MagicGetterAware;
/**
* Update Source
*
* @property-read string $title The title for this update source.
* @property-read string $connectionName The name (key) of the connection used to upload this update stream.
* @property-read string|null $directory The directory override for the connection.
* @property-read int $stream ARS update stream ID.
* @property-read string $baseName Base name for the update stream file on the remote server.
* @property-read string[] $formats Update formats, one or more of xml, ini, and inibare.
* @property-read Uploader $uploader The Uploader object to be used for this update source.
*
* @since 2.0.0
*/
class Source
{
use MagicGetterAware;
private string $title;
private string $connectionName;
private ?string $directory;
private int $stream;
private string $baseName;
private array $formats = [];
private Configuration $parent;
public function __construct(array $configuration, Configuration $parent)
{
$this->parent = $parent;
$this->stream = (int) ($configuration['stream'] ?? 0);
$this->title = $configuration['title'] ?? sprintf('Updates for stream %d', $this->stream);
$this->connectionName = $configuration['connection'] ?? '';
$this->directory = $configuration['directory'] ?? null;
$this->baseName = $configuration['base_name'] ?? sprintf('stream-%s', $this->stream);
$this->formats = $configuration['formats'] ?? ['xml'];
if ($this->stream <= 0)
{
throw new InvalidUpdateStream($this->stream);
}
if (!in_array($this->connectionName, $this->parent->connection->getConnectionKeys()))
{
throw new InvalidConnectionKey($this->connectionName);
}
if (empty($this->formats))
{
$this->formats = ['xml'];
}
$this->formats = array_unique($this->formats);
foreach ($this->formats as $format)
{
if (!in_array($format, ['xml', 'ini', 'inibare']))
{
throw new InvalidUpdateFormat($format);
}
}
}
/** @noinspection PhpUnusedPrivateMethodInspection */
private function getUploader(): Uploader
{
$connection = $this->parent->connection->getConnection($this->connectionName);
return $connection->getUploader($this->directory);
}
}