forked from ashleyhood/php-lxd
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLogs.php
More file actions
83 lines (71 loc) · 1.99 KB
/
Logs.php
File metadata and controls
83 lines (71 loc) · 1.99 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
<?php
namespace Opensaucesystems\Lxd\Endpoint\Instance;
use Opensaucesystems\Lxd\Endpoint\AbstractEndpoint;
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;
use Opensaucesystems\Lxd\Helpers\Str;
class Logs extends AbstractEndpoint
{
private $endpoint;
protected function getEndpoint()
{
return $this->endpoint;
}
public function setEndpoint(string $endpoint)
{
$this->endpoint = $endpoint;
}
/**
* List of logs for a container
*
* @param string $name Name of container
* @return array
*/
public function all($name)
{
$logs = [];
foreach ($this->get($this->getEndpoint().$name.'/logs/') as $log) {
$logs[] = str_replace(
'/'.$this->client->getApiVersion().$this->getEndpoint().$name.'/logs/',
'',
$log
);
}
return $logs;
}
/**
* Get the contents of a particular log file
*
* @param string $name Name of container
* @param string $log Name of log
* @return object
*/
public function read($name, $log)
{
return $this->get($this->getEndpoint().$name.'/logs/'.$log);
}
/**
* Remove a particular log file
*
* @param string $name Name of container
* @param string $log Name of log
* @return object
*/
public function remove($name, $log)
{
return $this->delete($this->getEndpoint().$name.'/logs/'.$log);
}
public function __get($endpoint)
{
$className = basename(str_replace('\\', '/', get_class($this)));
$class = __NAMESPACE__.'\\'.$className.'\\'.Str::studly($endpoint);
if (class_exists($class)) {
$class = new $class($this->client);
$class->setEndpoint($this->getEndpoint());
return $class;
} else {
throw new InvalidEndpointException(
'Endpoint '.$class.', not implemented.'
);
}
}
}