/Extras/swxCI/system/application/controllers/amfphp/DiscoveryService.php
PHP | 158 lines | 130 code | 10 blank | 18 comment | 33 complexity | 54e36f5277fa2ebfeef882fd5fd18c50 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
- <?php
- include_once(AMFPHP_BASE . "shared/util/MethodTable.php");
- /**
- * A built-in amfphp service that allows introspection into services and their methods.
- * Remove from production servers
- */
- class DiscoveryService
- {
- /**
- * Get the list of services
- * @returns An array of array ready to be bound to a Tree
- */
- function getServices()
- {
- $this->_omit = array();
- $this->_path = dirname(dirname(realpath(__FILE__))) . '/';
- $services = $this->_listServices();
- //Now sort on key
- ksort($services);
- $out = array();
- foreach($services as $key => $val)
- {
- if($key == "zzz_default")
- {
- foreach($val as $key2 => $val2)
- {
- $out[] = array("label" => $val2[0], "data" => $val2[1]);
- }
- }
- else
- {
- $children = array();
- foreach($val as $key2 => $val2)
- {
- $children[] = array("label" => $val2[0], "data" => $val2[1]);
- }
- $out[] = array("label" => $key, "children" => $children, "open" => true);
- }
- }
- return $out;
- }
-
- /**
- * Describe a service and all its methods
- * @param $data An object containing 'label' and 'data' keys
- */
- function describeService($data)
- {
- $className = $data['label'];
- //Sanitize path
- $path = str_replace('..', '', $data['data']);
- //Generate the method table from this info
- $this->_path = dirname(dirname(realpath(__FILE__))) . DIRECTORY_SEPARATOR;
-
- $methodTable = MethodTable::create($this->_path . $path . $className . '.php', NULL, $classComment);
- return array($methodTable, $classComment);
- }
-
- function _listServices($dir = "", $suffix = "")
- {
- if($dir == "")
- {
- $dir = $this->_path;
- }
- $services = array();
- if(in_array($suffix, $this->_omit)){ return; }
- if ($handle = opendir($dir . $suffix))
- {
- while (false !== ($file = readdir($handle)))
- {
- chdir(dirname(__FILE__));
- if ($file != "." && $file != "..")
- {
- if(is_file($dir . $suffix . $file))
- {
- if($file == 'index.php')
- {
- continue;
- }
-
- if(strpos($file, '.methodTable') !== FALSE)
- {
- continue;
- }
- $index = strrpos($file, '.');
- $before = substr($file, 0, $index);
- $after = substr($file, $index + 1);
-
- if($after == 'php')
- {
- $loc = "zzz_default";
- if($suffix != "")
- {
- $loc = str_replace(DIRECTORY_SEPARATOR,'.', substr($suffix, 0, -1));
- }
-
- if($services[$loc] == NULL)
- {
- $services[$loc] = array();
- }
- $services[$loc][] = array($before, $suffix);
- //array_push($this->_classes, $before);
- }
-
- }
- elseif(is_dir($dir . $suffix . $file))
- {
- if ($file == '_idvr')
- {
- continue;
- }
-
- $insideDir = $this->_listServices($dir, $suffix . $file . DIRECTORY_SEPARATOR);
- if(is_array($insideDir))
- {
- $services = $services + $insideDir;
- }
- }
- }
- }
- }else{
- //echo("error");
- }
- closedir($handle);
- return $services;
- }
-
- function listTemplates()
- {
- $templates = array();
- if ($handle = opendir('templates'))
- {
- while (false !== ($file = readdir($handle)))
- {
- //chdir(dirname(__FILE__));
- if ($file != "." && $file != "..")
- {
- if(is_file('./templates/' . $file))
- {
- $index = strrpos($file, '.');
- $before = substr($file, 0, $index);
- $after = substr($file, $index + 1);
-
- if($after == 'php')
- {
- $templates[] = $before;
- }
- }
- }
- }
- }
- else
- {
- trigger_error("Could not open templates dir");
- }
- return $templates;
- }
- }