|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Runner\Docker\Binary; |
|
6
|
|
|
|
|
7
|
|
|
use Ktomk\Pipelines\LibFs; |
|
8
|
|
|
use Ktomk\Pipelines\Yaml\Yaml; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class BinaryPackageYmlReader |
|
12
|
|
|
* |
|
13
|
|
|
* Read binary package information from a YAML file |
|
14
|
|
|
*/ |
|
15
|
|
|
class PackageYamlFileReader implements PackageInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $file; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* BinaryPackageYmlReader constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $file path to package YAML file to read |
|
26
|
|
|
*/ |
|
27
|
5 |
|
public function __construct($file) |
|
28
|
|
|
{ |
|
29
|
5 |
|
$this->file = LibFs::normalizePath($file); |
|
30
|
5 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return array |
|
34
|
|
|
*/ |
|
35
|
5 |
|
public function asPackageArray() |
|
36
|
|
|
{ |
|
37
|
5 |
|
$path = $this->file; |
|
38
|
5 |
|
if (!LibFs::isReadableFile($path)) { |
|
39
|
1 |
|
throw new \InvalidArgumentException( |
|
40
|
1 |
|
sprintf("not a readable file: '%s'", $path) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
4 |
|
$package = Yaml::buffer(file_get_contents($path)); |
|
44
|
|
|
|
|
45
|
4 |
|
$this->resolveUri($package['uri']); |
|
46
|
|
|
|
|
47
|
4 |
|
return $package; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* resolve local path URI relative to document location |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $uri |
|
54
|
|
|
*/ |
|
55
|
4 |
|
private function resolveUri(&$uri) |
|
56
|
|
|
{ |
|
57
|
4 |
|
if (null === $uri) { |
|
|
|
|
|
|
58
|
1 |
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// http/s is the only remote transport considered to be remote so far |
|
62
|
|
|
// as it is the only one used |
|
63
|
3 |
|
if (1 === preg_match('(^https?://)i', $uri)) { |
|
64
|
1 |
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
if (LibFs::isAbsolutePath($uri)) { |
|
68
|
1 |
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// TODO(tk): maybe this whole part as it's resolving? |
|
72
|
1 |
|
$baseDir = dirname($this->file); |
|
73
|
1 |
|
$buffer = $baseDir . '/' . $uri; |
|
74
|
1 |
|
$uri = LibFs::normalizePath($buffer); |
|
75
|
1 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|