Guest User

Untitled

a guest
May 31st, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. <?php
  2.  
  3. class DH_ClassInfo
  4. {
  5. private $dir;
  6.  
  7. public function __construct($dirPath)
  8. {
  9. if(is_dir($dirPath))
  10. $this->dir = $dirPath;
  11. else
  12. throw new Exception($dirPath . " is not Directory or its not Readable.");
  13. }
  14.  
  15. public function getControllerClassFiles()
  16. {
  17. $files = scandir($this->dir);
  18. return array_filter($files, "filterClassFile");
  19. }
  20.  
  21. public function getControllerClassNames()
  22. {
  23. $files = $this->getControllerClassFiles();
  24. $names = array();
  25. $classNames = array();
  26. foreach($files as $file) {
  27. $data = file($this->dir.DIRECTORY_SEPARATOR.$file, FILE_IGNORE_NEW_LINES);
  28. foreach(array_filter($data, "filterClassName") as $key) {
  29. array_push($names, $key);
  30. }
  31. }
  32. foreach($names as $name) {
  33. $nameArray = split('[ ]+', $name);
  34. array_push($classNames, $nameArray[1]);
  35. }
  36. return $classNames;
  37. }
  38.  
  39. public function getActionNames()
  40. {
  41. $files = $this->getControllerClassFiles();
  42. $actionNames = array();
  43. foreach($files as $file) {
  44. $names = array();
  45. $data = file($this->dir.DIRECTORY_SEPARATOR.$file, FILE_IGNORE_NEW_LINES);
  46. foreach(array_filter($data, "filterActionFunction") as $key) {
  47. array_push($names, $key);
  48. }
  49. $className = $this->getControllerClassName($this->dir.DIRECTORY_SEPARATOR.$file);
  50. $actionNames[$className] = array();
  51. foreach($names as $name) {
  52. $nameArray = split('[ ]+|\(', $name);
  53. $data = array_filter($nameArray, "filterActionName");
  54. array_push($actionNames[$className], current($data));
  55. }
  56. }
  57. return $actionNames;
  58. }
  59.  
  60. private function getControllerClassName($file)
  61. {
  62. $names = array();
  63. $classNames = array();
  64. $data = file($file, FILE_IGNORE_NEW_LINES);
  65. foreach(array_filter($data, "filterClassName") as $key) {
  66. array_push($names, $key);
  67. }
  68. foreach($names as $name) {
  69. $nameArray = split('[ ]+', $name);
  70. array_push($classNames, $nameArray[1]);
  71. }
  72. if(empty($classNames)) {
  73. return;
  74. } else {
  75. return $classNames[0];
  76. }
  77. }
  78. }
  79.  
  80. function filterClassFile($var)
  81. {
  82. preg_match('/.*Controller.php$/', $var, $matches);
  83. return $matches;
  84. }
  85.  
  86. function filterActionFunction($var)
  87. {
  88. preg_match('/.*function.*Action[\s]*\(/', $var, $matches);
  89. return $matches;
  90. }
  91.  
  92. function filterClassName($var)
  93. {
  94. preg_match('/^[\s]*class[\s]+[A-Za-z_0-9]+/', $var, $matches);
  95. return $matches;
  96. }
  97.  
  98. function filterActionName($var)
  99. {
  100. preg_match('/.*Action$/', $var, $matches);
  101. return $matches;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment