PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Extras/swxCI/system/application/controllers/amfphp/DiscoveryService.php

http://swx-format.googlecode.com/
PHP | 158 lines | 130 code | 10 blank | 18 comment | 33 complexity | 54e36f5277fa2ebfeef882fd5fd18c50 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. include_once(AMFPHP_BASE . "shared/util/MethodTable.php");
  3. /**
  4. * A built-in amfphp service that allows introspection into services and their methods.
  5. * Remove from production servers
  6. */
  7. class DiscoveryService
  8. {
  9. /**
  10. * Get the list of services
  11. * @returns An array of array ready to be bound to a Tree
  12. */
  13. function getServices()
  14. {
  15. $this->_omit = array();
  16. $this->_path = dirname(dirname(realpath(__FILE__))) . '/';
  17. $services = $this->_listServices();
  18. //Now sort on key
  19. ksort($services);
  20. $out = array();
  21. foreach($services as $key => $val)
  22. {
  23. if($key == "zzz_default")
  24. {
  25. foreach($val as $key2 => $val2)
  26. {
  27. $out[] = array("label" => $val2[0], "data" => $val2[1]);
  28. }
  29. }
  30. else
  31. {
  32. $children = array();
  33. foreach($val as $key2 => $val2)
  34. {
  35. $children[] = array("label" => $val2[0], "data" => $val2[1]);
  36. }
  37. $out[] = array("label" => $key, "children" => $children, "open" => true);
  38. }
  39. }
  40. return $out;
  41. }
  42. /**
  43. * Describe a service and all its methods
  44. * @param $data An object containing 'label' and 'data' keys
  45. */
  46. function describeService($data)
  47. {
  48. $className = $data['label'];
  49. //Sanitize path
  50. $path = str_replace('..', '', $data['data']);
  51. //Generate the method table from this info
  52. $this->_path = dirname(dirname(realpath(__FILE__))) . DIRECTORY_SEPARATOR;
  53. $methodTable = MethodTable::create($this->_path . $path . $className . '.php', NULL, $classComment);
  54. return array($methodTable, $classComment);
  55. }
  56. function _listServices($dir = "", $suffix = "")
  57. {
  58. if($dir == "")
  59. {
  60. $dir = $this->_path;
  61. }
  62. $services = array();
  63. if(in_array($suffix, $this->_omit)){ return; }
  64. if ($handle = opendir($dir . $suffix))
  65. {
  66. while (false !== ($file = readdir($handle)))
  67. {
  68. chdir(dirname(__FILE__));
  69. if ($file != "." && $file != "..")
  70. {
  71. if(is_file($dir . $suffix . $file))
  72. {
  73. if($file == 'index.php')
  74. {
  75. continue;
  76. }
  77. if(strpos($file, '.methodTable') !== FALSE)
  78. {
  79. continue;
  80. }
  81. $index = strrpos($file, '.');
  82. $before = substr($file, 0, $index);
  83. $after = substr($file, $index + 1);
  84. if($after == 'php')
  85. {
  86. $loc = "zzz_default";
  87. if($suffix != "")
  88. {
  89. $loc = str_replace(DIRECTORY_SEPARATOR,'.', substr($suffix, 0, -1));
  90. }
  91. if($services[$loc] == NULL)
  92. {
  93. $services[$loc] = array();
  94. }
  95. $services[$loc][] = array($before, $suffix);
  96. //array_push($this->_classes, $before);
  97. }
  98. }
  99. elseif(is_dir($dir . $suffix . $file))
  100. {
  101. if ($file == '_idvr')
  102. {
  103. continue;
  104. }
  105. $insideDir = $this->_listServices($dir, $suffix . $file . DIRECTORY_SEPARATOR);
  106. if(is_array($insideDir))
  107. {
  108. $services = $services + $insideDir;
  109. }
  110. }
  111. }
  112. }
  113. }else{
  114. //echo("error");
  115. }
  116. closedir($handle);
  117. return $services;
  118. }
  119. function listTemplates()
  120. {
  121. $templates = array();
  122. if ($handle = opendir('templates'))
  123. {
  124. while (false !== ($file = readdir($handle)))
  125. {
  126. //chdir(dirname(__FILE__));
  127. if ($file != "." && $file != "..")
  128. {
  129. if(is_file('./templates/' . $file))
  130. {
  131. $index = strrpos($file, '.');
  132. $before = substr($file, 0, $index);
  133. $after = substr($file, $index + 1);
  134. if($after == 'php')
  135. {
  136. $templates[] = $before;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. else
  143. {
  144. trigger_error("Could not open templates dir");
  145. }
  146. return $templates;
  147. }
  148. }