1
0

service_functions.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreScripts Scripts
  7. * @{
  8. */
  9. $aPathInfo = pathinfo(__FILE__);
  10. require_once ($aPathInfo['dirname'] . '/../inc/header.inc.php');
  11. require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
  12. /**
  13. * Command line interface for generating a list of service functions
  14. */
  15. class BxDolServiceFunctionsCmd
  16. {
  17. protected $_sInputFile = '';
  18. public function main()
  19. {
  20. $a = getopt('hi:');
  21. if (isset($a['h']) || !$a)
  22. $this->finish(0, $this->getHelp());
  23. if (isset($a['i']))
  24. $this->_sInputFile = '/' == $a['i'][1] ? $a['i'] : BX_DIRECTORY_PATH_ROOT . $a['i'];
  25. if (!$this->_sInputFile || !file_exists($this->_sInputFile))
  26. $this->finish(1, 'Input old file not exist - ' . $this->_sInputFile);
  27. if (false === ($a = file($this->_sInputFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)))
  28. $this->finish(2, 'Input file read error - ' . $this->_sInputFile);
  29. $this->process($a);
  30. }
  31. protected function process($a)
  32. {
  33. $aGroups = array(
  34. // System functions
  35. 'BxDolCmts' => 'System',
  36. 'BxDolRequest' => 'System',
  37. 'BxBaseServiceAccount' => 'System',
  38. 'BxBaseServiceCategory' => 'System',
  39. 'BxBaseServiceConnections' => 'System',
  40. 'BxBaseServiceLogin' => 'System',
  41. 'BxBaseServiceMetatags' => 'System',
  42. 'BxBaseServiceProfiles' => 'System',
  43. 'BxBaseServices' => 'System',
  44. 'BxBaseTemplateServices' => 'System',
  45. 'BxBaseAclServices' => 'System',
  46. 'BxBaseCmtsServices' => 'System',
  47. 'BxBaseUploaderServices' => 'System',
  48. 'BxBaseImageServices' => 'System',
  49. 'BxBaseLanguagesServices' => 'System',
  50. 'BxBaseLiveUpdatesServices' => 'System',
  51. 'BxBasePaymentsServices' => 'System',
  52. // Functions in all content modules
  53. 'BxBaseModGeneralModule' => 'General content modules',
  54. // Functions in Groups based modules (Groups, Events)
  55. 'BxBaseModGroupsModule' => 'Groups based modules',
  56. // Functions in Notifocations based modules (Notofocations, Timeline)
  57. 'BxBaseModNotificationsModule' => 'Notifications based modules',
  58. // Functions in Payments based modules
  59. 'BxBaseModPaymentCart' => 'Payments based modules',
  60. 'BxBaseModPaymentDetails' => 'Payments based modules',
  61. 'BxBaseModPaymentModule' => 'Payments based modules',
  62. 'BxBaseModPaymentOrders' => 'Payments based modules',
  63. 'BxBaseModPaymentSubscriptions' => 'Payments based modules',
  64. // Functions in Profiles based modules (Persons, Organizations)
  65. 'BxBaseModProfileModule' => 'Profiles based modules',
  66. // Functions in Text based modules (Posts, Forums)
  67. 'BxBaseModTextModule' => 'Text based modules',
  68. // Studio functionality
  69. 'BxDolStudioInstallerUtils' => 'Studio related functionality',
  70. 'BxDolStudioModules' => 'Studio related functionality',
  71. 'BxBaseStudioDashboard' => 'Studio related functionality',
  72. 'BxBaseStudioDesignServices' => 'Studio related functionality',
  73. 'BxBaseStudioLauncher' => 'Studio related functionality',
  74. 'BxBaseStudioSettingsServices' => 'Studio related functionality',
  75. // Individual modules
  76. '*' => 'Individual modules',
  77. );
  78. $aGroupedArray = array();
  79. foreach ($a as $s) {
  80. if (!preg_match('/(.*):[\s\w]+function\s(.*)/', $s, $m)) {
  81. $this->finish(2, 'FAIL!!! - ' . $s);
  82. continue;
  83. }
  84. if (!($aPath = pathinfo(BX_DIRECTORY_PATH_ROOT . $m[1])))
  85. continue;
  86. $sClass = $aPath['filename'];
  87. $sFunc = $m[2];
  88. $sGroup = isset($aGroups[$sClass]) ? $aGroups[$sClass] : $aGroups['*'];
  89. $aGroupedArray[$sGroup][] = $sClass . '::' . $sFunc . "\n";
  90. }
  91. foreach ($aGroupedArray as $sGroup => $aLines) {
  92. echo "\n// $sGroup\n";
  93. foreach ($aLines as $s)
  94. echo "$s";
  95. }
  96. }
  97. protected function getHelp()
  98. {
  99. $n = 21;
  100. $s = "\nUsage: php service_functions.php [options]\n";
  101. $s .= str_pad("\t -h", $n) . "Print this help\n";
  102. $s .= str_pad("\t -i <input_file>", $n) . "Input file\n\n";
  103. $s .= "Input file can be generated form the following command output:\n";
  104. $s .= str_pad("\t grep -r 'function service' * | grep -v updates | grep -v upgrade | grep -v BxDol\.php | grep -v hosting_api | grep -v BxBaseModConnectModule | grep -v -i ^bin | grep -v '/vendor/' > scripts/service_functions.txt\n", $n);
  105. $s .= "\n";
  106. return $s;
  107. }
  108. protected function finish ($iCode, $sMsg = null, $bAddLn = true)
  109. {
  110. if (null !== $sMsg)
  111. echo $sMsg . ($bAddLn ? "\n" : '');
  112. exit($iCode);
  113. }
  114. }
  115. $o = new BxDolServiceFunctionsCmd();
  116. $o->main();
  117. /** @} */