This repository was archived by the owner on Jul 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathManager.php
More file actions
84 lines (72 loc) · 1.98 KB
/
Manager.php
File metadata and controls
84 lines (72 loc) · 1.98 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
<?php
/*
* This file is part of the Supervisor Monitor project.
*
* (c) Márk Sági-Kazár <mark.sagikazar@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Supervisor\Monitor;
use fXmlRpc\Transport\StreamSocketTransport;
use fXmlRpc\Client;
use Supervisor\Connector\XmlRpc;
use Supervisor\Supervisor;
/**
* @author Márk Sági-Kazár <mark.sagikazar@gmail.com>
*/
class Manager
{
/**
* Created Supervisor instances
*
* @var Supervisor[]
*/
protected $instances = [];
/**
* @var array
*/
protected $config;
/**
* @param array $config
*/
public function __construct(array $config)
{
$this->config = $config;
}
/**
* Returns a specific instance
*
* @param string $instance
*
* @return Supervisor
*/
public function get($instance)
{
if (isset($this->instances[$instance])) {
return $this->instances[$instance];
} elseif (!isset($this->config[$instance])) {
throw new \InvalidArgumentException(sprintf('Supervisor instance "%s" cannot be found', $instance));
}
$config = $this->config[$instance];
$transport = new StreamSocketTransport;
if (array_key_exists('username', $config) && array_key_exists('username', $config)) {
$transport->setHeader('Authorization', 'Basic '.base64_encode(sprintf('%s:%s', $config['username'], $config['password'])));
}
$client = new Client($config['url'], $transport);
$connector = new XmlRpc($client);
return $this->instances[$instance] = new Supervisor($connector);
}
/**
* Returns all Supervisor instances
*
* @return Superisor[]
*/
public function getAll()
{
foreach (array_keys($this->config) as $instance) {
$this->get($instance);
}
return $this->instances;
}
}