PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/sites/all/modules/contrib/civicrm/packages/PHP/Beautifier/Filter/ListClassFunction.filter.php

https://gitlab.com/virtualrealms/d7civicrm
PHP | 150 lines | 92 code | 0 blank | 58 comment | 11 complexity | 282ea5b3592b3aaf08061496da4dfb8f MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Create a list of functions and classes in the script
  5. *
  6. * PHP version 5
  7. *
  8. * LICENSE: This source file is subject to version 3.0 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. * @category PHP
  14. * @package PHP_Beautifier
  15. * @subpackage Filter
  16. * @author Claudio Bustos <cdx@users.sourceforge.com>
  17. * @copyright 2004-2006 Claudio Bustos
  18. * @link http://pear.php.net/package/PHP_Beautifier
  19. * @link http://beautifyphp.sourceforge.net
  20. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  21. * @version CVS: $Id:$
  22. */
  23. /**
  24. * Create a list of functions and classes in the script
  25. * By default, this Filter puts the list at the beggining of the script.
  26. * If you want it in another position, put a comment like that
  27. * <pre>
  28. * // Class and Function List
  29. * </pre>
  30. * The script lookup for the string 'Class and Function List' in a comment and replace the entire comment with the list
  31. * The settings are
  32. * - list_functions: List functions (0 or 1). Default:1
  33. * - list_classes: List classes (0 or 1). Default:1
  34. * @todo List functions inside classes as methods
  35. * @category PHP
  36. * @package PHP_Beautifier
  37. * @subpackage Filter
  38. * @author Claudio Bustos <cdx@users.sourceforge.com>
  39. * @copyright 2004-2006 Claudio Bustos
  40. * @link http://pear.php.net/package/PHP_Beautifier
  41. * @link http://beautifyphp.sourceforge.net
  42. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  43. * @version Release: 0.1.14
  44. */
  45. class PHP_Beautifier_Filter_ListClassFunction extends PHP_Beautifier_Filter
  46. {
  47. protected $aFilterTokenFunctions = array(
  48. T_CLASS => 't_class',
  49. T_FUNCTION => 't_function',
  50. T_COMMENT => 't_comment',
  51. T_OPEN_TAG => 't_open_tag'
  52. );
  53. private $aFunctions = array();
  54. private $aClasses = array();
  55. private $iComment;
  56. private $iOpenTag = null;
  57. protected $aSettings = array(
  58. 'list_functions' => true,
  59. 'list_classes' => true
  60. );
  61. protected $sDescription = 'Create a list of functions and classes in the script';
  62. private $aInclude = array(
  63. 'functions' => true,
  64. 'classes' => true
  65. );
  66. public function __construct(PHP_Beautifier $oBeaut, $aSettings = array())
  67. {
  68. parent::__construct($oBeaut, $aSettings);
  69. $this->addSettingDefinition('list_functions', 'bool', 'List Functions inside the file');
  70. $this->addSettingDefinition('list_classes', 'bool', 'List Classes inside the file');
  71. }
  72. function t_function($sTag)
  73. {
  74. if ($this->aInclude['functions']) {
  75. $sNext = $this->oBeaut->getNextTokenContent(1);
  76. if ($sNext == '&') {
  77. $sNext.= $this->oBeaut->getNextTokenContent(2);
  78. }
  79. array_push($this->aFunctions, $sNext);
  80. }
  81. return PHP_Beautifier_Filter::BYPASS;
  82. }
  83. function includeInList($sTag, $sValue)
  84. {
  85. $this->aInclude[$sTag] = $sValue;
  86. }
  87. function t_class($sTag)
  88. {
  89. if ($this->aInclude['classes']) {
  90. $sClassName = $this->oBeaut->getNextTokenContent(1);
  91. if ($this->oBeaut->isNextTokenConstant(T_EXTENDS, 2)) {
  92. $sClassName.= ' extends ' . $this->oBeaut->getNextTokenContent(3);
  93. }
  94. array_push($this->aClasses, $sClassName);
  95. }
  96. return PHP_Beautifier_Filter::BYPASS;
  97. }
  98. function t_doc_comment($sTag)
  99. {
  100. if (strpos($sTag, 'Class and Function List') !== FALSE) {
  101. $this->iComment = $this->oBeaut->iCount;
  102. }
  103. return PHP_Beautifier_Filter::BYPASS;
  104. }
  105. function t_open_tag($sTag)
  106. {
  107. if (is_null($this->iOpenTag)) {
  108. $this->iOpenTag = $this->oBeaut->iCount;
  109. }
  110. return PHP_Beautifier_Filter::BYPASS;
  111. }
  112. function postProcess()
  113. {
  114. $sNL = $this->oBeaut->sNewLine;
  115. $aOut = array(
  116. "/**",
  117. "* Class and Function List:"
  118. );
  119. if ($this->getSetting('list_functions')) {
  120. $aOut[] = "* Function list:";
  121. foreach($this->aFunctions as $sFunction) {
  122. $aOut[] = "* - " . $sFunction . "()";
  123. }
  124. }
  125. if ($this->getSetting('list_classes')) {
  126. $aOut[] = "* Classes list:";
  127. foreach($this->aClasses as $sClass) {
  128. $aOut[] = "* - " . $sClass;
  129. }
  130. }
  131. $aOut[] = "*/";
  132. if ($this->iComment) {
  133. // Determine the previous Indent
  134. $sComment = $this->oBeaut->getTokenAssocText($this->iComment);
  135. if (preg_match("/" . addcslashes($sNL, "\r\n") . "([ \t]+)/ms", $sComment, $aMatch)) {
  136. $sPrevio = $sNL . $aMatch[1];
  137. } else {
  138. $sPrevio = $sNL;
  139. }
  140. $sText = implode($sPrevio, $aOut) . $sNL;
  141. $this->oBeaut->replaceTokenAssoc($this->iComment, $sText);
  142. } else {
  143. $sPrevio = $sNL /*.str_repeat($this->oBeaut->sIndentChar, $this->oBeaut->iIndentNumber)*/;
  144. $sTag = trim($this->oBeaut->getTokenAssocText($this->iOpenTag)) . "\n";
  145. $sText = $sPrevio . implode($sPrevio, $aOut);
  146. $this->oBeaut->replaceTokenAssoc($this->iOpenTag, rtrim($sTag) . $sText . $sPrevio);
  147. }
  148. }
  149. }
  150. ?>