ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\Utils\PhpFunctionsScanner Class Reference
+ Inheritance diagram for Gettext\Utils\PhpFunctionsScanner:
+ Collaboration diagram for Gettext\Utils\PhpFunctionsScanner:

Public Member Functions

 enableCommentsExtraction ($tag='')
 Enable extracting comments that start with a tag (if $tag is empty all the comments will be extracted). More...
 
 disableCommentsExtraction ()
 Disable comments extraction. More...
 
 __construct ($code)
 Constructor. More...
 
 getFunctions ()
 {Scan and returns the functions and the arguments.
Returns
array
} More...
 
- Public Member Functions inherited from Gettext\Utils\FunctionsScanner
 getFunctions ()
 Scan and returns the functions and the arguments. More...
 
 saveGettextFunctions (array $functions, Translations $translations, $file='')
 Search for specific functions and create translations. More...
 

Protected Member Functions

 parsePhpComment ($value)
 

Protected Attributes

 $tokens
 
 $extractComments = false
 

Detailed Description

Definition at line 7 of file PhpFunctionsScanner.php.

Constructor & Destructor Documentation

◆ __construct()

Gettext\Utils\PhpFunctionsScanner::__construct (   $code)

Constructor.

Parameters
string$codeThe php code to scan

Definition at line 46 of file PhpFunctionsScanner.php.

47 {
48 $this->tokens = array_values(
49 array_filter(
50 token_get_all($code),
51 function ($token) {
52 return !is_array($token) || $token[0] !== T_WHITESPACE;
53 }
54 )
55 );
56 }
$code
Definition: example_050.php:99

References $code.

Member Function Documentation

◆ disableCommentsExtraction()

Gettext\Utils\PhpFunctionsScanner::disableCommentsExtraction ( )

Disable comments extraction.

Definition at line 36 of file PhpFunctionsScanner.php.

37 {
38 $this->extractComments = false;
39 }

◆ enableCommentsExtraction()

Gettext\Utils\PhpFunctionsScanner::enableCommentsExtraction (   $tag = '')

Enable extracting comments that start with a tag (if $tag is empty all the comments will be extracted).

Parameters
string$tag

Definition at line 28 of file PhpFunctionsScanner.php.

29 {
30 $this->extractComments = (string) $tag;
31 }
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35

References $tag.

◆ getFunctions()

Gettext\Utils\PhpFunctionsScanner::getFunctions ( )

{Scan and returns the functions and the arguments.

Returns
array
}

Reimplemented from Gettext\Utils\FunctionsScanner.

Definition at line 61 of file PhpFunctionsScanner.php.

62 {
63 $count = count($this->tokens);
64 $bufferFunctions = array();
65 /* @var ParsedFunction[] $bufferFunctions */
66 $functions = array();
67 /* @var ParsedFunction[] $functions */
68
69 for ($k = 0; $k < $count; ++$k) {
70 $value = $this->tokens[$k];
71
72 if (is_string($value)) {
73 if (isset($bufferFunctions[0])) {
74 switch ($value) {
75 case ',':
76 $bufferFunctions[0]->nextArgument();
77 break;
78 case ')':
79 $functions[] = array_shift($bufferFunctions)->close();
80 break;
81 case '.':
82 break;
83 default:
84 $bufferFunctions[0]->stopArgument();
85 break;
86 }
87 }
88 continue;
89 }
90
91 switch ($value[0]) {
92 case T_CONSTANT_ENCAPSED_STRING:
93 //add an argument to the current function
94 if (isset($bufferFunctions[0])) {
95 $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1]));
96 }
97 break;
98 case T_STRING:
99 if (isset($bufferFunctions[0])) {
100 $bufferFunctions[0]->stopArgument();
101 }
102 //new function found
103 for ($j = $k + 1; $j < $count; ++$j) {
104 $nextToken = $this->tokens[$j];
105 if (is_array($nextToken) && $nextToken[0] === T_COMMENT) {
106 continue;
107 }
108 if ($nextToken === '(') {
109 $newFunction = new ParsedFunction($value[1], $value[2]);
110 if ($k > 0 && is_array($this->tokens[$k - 1]) && $this->tokens[$k - 1][0] === T_COMMENT) {
111 $comment = $this->parsePhpComment($this->tokens[$k - 1][1]);
112 if ($comment !== null) {
113 $newFunction->addComment($comment);
114 }
115 }
116 array_unshift($bufferFunctions, $newFunction);
117 $k = $j;
118 }
119 break;
120 }
121 break;
122 case T_COMMENT:
123 if (isset($bufferFunctions[0])) {
124 $comment = $this->parsePhpComment($value[1]);
125 if ($comment !== null) {
126 $bufferFunctions[0]->addComment($comment);
127 }
128 }
129 break;
130 default:
131 if (isset($bufferFunctions[0])) {
132 $bufferFunctions[0]->stopArgument();
133 }
134 break;
135 }
136 }
137
138 return $functions;
139 }
$comment
Definition: buildRTE.php:83
static convertString($value)
Decodes a T_CONSTANT_ENCAPSED_STRING string.
Definition: PhpCode.php:72

References $comment, Gettext\Extractors\PhpCode\convertString(), and Gettext\Utils\PhpFunctionsScanner\parsePhpComment().

+ Here is the call graph for this function:

◆ parsePhpComment()

Gettext\Utils\PhpFunctionsScanner::parsePhpComment (   $value)
protected

Definition at line 141 of file PhpFunctionsScanner.php.

142 {
143 $result = null;
144 if ($this->extractComments !== false) {
145 if ($value[0] === '#') {
146 $value = substr($value, 1);
147 } elseif ($value[1] === '/') {
148 $value = substr($value, 2);
149 } else {
150 $value = substr($value, 2, -2);
151 }
152 $value = trim($value);
153 if ($value !== '' && ($this->extractComments === '' || strpos($value, $this->extractComments) === 0)) {
154 $result = $value;
155 }
156 }
157
158 return $result;
159 }
$result

References $result.

Referenced by Gettext\Utils\PhpFunctionsScanner\getFunctions().

+ Here is the caller graph for this function:

Field Documentation

◆ $extractComments

Gettext\Utils\PhpFunctionsScanner::$extractComments = false
protected

Definition at line 21 of file PhpFunctionsScanner.php.

◆ $tokens

Gettext\Utils\PhpFunctionsScanner::$tokens
protected

Definition at line 14 of file PhpFunctionsScanner.php.


The documentation for this class was generated from the following file: