add image renderer
[phorkie.git] / src / phorkie / Tool / Manager.php
1 <?php
2 namespace phorkie;
3
4
5 class Tool_Manager
6 {
7     public function getSuitable(File $file)
8     {
9         $ext = $file->getExt();
10         $suitables = array();
11         foreach ($GLOBALS['phorkie']['tools'] as $class) {
12             if (array_search($ext, $class::$arSupportedExtensions) !== false) {
13                 $suitables[] = new Tool_Info($class);
14             }
15         }
16         return $suitables;
17     }
18
19     /**
20      * Returns the class name from a tool name
21      *
22      * @param string $name Full class name or short name without
23      *                     'phorkie\\Tool_' prefix
24      *
25      * @return string Class name or NULL if not found
26      */
27     public function getClass($name)
28     {
29         if (strpos($name, '\\') === false && strpos($name, '_') === false) {
30             return '\\phorkie\\Tool_' . $name;
31         }
32         return $name;
33     }
34
35     public function loadTool($name)
36     {
37         $class = $this->getClass($name);
38         if (!class_exists($class, true)) {
39             throw new Exception('Tool does not exist: ' . $class);
40         }
41         
42         return new $class();
43     }
44 }
45
46 ?>