blob: ca93b4a07319382f7f6adc3573eca01d85340cc6 (
plain)
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
|
<?php
namespace phorkie;
class Tool_Manager
{
public function getSuitable(File $file)
{
$ext = $file->getExt();
$suitables = array();
foreach ($GLOBALS['phorkie']['tools'] as $class => $arSetup) {
if (array_search($ext, $class::$arSupportedExtensions) !== false) {
$suitables[] = new Tool_Info($class);
}
}
return $suitables;
}
/**
* Returns the class name from a tool name
*
* @param string $name Full class name or short name without
* 'phorkie\\Tool_' prefix
*
* @return string Class name or NULL if not found
*/
public function getClass($name)
{
if (strpos($name, '\\') === false && strpos($name, '_') === false) {
return '\\phorkie\\Tool_' . $name;
}
return $name;
}
public function loadTool($name)
{
$class = $this->getClass($name);
if (!class_exists($class, true)) {
throw new Exception('Tool does not exist: ' . $class);
}
return new $class();
}
}
?>
|