/
Manager.php
42 lines (36 loc) · 1.1 KB
/
Manager.php
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
<?php
namespace Respect\Daemon;
use Respect\Daemon\Exceptions\DirectoryNotFoundException;
use \UnexpectedValueException;
class Manager
{
public static function getInstance($adapter = null)
{
if (!is_null($adapter)) {
$adapterName = '\Respect\Daemon\Adapters\\' . $adapter;
return new $adapterName;
} else {
$adapters = static::getAvailableAdapters();
$adapterName = '\Respect\Daemon\Adapters\\' . array_unshift($adapters);
return new $adapterName;
}
return false;
}
public static function getAvailableAdapters()
{
$adapters = array();
foreach (new DirectoryIterator(__DIR__ . '/Adapter') as $a) {
require_once $a->getPath();
$adapterName = $a->getBasename('.php');
$runs = call_user_func(
array(
'\Respect\Daemon\Adapters\\' . $adapterName,
'runsOnEnvironment'
)
);
if ($runs)
$adapters[] = $adapterName;
}
return $adapters;
}
}