# Source for file DiscoveryService.php

Documentation is available at DiscoveryService.php

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. }
43. /**
44. * Describe a service and all its methods
45. * @param $data An object containing 'label' and 'data' keys
46. */
47. function describeService($data)
48. {
49. $className = $data['label'];
50. //Sanitize path
51. $path = str_replace('..', '', $data['data']);
52. //Generate the method table from this info
53. $this->_path = dirname(dirname(realpath(__FILE__))) . DIRECTORY_SEPARATOR;
55. $methodTable = MethodTable::create($this->_path . $path . $className . '.php', NULL, $classComment);
56. return array($methodTable, $classComment);
57. }
59. function _listServices($dir = "", $suffix = "")
60. {
61. if($dir == "")
62. {
63. $dir = $this->_path;
64. }
65. $services = array();
66. if(in_array($suffix, $this->_omit)){ return; }
67. if ($handle = opendir($dir . $suffix))
68. {
69. while (false !== ($file = readdir($handle)))
70. {
71. chdir(dirname(__FILE__));
72. if ($file != "." && $file != "..")
73. {
74. if(is_file($dir . $suffix . $file))
75. {
76. if(strpos($file, '.methodTable') !== FALSE)
77. {
78. continue;
79. }
80. $index = strrpos($file, '.');
81. $before = substr($file, 0, $index);
82. $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. }
92. if($services[$loc] == NULL)
93. {
94. $services[$loc] = array();
95. }
96. $services[$loc][] = array($before, $suffix);
97. //array_push($this->_classes, $before);
98. }
100. }
101. elseif(is_dir($dir . $suffix . $file))
102. {
103. $insideDir = $this->_listServices($dir, $suffix . $file . DIRECTORY_SEPARATOR);
104. if(is_array($insideDir))
105. {
106. $services = $services + $insideDir;
107. }
108. }
109. }
110. }
111. }else{
112. //echo("error");
113. }
114. closedir($handle);
115. return $services;
116. }
118. function listTemplates()
119. {
120. $templates = array();
121. if ($handle = opendir('templates'))
122. {
123. while (false !== ($file = readdir($handle)))
124. {
125. //chdir(dirname(__FILE__));
126. if ($file != "." && $file != "..")
127. {
128. if(is_file('./templates/' . $file))
129. {
130. $index = strrpos($file, '.');
131. $before = substr($file, 0, $index);
132. $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. }

Documentation generated on Fri, 06 Jul 2007 19:54:48 +0100 by phpDocumentor 1.3.1