forked from docker-php/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortCollection.php
More file actions
82 lines (68 loc) · 1.46 KB
/
Copy pathPortCollection.php
File metadata and controls
82 lines (68 loc) · 1.46 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
<?php
namespace Docker;
use Docker\Exception;
/**
* Docker\PortCollection
*/
class PortCollection implements PortSpecInterface
{
/**
* @var array
*/
private $ports;
/**
* @param integer|string ...$ports
*/
public function __construct()
{
$args = func_get_args();
foreach ($args as $port) {
if ($port instanceof Port) {
$this->add($port);
} elseif (is_string($port) || is_integer($port)) {
$this->add(new Port($port));
} else {
throw new Exception('Invalid port definition "('.gettype($port).') '.var_export($port, true).'"');
}
}
}
/**
* @return array
*/
public function toSpec()
{
$spec = [];
foreach ($this->ports as $port) {
$spec = array_merge($spec, $port->toSpec());
}
return $spec;
}
/**
* @return array
*/
public function toExposedPorts()
{
$exposed = [];
foreach ($this->ports as $port) {
$exposed = array_merge($exposed, $port->toExposedPorts());
}
return $exposed;
}
/**
* @param Docker\Port
*
* @return Docker\PortCollection
*/
public function add(Port $port)
{
$this->ports[] = $port;
return $this;
}
/**
* @return array
*/
public function all()
{
return $this->ports;
}
}